7 PostScriptBegin
= 190 # Set driver state to PostScript
8 PostScriptEnd
= 191 # Restore QuickDraw state
9 PostScriptHandle
= 192 # PostScript data referenced in handle
11 CHUNK_SIZE
= 0x8000 # max size of PicComment
14 """embed text as plain PostScript in print job."""
15 handle
= Res
.Resource('')
16 Qd
.PicComment(PostScriptBegin
, 0, handle
)
18 chunk
= text
[:CHUNK_SIZE
]
19 text
= text
[CHUNK_SIZE
:]
21 Qd
.PicComment(PostScriptHandle
, len(chunk
), handle
)
23 Qd
.PicComment(PostScriptEnd
, 0, handle
)
25 # create a new print record
26 printrecord
= Printing
.NewTPrintRecord()
31 # initialize print record with default values
32 Printing
.PrintDefault(printrecord
)
34 # page setup, ok is 0 when user cancelled
35 ok
= Printing
.PrStlDialog(printrecord
)
37 raise KeyboardInterrupt
38 # at this stage, you should save the print record in your document for later
41 # print job dialog, ok is 0 when user cancelled
42 ok
= Printing
.PrJobDialog(printrecord
)
44 raise KeyboardInterrupt
47 port
= Printing
.PrOpenDoc(printrecord
)
48 # port is the Printer's GrafPort, it is also the current port, so no need to Qd.SetPort(port)
50 # start printing a page
51 # XXX should really look up what pages to print by
52 # inspecting the print record.
53 Printing
.PrOpenPage(port
, None)
55 # use QuickDraw like in any other GrafPort
56 Qd
.FrameRect((10, 250, 100, 500))
57 Qd
.FrameRect((10, 510, 100, 600))
60 Qd
.TextFont(Fm
.GetFNum("Helvetica"))
61 Qd
.DrawString("It rreally works!")
64 Qd
.DrawString("(and now for a little PostScript...)")
66 # example PostScript code
68 % the coordinate system is the quickdraw one, which is flipped
69 % compared to the default PS one. That means text will appear
70 % flipped when used directly from PostScript.
71 % As an example we start by defining a custom scalefont operator
73 /myscalefont{[exch 0 0 2 index neg 0 0]makefont}def
76 0 30 lineto 10000 30 lineto
77 10000 0 lineto closepath fill
79 5 25 moveto /Courier findfont 20 myscalefont setfont
80 (Printed with PostScript!) show
81 2 setlinewidth [10 10 5 10] 0 setdash 5 5 moveto 400 0 rlineto stroke
83 # embed the PostScript code in the print job
86 # when done with the page
87 Printing
.PrClosePage(port
)
89 # when done with the document
90 Printing
.PrCloseDoc(port
)