DynaPDF Manual - Page 234

Previous Page 233 Index Next Page 235

Function Reference

Page 234 of 770

pdfSetFillColorEx(pdf, color, 3);

pdfRectangle(pdf, 50.0, 150.0, 200.0, 100.0, fmFill);

pdfEndPage(pdf);

Example 2:

In this example we want to define a DeviceN color space that contains 2 spot colors and the process

color yellow. The alternate color space for the spot colors is DeviceCMYK in this example and the

process colorant is defined in this color space too.

The tint transformation function for such a color space must be able to compute one color from

arbitrary combinations of these three colors. So, we need essentially a blend function expressed in

PostScript syntax.

The definition of a blend function is not difficult but long because the entire code is stack based.

However, let us first keep in mind what we need to do. We have already three values on the stack

when the function is executed. These are the tint values which were passed to the DeviceN color

space. We need to multiply the tint values with the four components of the alternate color

representations of all three channels and finally we need to combine these three colors so that we get

the resulting output color. This sounds difficult, because a lot of multiplications and additions are

required to produce the wished result, but you'll see it's easier as it looks like.

The used colors in the DeviceN color space are defined as follows:

Colorant name

CMYK representation

PANTONE 345 CVC (coated)

{0.38, 0.00, 0.34, 0.0} or { 97,

0,

87, 0}

PANTONE 293 CVC (coated)

{1.00, 0.56, 0.00, 0.0} or {255, 143,

0, 0}

Yellow

{0.00, 0.00, 1.00, 0.0} or {

0,

0, 255, 0}

The CMYK color values of the spot colors are taken from the color picker of Adobe's Photoshop.

Now, we have all information we need to create the PostScript calculator function.

The multiplication of the color channels with the tint values must be done for all three colors

included in the color space. Because these are repeating operations we can easily develop a function

that creates the necessary code for us:

// The following function creates the PostScript code to multiply the tint

// values with the components of the CMYK color representation. 0 and 1

// color values are optimized to more efficient code.

UI32 AddOperator(char* Dest, float Value, UI32 Index)

{

if (Value == 0.0f)

// Zero is always zero

return sprintf(Dest, "0 ");

else if (Value == 1.0f) // 1.0 represents the tint value

return sprintf(Dest, "%d index ", Index);

else // Other color values must be multiplied with the tint value

return sprintf(Dest, "%d index %.2f mul ", Index, Value);

}

Previous topic: Example 1:

Next topic: CreateExtGState