DynaPDF Manual - Page 260

Previous Page 259   Index   Next Page 261

Function Reference
Page 260 of 839
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 almost finished. 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"};
const char* pcs[] = {"Cyan", "Magenta", "Yellow", "Black"};
float colors[] =
{
// The CMYK color values are taken from Adobe's Photoshop
0.38f, 0.00f, 0.34f, 0.0f, // Definition of the first spot color
1.00f, 0.56f, 0.00f, 0.0f, // Definition of the second spot color
0.00f, 0.00f, 1.00f, 0.0f
// Definition of the process color
};
pdfSetOnErrorProc(PDF, NULL, PDFError);
if (!pdfCreateNewPDF(PDF, "test.pdf")) return -2;
pdfAppend(PDF);
// We need to create the PostScript calculator function first because
// it is a required parameter of pdfCreateDeviceNColorSpace().
CreateBlendFunction(psFunc, colors, sizeof(colors) / sizeof(float));
// Create the DeviceN color space
cs = pdfCreateDeviceNColorSpace(
PDF,
// Instance pointer
cls,
// The colorants array
3,
// Number of colorants in the array
psFunc,
// Our PostScript tint transformation function
esDeviceCMYK, // Alternate color space
-1);
// No handle is required for a device color space
if (cs < 0) return cs;
// We create also Separation color spaces for the spot colors and add
// these color spaces as an attribute to the DeviceN color space:
UI32 separations[2];
// First spot color
separations [0] = pdfCreateSeparationCS(
PDF,
cls[0],
esDeviceCMYK,
-1,
PDF_CMYK(97, 0, 87, 0)); // 0.38 * 255, 0 * 255, 0.34 * 255, 0 * 255
 

Previous topic: Example 1:, Example 2:

Next topic: CreateDPartRoot