New clear Objective-C

I have come here to chew bubblegum and write code ... and I'm all out of bubblegum.

Saturday, July 07, 2007

CGShading and PDF 1.4

The document Core Graphics Reference Collection states "Core Graphics technologies include Quartz 2D, the drawing API that implements a superset of the PDF 1.4 specification", which is in turn defined here: PDF Reference 1.4.

The public API for CGShading in Quartz 2D allows you to create two types of shadings, axial via CGShadingCreateAxial and radial via CGShadingCreateRadial.

Page 232 of the PDF 1.4 reference begins the discussion on shading where it goes on to define seven types of shadings, function based, axial, radial, free-form Gouraud-shaded triangle mesh, lattice-form Gouraud-shaded triangle mesh, Coons patch mesh and Tensor-product patch mesh.

Well, so much for Quartz 2D being a "superset" of PDF 1.4.

The public API for CGFunction allows you to create one type of function, a sampled function.

The PDF 1.4 specification defines 4 types of functions, sampled, exponential interpolation, stitching, and PostScript calculator.

At this point one could argue that the CGFunction API allows you to create any of the function types because you can code up the function however you want. While this does work in an interactive environment, once you print you are exclusively in the realm of sampled functions as the PDF generation can not magically turn your C function into a PDF function definition other than sampled.

The sampling rate of the CGFunction appears to be fixed, CoreGraphics calls your sampling function 4097 times regardless of how big or small the gradient is. 10 pixel wide gradient? 4097 times, 100,000 pixel wide gradient? 4097 times. In practice this isn't a big deal, the sampling rate is high enough to disguise any error, although far too high for most small gradients.

While the lack of the more sophisticated shading types seems reasonable for most applications, it does make it disingenuous to say that Quartz 2D is a superset of PDF 1.4.

The thing that disturbs me the most is that the CGFunction API uses a callback, the first three and definitely most popular function types are very easily represented without callbacks. One could argue that in order to do the PostScript calculator function type this would be most easily done with callbacks - but it is turned into a sampled function anyway, so what would be the point. The PDF function specifications are right there in the PDF specification, I don't know why Apple didn't use them.

2 Comments:

At 7/08/2007 4:36 PM, Centrosphere said...

"...the PDF generation can not magically turn your C function into a PDF function definition other than sampled."

Do rewrite your PDF generation so that it can.

As you have already stated, the sample rate is fully adequate for the task.

 
At 7/12/2007 10:39 PM, cjwl said...

So much for the "Unified print and imaging model"

Porting to OS X

 

Post a Comment

<< Home