Blame


1 b855148c 2004-05-16 devnull %
2 b855148c 2004-05-16 devnull % Procedures that let you print any number of pages on each sheet of paper. It's
3 b855148c 2004-05-16 devnull % far from perfect and won't handle everything (eg. it's not recursive), but should
4 b855148c 2004-05-16 devnull % be good enough for now. Assumes the default page coordinate system has been set
5 b855148c 2004-05-16 devnull % up before setupforms is called. lastpage makes certain the last page is printed,
6 b855148c 2004-05-16 devnull % and should be called immediately after the %%Trailer comment.
7 b855148c 2004-05-16 devnull %
8 b855148c 2004-05-16 devnull % Three lines of code needed for page image clipping have been commented out for
9 b855148c 2004-05-16 devnull % now. It works, but can really slow things down on some versions of PostScript.
10 b855148c 2004-05-16 devnull % Uncomment them if you want to clip pages.
11 b855148c 2004-05-16 devnull %
12 b855148c 2004-05-16 devnull
13 b855148c 2004-05-16 devnull /setupforms {
14 b855148c 2004-05-16 devnull /formsperpage exch def
15 b855148c 2004-05-16 devnull
16 b855148c 2004-05-16 devnull /currentform 0 def
17 b855148c 2004-05-16 devnull /slop 5 def
18 b855148c 2004-05-16 devnull /min {2 copy gt {exch} if pop} def
19 b855148c 2004-05-16 devnull
20 b855148c 2004-05-16 devnull %
21 b855148c 2004-05-16 devnull % Save the current environment so the real showpage can be restored when we're all
22 b855148c 2004-05-16 devnull % done. Occasionally helps when a banner page is included with the job.
23 b855148c 2004-05-16 devnull %
24 b855148c 2004-05-16 devnull
25 b855148c 2004-05-16 devnull /saveobj save def
26 b855148c 2004-05-16 devnull
27 b855148c 2004-05-16 devnull %
28 b855148c 2004-05-16 devnull % Number of rows and columns we'll need - may exchange them later.
29 b855148c 2004-05-16 devnull %
30 b855148c 2004-05-16 devnull
31 b855148c 2004-05-16 devnull /columns formsperpage sqrt ceiling cvi def
32 b855148c 2004-05-16 devnull /rows formsperpage columns div ceiling cvi def
33 b855148c 2004-05-16 devnull
34 b855148c 2004-05-16 devnull %
35 b855148c 2004-05-16 devnull % Slop leaves a little room around the edge so page images can be outlined and have
36 b855148c 2004-05-16 devnull % the borders show up. Distance is in default coordinates, so we need to figure out
37 b855148c 2004-05-16 devnull % how it maps into user coordinates.
38 b855148c 2004-05-16 devnull %
39 b855148c 2004-05-16 devnull
40 b855148c 2004-05-16 devnull 6 array defaultmatrix
41 b855148c 2004-05-16 devnull 6 array currentmatrix
42 b855148c 2004-05-16 devnull 6 array invertmatrix
43 b855148c 2004-05-16 devnull 6 array concatmatrix
44 b855148c 2004-05-16 devnull /tempmatrix exch def
45 b855148c 2004-05-16 devnull
46 b855148c 2004-05-16 devnull 0 slop tempmatrix dtransform dup mul exch dup mul add sqrt
47 b855148c 2004-05-16 devnull /slop exch def
48 b855148c 2004-05-16 devnull
49 b855148c 2004-05-16 devnull %
50 b855148c 2004-05-16 devnull % Determine how big the image area is, using the clipping path bounding box minus
51 b855148c 2004-05-16 devnull % a little and leave the coordinates of the lower left corner of the clipping path
52 b855148c 2004-05-16 devnull % on the stack. Also temporarily set the size of each page (ie. formheight and
53 b855148c 2004-05-16 devnull % formwidth) from the clipping path - just in case old software uses this stuff.
54 b855148c 2004-05-16 devnull % Only works for coordinate systems that have been rotated by a multiple of 90
55 b855148c 2004-05-16 devnull % degrees.
56 b855148c 2004-05-16 devnull %
57 b855148c 2004-05-16 devnull
58 b855148c 2004-05-16 devnull newpath clippath pathbbox
59 b855148c 2004-05-16 devnull 2 index sub dup /formheight exch def slop 2 mul sub /pageheight exch def
60 b855148c 2004-05-16 devnull 2 index sub dup /formwidth exch def slop 2 mul sub /pagewidth exch def
61 b855148c 2004-05-16 devnull
62 b855148c 2004-05-16 devnull %
63 b855148c 2004-05-16 devnull % New translators all store the size of each page in default coordinates in the
64 b855148c 2004-05-16 devnull % pagebbox array and it can be different than the size determined by the clipping
65 b855148c 2004-05-16 devnull % path. If we can find pagebbox use it to set the real dimensions of each page.
66 b855148c 2004-05-16 devnull % Leaves the coordinates of the lower left corner on the stack, (either from
67 b855148c 2004-05-16 devnull % pagebbox or clippath) so four numbers are there when we're done.
68 b855148c 2004-05-16 devnull %
69 b855148c 2004-05-16 devnull
70 b855148c 2004-05-16 devnull userdict /gotpagebbox known userdict /pagebbox known and {
71 b855148c 2004-05-16 devnull newpath
72 b855148c 2004-05-16 devnull pagebbox 0 get pagebbox 1 get tempmatrix transform moveto
73 b855148c 2004-05-16 devnull pagebbox 0 get pagebbox 3 get tempmatrix transform lineto
74 b855148c 2004-05-16 devnull pagebbox 2 get pagebbox 3 get tempmatrix transform lineto
75 b855148c 2004-05-16 devnull pagebbox 2 get pagebbox 1 get tempmatrix transform lineto
76 b855148c 2004-05-16 devnull closepath pathbbox
77 b855148c 2004-05-16 devnull 2 index sub /formheight exch def
78 b855148c 2004-05-16 devnull 2 index sub /formwidth exch def
79 b855148c 2004-05-16 devnull } {2 copy} ifelse
80 b855148c 2004-05-16 devnull
81 b855148c 2004-05-16 devnull %
82 b855148c 2004-05-16 devnull % Top two numbers are the displacement from the job's origin to the lower left
83 b855148c 2004-05-16 devnull % corner of each page image when we finish setting up the new coordinate system.
84 b855148c 2004-05-16 devnull %
85 b855148c 2004-05-16 devnull
86 b855148c 2004-05-16 devnull /ycorner exch def
87 b855148c 2004-05-16 devnull /xcorner exch def
88 b855148c 2004-05-16 devnull
89 b855148c 2004-05-16 devnull %
90 b855148c 2004-05-16 devnull % The two numbers left on the stack are the coordinates of the lower left corner
91 b855148c 2004-05-16 devnull % of the clipping path. Go there and then up a bit so page images can be outlined.
92 b855148c 2004-05-16 devnull %
93 b855148c 2004-05-16 devnull
94 b855148c 2004-05-16 devnull translate
95 b855148c 2004-05-16 devnull slop slop translate
96 b855148c 2004-05-16 devnull
97 b855148c 2004-05-16 devnull %
98 b855148c 2004-05-16 devnull % If the page is wider than high we may be able to do better if we exchange rows
99 b855148c 2004-05-16 devnull % and columns. Won't make a difference in the current orientation or if rows and
100 b855148c 2004-05-16 devnull % columns are the same.
101 b855148c 2004-05-16 devnull %
102 b855148c 2004-05-16 devnull
103 b855148c 2004-05-16 devnull pagewidth pageheight gt {
104 b855148c 2004-05-16 devnull rows columns /rows exch def /columns exch def
105 b855148c 2004-05-16 devnull } if
106 b855148c 2004-05-16 devnull
107 b855148c 2004-05-16 devnull %
108 b855148c 2004-05-16 devnull % Find the orientation and scaling that makes things as large as possible. More
109 b855148c 2004-05-16 devnull % than what's really needed. First calculation essentially finds the minimum of
110 b855148c 2004-05-16 devnull % 1/rows and 1/columns.
111 b855148c 2004-05-16 devnull %
112 b855148c 2004-05-16 devnull
113 b855148c 2004-05-16 devnull pagewidth formwidth columns mul div pageheight formheight rows mul div min
114 b855148c 2004-05-16 devnull pageheight formwidth columns mul div pagewidth formheight rows mul div min
115 b855148c 2004-05-16 devnull
116 b855148c 2004-05-16 devnull 2 copy lt {
117 b855148c 2004-05-16 devnull rotation 1 eq {
118 b855148c 2004-05-16 devnull landscape {
119 b855148c 2004-05-16 devnull 0 pageheight translate
120 b855148c 2004-05-16 devnull -90 rotate
121 b855148c 2004-05-16 devnull }{
122 b855148c 2004-05-16 devnull pagewidth 0 translate
123 b855148c 2004-05-16 devnull 90 rotate
124 b855148c 2004-05-16 devnull } ifelse
125 b855148c 2004-05-16 devnull }{
126 b855148c 2004-05-16 devnull landscape {
127 b855148c 2004-05-16 devnull pagewidth 0 translate
128 b855148c 2004-05-16 devnull 90 rotate
129 b855148c 2004-05-16 devnull }{
130 b855148c 2004-05-16 devnull 0 pageheight translate
131 b855148c 2004-05-16 devnull -90 rotate
132 b855148c 2004-05-16 devnull } ifelse
133 b855148c 2004-05-16 devnull } ifelse
134 b855148c 2004-05-16 devnull pagewidth pageheight /pagewidth exch def /pageheight exch def
135 b855148c 2004-05-16 devnull exch
136 b855148c 2004-05-16 devnull } if
137 b855148c 2004-05-16 devnull
138 b855148c 2004-05-16 devnull %
139 b855148c 2004-05-16 devnull % Second number from the top is the best choice. Scale so everything will fit on
140 b855148c 2004-05-16 devnull % the current page, go back to the original origin, and then get ready for the
141 b855148c 2004-05-16 devnull % first page - which goes in the upper left corner.
142 b855148c 2004-05-16 devnull %
143 b855148c 2004-05-16 devnull
144 b855148c 2004-05-16 devnull pop dup dup scale
145 b855148c 2004-05-16 devnull xcorner neg ycorner neg translate
146 b855148c 2004-05-16 devnull 0 rows 1 sub formheight mul translate
147 b855148c 2004-05-16 devnull
148 b855148c 2004-05-16 devnull %
149 b855148c 2004-05-16 devnull % Try to center everything on the page - scaling we used is on top of the stack.
150 b855148c 2004-05-16 devnull %
151 b855148c 2004-05-16 devnull
152 b855148c 2004-05-16 devnull dup pagewidth exch div formwidth columns mul sub 2 div
153 b855148c 2004-05-16 devnull exch pageheight exch div formheight rows mul sub 2 div translate
154 b855148c 2004-05-16 devnull
155 b855148c 2004-05-16 devnull %
156 b855148c 2004-05-16 devnull % Redefine showpage.
157 b855148c 2004-05-16 devnull %
158 b855148c 2004-05-16 devnull
159 b855148c 2004-05-16 devnull /!PreForms~showpage~ /showpage load def % save current showpage
160 b855148c 2004-05-16 devnull
161 b855148c 2004-05-16 devnull /showpage {
162 b855148c 2004-05-16 devnull saveobj restore
163 b855148c 2004-05-16 devnull % initclip
164 b855148c 2004-05-16 devnull formsperpage 1 gt {
165 b855148c 2004-05-16 devnull gsave .1 setlinewidth outlineform stroke grestore
166 b855148c 2004-05-16 devnull } if
167 b855148c 2004-05-16 devnull formwidth 0 translate
168 b855148c 2004-05-16 devnull /currentform currentform 1 add def
169 b855148c 2004-05-16 devnull currentform columns mod 0 eq {
170 b855148c 2004-05-16 devnull columns formwidth mul neg formheight neg translate
171 b855148c 2004-05-16 devnull } if
172 b855148c 2004-05-16 devnull currentform formsperpage mod 0 eq {
173 b855148c 2004-05-16 devnull gsave !PreForms~showpage~ grestore
174 b855148c 2004-05-16 devnull currentform columns mod formwidth mul neg
175 b855148c 2004-05-16 devnull formsperpage columns idiv formheight mul translate
176 b855148c 2004-05-16 devnull /currentform 0 def
177 b855148c 2004-05-16 devnull } if
178 b855148c 2004-05-16 devnull % outlineform clip newpath
179 b855148c 2004-05-16 devnull /saveobj save def
180 b855148c 2004-05-16 devnull } bind def
181 b855148c 2004-05-16 devnull
182 b855148c 2004-05-16 devnull /outlineform {
183 b855148c 2004-05-16 devnull newpath
184 b855148c 2004-05-16 devnull xcorner ycorner moveto
185 b855148c 2004-05-16 devnull formwidth 0 rlineto
186 b855148c 2004-05-16 devnull 0 formheight rlineto
187 b855148c 2004-05-16 devnull formwidth neg 0 rlineto
188 b855148c 2004-05-16 devnull closepath
189 b855148c 2004-05-16 devnull } bind def
190 b855148c 2004-05-16 devnull
191 b855148c 2004-05-16 devnull /lastpage {
192 b855148c 2004-05-16 devnull formsperpage 1 gt {
193 b855148c 2004-05-16 devnull currentform 0 ne {
194 b855148c 2004-05-16 devnull /saveobj save def
195 b855148c 2004-05-16 devnull 0 1 formsperpage currentform sub formsperpage mod {
196 b855148c 2004-05-16 devnull pop showpage
197 b855148c 2004-05-16 devnull } for
198 b855148c 2004-05-16 devnull saveobj restore
199 b855148c 2004-05-16 devnull } if
200 b855148c 2004-05-16 devnull saveobj restore
201 b855148c 2004-05-16 devnull saveobj restore
202 b855148c 2004-05-16 devnull } if
203 b855148c 2004-05-16 devnull } def
204 b855148c 2004-05-16 devnull
205 b855148c 2004-05-16 devnull %
206 b855148c 2004-05-16 devnull % Clip the first page image and save the environment we just set up, including
207 b855148c 2004-05-16 devnull % the redefined showpage.
208 b855148c 2004-05-16 devnull %
209 b855148c 2004-05-16 devnull
210 b855148c 2004-05-16 devnull % outlineform clip
211 b855148c 2004-05-16 devnull newpath
212 b855148c 2004-05-16 devnull /saveobj save def
213 b855148c 2004-05-16 devnull } def