Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Imaging With QuickDraw /
Appendix B - Using Picture Comments for Printing


Using PostScript Picture Comments

You can access the PostScript language directly using the PostScriptHandle 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 the PostScriptBegin picture comment. The driver uses the PostScript save and restore operators to preserve the state of the PostScript interpreter. When the driver receives the PostScriptEnd 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 the dataHandle parameter of the PicComment procedure. The driver performs no preprocessing or error checking on this code. The handle contains text with no length byte or word; use the dataSize 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 use PostScriptBegin and PostScriptEnd around any PostScriptHandle 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 the PostScriptHandle picture comment to the PostScript printer driver. DoPostScriptLine should be called only between PostScriptBegin and PostScriptEnd picture comments, as shown in the application-defined procedure DoPostScriptComments.

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.

For more information on the PostScript language, see the PostScript Language Reference Manual, second edition, available from Addison-Wesley.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996