DynaPDF Manual - Page 234

Previous Page 233   Index   Next Page 235

Function Reference
Page 234 of 777
For more information on these operators, see Appendix B of the PostScript Language Reference,
Third Edition. The operand syntax for PostScript calculator functions follows PDF conventions
rather than PostScript conventions. The entire code defining the function is enclosed in braces { }.
Braces also delimit expressions that are executed conditionally by the if and ifelse operators:
boolean { expression } if
boolean { expression1 } { expression2 } ifelse
This construct is purely syntactic; unlike in PostScript, no "procedure objects" are involved.
When executing the function, the application pushes first the tint values of the setcolor operator or
the corresponding image components on the stack. The function is then executed and the remaining
components on the stack are adjusted to the valid input range of the alternate color space and then
passed to it.
Note also that the remaining components on the stack must match the number of input colorants of
the alternate color space. It is an error to leave more or less components on the stack than supported
by the alternate color space.
Example 1:
In this example we create a DeviceN color space that contains the process colorants Cyan, Magenta,
and Yellow. The alternate color space is of course DeviceCMYK. The definition of the PostScript
calculator function is very simple in this example because we need to add the missing Black
component only. The array cls includes also the Black component here because we need the colorant
names later to add the definition of the process components to the DeviceN color space:
const char* cls[] = {"Cyan", "Magenta", "Yellow", "Black"};
const char ps[] = "{0}"; // Just add the missing Black component
// Note that the Black component is not part of the DeviceN color space
SI32 cs = pdfCreateDeviceNColorSpace(pdf, cls, 3, ps, esDeviceCMYK, -1);
// Optional but strongly recommended: Add the defintion of the process
// colorants to the DeviceN color space.
pdfAddDeviceNProcessColorants(pdf, cls, 4, esDeviceCMYK, -1);
// Draw a rectangle in the alternate DeviceCMYK color space
pdfSetFillColorSpace(pdf, csDeviceCMYK);
pdfSetFillColor(pdf, PDF_CMYK(135, 65, 160, 0));
pdfRectangle(pdf, 50.0, 50.0, 200.0, 100.0, fmFill);
// Now we use the DeviceN color space. The colors of both rectangles must
// be identically. If you see a difference, then disable the output
// preview in Adobe's Acrobat, since the color is converted into the
// simulation profile otherwise...
pdfSetExtColorSpace(pdf, cs);
BYTE color[] = {135, 65, 160};

Previous topic: Process colorant attributes, How to create the PostScript Calculator Function?

Next topic: Example 2: