Important: The information in this document is obsolete and should not be used for new development.
Using PostScript Picture Comments
You can access the PostScript language directly using thePostScriptHandle
picture comment, and so bypass QuickDraw entirely. When you send PostScript code directly to the printer driver, it sends your code directly to the printer with no preprocessing and no error checking.
- Note
- These picture comments affect the state of the PostScript drawing environment and can have such effects as printing blank pages. Also, many PostScript printer drivers do not use the same version of PostScript and produce different outputs with the same commands; you should test your code on as many PostScript printers as possible. In all cases, use the PostScript picture comments with extreme caution.
Calling PostScript Routines Directly
Your application can tell the printer driver to disable all QuickDraw drawing routines by using thePostScriptBegin
picture comment. The driver uses the PostScriptsave
andrestore
operators to preserve the state of the PostScript interpreter. When the driver receives thePostScriptEnd
picture comment, it reenables QuickDraw drawing routines.You send PostScript code to the driver via the
PostScriptHandle
picture comment by including a handle to the PostScript code in thedataHandle
parameter of thePicComment
procedure. The driver performs no preprocessing or error checking on this code. The handle contains text with no length byte or word; use thedataSize
parameter to convey the length of the PostScript code. (As with all picture comments, the handle you pass belongs to you, and you must dispose of it when you're finished with it.) You indicate the end of the PostScript commands with a carriage return (ASCII $0D). You must usePostScriptBegin
andPostScriptEnd
around anyPostScriptHandle
comments; otherwise, the PostScript driver will not properly save and restore the PostScript drawing environment.Listing B-11 gives an example of an application-defined procedure called
DoPostScriptLine
. The procedure is used to transmit a string of PostScript code through thePostScriptHandle
picture comment to the PostScript printer driver.DoPostScriptLine
should be called only betweenPostScriptBegin
andPostScriptEnd
picture comments, as shown in the application-defined procedureDoPostScriptComments
.Listing B-11 Sending PostScript code directly to the printer
PROCEDURE DoPostScriptLine(s: Str255); VAR h: Handle; BEGIN h := NewHandle(256); IF h = NIL THEN DebugStr('NewHandle failed'); BlockMove(@s[1], h^, Length(s)); PicComment(PostScriptHandle, Length(s), h); h^^ := 13; PicComment(PostScriptHandle, 1, h); {add a carriage return} DisposeHandle(h); END; PROCEDURE DoPostScriptComments; BEGIN {first, the simple example} PicComment(PostScriptBegin,0,NIL); DoPostScriptLine('100 100 moveto 0 100 rlineto 100 0 rlineto '); DoPostScriptLine('0 -100 rlineto -100 0 rlineto'); DoPostScriptLine('stroke'); MoveTo(30,30); DrawString('This text does not appear on PostScript printers.'); PicComment(PostScriptEnd,0,NIL); END;Optimizing PostScript Printing
Although your printing code should be device-independent, you can optimize it for a PostScript printer. However, you cannot be sure that the current printer is a PostScript printer, so you may need to create two versions of the same drawing code: one for a PostScript printer and one for a QuickDraw printer, as described previously in this appendix.For printing to a PostScript printer, you'll need to observe the following limitations:
Although the PostScript LaserWriter printer is relatively fast, there are some techniques an application can use to ensure its maximum performance.
- Regions aren't supported; try to simulate them with polygons or bitmaps.
- Clipping regions should be limited to rectangles. PostScript clips nonsquare patterns to squares.
- The
Invert
data type, part of the QuickDrawGrafVerb
data type, is not supported by the PostScript LaserWriter printer driver.- The PostScript LaserWriter driver does not support all Boolean transfer modes. It supports the
srcCopy
,srcOr
,srcBic
,notSrcCopy
, andnotSrcBic
modes for bitmaps and text. For all other objects drawn with QuickDraw, the PostScript LaserWriter driver supports only thesrcCopy
mode.- There can be a small difference in glyph widths between fonts rendered on the screen and on the printer. Only the endpoints of text strings are the same.
- Only PostScript Level 2 supports color patterns that use colors other than red, green, blue, cyan, yellow, magenta, white, and black.
- The printer may print some large patterns at half size or smaller sizes, depending on its resolution.
- Polygons and smoothed polygons that result in the creation of paths larger than the limit of the PostScript printer (typically 1500 or 3000, depending on the version of PostScript) result in a PostScript error.
For more information on the PostScript language, see the PostScript Language Reference Manual, second edition, available from Addison-Wesley.
- Printing patterns takes time, because the bitmap for the pattern has to be built. The black-and-white patterns, and some of the gray patterns, have been optimized to use the PostScript grayscales.
- Use the
TextBegin
picture comment for text alignment. In the cases of flush left, flush right, or centered alignment, only the left, right, or center points are accurate, respectively; in the case of fully justified text, both the left and right endpoints are accurate.- If you want to position each glyph independently, use the
LineLayoutOff
andStringBegin
picture comments. If you are trying to position glyphs and the driver is trying to position glyphs too, there is conflict, and printing takes much longer than necessary.