DynaPDF Manual - Page 235

Previous Page 234   Index   Next Page 236

Function Reference
Page 235 of 770
// Note that this function does not allocate memory. The string must be
// long enough to hold the resulting PostScript code. The function can
// be used to create the blend function for DeviceN color spaces with up
// to 32 color channels. The alternate color space must be DeviceCMYK or
// an ICCBased color space whose base color space is in turn DeviceCMYK.
// Since the alternate color space must be DeviceCMYK, NumColorants is
// always a multiple of 4!
void CreateBlendFunction(
char* Dest,
// Destination string buffer
float* Colorants,
// Array of color values
UI32 NumColorants) // Must be a multiple of 4!
{
UI32 i, j, len = 1;
UI32 numColors = NumColorants / 4;
UI32
index = numColors - 1;
Dest[0] = '{'; // The PostScript code must be enclosed in braces
for (i = 0; i < 4; i++, index++)
{
for (j = 0; j < NumColorants; j += 4)
{
// Create code to multiply the tint values with the color values
len += AddOperator(Dest + len, Colorants[i+j], index);
}
// Add the resulting components. No range check is required...
for (j = 0; j < numColors - 1; j++)
len += sprintf(Dest + len, "add ");
}
// We are nearly finish. Place the tint values on top of the stack
len += sprintf(Dest + len, "%d 4 roll", index +1);
// Remove the tint values from the stack
for (j = 0; j < numColors; j++)
len += sprintf(Dest + len, " pop");
strcpy(Dest + len, "}"); // Finish the code with a brace
}
Now we have a simple function that creates the required PostScript code for us. The usage is as
follows:
// This is our error callback function.
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode,
const char* ErrMessage, SI32 ErrType)
{
printf("%s\n", ErrMessage);
return 0;
}
SI32 TestDeviceNColorSpace(const PPDF* PDF)
{
SI32 cs;
char psFunc[512]; // Buffer that holds the PostScript code
const char* cls[] = {"PANTONE 345 CVC", "PANTONE 293 CVC", "Yellow"};
 

Previous topic: Example 2:

Next topic: CreateExtGState