CD_PS - PostScript Driver (cdps.h)
This drivers allows generating a PostScript file. This format was created to be a high-quality graphics language for printers and is currently supported by several printers. If your printer supports PostScript, you can send the file generated by the driver directly to the printer port. Usually, the filename has an extension .PS or .EPS. The driver generates level-2 PostScript, therefore some PostScript viewers might present errors. The format's copyrights are property of Adobe Systems.
Use
The file is created and opened by calling function cdCreateCanvas(CD_PS, Data), in which Data contains the filename and canvas dimensions. This function opens the file and writes its header. Then, other functions in the CD library can be called as usual. The Data parameter string has the following format:
"filename -p[paper] -w[width] -h[height] -l[left] -r[right] -b[bottom] -t[top] -s[resolution] [-e] [-g] [-o] [-1] d[margin]" or in C
"%s -p%d -w%g -h%g -l%g -r%g -b%g -t%g -s%d -e -o -1 -g -d%g"The filename must be inside double quotes (") if it has spaces. Any amount of such canvases may exist simultaneously. It is important to note that a call to function cdKillCanvas is required to close the file properly.
Paper Size - The default paper size is A4. It is possible to change it by using one of the predefined sizes - CD_A0, CD_A1, CD_A2, CD_A3, CD_A4, CD_A5, CD_LETTER and CD_LEGAL - with parameter "-p". It is also possible to define a paper in a particular size by using parameters "-w" e "-h". Values are provided in millimeters.
Width (mm) | Length (mm) | |
---|---|---|
A0 | 841 | 1187 |
A1 | 594 | 841 |
A2 | 420 | 594 |
A3 | 297 | 420 |
A4 | 210 | 297 |
A5 | 148 | 210 |
Letter | 216 | 279 |
Legal | 216 | 356 |
Margins - The margins are controlled by parameters "-l" "-r" "-t" and "-b" (left, right, top, bottom). Values are provided in millimeters. Default margins are 25.4 mm to all parameters. You can draw only inside the margins.
Resolution - Resolution is used to convert values from millimeters to pixels (the same as points, but the number of points is per inch - DPI). Use parameter "-s" to configure the resolution. The default value is 300 DPI.
Orientation - The page can be oriented as portrait or landscape. The default value is portrait, but when the parameter "-o" is used, the horizontal and vertical values are switched.
EPS - The PostScript file can be in an Encapsulated PostScript format. For such, simply specify the parameter "-e". It is useful for other applications to import the PostScript file. You can define the margins of the bounding box by means of parameter "-d", in millimeters.
Debug - Parameter "-g" adds a series of comments to the PS file, making the beginning and end of a command from the CD library explicit. It is useful only for those who understand PostScript and wish to identify a problem. It considerably increases the file size.
Level 1 - Parameter "-1" forces the driver to generate a level-1 PostScript. In this case, pattern, stipple and hatch are not supported.
Pages - Use function cdFlush to change to a new page. The previous page will not be changed.
Behavior of Functions
Control
- cdPlay: does nothing, returns CD_ERROR.
- cdFlush: changes to a new page, preserving the previous one. Does nothing in EPS mode.
- cdClear: does nothing.
Coordinate System & Clipping
- cdGetCanvasSize: returns the page's size within the margins (drawing area).
- cdUpdateYAxis: does nothing.
- Complex Regions: not supported.
Attributes
- cdBackground does nothing, returns CD_WHITE.
- cdBackOpacity: does nothing, returns CD_TRANSPARENT.
- cdWriteMode: does nothing, returns CD_REPLACE.
- cdFontDim: is simulated.
- cdNativeFont: selects a PostScript font, given its name and size ("fontname size" or, in C style, "%s %d").
- cdTextSize: is simulated.
- cdHatch: is always opaque (to be implemented).
- cdStipple: is always opaque (to be implemented).
- cdTextAlignment: Baseline is the same as South.
- cdFont: see the font mapping table for the equivalence used to map CD fonts into PS fonts:
CD Fonts | PS Fonts |
---|---|
CD_SYSTEM | Courier |
CD_COURIER | Courier |
CD_TIMES_ROMAN | Times |
CD_HELVETICA | Helvetica |
Colors
- cdGetColorPlanes: returns 24.
- cdPalette: does nothing.
Client Images
- cdGetImageRGB: does nothing.
- cdPutImageMap: stores an RGB image in the file (to be implemented).
- cdPutImageRGBA: alpha is ignored (to be implemented).
Primitives
Server Images
- All functions do nothing.
WC
- Implemented directly in the driver.
Exclusive Attributes
- "POLYHOLE": defines the index of a vertex where there is a hole in a closed polygon. It will affect the next cdEnd. Can be called several times between cdBegin and cdEnd to define holes. The value passed must be a string containing an integer ("%d"). If the value of the attribute passed is NULL, all holes will no longer be considered. When consulted returns the current number of holes ("%d"). It can have a maximum of 500 holes.
- "CMD": saves a string directly to the file. Allows adding PostScript commands to the file generated by the CD library. (set only)
- "ROTATE": allows the usage of 1 angle and 1 coordinate (x, y), that define a global rotation transformation centered in the specified coordinate. Use 1 real and 2 integer values inside a string ("%g %d %d" = angle x y).