Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3243086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:23:29+00:00 2026-05-17T18:23:29+00:00

I have objects containing Quartz-2D references (describing colors, fill patterns, gradients and shadows) in

  • 0

I have objects containing Quartz-2D references (describing colors, fill patterns, gradients and shadows) in Cocoa. I would like to implement the NSCoding protocol in my objects and thus need to serialize those opaque Quartz-2D structures.

Possible solutions might be:

  • Define a set of properties in my objects that allow to setup the data structures from scratch whenever they are needed. Those can then be serialized easily. Example: Store four floats for red, green, blue, and alpha, then use CGColorCreate. Disadvantage: Duplication of information, thus potential consistency and (so far minor) space consumption issues. I would need to write property setters manually that recreate the Quartz structure whenever a component changes. That would bloat my code substantially.

  • Read out the properties using Quartz functions. Example: Use CGColorGetComponents for colors. Disadvantage: It seems to work for colors. But there are no equivalent functions for other structures, so I don’t see how this could work for things like gradients, shadings, shadows etc.

  • Read out the properties directly from the raw, opaque structures. Disadvantage: As the documentation says, the structures are supposed to be opaque. So in case something changes under the hood, my code will break. (Apple certainly would not have provided a function like CGColorGetComponents if that was supposed to be done.) Furthermore, things like the CGFunctionRef inside a CGShadingRef would really be asking for trouble.

What is the best practice for serializing Quartz structures?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:23:29+00:00Added an answer on May 17, 2026 at 6:23 pm

    The answer pretty much varies from one class to the next:

    • CGImage: Use CGImageDestination to make a TIFF file of it. (Equivalent to NSImage’s TIFFRepresentation method.)
    • CGPath: Write an applier function you can use to describe the path’s elements as, say, PostScript code. Write a simple interpreter to go the other direction.
    • CGColorSpace: You can export the ICC representation.
    • CGColor: As you described, but don’t forget to include the color space.
    • CGLayer: Convoluted: Make a bitmap context, draw the layer into it, and dump an image of the context, then serialize that.
    • CGFont: The name should be enough for most applications. If you’re being really fancy (i.e., using the variations feature), you’ll want to include the font’s variations dictionary. You’ll have to maintain your knowledge of the font size separately, since CGFont doesn’t have one and CGContext doesn’t let you get the one you set in it.
    • CGPDFDocument: From a quick look, it looks like CGPDFObjects are all immutable, so you’d just archive the original PDF data or the URL you got it from.
    • CGGradient, CGPattern, CGShading, and most other classes: Yup, you’re screwed. You’ll just need to maintain all of the information you created the object with separately.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have div containing a list of flash objects. The list is long so
I have a list of objects, each containing an Id, Code and Description. I
So I have a list of objects containing a name and number bound to
TextField objects have a built in context menu containing items which target cut, copy,
Say I have an arbitrary number of collections, each containing objects of the same
I'm completely puzzled here. I have a list of objects each containing a location.
I have a object built through a factory containing my parameters read from the
I have a GridView where one column is bound to an object property containing
I have two objects, let's call them Input and Output Input has properties Input_ID
I have a bunch of objects in a flat structure. These objects have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.