New PS/PDF backend: first attempt at generating the index
[platform/upstream/nasm.git] / doc / head.ps
1 % $Id$
2 %
3 % PostScript header for NASM documentation
4 %
5
6 % Avoid barfing on old PS implementations
7 /pdfmark where
8 {pop} {userdict /pdfmark /cleartomark load put} ifelse
9 /setpagedevice where
10 {pop} {userdict /setpagedevice /pop load put} ifelse
11
12 % Useful definition
13 /space 32 def
14
15 %
16 % This asks the PostScript interpreter for the proper size paper
17 %
18 /setpagesize {
19   1 dict dup /PageSize [pagewidth pageheight] put setpagedevice
20 } def
21
22 %
23 % Code to handle links
24 %
25 /min { 2 copy gt { exch } if pop } def
26 /max { 2 copy lt { exch } if pop } def
27
28 /lkbegun 0 def
29 /lktype null def
30 /lkury 0 def
31 /lkurx 0 def
32 /lklly 0 def
33 /lkllx 0 def
34 /lkxmarg 1 def  % Extra space for link in x dir
35 /lkymarg 1 def  % Extra space for link in y dir
36 /lktarget () def
37
38 % target type --
39 /linkbegin {
40   userdict begin
41     /lkbegun 1 def
42     /lktype exch def
43     /lktarget exch def
44   end
45 } def
46
47 % target --
48 /linkbegindest {
49   /Dest linkbegin
50 } def
51
52 % uristring --
53 /linkbeginuri {
54   /URI linkbegin
55 } def
56
57 % pageno --
58 /linkbeginpage {
59   /Page linkbegin
60 } def
61
62 % string spacepadding --
63 /linkshow {
64   userdict begin
65     /lspad exch def /lss exch def
66     lkbegun 0 ne {
67       gsave lss true charpath flattenpath pathbbox grestore
68       lkbegun 1 eq {
69         /lkury exch def
70         lss spacecount lspad mul add /lkurx exch def
71         /lklly exch def
72         /lkllx exch def
73         /lkbegun 2 def
74       } {
75         lkury max /lkury exch def
76         lss spacecount lspad mul add lkurx max /lkurx exch def
77         lklly min /lklly exch def
78         lkllx min /lkllx exch def
79       } ifelse
80     } if
81     lspad 0 space lss widthshow
82   end
83 } def
84
85 % --
86 /linkend {
87   userdict begin
88     [ lktype /Dest eq {
89         /Dest lktarget
90       } {
91         lktype /URI eq {
92           /Action
93           % << .. >> would be languagelevel 2 :(
94           2 dict dup /Subtype /URI put dup /URI lktarget put
95         } {
96            /Dest lktarget
97 %          /Page lktarget /View [ /XYZ 0 pageheight null ]
98         } ifelse
99       } ifelse
100       /Border [0 0 0]
101       /Rect [ lkllx lkxmarg sub
102               lklly lkymarg sub
103               lkurx lkxmarg add
104               lkury lkymarg add ]
105       /Subtype /Link
106       /ANN pdfmark
107     /lkbegun 0 def
108   end
109 } def
110
111 % targetname --
112 /linkdest {
113   [ /Dest 3 -1 roll
114     /View [ /XYZ currentpoint null ]
115     /DEST pdfmark
116 } def
117
118 % A "fontset" is an array of fonts; a "stream" is an array of strings
119 % and numbers or procedures:
120 % [ 0 (Foo) ( ) (mani) ( ) 1 (padme) 0 ( ) (hum.) ]
121 % A number choses a font from the current fontset.
122 % A procedure is invoked as-is when printing the stream.
123 %
124 % When printing justified, an equal amount of space is added in
125 % between each string.
126
127 % string -- spacecount
128 % Count space characters in a string
129 /spacecount {
130   0 exch {
131     space eq { 1 add } if
132   } forall
133 } def
134
135 % stream fontset -- spacecount width
136 % Get the width of a stream in the given fontset, and the
137 % number of space characters in the stream
138 /streamwidth {
139   gsave
140     6 dict begin
141       /f exch def
142       /w 0 def
143       /s 0 def
144       f 0 get setfont
145       /integertype {
146         f exch get setfont
147       } def
148       /stringtype {
149         dup stringwidth pop w add /w exch def
150         spacecount s add /s exch def
151       } def
152       /arraytype { pop } def
153       % The input stream is on the top of the stack now
154       {
155         dup type exec
156       } forall
157       s w
158     end
159   grestore
160 } def
161
162 % stream fontset spacer --
163 % Show the stream in the given fontset, but add a certain amount
164 % of space to each space character
165 /showstreamspc {
166   5 dict begin
167     /spc exch def
168     /f exch def
169     f 0 get setfont
170     /integertype {
171       f exch get setfont
172     } def
173     /stringtype {
174       spc linkshow
175     } def
176     /arraytype {
177       exec
178     } def
179     % Now stream is on the top of the stack
180     {
181       dup type exec
182     } forall
183   end
184 } def
185
186 % stream fontset --
187 % Show the stream in the given fontset, with no extra spacing
188 /showstream {
189   0 showstreamspc
190 } def
191
192 % stream fontset totalspace --
193 % Show the stream justified to fit into a certain number of pixels
194 /showstreamjust {
195   userdict begin
196     /ts exch def /fs exch def /st exch def
197       st fs
198         st fs streamwidth ts exch sub exch
199         dup 0 gt { div } { pop } ifelse
200       showstreamspc
201     end
202 } def
203
204 /bullmarg lmarg bulladj add def
205 /lwidth pagewidth lmarg sub rmarg sub def
206 /bwidth lwidth bulladj sub def
207
208 %
209 % The various paragraph types
210 % The number at the end indicates start (1) of para, end (2) of para
211 %
212 /chapline {
213         currentpoint exch pop 10 sub lmarg exch moveto
214         0 setlinecap 3 setlinewidth
215         lwidth 0 rlineto stroke
216 } def
217
218 /chap0 { lmarg exch moveto cfont lwidth showstreamjust } def
219 /chap1 { lmarg exch moveto cfont lwidth showstreamjust } def
220 /chap2 { lmarg exch moveto cfont showstream chapline } def
221 /chap3 { lmarg exch moveto cfont showstream chapline } def
222
223 /appn0 {chap0} def
224 /appn1 {chap1} def
225 /appn2 {chap2} def
226 /appn3 {chap3} def
227
228 % lbl ypos fontset -- ypos
229 /headlbl {
230   3 -1 roll [exch (  )] exch % ypos strm fontset
231   2 copy % ypos strm fontset strm fontset
232   streamwidth % ypos strm fontset spccount width
233   lmarg exch sub % ypos strm fontset spccount xpos
234   4 index % ypos strm fontset spccount xpos ypos
235   moveto % ypos strm fontset spccount
236   pop % ypos strm fontset spccount
237   showstream % ypos
238 } def
239
240 /head0 { lmarg exch moveto hfont lwidth showstreamjust } def
241 /head1 { hfont headlbl lmarg exch moveto hfont lwidth showstreamjust } def
242 /head2 { lmarg exch moveto hfont showstream } def
243 /head3 { hfont headlbl lmarg exch moveto hfont showstream } def
244
245 /subh0 { lmarg exch moveto sfont lwidth showstreamjust } def
246 /subh1 { sfont headlbl lmarg exch moveto sfont lwidth showstreamjust } def
247 /subh2 { lmarg exch moveto sfont showstream } def
248 /subh3 { sfont headlbl lmarg exch moveto sfont showstream } def
249
250 /norm0 { lmarg exch moveto tfont lwidth showstreamjust } def
251 /norm1 { lmarg exch moveto tfont lwidth showstreamjust } def
252 /norm2 { lmarg exch moveto tfont showstream } def
253 /norm3 { lmarg exch moveto tfont showstream } def
254
255 /code0 { lmarg exch moveto tfont showstream } def
256 /code1 { lmarg exch moveto tfont showstream } def
257 /code2 { lmarg exch moveto tfont showstream } def
258 /code3 { lmarg exch moveto tfont showstream } def
259
260 /bull0 { bullmarg exch moveto tfont bwidth showstreamjust } def
261 /bull1 { dup lmarg exch moveto [(\267)] tfont showstream
262          bullmarg exch moveto tfont bwidth showstreamjust } def
263 /bull2 { bullmarg exch moveto tfont showstream } def
264 /bull3 { dup lmarg exch moveto [(\267)] tfont showstream
265          bullmarg exch moveto tfont showstream } def
266
267 /tocw0 lwidth tocpnz sub def
268 /tocw1 tocw0 tocind sub def
269 /tocw2 tocw1 tocind sub def
270
271 /tocx0 lmarg def
272 /tocx1 tocx0 tocind add def
273 /tocx2 tocx1 tocind add def
274
275 /tocpn {
276   tfont0 setfont
277   3 dict begin
278     /s exch def
279     /x s stringwidth pop pagewidth rmarg sub exch sub def
280     currentpoint /y exch def
281     lmarg sub tocdots div ceiling tocdots mul lmarg add
282     tocdots x {
283       y moveto (.) 0 linkshow
284     } for
285     x y moveto s 0 linkshow
286   end
287   linkend
288 } def
289
290 /toc00 { tocx0 exch moveto 0 rmoveto tfont showstream } def
291 /toc01 { tocx0 exch moveto
292          linkbegindest tfont0 setfont 0 linkshow tfont showstream } def
293 /toc02 { tocx0 exch moveto 3 1 roll
294          0 rmoveto tfont showstream tocpn } def
295 /toc03 { tocx0 exch moveto 4 1 roll
296          linkbegindest tfont0 setfont 0 linkshow tfont showstream tocpn } def
297
298 /toc10 { tocx1 exch moveto 0 rmoveto tfont showstream } def
299 /toc11 { tocx1 exch moveto
300          linkbegindest tfont0 setfont 0 linkshow tfont showstream } def
301 /toc12 { tocx1 exch moveto 3 1 roll
302          0 rmoveto tfont showstream tocpn } def
303 /toc13 { tocx1 exch moveto 4 1 roll
304          linkbegindest tfont0 setfont 0 linkshow tfont showstream tocpn } def
305
306 /toc20 { tocx2 exch moveto 0 rmoveto tfont showstream } def
307 /toc21 { tocx2 exch moveto
308          linkbegindest tfont0 setfont 0 linkshow tfont showstream } def
309 /toc22 { tocx2 exch moveto 3 1 roll
310          0 rmoveto tfont showstream tocpn } def
311 /toc23 { tocx2 exch moveto 4 1 roll
312          linkbegindest tfont0 setfont 0 linkshow tfont showstream tocpn } def
313
314 % Spacing between index columns
315 /indexcolumn pagewidth lmarg sub rmarg sub idxgutter add idxcolumns div def
316 % Width of an individual index column
317 /indexcolwid indexcolumn idxgutter sub def
318
319 /idx03 {
320   2 dict begin
321     indexcolumn mul lmarg add
322     /x exch def /y exch def x y moveto
323     exch tfont showstream
324     dup tfont streamwidth
325     x indexcolwid add exch sub exch pop y moveto
326     tfont showstream
327   end
328 } def
329 /idx00 {idx03} def
330 /idx01 {idx03} def
331 /idx02 {idx03} def
332
333 %
334 % Page numbers
335 %
336 /pagey botmarg pymarg sub def
337 /pagel lmarg plmarg sub def
338 /pager pagewidth rmarg sub prmarg add def
339
340 /pageeven { pagel pagey moveto sfont0 setfont show } def
341 /pageodd  { sfont0 setfont dup stringwidth pop pager exch sub
342             pagey moveto show } def
343
344 %
345 % Functions invoked during parsing
346 %
347 /xa { linkdest } def
348 /pa { 0 pageheight moveto linkdest } def
349 /xl { linkbegindest } def
350 /wl { linkbeginuri } def
351 /pl { linkbeginpage } def
352 /el { linkend } def
353
354 %
355 % PDF viewer options
356 %
357 [/PageMode /UseOutlines /DOCVIEW pdfmark        % Display bookmarks
358