1*32a712daSGarrett D'Amore /* $Id: term_ps.c,v 1.54 2011/10/16 12:20:34 schwarze Exp $ */
2*32a712daSGarrett D'Amore /*
3*32a712daSGarrett D'Amore * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*32a712daSGarrett D'Amore *
5*32a712daSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any
6*32a712daSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above
7*32a712daSGarrett D'Amore * copyright notice and this permission notice appear in all copies.
8*32a712daSGarrett D'Amore *
9*32a712daSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*32a712daSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*32a712daSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*32a712daSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*32a712daSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*32a712daSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*32a712daSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*32a712daSGarrett D'Amore */
17*32a712daSGarrett D'Amore #ifdef HAVE_CONFIG_H
18*32a712daSGarrett D'Amore #include "config.h"
19*32a712daSGarrett D'Amore #endif
20*32a712daSGarrett D'Amore
21*32a712daSGarrett D'Amore #include <sys/types.h>
22*32a712daSGarrett D'Amore
23*32a712daSGarrett D'Amore #include <assert.h>
24*32a712daSGarrett D'Amore #include <stdarg.h>
25*32a712daSGarrett D'Amore #include <stdint.h>
26*32a712daSGarrett D'Amore #include <stdio.h>
27*32a712daSGarrett D'Amore #include <stdlib.h>
28*32a712daSGarrett D'Amore #include <string.h>
29*32a712daSGarrett D'Amore #include <time.h>
30*32a712daSGarrett D'Amore #include <unistd.h>
31*32a712daSGarrett D'Amore
32*32a712daSGarrett D'Amore #include "mandoc.h"
33*32a712daSGarrett D'Amore #include "out.h"
34*32a712daSGarrett D'Amore #include "main.h"
35*32a712daSGarrett D'Amore #include "term.h"
36*32a712daSGarrett D'Amore
37*32a712daSGarrett D'Amore /* These work the buffer used by the header and footer. */
38*32a712daSGarrett D'Amore #define PS_BUFSLOP 128
39*32a712daSGarrett D'Amore
40*32a712daSGarrett D'Amore /* Convert PostScript point "x" to an AFM unit. */
41*32a712daSGarrett D'Amore #define PNT2AFM(p, x) /* LINTED */ \
42*32a712daSGarrett D'Amore (size_t)((double)(x) * (1000.0 / (double)(p)->ps->scale))
43*32a712daSGarrett D'Amore
44*32a712daSGarrett D'Amore /* Convert an AFM unit "x" to a PostScript points */
45*32a712daSGarrett D'Amore #define AFM2PNT(p, x) /* LINTED */ \
46*32a712daSGarrett D'Amore ((double)(x) / (1000.0 / (double)(p)->ps->scale))
47*32a712daSGarrett D'Amore
48*32a712daSGarrett D'Amore struct glyph {
49*32a712daSGarrett D'Amore unsigned short wx; /* WX in AFM */
50*32a712daSGarrett D'Amore };
51*32a712daSGarrett D'Amore
52*32a712daSGarrett D'Amore struct font {
53*32a712daSGarrett D'Amore const char *name; /* FontName in AFM */
54*32a712daSGarrett D'Amore #define MAXCHAR 95 /* total characters we can handle */
55*32a712daSGarrett D'Amore struct glyph gly[MAXCHAR]; /* glyph metrics */
56*32a712daSGarrett D'Amore };
57*32a712daSGarrett D'Amore
58*32a712daSGarrett D'Amore struct termp_ps {
59*32a712daSGarrett D'Amore int flags;
60*32a712daSGarrett D'Amore #define PS_INLINE (1 << 0) /* we're in a word */
61*32a712daSGarrett D'Amore #define PS_MARGINS (1 << 1) /* we're in the margins */
62*32a712daSGarrett D'Amore #define PS_NEWPAGE (1 << 2) /* new page, no words yet */
63*32a712daSGarrett D'Amore size_t pscol; /* visible column (AFM units) */
64*32a712daSGarrett D'Amore size_t psrow; /* visible row (AFM units) */
65*32a712daSGarrett D'Amore char *psmarg; /* margin buf */
66*32a712daSGarrett D'Amore size_t psmargsz; /* margin buf size */
67*32a712daSGarrett D'Amore size_t psmargcur; /* cur index in margin buf */
68*32a712daSGarrett D'Amore char last; /* character buffer */
69*32a712daSGarrett D'Amore enum termfont lastf; /* last set font */
70*32a712daSGarrett D'Amore size_t scale; /* font scaling factor */
71*32a712daSGarrett D'Amore size_t pages; /* number of pages shown */
72*32a712daSGarrett D'Amore size_t lineheight; /* line height (AFM units) */
73*32a712daSGarrett D'Amore size_t top; /* body top (AFM units) */
74*32a712daSGarrett D'Amore size_t bottom; /* body bottom (AFM units) */
75*32a712daSGarrett D'Amore size_t height; /* page height (AFM units */
76*32a712daSGarrett D'Amore size_t width; /* page width (AFM units) */
77*32a712daSGarrett D'Amore size_t left; /* body left (AFM units) */
78*32a712daSGarrett D'Amore size_t header; /* header pos (AFM units) */
79*32a712daSGarrett D'Amore size_t footer; /* footer pos (AFM units) */
80*32a712daSGarrett D'Amore size_t pdfbytes; /* current output byte */
81*32a712daSGarrett D'Amore size_t pdflastpg; /* byte of last page mark */
82*32a712daSGarrett D'Amore size_t pdfbody; /* start of body object */
83*32a712daSGarrett D'Amore size_t *pdfobjs; /* table of object offsets */
84*32a712daSGarrett D'Amore size_t pdfobjsz; /* size of pdfobjs */
85*32a712daSGarrett D'Amore };
86*32a712daSGarrett D'Amore
87*32a712daSGarrett D'Amore static double ps_hspan(const struct termp *,
88*32a712daSGarrett D'Amore const struct roffsu *);
89*32a712daSGarrett D'Amore static size_t ps_width(const struct termp *, int);
90*32a712daSGarrett D'Amore static void ps_advance(struct termp *, size_t);
91*32a712daSGarrett D'Amore static void ps_begin(struct termp *);
92*32a712daSGarrett D'Amore static void ps_closepage(struct termp *);
93*32a712daSGarrett D'Amore static void ps_end(struct termp *);
94*32a712daSGarrett D'Amore static void ps_endline(struct termp *);
95*32a712daSGarrett D'Amore static void ps_fclose(struct termp *);
96*32a712daSGarrett D'Amore static void ps_growbuf(struct termp *, size_t);
97*32a712daSGarrett D'Amore static void ps_letter(struct termp *, int);
98*32a712daSGarrett D'Amore static void ps_pclose(struct termp *);
99*32a712daSGarrett D'Amore static void ps_pletter(struct termp *, int);
100*32a712daSGarrett D'Amore static void ps_printf(struct termp *, const char *, ...);
101*32a712daSGarrett D'Amore static void ps_putchar(struct termp *, char);
102*32a712daSGarrett D'Amore static void ps_setfont(struct termp *, enum termfont);
103*32a712daSGarrett D'Amore static struct termp *pspdf_alloc(char *);
104*32a712daSGarrett D'Amore static void pdf_obj(struct termp *, size_t);
105*32a712daSGarrett D'Amore
106*32a712daSGarrett D'Amore /*
107*32a712daSGarrett D'Amore * We define, for the time being, three fonts: bold, oblique/italic, and
108*32a712daSGarrett D'Amore * normal (roman). The following table hard-codes the font metrics for
109*32a712daSGarrett D'Amore * ASCII, i.e., 32--127.
110*32a712daSGarrett D'Amore */
111*32a712daSGarrett D'Amore
112*32a712daSGarrett D'Amore static const struct font fonts[TERMFONT__MAX] = {
113*32a712daSGarrett D'Amore { "Times-Roman", {
114*32a712daSGarrett D'Amore { 250 },
115*32a712daSGarrett D'Amore { 333 },
116*32a712daSGarrett D'Amore { 408 },
117*32a712daSGarrett D'Amore { 500 },
118*32a712daSGarrett D'Amore { 500 },
119*32a712daSGarrett D'Amore { 833 },
120*32a712daSGarrett D'Amore { 778 },
121*32a712daSGarrett D'Amore { 333 },
122*32a712daSGarrett D'Amore { 333 },
123*32a712daSGarrett D'Amore { 333 },
124*32a712daSGarrett D'Amore { 500 },
125*32a712daSGarrett D'Amore { 564 },
126*32a712daSGarrett D'Amore { 250 },
127*32a712daSGarrett D'Amore { 333 },
128*32a712daSGarrett D'Amore { 250 },
129*32a712daSGarrett D'Amore { 278 },
130*32a712daSGarrett D'Amore { 500 },
131*32a712daSGarrett D'Amore { 500 },
132*32a712daSGarrett D'Amore { 500 },
133*32a712daSGarrett D'Amore { 500 },
134*32a712daSGarrett D'Amore { 500 },
135*32a712daSGarrett D'Amore { 500 },
136*32a712daSGarrett D'Amore { 500 },
137*32a712daSGarrett D'Amore { 500 },
138*32a712daSGarrett D'Amore { 500 },
139*32a712daSGarrett D'Amore { 500 },
140*32a712daSGarrett D'Amore { 278 },
141*32a712daSGarrett D'Amore { 278 },
142*32a712daSGarrett D'Amore { 564 },
143*32a712daSGarrett D'Amore { 564 },
144*32a712daSGarrett D'Amore { 564 },
145*32a712daSGarrett D'Amore { 444 },
146*32a712daSGarrett D'Amore { 921 },
147*32a712daSGarrett D'Amore { 722 },
148*32a712daSGarrett D'Amore { 667 },
149*32a712daSGarrett D'Amore { 667 },
150*32a712daSGarrett D'Amore { 722 },
151*32a712daSGarrett D'Amore { 611 },
152*32a712daSGarrett D'Amore { 556 },
153*32a712daSGarrett D'Amore { 722 },
154*32a712daSGarrett D'Amore { 722 },
155*32a712daSGarrett D'Amore { 333 },
156*32a712daSGarrett D'Amore { 389 },
157*32a712daSGarrett D'Amore { 722 },
158*32a712daSGarrett D'Amore { 611 },
159*32a712daSGarrett D'Amore { 889 },
160*32a712daSGarrett D'Amore { 722 },
161*32a712daSGarrett D'Amore { 722 },
162*32a712daSGarrett D'Amore { 556 },
163*32a712daSGarrett D'Amore { 722 },
164*32a712daSGarrett D'Amore { 667 },
165*32a712daSGarrett D'Amore { 556 },
166*32a712daSGarrett D'Amore { 611 },
167*32a712daSGarrett D'Amore { 722 },
168*32a712daSGarrett D'Amore { 722 },
169*32a712daSGarrett D'Amore { 944 },
170*32a712daSGarrett D'Amore { 722 },
171*32a712daSGarrett D'Amore { 722 },
172*32a712daSGarrett D'Amore { 611 },
173*32a712daSGarrett D'Amore { 333 },
174*32a712daSGarrett D'Amore { 278 },
175*32a712daSGarrett D'Amore { 333 },
176*32a712daSGarrett D'Amore { 469 },
177*32a712daSGarrett D'Amore { 500 },
178*32a712daSGarrett D'Amore { 333 },
179*32a712daSGarrett D'Amore { 444 },
180*32a712daSGarrett D'Amore { 500 },
181*32a712daSGarrett D'Amore { 444 },
182*32a712daSGarrett D'Amore { 500},
183*32a712daSGarrett D'Amore { 444},
184*32a712daSGarrett D'Amore { 333},
185*32a712daSGarrett D'Amore { 500},
186*32a712daSGarrett D'Amore { 500},
187*32a712daSGarrett D'Amore { 278},
188*32a712daSGarrett D'Amore { 278},
189*32a712daSGarrett D'Amore { 500},
190*32a712daSGarrett D'Amore { 278},
191*32a712daSGarrett D'Amore { 778},
192*32a712daSGarrett D'Amore { 500},
193*32a712daSGarrett D'Amore { 500},
194*32a712daSGarrett D'Amore { 500},
195*32a712daSGarrett D'Amore { 500},
196*32a712daSGarrett D'Amore { 333},
197*32a712daSGarrett D'Amore { 389},
198*32a712daSGarrett D'Amore { 278},
199*32a712daSGarrett D'Amore { 500},
200*32a712daSGarrett D'Amore { 500},
201*32a712daSGarrett D'Amore { 722},
202*32a712daSGarrett D'Amore { 500},
203*32a712daSGarrett D'Amore { 500},
204*32a712daSGarrett D'Amore { 444},
205*32a712daSGarrett D'Amore { 480},
206*32a712daSGarrett D'Amore { 200},
207*32a712daSGarrett D'Amore { 480},
208*32a712daSGarrett D'Amore { 541},
209*32a712daSGarrett D'Amore } },
210*32a712daSGarrett D'Amore { "Times-Bold", {
211*32a712daSGarrett D'Amore { 250 },
212*32a712daSGarrett D'Amore { 333 },
213*32a712daSGarrett D'Amore { 555 },
214*32a712daSGarrett D'Amore { 500 },
215*32a712daSGarrett D'Amore { 500 },
216*32a712daSGarrett D'Amore { 1000 },
217*32a712daSGarrett D'Amore { 833 },
218*32a712daSGarrett D'Amore { 333 },
219*32a712daSGarrett D'Amore { 333 },
220*32a712daSGarrett D'Amore { 333 },
221*32a712daSGarrett D'Amore { 500 },
222*32a712daSGarrett D'Amore { 570 },
223*32a712daSGarrett D'Amore { 250 },
224*32a712daSGarrett D'Amore { 333 },
225*32a712daSGarrett D'Amore { 250 },
226*32a712daSGarrett D'Amore { 278 },
227*32a712daSGarrett D'Amore { 500 },
228*32a712daSGarrett D'Amore { 500 },
229*32a712daSGarrett D'Amore { 500 },
230*32a712daSGarrett D'Amore { 500 },
231*32a712daSGarrett D'Amore { 500 },
232*32a712daSGarrett D'Amore { 500 },
233*32a712daSGarrett D'Amore { 500 },
234*32a712daSGarrett D'Amore { 500 },
235*32a712daSGarrett D'Amore { 500 },
236*32a712daSGarrett D'Amore { 500 },
237*32a712daSGarrett D'Amore { 333 },
238*32a712daSGarrett D'Amore { 333 },
239*32a712daSGarrett D'Amore { 570 },
240*32a712daSGarrett D'Amore { 570 },
241*32a712daSGarrett D'Amore { 570 },
242*32a712daSGarrett D'Amore { 500 },
243*32a712daSGarrett D'Amore { 930 },
244*32a712daSGarrett D'Amore { 722 },
245*32a712daSGarrett D'Amore { 667 },
246*32a712daSGarrett D'Amore { 722 },
247*32a712daSGarrett D'Amore { 722 },
248*32a712daSGarrett D'Amore { 667 },
249*32a712daSGarrett D'Amore { 611 },
250*32a712daSGarrett D'Amore { 778 },
251*32a712daSGarrett D'Amore { 778 },
252*32a712daSGarrett D'Amore { 389 },
253*32a712daSGarrett D'Amore { 500 },
254*32a712daSGarrett D'Amore { 778 },
255*32a712daSGarrett D'Amore { 667 },
256*32a712daSGarrett D'Amore { 944 },
257*32a712daSGarrett D'Amore { 722 },
258*32a712daSGarrett D'Amore { 778 },
259*32a712daSGarrett D'Amore { 611 },
260*32a712daSGarrett D'Amore { 778 },
261*32a712daSGarrett D'Amore { 722 },
262*32a712daSGarrett D'Amore { 556 },
263*32a712daSGarrett D'Amore { 667 },
264*32a712daSGarrett D'Amore { 722 },
265*32a712daSGarrett D'Amore { 722 },
266*32a712daSGarrett D'Amore { 1000 },
267*32a712daSGarrett D'Amore { 722 },
268*32a712daSGarrett D'Amore { 722 },
269*32a712daSGarrett D'Amore { 667 },
270*32a712daSGarrett D'Amore { 333 },
271*32a712daSGarrett D'Amore { 278 },
272*32a712daSGarrett D'Amore { 333 },
273*32a712daSGarrett D'Amore { 581 },
274*32a712daSGarrett D'Amore { 500 },
275*32a712daSGarrett D'Amore { 333 },
276*32a712daSGarrett D'Amore { 500 },
277*32a712daSGarrett D'Amore { 556 },
278*32a712daSGarrett D'Amore { 444 },
279*32a712daSGarrett D'Amore { 556 },
280*32a712daSGarrett D'Amore { 444 },
281*32a712daSGarrett D'Amore { 333 },
282*32a712daSGarrett D'Amore { 500 },
283*32a712daSGarrett D'Amore { 556 },
284*32a712daSGarrett D'Amore { 278 },
285*32a712daSGarrett D'Amore { 333 },
286*32a712daSGarrett D'Amore { 556 },
287*32a712daSGarrett D'Amore { 278 },
288*32a712daSGarrett D'Amore { 833 },
289*32a712daSGarrett D'Amore { 556 },
290*32a712daSGarrett D'Amore { 500 },
291*32a712daSGarrett D'Amore { 556 },
292*32a712daSGarrett D'Amore { 556 },
293*32a712daSGarrett D'Amore { 444 },
294*32a712daSGarrett D'Amore { 389 },
295*32a712daSGarrett D'Amore { 333 },
296*32a712daSGarrett D'Amore { 556 },
297*32a712daSGarrett D'Amore { 500 },
298*32a712daSGarrett D'Amore { 722 },
299*32a712daSGarrett D'Amore { 500 },
300*32a712daSGarrett D'Amore { 500 },
301*32a712daSGarrett D'Amore { 444 },
302*32a712daSGarrett D'Amore { 394 },
303*32a712daSGarrett D'Amore { 220 },
304*32a712daSGarrett D'Amore { 394 },
305*32a712daSGarrett D'Amore { 520 },
306*32a712daSGarrett D'Amore } },
307*32a712daSGarrett D'Amore { "Times-Italic", {
308*32a712daSGarrett D'Amore { 250 },
309*32a712daSGarrett D'Amore { 333 },
310*32a712daSGarrett D'Amore { 420 },
311*32a712daSGarrett D'Amore { 500 },
312*32a712daSGarrett D'Amore { 500 },
313*32a712daSGarrett D'Amore { 833 },
314*32a712daSGarrett D'Amore { 778 },
315*32a712daSGarrett D'Amore { 333 },
316*32a712daSGarrett D'Amore { 333 },
317*32a712daSGarrett D'Amore { 333 },
318*32a712daSGarrett D'Amore { 500 },
319*32a712daSGarrett D'Amore { 675 },
320*32a712daSGarrett D'Amore { 250 },
321*32a712daSGarrett D'Amore { 333 },
322*32a712daSGarrett D'Amore { 250 },
323*32a712daSGarrett D'Amore { 278 },
324*32a712daSGarrett D'Amore { 500 },
325*32a712daSGarrett D'Amore { 500 },
326*32a712daSGarrett D'Amore { 500 },
327*32a712daSGarrett D'Amore { 500 },
328*32a712daSGarrett D'Amore { 500 },
329*32a712daSGarrett D'Amore { 500 },
330*32a712daSGarrett D'Amore { 500 },
331*32a712daSGarrett D'Amore { 500 },
332*32a712daSGarrett D'Amore { 500 },
333*32a712daSGarrett D'Amore { 500 },
334*32a712daSGarrett D'Amore { 333 },
335*32a712daSGarrett D'Amore { 333 },
336*32a712daSGarrett D'Amore { 675 },
337*32a712daSGarrett D'Amore { 675 },
338*32a712daSGarrett D'Amore { 675 },
339*32a712daSGarrett D'Amore { 500 },
340*32a712daSGarrett D'Amore { 920 },
341*32a712daSGarrett D'Amore { 611 },
342*32a712daSGarrett D'Amore { 611 },
343*32a712daSGarrett D'Amore { 667 },
344*32a712daSGarrett D'Amore { 722 },
345*32a712daSGarrett D'Amore { 611 },
346*32a712daSGarrett D'Amore { 611 },
347*32a712daSGarrett D'Amore { 722 },
348*32a712daSGarrett D'Amore { 722 },
349*32a712daSGarrett D'Amore { 333 },
350*32a712daSGarrett D'Amore { 444 },
351*32a712daSGarrett D'Amore { 667 },
352*32a712daSGarrett D'Amore { 556 },
353*32a712daSGarrett D'Amore { 833 },
354*32a712daSGarrett D'Amore { 667 },
355*32a712daSGarrett D'Amore { 722 },
356*32a712daSGarrett D'Amore { 611 },
357*32a712daSGarrett D'Amore { 722 },
358*32a712daSGarrett D'Amore { 611 },
359*32a712daSGarrett D'Amore { 500 },
360*32a712daSGarrett D'Amore { 556 },
361*32a712daSGarrett D'Amore { 722 },
362*32a712daSGarrett D'Amore { 611 },
363*32a712daSGarrett D'Amore { 833 },
364*32a712daSGarrett D'Amore { 611 },
365*32a712daSGarrett D'Amore { 556 },
366*32a712daSGarrett D'Amore { 556 },
367*32a712daSGarrett D'Amore { 389 },
368*32a712daSGarrett D'Amore { 278 },
369*32a712daSGarrett D'Amore { 389 },
370*32a712daSGarrett D'Amore { 422 },
371*32a712daSGarrett D'Amore { 500 },
372*32a712daSGarrett D'Amore { 333 },
373*32a712daSGarrett D'Amore { 500 },
374*32a712daSGarrett D'Amore { 500 },
375*32a712daSGarrett D'Amore { 444 },
376*32a712daSGarrett D'Amore { 500 },
377*32a712daSGarrett D'Amore { 444 },
378*32a712daSGarrett D'Amore { 278 },
379*32a712daSGarrett D'Amore { 500 },
380*32a712daSGarrett D'Amore { 500 },
381*32a712daSGarrett D'Amore { 278 },
382*32a712daSGarrett D'Amore { 278 },
383*32a712daSGarrett D'Amore { 444 },
384*32a712daSGarrett D'Amore { 278 },
385*32a712daSGarrett D'Amore { 722 },
386*32a712daSGarrett D'Amore { 500 },
387*32a712daSGarrett D'Amore { 500 },
388*32a712daSGarrett D'Amore { 500 },
389*32a712daSGarrett D'Amore { 500 },
390*32a712daSGarrett D'Amore { 389 },
391*32a712daSGarrett D'Amore { 389 },
392*32a712daSGarrett D'Amore { 278 },
393*32a712daSGarrett D'Amore { 500 },
394*32a712daSGarrett D'Amore { 444 },
395*32a712daSGarrett D'Amore { 667 },
396*32a712daSGarrett D'Amore { 444 },
397*32a712daSGarrett D'Amore { 444 },
398*32a712daSGarrett D'Amore { 389 },
399*32a712daSGarrett D'Amore { 400 },
400*32a712daSGarrett D'Amore { 275 },
401*32a712daSGarrett D'Amore { 400 },
402*32a712daSGarrett D'Amore { 541 },
403*32a712daSGarrett D'Amore } },
404*32a712daSGarrett D'Amore };
405*32a712daSGarrett D'Amore
406*32a712daSGarrett D'Amore void *
pdf_alloc(char * outopts)407*32a712daSGarrett D'Amore pdf_alloc(char *outopts)
408*32a712daSGarrett D'Amore {
409*32a712daSGarrett D'Amore struct termp *p;
410*32a712daSGarrett D'Amore
411*32a712daSGarrett D'Amore if (NULL != (p = pspdf_alloc(outopts)))
412*32a712daSGarrett D'Amore p->type = TERMTYPE_PDF;
413*32a712daSGarrett D'Amore
414*32a712daSGarrett D'Amore return(p);
415*32a712daSGarrett D'Amore }
416*32a712daSGarrett D'Amore
417*32a712daSGarrett D'Amore void *
ps_alloc(char * outopts)418*32a712daSGarrett D'Amore ps_alloc(char *outopts)
419*32a712daSGarrett D'Amore {
420*32a712daSGarrett D'Amore struct termp *p;
421*32a712daSGarrett D'Amore
422*32a712daSGarrett D'Amore if (NULL != (p = pspdf_alloc(outopts)))
423*32a712daSGarrett D'Amore p->type = TERMTYPE_PS;
424*32a712daSGarrett D'Amore
425*32a712daSGarrett D'Amore return(p);
426*32a712daSGarrett D'Amore }
427*32a712daSGarrett D'Amore
428*32a712daSGarrett D'Amore static struct termp *
pspdf_alloc(char * outopts)429*32a712daSGarrett D'Amore pspdf_alloc(char *outopts)
430*32a712daSGarrett D'Amore {
431*32a712daSGarrett D'Amore struct termp *p;
432*32a712daSGarrett D'Amore unsigned int pagex, pagey;
433*32a712daSGarrett D'Amore size_t marginx, marginy, lineheight;
434*32a712daSGarrett D'Amore const char *toks[2];
435*32a712daSGarrett D'Amore const char *pp;
436*32a712daSGarrett D'Amore char *v;
437*32a712daSGarrett D'Amore
438*32a712daSGarrett D'Amore p = mandoc_calloc(1, sizeof(struct termp));
439*32a712daSGarrett D'Amore p->enc = TERMENC_ASCII;
440*32a712daSGarrett D'Amore p->ps = mandoc_calloc(1, sizeof(struct termp_ps));
441*32a712daSGarrett D'Amore
442*32a712daSGarrett D'Amore p->advance = ps_advance;
443*32a712daSGarrett D'Amore p->begin = ps_begin;
444*32a712daSGarrett D'Amore p->end = ps_end;
445*32a712daSGarrett D'Amore p->endline = ps_endline;
446*32a712daSGarrett D'Amore p->hspan = ps_hspan;
447*32a712daSGarrett D'Amore p->letter = ps_letter;
448*32a712daSGarrett D'Amore p->width = ps_width;
449*32a712daSGarrett D'Amore
450*32a712daSGarrett D'Amore toks[0] = "paper";
451*32a712daSGarrett D'Amore toks[1] = NULL;
452*32a712daSGarrett D'Amore
453*32a712daSGarrett D'Amore pp = NULL;
454*32a712daSGarrett D'Amore
455*32a712daSGarrett D'Amore while (outopts && *outopts)
456*32a712daSGarrett D'Amore switch (getsubopt(&outopts, UNCONST(toks), &v)) {
457*32a712daSGarrett D'Amore case (0):
458*32a712daSGarrett D'Amore pp = v;
459*32a712daSGarrett D'Amore break;
460*32a712daSGarrett D'Amore default:
461*32a712daSGarrett D'Amore break;
462*32a712daSGarrett D'Amore }
463*32a712daSGarrett D'Amore
464*32a712daSGarrett D'Amore /* Default to US letter (millimetres). */
465*32a712daSGarrett D'Amore
466*32a712daSGarrett D'Amore pagex = 216;
467*32a712daSGarrett D'Amore pagey = 279;
468*32a712daSGarrett D'Amore
469*32a712daSGarrett D'Amore /*
470*32a712daSGarrett D'Amore * The ISO-269 paper sizes can be calculated automatically, but
471*32a712daSGarrett D'Amore * it would require bringing in -lm for pow() and I'd rather not
472*32a712daSGarrett D'Amore * do that. So just do it the easy way for now. Since this
473*32a712daSGarrett D'Amore * only happens once, I'm not terribly concerned.
474*32a712daSGarrett D'Amore */
475*32a712daSGarrett D'Amore
476*32a712daSGarrett D'Amore if (pp && strcasecmp(pp, "letter")) {
477*32a712daSGarrett D'Amore if (0 == strcasecmp(pp, "a3")) {
478*32a712daSGarrett D'Amore pagex = 297;
479*32a712daSGarrett D'Amore pagey = 420;
480*32a712daSGarrett D'Amore } else if (0 == strcasecmp(pp, "a4")) {
481*32a712daSGarrett D'Amore pagex = 210;
482*32a712daSGarrett D'Amore pagey = 297;
483*32a712daSGarrett D'Amore } else if (0 == strcasecmp(pp, "a5")) {
484*32a712daSGarrett D'Amore pagex = 148;
485*32a712daSGarrett D'Amore pagey = 210;
486*32a712daSGarrett D'Amore } else if (0 == strcasecmp(pp, "legal")) {
487*32a712daSGarrett D'Amore pagex = 216;
488*32a712daSGarrett D'Amore pagey = 356;
489*32a712daSGarrett D'Amore } else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey))
490*32a712daSGarrett D'Amore fprintf(stderr, "%s: Unknown paper\n", pp);
491*32a712daSGarrett D'Amore }
492*32a712daSGarrett D'Amore
493*32a712daSGarrett D'Amore /*
494*32a712daSGarrett D'Amore * This MUST be defined before any PNT2AFM or AFM2PNT
495*32a712daSGarrett D'Amore * calculations occur.
496*32a712daSGarrett D'Amore */
497*32a712daSGarrett D'Amore
498*32a712daSGarrett D'Amore p->ps->scale = 11;
499*32a712daSGarrett D'Amore
500*32a712daSGarrett D'Amore /* Remember millimetres -> AFM units. */
501*32a712daSGarrett D'Amore
502*32a712daSGarrett D'Amore pagex = PNT2AFM(p, ((double)pagex * 2.834));
503*32a712daSGarrett D'Amore pagey = PNT2AFM(p, ((double)pagey * 2.834));
504*32a712daSGarrett D'Amore
505*32a712daSGarrett D'Amore /* Margins are 1/9 the page x and y. */
506*32a712daSGarrett D'Amore
507*32a712daSGarrett D'Amore marginx = /* LINTED */
508*32a712daSGarrett D'Amore (size_t)((double)pagex / 9.0);
509*32a712daSGarrett D'Amore marginy = /* LINTED */
510*32a712daSGarrett D'Amore (size_t)((double)pagey / 9.0);
511*32a712daSGarrett D'Amore
512*32a712daSGarrett D'Amore /* Line-height is 1.4em. */
513*32a712daSGarrett D'Amore
514*32a712daSGarrett D'Amore lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4));
515*32a712daSGarrett D'Amore
516*32a712daSGarrett D'Amore p->ps->width = (size_t)pagex;
517*32a712daSGarrett D'Amore p->ps->height = (size_t)pagey;
518*32a712daSGarrett D'Amore p->ps->header = pagey - (marginy / 2) - (lineheight / 2);
519*32a712daSGarrett D'Amore p->ps->top = pagey - marginy;
520*32a712daSGarrett D'Amore p->ps->footer = (marginy / 2) - (lineheight / 2);
521*32a712daSGarrett D'Amore p->ps->bottom = marginy;
522*32a712daSGarrett D'Amore p->ps->left = marginx;
523*32a712daSGarrett D'Amore p->ps->lineheight = lineheight;
524*32a712daSGarrett D'Amore
525*32a712daSGarrett D'Amore p->defrmargin = pagex - (marginx * 2);
526*32a712daSGarrett D'Amore return(p);
527*32a712daSGarrett D'Amore }
528*32a712daSGarrett D'Amore
529*32a712daSGarrett D'Amore
530*32a712daSGarrett D'Amore void
pspdf_free(void * arg)531*32a712daSGarrett D'Amore pspdf_free(void *arg)
532*32a712daSGarrett D'Amore {
533*32a712daSGarrett D'Amore struct termp *p;
534*32a712daSGarrett D'Amore
535*32a712daSGarrett D'Amore p = (struct termp *)arg;
536*32a712daSGarrett D'Amore
537*32a712daSGarrett D'Amore if (p->ps->psmarg)
538*32a712daSGarrett D'Amore free(p->ps->psmarg);
539*32a712daSGarrett D'Amore if (p->ps->pdfobjs)
540*32a712daSGarrett D'Amore free(p->ps->pdfobjs);
541*32a712daSGarrett D'Amore
542*32a712daSGarrett D'Amore free(p->ps);
543*32a712daSGarrett D'Amore term_free(p);
544*32a712daSGarrett D'Amore }
545*32a712daSGarrett D'Amore
546*32a712daSGarrett D'Amore
547*32a712daSGarrett D'Amore static void
ps_printf(struct termp * p,const char * fmt,...)548*32a712daSGarrett D'Amore ps_printf(struct termp *p, const char *fmt, ...)
549*32a712daSGarrett D'Amore {
550*32a712daSGarrett D'Amore va_list ap;
551*32a712daSGarrett D'Amore int pos, len;
552*32a712daSGarrett D'Amore
553*32a712daSGarrett D'Amore va_start(ap, fmt);
554*32a712daSGarrett D'Amore
555*32a712daSGarrett D'Amore /*
556*32a712daSGarrett D'Amore * If we're running in regular mode, then pipe directly into
557*32a712daSGarrett D'Amore * vprintf(). If we're processing margins, then push the data
558*32a712daSGarrett D'Amore * into our growable margin buffer.
559*32a712daSGarrett D'Amore */
560*32a712daSGarrett D'Amore
561*32a712daSGarrett D'Amore if ( ! (PS_MARGINS & p->ps->flags)) {
562*32a712daSGarrett D'Amore len = vprintf(fmt, ap);
563*32a712daSGarrett D'Amore va_end(ap);
564*32a712daSGarrett D'Amore p->ps->pdfbytes += /* LINTED */
565*32a712daSGarrett D'Amore len < 0 ? 0 : (size_t)len;
566*32a712daSGarrett D'Amore return;
567*32a712daSGarrett D'Amore }
568*32a712daSGarrett D'Amore
569*32a712daSGarrett D'Amore /*
570*32a712daSGarrett D'Amore * XXX: I assume that the in-margin print won't exceed
571*32a712daSGarrett D'Amore * PS_BUFSLOP (128 bytes), which is reasonable but still an
572*32a712daSGarrett D'Amore * assumption that will cause pukeage if it's not the case.
573*32a712daSGarrett D'Amore */
574*32a712daSGarrett D'Amore
575*32a712daSGarrett D'Amore ps_growbuf(p, PS_BUFSLOP);
576*32a712daSGarrett D'Amore
577*32a712daSGarrett D'Amore pos = (int)p->ps->psmargcur;
578*32a712daSGarrett D'Amore vsnprintf(&p->ps->psmarg[pos], PS_BUFSLOP, fmt, ap);
579*32a712daSGarrett D'Amore
580*32a712daSGarrett D'Amore va_end(ap);
581*32a712daSGarrett D'Amore
582*32a712daSGarrett D'Amore p->ps->psmargcur = strlen(p->ps->psmarg);
583*32a712daSGarrett D'Amore }
584*32a712daSGarrett D'Amore
585*32a712daSGarrett D'Amore
586*32a712daSGarrett D'Amore static void
ps_putchar(struct termp * p,char c)587*32a712daSGarrett D'Amore ps_putchar(struct termp *p, char c)
588*32a712daSGarrett D'Amore {
589*32a712daSGarrett D'Amore int pos;
590*32a712daSGarrett D'Amore
591*32a712daSGarrett D'Amore /* See ps_printf(). */
592*32a712daSGarrett D'Amore
593*32a712daSGarrett D'Amore if ( ! (PS_MARGINS & p->ps->flags)) {
594*32a712daSGarrett D'Amore /* LINTED */
595*32a712daSGarrett D'Amore putchar(c);
596*32a712daSGarrett D'Amore p->ps->pdfbytes++;
597*32a712daSGarrett D'Amore return;
598*32a712daSGarrett D'Amore }
599*32a712daSGarrett D'Amore
600*32a712daSGarrett D'Amore ps_growbuf(p, 2);
601*32a712daSGarrett D'Amore
602*32a712daSGarrett D'Amore pos = (int)p->ps->psmargcur++;
603*32a712daSGarrett D'Amore p->ps->psmarg[pos++] = c;
604*32a712daSGarrett D'Amore p->ps->psmarg[pos] = '\0';
605*32a712daSGarrett D'Amore }
606*32a712daSGarrett D'Amore
607*32a712daSGarrett D'Amore
608*32a712daSGarrett D'Amore static void
pdf_obj(struct termp * p,size_t obj)609*32a712daSGarrett D'Amore pdf_obj(struct termp *p, size_t obj)
610*32a712daSGarrett D'Amore {
611*32a712daSGarrett D'Amore
612*32a712daSGarrett D'Amore assert(obj > 0);
613*32a712daSGarrett D'Amore
614*32a712daSGarrett D'Amore if ((obj - 1) >= p->ps->pdfobjsz) {
615*32a712daSGarrett D'Amore p->ps->pdfobjsz = obj + 128;
616*32a712daSGarrett D'Amore p->ps->pdfobjs = realloc
617*32a712daSGarrett D'Amore (p->ps->pdfobjs,
618*32a712daSGarrett D'Amore p->ps->pdfobjsz * sizeof(size_t));
619*32a712daSGarrett D'Amore if (NULL == p->ps->pdfobjs) {
620*32a712daSGarrett D'Amore perror(NULL);
621*32a712daSGarrett D'Amore exit((int)MANDOCLEVEL_SYSERR);
622*32a712daSGarrett D'Amore }
623*32a712daSGarrett D'Amore }
624*32a712daSGarrett D'Amore
625*32a712daSGarrett D'Amore p->ps->pdfobjs[(int)obj - 1] = p->ps->pdfbytes;
626*32a712daSGarrett D'Amore ps_printf(p, "%zu 0 obj\n", obj);
627*32a712daSGarrett D'Amore }
628*32a712daSGarrett D'Amore
629*32a712daSGarrett D'Amore
630*32a712daSGarrett D'Amore static void
ps_closepage(struct termp * p)631*32a712daSGarrett D'Amore ps_closepage(struct termp *p)
632*32a712daSGarrett D'Amore {
633*32a712daSGarrett D'Amore int i;
634*32a712daSGarrett D'Amore size_t len, base;
635*32a712daSGarrett D'Amore
636*32a712daSGarrett D'Amore /*
637*32a712daSGarrett D'Amore * Close out a page that we've already flushed to output. In
638*32a712daSGarrett D'Amore * PostScript, we simply note that the page must be showed. In
639*32a712daSGarrett D'Amore * PDF, we must now create the Length, Resource, and Page node
640*32a712daSGarrett D'Amore * for the page contents.
641*32a712daSGarrett D'Amore */
642*32a712daSGarrett D'Amore
643*32a712daSGarrett D'Amore assert(p->ps->psmarg && p->ps->psmarg[0]);
644*32a712daSGarrett D'Amore ps_printf(p, "%s", p->ps->psmarg);
645*32a712daSGarrett D'Amore
646*32a712daSGarrett D'Amore if (TERMTYPE_PS != p->type) {
647*32a712daSGarrett D'Amore ps_printf(p, "ET\n");
648*32a712daSGarrett D'Amore
649*32a712daSGarrett D'Amore len = p->ps->pdfbytes - p->ps->pdflastpg;
650*32a712daSGarrett D'Amore base = p->ps->pages * 4 + p->ps->pdfbody;
651*32a712daSGarrett D'Amore
652*32a712daSGarrett D'Amore ps_printf(p, "endstream\nendobj\n");
653*32a712daSGarrett D'Amore
654*32a712daSGarrett D'Amore /* Length of content. */
655*32a712daSGarrett D'Amore pdf_obj(p, base + 1);
656*32a712daSGarrett D'Amore ps_printf(p, "%zu\nendobj\n", len);
657*32a712daSGarrett D'Amore
658*32a712daSGarrett D'Amore /* Resource for content. */
659*32a712daSGarrett D'Amore pdf_obj(p, base + 2);
660*32a712daSGarrett D'Amore ps_printf(p, "<<\n/ProcSet [/PDF /Text]\n");
661*32a712daSGarrett D'Amore ps_printf(p, "/Font <<\n");
662*32a712daSGarrett D'Amore for (i = 0; i < (int)TERMFONT__MAX; i++)
663*32a712daSGarrett D'Amore ps_printf(p, "/F%d %d 0 R\n", i, 3 + i);
664*32a712daSGarrett D'Amore ps_printf(p, ">>\n>>\n");
665*32a712daSGarrett D'Amore
666*32a712daSGarrett D'Amore /* Page node. */
667*32a712daSGarrett D'Amore pdf_obj(p, base + 3);
668*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
669*32a712daSGarrett D'Amore ps_printf(p, "/Type /Page\n");
670*32a712daSGarrett D'Amore ps_printf(p, "/Parent 2 0 R\n");
671*32a712daSGarrett D'Amore ps_printf(p, "/Resources %zu 0 R\n", base + 2);
672*32a712daSGarrett D'Amore ps_printf(p, "/Contents %zu 0 R\n", base);
673*32a712daSGarrett D'Amore ps_printf(p, ">>\nendobj\n");
674*32a712daSGarrett D'Amore } else
675*32a712daSGarrett D'Amore ps_printf(p, "showpage\n");
676*32a712daSGarrett D'Amore
677*32a712daSGarrett D'Amore p->ps->pages++;
678*32a712daSGarrett D'Amore p->ps->psrow = p->ps->top;
679*32a712daSGarrett D'Amore assert( ! (PS_NEWPAGE & p->ps->flags));
680*32a712daSGarrett D'Amore p->ps->flags |= PS_NEWPAGE;
681*32a712daSGarrett D'Amore }
682*32a712daSGarrett D'Amore
683*32a712daSGarrett D'Amore
684*32a712daSGarrett D'Amore /* ARGSUSED */
685*32a712daSGarrett D'Amore static void
ps_end(struct termp * p)686*32a712daSGarrett D'Amore ps_end(struct termp *p)
687*32a712daSGarrett D'Amore {
688*32a712daSGarrett D'Amore size_t i, xref, base;
689*32a712daSGarrett D'Amore
690*32a712daSGarrett D'Amore /*
691*32a712daSGarrett D'Amore * At the end of the file, do one last showpage. This is the
692*32a712daSGarrett D'Amore * same behaviour as groff(1) and works for multiple pages as
693*32a712daSGarrett D'Amore * well as just one.
694*32a712daSGarrett D'Amore */
695*32a712daSGarrett D'Amore
696*32a712daSGarrett D'Amore if ( ! (PS_NEWPAGE & p->ps->flags)) {
697*32a712daSGarrett D'Amore assert(0 == p->ps->flags);
698*32a712daSGarrett D'Amore assert('\0' == p->ps->last);
699*32a712daSGarrett D'Amore ps_closepage(p);
700*32a712daSGarrett D'Amore }
701*32a712daSGarrett D'Amore
702*32a712daSGarrett D'Amore if (TERMTYPE_PS == p->type) {
703*32a712daSGarrett D'Amore ps_printf(p, "%%%%Trailer\n");
704*32a712daSGarrett D'Amore ps_printf(p, "%%%%Pages: %zu\n", p->ps->pages);
705*32a712daSGarrett D'Amore ps_printf(p, "%%%%EOF\n");
706*32a712daSGarrett D'Amore return;
707*32a712daSGarrett D'Amore }
708*32a712daSGarrett D'Amore
709*32a712daSGarrett D'Amore pdf_obj(p, 2);
710*32a712daSGarrett D'Amore ps_printf(p, "<<\n/Type /Pages\n");
711*32a712daSGarrett D'Amore ps_printf(p, "/MediaBox [0 0 %zu %zu]\n",
712*32a712daSGarrett D'Amore (size_t)AFM2PNT(p, p->ps->width),
713*32a712daSGarrett D'Amore (size_t)AFM2PNT(p, p->ps->height));
714*32a712daSGarrett D'Amore
715*32a712daSGarrett D'Amore ps_printf(p, "/Count %zu\n", p->ps->pages);
716*32a712daSGarrett D'Amore ps_printf(p, "/Kids [");
717*32a712daSGarrett D'Amore
718*32a712daSGarrett D'Amore for (i = 0; i < p->ps->pages; i++)
719*32a712daSGarrett D'Amore ps_printf(p, " %zu 0 R", i * 4 +
720*32a712daSGarrett D'Amore p->ps->pdfbody + 3);
721*32a712daSGarrett D'Amore
722*32a712daSGarrett D'Amore base = (p->ps->pages - 1) * 4 +
723*32a712daSGarrett D'Amore p->ps->pdfbody + 4;
724*32a712daSGarrett D'Amore
725*32a712daSGarrett D'Amore ps_printf(p, "]\n>>\nendobj\n");
726*32a712daSGarrett D'Amore pdf_obj(p, base);
727*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
728*32a712daSGarrett D'Amore ps_printf(p, "/Type /Catalog\n");
729*32a712daSGarrett D'Amore ps_printf(p, "/Pages 2 0 R\n");
730*32a712daSGarrett D'Amore ps_printf(p, ">>\n");
731*32a712daSGarrett D'Amore xref = p->ps->pdfbytes;
732*32a712daSGarrett D'Amore ps_printf(p, "xref\n");
733*32a712daSGarrett D'Amore ps_printf(p, "0 %zu\n", base + 1);
734*32a712daSGarrett D'Amore ps_printf(p, "0000000000 65535 f \n");
735*32a712daSGarrett D'Amore
736*32a712daSGarrett D'Amore for (i = 0; i < base; i++)
737*32a712daSGarrett D'Amore ps_printf(p, "%.10zu 00000 n \n",
738*32a712daSGarrett D'Amore p->ps->pdfobjs[(int)i]);
739*32a712daSGarrett D'Amore
740*32a712daSGarrett D'Amore ps_printf(p, "trailer\n");
741*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
742*32a712daSGarrett D'Amore ps_printf(p, "/Size %zu\n", base + 1);
743*32a712daSGarrett D'Amore ps_printf(p, "/Root %zu 0 R\n", base);
744*32a712daSGarrett D'Amore ps_printf(p, "/Info 1 0 R\n");
745*32a712daSGarrett D'Amore ps_printf(p, ">>\n");
746*32a712daSGarrett D'Amore ps_printf(p, "startxref\n");
747*32a712daSGarrett D'Amore ps_printf(p, "%zu\n", xref);
748*32a712daSGarrett D'Amore ps_printf(p, "%%%%EOF\n");
749*32a712daSGarrett D'Amore }
750*32a712daSGarrett D'Amore
751*32a712daSGarrett D'Amore
752*32a712daSGarrett D'Amore static void
ps_begin(struct termp * p)753*32a712daSGarrett D'Amore ps_begin(struct termp *p)
754*32a712daSGarrett D'Amore {
755*32a712daSGarrett D'Amore time_t t;
756*32a712daSGarrett D'Amore int i;
757*32a712daSGarrett D'Amore
758*32a712daSGarrett D'Amore /*
759*32a712daSGarrett D'Amore * Print margins into margin buffer. Nothing gets output to the
760*32a712daSGarrett D'Amore * screen yet, so we don't need to initialise the primary state.
761*32a712daSGarrett D'Amore */
762*32a712daSGarrett D'Amore
763*32a712daSGarrett D'Amore if (p->ps->psmarg) {
764*32a712daSGarrett D'Amore assert(p->ps->psmargsz);
765*32a712daSGarrett D'Amore p->ps->psmarg[0] = '\0';
766*32a712daSGarrett D'Amore }
767*32a712daSGarrett D'Amore
768*32a712daSGarrett D'Amore /*p->ps->pdfbytes = 0;*/
769*32a712daSGarrett D'Amore p->ps->psmargcur = 0;
770*32a712daSGarrett D'Amore p->ps->flags = PS_MARGINS;
771*32a712daSGarrett D'Amore p->ps->pscol = p->ps->left;
772*32a712daSGarrett D'Amore p->ps->psrow = p->ps->header;
773*32a712daSGarrett D'Amore
774*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_NONE);
775*32a712daSGarrett D'Amore
776*32a712daSGarrett D'Amore (*p->headf)(p, p->argf);
777*32a712daSGarrett D'Amore (*p->endline)(p);
778*32a712daSGarrett D'Amore
779*32a712daSGarrett D'Amore p->ps->pscol = p->ps->left;
780*32a712daSGarrett D'Amore p->ps->psrow = p->ps->footer;
781*32a712daSGarrett D'Amore
782*32a712daSGarrett D'Amore (*p->footf)(p, p->argf);
783*32a712daSGarrett D'Amore (*p->endline)(p);
784*32a712daSGarrett D'Amore
785*32a712daSGarrett D'Amore p->ps->flags &= ~PS_MARGINS;
786*32a712daSGarrett D'Amore
787*32a712daSGarrett D'Amore assert(0 == p->ps->flags);
788*32a712daSGarrett D'Amore assert(p->ps->psmarg);
789*32a712daSGarrett D'Amore assert('\0' != p->ps->psmarg[0]);
790*32a712daSGarrett D'Amore
791*32a712daSGarrett D'Amore /*
792*32a712daSGarrett D'Amore * Print header and initialise page state. Following this,
793*32a712daSGarrett D'Amore * stuff gets printed to the screen, so make sure we're sane.
794*32a712daSGarrett D'Amore */
795*32a712daSGarrett D'Amore
796*32a712daSGarrett D'Amore t = time(NULL);
797*32a712daSGarrett D'Amore
798*32a712daSGarrett D'Amore if (TERMTYPE_PS == p->type) {
799*32a712daSGarrett D'Amore ps_printf(p, "%%!PS-Adobe-3.0\n");
800*32a712daSGarrett D'Amore ps_printf(p, "%%%%CreationDate: %s", ctime(&t));
801*32a712daSGarrett D'Amore ps_printf(p, "%%%%DocumentData: Clean7Bit\n");
802*32a712daSGarrett D'Amore ps_printf(p, "%%%%Orientation: Portrait\n");
803*32a712daSGarrett D'Amore ps_printf(p, "%%%%Pages: (atend)\n");
804*32a712daSGarrett D'Amore ps_printf(p, "%%%%PageOrder: Ascend\n");
805*32a712daSGarrett D'Amore ps_printf(p, "%%%%DocumentMedia: "
806*32a712daSGarrett D'Amore "Default %zu %zu 0 () ()\n",
807*32a712daSGarrett D'Amore (size_t)AFM2PNT(p, p->ps->width),
808*32a712daSGarrett D'Amore (size_t)AFM2PNT(p, p->ps->height));
809*32a712daSGarrett D'Amore ps_printf(p, "%%%%DocumentNeededResources: font");
810*32a712daSGarrett D'Amore
811*32a712daSGarrett D'Amore for (i = 0; i < (int)TERMFONT__MAX; i++)
812*32a712daSGarrett D'Amore ps_printf(p, " %s", fonts[i].name);
813*32a712daSGarrett D'Amore
814*32a712daSGarrett D'Amore ps_printf(p, "\n%%%%EndComments\n");
815*32a712daSGarrett D'Amore } else {
816*32a712daSGarrett D'Amore ps_printf(p, "%%PDF-1.1\n");
817*32a712daSGarrett D'Amore pdf_obj(p, 1);
818*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
819*32a712daSGarrett D'Amore ps_printf(p, ">>\n");
820*32a712daSGarrett D'Amore ps_printf(p, "endobj\n");
821*32a712daSGarrett D'Amore
822*32a712daSGarrett D'Amore for (i = 0; i < (int)TERMFONT__MAX; i++) {
823*32a712daSGarrett D'Amore pdf_obj(p, (size_t)i + 3);
824*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
825*32a712daSGarrett D'Amore ps_printf(p, "/Type /Font\n");
826*32a712daSGarrett D'Amore ps_printf(p, "/Subtype /Type1\n");
827*32a712daSGarrett D'Amore ps_printf(p, "/Name /F%zu\n", i);
828*32a712daSGarrett D'Amore ps_printf(p, "/BaseFont /%s\n", fonts[i].name);
829*32a712daSGarrett D'Amore ps_printf(p, ">>\n");
830*32a712daSGarrett D'Amore }
831*32a712daSGarrett D'Amore }
832*32a712daSGarrett D'Amore
833*32a712daSGarrett D'Amore p->ps->pdfbody = (size_t)TERMFONT__MAX + 3;
834*32a712daSGarrett D'Amore p->ps->pscol = p->ps->left;
835*32a712daSGarrett D'Amore p->ps->psrow = p->ps->top;
836*32a712daSGarrett D'Amore p->ps->flags |= PS_NEWPAGE;
837*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_NONE);
838*32a712daSGarrett D'Amore }
839*32a712daSGarrett D'Amore
840*32a712daSGarrett D'Amore
841*32a712daSGarrett D'Amore static void
ps_pletter(struct termp * p,int c)842*32a712daSGarrett D'Amore ps_pletter(struct termp *p, int c)
843*32a712daSGarrett D'Amore {
844*32a712daSGarrett D'Amore int f;
845*32a712daSGarrett D'Amore
846*32a712daSGarrett D'Amore /*
847*32a712daSGarrett D'Amore * If we haven't opened a page context, then output that we're
848*32a712daSGarrett D'Amore * in a new page and make sure the font is correctly set.
849*32a712daSGarrett D'Amore */
850*32a712daSGarrett D'Amore
851*32a712daSGarrett D'Amore if (PS_NEWPAGE & p->ps->flags) {
852*32a712daSGarrett D'Amore if (TERMTYPE_PS == p->type) {
853*32a712daSGarrett D'Amore ps_printf(p, "%%%%Page: %zu %zu\n",
854*32a712daSGarrett D'Amore p->ps->pages + 1,
855*32a712daSGarrett D'Amore p->ps->pages + 1);
856*32a712daSGarrett D'Amore ps_printf(p, "/%s %zu selectfont\n",
857*32a712daSGarrett D'Amore fonts[(int)p->ps->lastf].name,
858*32a712daSGarrett D'Amore p->ps->scale);
859*32a712daSGarrett D'Amore } else {
860*32a712daSGarrett D'Amore pdf_obj(p, p->ps->pdfbody +
861*32a712daSGarrett D'Amore p->ps->pages * 4);
862*32a712daSGarrett D'Amore ps_printf(p, "<<\n");
863*32a712daSGarrett D'Amore ps_printf(p, "/Length %zu 0 R\n",
864*32a712daSGarrett D'Amore p->ps->pdfbody + 1 +
865*32a712daSGarrett D'Amore p->ps->pages * 4);
866*32a712daSGarrett D'Amore ps_printf(p, ">>\nstream\n");
867*32a712daSGarrett D'Amore }
868*32a712daSGarrett D'Amore p->ps->pdflastpg = p->ps->pdfbytes;
869*32a712daSGarrett D'Amore p->ps->flags &= ~PS_NEWPAGE;
870*32a712daSGarrett D'Amore }
871*32a712daSGarrett D'Amore
872*32a712daSGarrett D'Amore /*
873*32a712daSGarrett D'Amore * If we're not in a PostScript "word" context, then open one
874*32a712daSGarrett D'Amore * now at the current cursor.
875*32a712daSGarrett D'Amore */
876*32a712daSGarrett D'Amore
877*32a712daSGarrett D'Amore if ( ! (PS_INLINE & p->ps->flags)) {
878*32a712daSGarrett D'Amore if (TERMTYPE_PS != p->type) {
879*32a712daSGarrett D'Amore ps_printf(p, "BT\n/F%d %zu Tf\n",
880*32a712daSGarrett D'Amore (int)p->ps->lastf,
881*32a712daSGarrett D'Amore p->ps->scale);
882*32a712daSGarrett D'Amore ps_printf(p, "%.3f %.3f Td\n(",
883*32a712daSGarrett D'Amore AFM2PNT(p, p->ps->pscol),
884*32a712daSGarrett D'Amore AFM2PNT(p, p->ps->psrow));
885*32a712daSGarrett D'Amore } else
886*32a712daSGarrett D'Amore ps_printf(p, "%.3f %.3f moveto\n(",
887*32a712daSGarrett D'Amore AFM2PNT(p, p->ps->pscol),
888*32a712daSGarrett D'Amore AFM2PNT(p, p->ps->psrow));
889*32a712daSGarrett D'Amore p->ps->flags |= PS_INLINE;
890*32a712daSGarrett D'Amore }
891*32a712daSGarrett D'Amore
892*32a712daSGarrett D'Amore assert( ! (PS_NEWPAGE & p->ps->flags));
893*32a712daSGarrett D'Amore
894*32a712daSGarrett D'Amore /*
895*32a712daSGarrett D'Amore * We need to escape these characters as per the PostScript
896*32a712daSGarrett D'Amore * specification. We would also escape non-graphable characters
897*32a712daSGarrett D'Amore * (like tabs), but none of them would get to this point and
898*32a712daSGarrett D'Amore * it's superfluous to abort() on them.
899*32a712daSGarrett D'Amore */
900*32a712daSGarrett D'Amore
901*32a712daSGarrett D'Amore switch (c) {
902*32a712daSGarrett D'Amore case ('('):
903*32a712daSGarrett D'Amore /* FALLTHROUGH */
904*32a712daSGarrett D'Amore case (')'):
905*32a712daSGarrett D'Amore /* FALLTHROUGH */
906*32a712daSGarrett D'Amore case ('\\'):
907*32a712daSGarrett D'Amore ps_putchar(p, '\\');
908*32a712daSGarrett D'Amore break;
909*32a712daSGarrett D'Amore default:
910*32a712daSGarrett D'Amore break;
911*32a712daSGarrett D'Amore }
912*32a712daSGarrett D'Amore
913*32a712daSGarrett D'Amore /* Write the character and adjust where we are on the page. */
914*32a712daSGarrett D'Amore
915*32a712daSGarrett D'Amore f = (int)p->ps->lastf;
916*32a712daSGarrett D'Amore
917*32a712daSGarrett D'Amore if (c <= 32 || (c - 32 >= MAXCHAR)) {
918*32a712daSGarrett D'Amore ps_putchar(p, ' ');
919*32a712daSGarrett D'Amore p->ps->pscol += (size_t)fonts[f].gly[0].wx;
920*32a712daSGarrett D'Amore return;
921*32a712daSGarrett D'Amore }
922*32a712daSGarrett D'Amore
923*32a712daSGarrett D'Amore ps_putchar(p, (char)c);
924*32a712daSGarrett D'Amore c -= 32;
925*32a712daSGarrett D'Amore p->ps->pscol += (size_t)fonts[f].gly[c].wx;
926*32a712daSGarrett D'Amore }
927*32a712daSGarrett D'Amore
928*32a712daSGarrett D'Amore
929*32a712daSGarrett D'Amore static void
ps_pclose(struct termp * p)930*32a712daSGarrett D'Amore ps_pclose(struct termp *p)
931*32a712daSGarrett D'Amore {
932*32a712daSGarrett D'Amore
933*32a712daSGarrett D'Amore /*
934*32a712daSGarrett D'Amore * Spit out that we're exiting a word context (this is a
935*32a712daSGarrett D'Amore * "partial close" because we don't check the last-char buffer
936*32a712daSGarrett D'Amore * or anything).
937*32a712daSGarrett D'Amore */
938*32a712daSGarrett D'Amore
939*32a712daSGarrett D'Amore if ( ! (PS_INLINE & p->ps->flags))
940*32a712daSGarrett D'Amore return;
941*32a712daSGarrett D'Amore
942*32a712daSGarrett D'Amore if (TERMTYPE_PS != p->type) {
943*32a712daSGarrett D'Amore ps_printf(p, ") Tj\nET\n");
944*32a712daSGarrett D'Amore } else
945*32a712daSGarrett D'Amore ps_printf(p, ") show\n");
946*32a712daSGarrett D'Amore
947*32a712daSGarrett D'Amore p->ps->flags &= ~PS_INLINE;
948*32a712daSGarrett D'Amore }
949*32a712daSGarrett D'Amore
950*32a712daSGarrett D'Amore
951*32a712daSGarrett D'Amore static void
ps_fclose(struct termp * p)952*32a712daSGarrett D'Amore ps_fclose(struct termp *p)
953*32a712daSGarrett D'Amore {
954*32a712daSGarrett D'Amore
955*32a712daSGarrett D'Amore /*
956*32a712daSGarrett D'Amore * Strong closure: if we have a last-char, spit it out after
957*32a712daSGarrett D'Amore * checking that we're in the right font mode. This will of
958*32a712daSGarrett D'Amore * course open a new scope, if applicable.
959*32a712daSGarrett D'Amore *
960*32a712daSGarrett D'Amore * Following this, close out any scope that's open.
961*32a712daSGarrett D'Amore */
962*32a712daSGarrett D'Amore
963*32a712daSGarrett D'Amore if ('\0' != p->ps->last) {
964*32a712daSGarrett D'Amore if (p->ps->lastf != TERMFONT_NONE) {
965*32a712daSGarrett D'Amore ps_pclose(p);
966*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_NONE);
967*32a712daSGarrett D'Amore }
968*32a712daSGarrett D'Amore ps_pletter(p, p->ps->last);
969*32a712daSGarrett D'Amore p->ps->last = '\0';
970*32a712daSGarrett D'Amore }
971*32a712daSGarrett D'Amore
972*32a712daSGarrett D'Amore if ( ! (PS_INLINE & p->ps->flags))
973*32a712daSGarrett D'Amore return;
974*32a712daSGarrett D'Amore
975*32a712daSGarrett D'Amore ps_pclose(p);
976*32a712daSGarrett D'Amore }
977*32a712daSGarrett D'Amore
978*32a712daSGarrett D'Amore
979*32a712daSGarrett D'Amore static void
ps_letter(struct termp * p,int arg)980*32a712daSGarrett D'Amore ps_letter(struct termp *p, int arg)
981*32a712daSGarrett D'Amore {
982*32a712daSGarrett D'Amore char cc, c;
983*32a712daSGarrett D'Amore
984*32a712daSGarrett D'Amore /* LINTED */
985*32a712daSGarrett D'Amore c = arg >= 128 || arg <= 0 ? '?' : arg;
986*32a712daSGarrett D'Amore
987*32a712daSGarrett D'Amore /*
988*32a712daSGarrett D'Amore * State machine dictates whether to buffer the last character
989*32a712daSGarrett D'Amore * or not. Basically, encoded words are detected by checking if
990*32a712daSGarrett D'Amore * we're an "8" and switching on the buffer. Then we put "8" in
991*32a712daSGarrett D'Amore * our buffer, and on the next charater, flush both character
992*32a712daSGarrett D'Amore * and buffer. Thus, "regular" words are detected by having a
993*32a712daSGarrett D'Amore * regular character and a regular buffer character.
994*32a712daSGarrett D'Amore */
995*32a712daSGarrett D'Amore
996*32a712daSGarrett D'Amore if ('\0' == p->ps->last) {
997*32a712daSGarrett D'Amore assert(8 != c);
998*32a712daSGarrett D'Amore p->ps->last = c;
999*32a712daSGarrett D'Amore return;
1000*32a712daSGarrett D'Amore } else if (8 == p->ps->last) {
1001*32a712daSGarrett D'Amore assert(8 != c);
1002*32a712daSGarrett D'Amore p->ps->last = '\0';
1003*32a712daSGarrett D'Amore } else if (8 == c) {
1004*32a712daSGarrett D'Amore assert(8 != p->ps->last);
1005*32a712daSGarrett D'Amore if ('_' == p->ps->last) {
1006*32a712daSGarrett D'Amore if (p->ps->lastf != TERMFONT_UNDER) {
1007*32a712daSGarrett D'Amore ps_pclose(p);
1008*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_UNDER);
1009*32a712daSGarrett D'Amore }
1010*32a712daSGarrett D'Amore } else if (p->ps->lastf != TERMFONT_BOLD) {
1011*32a712daSGarrett D'Amore ps_pclose(p);
1012*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_BOLD);
1013*32a712daSGarrett D'Amore }
1014*32a712daSGarrett D'Amore p->ps->last = c;
1015*32a712daSGarrett D'Amore return;
1016*32a712daSGarrett D'Amore } else {
1017*32a712daSGarrett D'Amore if (p->ps->lastf != TERMFONT_NONE) {
1018*32a712daSGarrett D'Amore ps_pclose(p);
1019*32a712daSGarrett D'Amore ps_setfont(p, TERMFONT_NONE);
1020*32a712daSGarrett D'Amore }
1021*32a712daSGarrett D'Amore cc = p->ps->last;
1022*32a712daSGarrett D'Amore p->ps->last = c;
1023*32a712daSGarrett D'Amore c = cc;
1024*32a712daSGarrett D'Amore }
1025*32a712daSGarrett D'Amore
1026*32a712daSGarrett D'Amore ps_pletter(p, c);
1027*32a712daSGarrett D'Amore }
1028*32a712daSGarrett D'Amore
1029*32a712daSGarrett D'Amore
1030*32a712daSGarrett D'Amore static void
ps_advance(struct termp * p,size_t len)1031*32a712daSGarrett D'Amore ps_advance(struct termp *p, size_t len)
1032*32a712daSGarrett D'Amore {
1033*32a712daSGarrett D'Amore
1034*32a712daSGarrett D'Amore /*
1035*32a712daSGarrett D'Amore * Advance some spaces. This can probably be made smarter,
1036*32a712daSGarrett D'Amore * i.e., to have multiple space-separated words in the same
1037*32a712daSGarrett D'Amore * scope, but this is easier: just close out the current scope
1038*32a712daSGarrett D'Amore * and readjust our column settings.
1039*32a712daSGarrett D'Amore */
1040*32a712daSGarrett D'Amore
1041*32a712daSGarrett D'Amore ps_fclose(p);
1042*32a712daSGarrett D'Amore p->ps->pscol += len;
1043*32a712daSGarrett D'Amore }
1044*32a712daSGarrett D'Amore
1045*32a712daSGarrett D'Amore
1046*32a712daSGarrett D'Amore static void
ps_endline(struct termp * p)1047*32a712daSGarrett D'Amore ps_endline(struct termp *p)
1048*32a712daSGarrett D'Amore {
1049*32a712daSGarrett D'Amore
1050*32a712daSGarrett D'Amore /* Close out any scopes we have open: we're at eoln. */
1051*32a712daSGarrett D'Amore
1052*32a712daSGarrett D'Amore ps_fclose(p);
1053*32a712daSGarrett D'Amore
1054*32a712daSGarrett D'Amore /*
1055*32a712daSGarrett D'Amore * If we're in the margin, don't try to recalculate our current
1056*32a712daSGarrett D'Amore * row. XXX: if the column tries to be fancy with multiple
1057*32a712daSGarrett D'Amore * lines, we'll do nasty stuff.
1058*32a712daSGarrett D'Amore */
1059*32a712daSGarrett D'Amore
1060*32a712daSGarrett D'Amore if (PS_MARGINS & p->ps->flags)
1061*32a712daSGarrett D'Amore return;
1062*32a712daSGarrett D'Amore
1063*32a712daSGarrett D'Amore /* Left-justify. */
1064*32a712daSGarrett D'Amore
1065*32a712daSGarrett D'Amore p->ps->pscol = p->ps->left;
1066*32a712daSGarrett D'Amore
1067*32a712daSGarrett D'Amore /* If we haven't printed anything, return. */
1068*32a712daSGarrett D'Amore
1069*32a712daSGarrett D'Amore if (PS_NEWPAGE & p->ps->flags)
1070*32a712daSGarrett D'Amore return;
1071*32a712daSGarrett D'Amore
1072*32a712daSGarrett D'Amore /*
1073*32a712daSGarrett D'Amore * Put us down a line. If we're at the page bottom, spit out a
1074*32a712daSGarrett D'Amore * showpage and restart our row.
1075*32a712daSGarrett D'Amore */
1076*32a712daSGarrett D'Amore
1077*32a712daSGarrett D'Amore if (p->ps->psrow >= p->ps->lineheight +
1078*32a712daSGarrett D'Amore p->ps->bottom) {
1079*32a712daSGarrett D'Amore p->ps->psrow -= p->ps->lineheight;
1080*32a712daSGarrett D'Amore return;
1081*32a712daSGarrett D'Amore }
1082*32a712daSGarrett D'Amore
1083*32a712daSGarrett D'Amore ps_closepage(p);
1084*32a712daSGarrett D'Amore }
1085*32a712daSGarrett D'Amore
1086*32a712daSGarrett D'Amore
1087*32a712daSGarrett D'Amore static void
ps_setfont(struct termp * p,enum termfont f)1088*32a712daSGarrett D'Amore ps_setfont(struct termp *p, enum termfont f)
1089*32a712daSGarrett D'Amore {
1090*32a712daSGarrett D'Amore
1091*32a712daSGarrett D'Amore assert(f < TERMFONT__MAX);
1092*32a712daSGarrett D'Amore p->ps->lastf = f;
1093*32a712daSGarrett D'Amore
1094*32a712daSGarrett D'Amore /*
1095*32a712daSGarrett D'Amore * If we're still at the top of the page, let the font-setting
1096*32a712daSGarrett D'Amore * be delayed until we actually have stuff to print.
1097*32a712daSGarrett D'Amore */
1098*32a712daSGarrett D'Amore
1099*32a712daSGarrett D'Amore if (PS_NEWPAGE & p->ps->flags)
1100*32a712daSGarrett D'Amore return;
1101*32a712daSGarrett D'Amore
1102*32a712daSGarrett D'Amore if (TERMTYPE_PS == p->type)
1103*32a712daSGarrett D'Amore ps_printf(p, "/%s %zu selectfont\n",
1104*32a712daSGarrett D'Amore fonts[(int)f].name,
1105*32a712daSGarrett D'Amore p->ps->scale);
1106*32a712daSGarrett D'Amore else
1107*32a712daSGarrett D'Amore ps_printf(p, "/F%d %zu Tf\n",
1108*32a712daSGarrett D'Amore (int)f,
1109*32a712daSGarrett D'Amore p->ps->scale);
1110*32a712daSGarrett D'Amore }
1111*32a712daSGarrett D'Amore
1112*32a712daSGarrett D'Amore
1113*32a712daSGarrett D'Amore /* ARGSUSED */
1114*32a712daSGarrett D'Amore static size_t
ps_width(const struct termp * p,int c)1115*32a712daSGarrett D'Amore ps_width(const struct termp *p, int c)
1116*32a712daSGarrett D'Amore {
1117*32a712daSGarrett D'Amore
1118*32a712daSGarrett D'Amore if (c <= 32 || c - 32 >= MAXCHAR)
1119*32a712daSGarrett D'Amore return((size_t)fonts[(int)TERMFONT_NONE].gly[0].wx);
1120*32a712daSGarrett D'Amore
1121*32a712daSGarrett D'Amore c -= 32;
1122*32a712daSGarrett D'Amore return((size_t)fonts[(int)TERMFONT_NONE].gly[c].wx);
1123*32a712daSGarrett D'Amore }
1124*32a712daSGarrett D'Amore
1125*32a712daSGarrett D'Amore
1126*32a712daSGarrett D'Amore static double
ps_hspan(const struct termp * p,const struct roffsu * su)1127*32a712daSGarrett D'Amore ps_hspan(const struct termp *p, const struct roffsu *su)
1128*32a712daSGarrett D'Amore {
1129*32a712daSGarrett D'Amore double r;
1130*32a712daSGarrett D'Amore
1131*32a712daSGarrett D'Amore /*
1132*32a712daSGarrett D'Amore * All of these measurements are derived by converting from the
1133*32a712daSGarrett D'Amore * native measurement to AFM units.
1134*32a712daSGarrett D'Amore */
1135*32a712daSGarrett D'Amore
1136*32a712daSGarrett D'Amore switch (su->unit) {
1137*32a712daSGarrett D'Amore case (SCALE_CM):
1138*32a712daSGarrett D'Amore r = PNT2AFM(p, su->scale * 28.34);
1139*32a712daSGarrett D'Amore break;
1140*32a712daSGarrett D'Amore case (SCALE_IN):
1141*32a712daSGarrett D'Amore r = PNT2AFM(p, su->scale * 72);
1142*32a712daSGarrett D'Amore break;
1143*32a712daSGarrett D'Amore case (SCALE_PC):
1144*32a712daSGarrett D'Amore r = PNT2AFM(p, su->scale * 12);
1145*32a712daSGarrett D'Amore break;
1146*32a712daSGarrett D'Amore case (SCALE_PT):
1147*32a712daSGarrett D'Amore r = PNT2AFM(p, su->scale * 100);
1148*32a712daSGarrett D'Amore break;
1149*32a712daSGarrett D'Amore case (SCALE_EM):
1150*32a712daSGarrett D'Amore r = su->scale *
1151*32a712daSGarrett D'Amore fonts[(int)TERMFONT_NONE].gly[109 - 32].wx;
1152*32a712daSGarrett D'Amore break;
1153*32a712daSGarrett D'Amore case (SCALE_MM):
1154*32a712daSGarrett D'Amore r = PNT2AFM(p, su->scale * 2.834);
1155*32a712daSGarrett D'Amore break;
1156*32a712daSGarrett D'Amore case (SCALE_EN):
1157*32a712daSGarrett D'Amore r = su->scale *
1158*32a712daSGarrett D'Amore fonts[(int)TERMFONT_NONE].gly[110 - 32].wx;
1159*32a712daSGarrett D'Amore break;
1160*32a712daSGarrett D'Amore case (SCALE_VS):
1161*32a712daSGarrett D'Amore r = su->scale * p->ps->lineheight;
1162*32a712daSGarrett D'Amore break;
1163*32a712daSGarrett D'Amore default:
1164*32a712daSGarrett D'Amore r = su->scale;
1165*32a712daSGarrett D'Amore break;
1166*32a712daSGarrett D'Amore }
1167*32a712daSGarrett D'Amore
1168*32a712daSGarrett D'Amore return(r);
1169*32a712daSGarrett D'Amore }
1170*32a712daSGarrett D'Amore
1171*32a712daSGarrett D'Amore static void
ps_growbuf(struct termp * p,size_t sz)1172*32a712daSGarrett D'Amore ps_growbuf(struct termp *p, size_t sz)
1173*32a712daSGarrett D'Amore {
1174*32a712daSGarrett D'Amore if (p->ps->psmargcur + sz <= p->ps->psmargsz)
1175*32a712daSGarrett D'Amore return;
1176*32a712daSGarrett D'Amore
1177*32a712daSGarrett D'Amore if (sz < PS_BUFSLOP)
1178*32a712daSGarrett D'Amore sz = PS_BUFSLOP;
1179*32a712daSGarrett D'Amore
1180*32a712daSGarrett D'Amore p->ps->psmargsz += sz;
1181*32a712daSGarrett D'Amore
1182*32a712daSGarrett D'Amore p->ps->psmarg = mandoc_realloc
1183*32a712daSGarrett D'Amore (p->ps->psmarg, p->ps->psmargsz);
1184*32a712daSGarrett D'Amore }
1185*32a712daSGarrett D'Amore
1186