]> git.cameronkatri.com Git - mandoc.git/blob - term_ps.c
Set line-height to be 1.4em. Removed check for minimum margins that are no
[mandoc.git] / term_ps.c
1 /* $Id: term_ps.c,v 1.31 2010/07/04 20:06:59 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/param.h>
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <time.h>
30 #include <unistd.h>
31
32 #include "out.h"
33 #include "main.h"
34 #include "term.h"
35
36 /* Convert PostScript point "x" to an AFM unit. */
37 #define PNT2AFM(p, x) /* LINTED */ \
38 (size_t)((double)(x) * (1000.0 / (double)(p)->engine.ps.scale))
39
40 /* Convert an AFM unit "x" to a PostScript points */
41 #define AFM2PNT(p, x) /* LINTED */ \
42 (size_t)((double)(x) / (1000.0 / (double)(p)->engine.ps.scale))
43
44 struct glyph {
45 size_t wx; /* WX in AFM */
46 };
47
48 struct font {
49 const char *name; /* FontName in AFM */
50 #define MAXCHAR 95 /* total characters we can handle */
51 struct glyph gly[MAXCHAR]; /* glyph metrics */
52 };
53
54 /*
55 * We define, for the time being, three fonts: bold, oblique/italic, and
56 * normal (roman). The following table hard-codes the font metrics for
57 * ASCII, i.e., 32--127.
58 */
59
60 static const struct font fonts[TERMFONT__MAX] = {
61 { "Times-Roman", {
62 { 250 },
63 { 333 },
64 { 408 },
65 { 500 },
66 { 500 },
67 { 833 },
68 { 778 },
69 { 333 },
70 { 333 },
71 { 333 },
72 { 500 },
73 { 564 },
74 { 250 },
75 { 333 },
76 { 250 },
77 { 278 },
78 { 500 },
79 { 500 },
80 { 500 },
81 { 500 },
82 { 500 },
83 { 500 },
84 { 500 },
85 { 500 },
86 { 500 },
87 { 500 },
88 { 278 },
89 { 278 },
90 { 564 },
91 { 564 },
92 { 564 },
93 { 444 },
94 { 921 },
95 { 722 },
96 { 667 },
97 { 667 },
98 { 722 },
99 { 611 },
100 { 556 },
101 { 722 },
102 { 722 },
103 { 333 },
104 { 389 },
105 { 722 },
106 { 611 },
107 { 889 },
108 { 722 },
109 { 722 },
110 { 556 },
111 { 722 },
112 { 667 },
113 { 556 },
114 { 611 },
115 { 722 },
116 { 722 },
117 { 944 },
118 { 722 },
119 { 722 },
120 { 611 },
121 { 333 },
122 { 278 },
123 { 333 },
124 { 469 },
125 { 500 },
126 { 333 },
127 { 444 },
128 { 500 },
129 { 444 },
130 { 500},
131 { 444},
132 { 333},
133 { 500},
134 { 500},
135 { 278},
136 { 278},
137 { 500},
138 { 278},
139 { 778},
140 { 500},
141 { 500},
142 { 500},
143 { 500},
144 { 333},
145 { 389},
146 { 278},
147 { 500},
148 { 500},
149 { 722},
150 { 500},
151 { 500},
152 { 444},
153 { 480},
154 { 200},
155 { 480},
156 { 541},
157 } },
158 { "Times-Bold", {
159 { 250 },
160 { 333 },
161 { 555 },
162 { 500 },
163 { 500 },
164 { 1000 },
165 { 833 },
166 { 333 },
167 { 333 },
168 { 333 },
169 { 500 },
170 { 570 },
171 { 250 },
172 { 333 },
173 { 250 },
174 { 278 },
175 { 500 },
176 { 500 },
177 { 500 },
178 { 500 },
179 { 500 },
180 { 500 },
181 { 500 },
182 { 500 },
183 { 500 },
184 { 500 },
185 { 333 },
186 { 333 },
187 { 570 },
188 { 570 },
189 { 570 },
190 { 500 },
191 { 930 },
192 { 722 },
193 { 667 },
194 { 722 },
195 { 722 },
196 { 667 },
197 { 611 },
198 { 778 },
199 { 778 },
200 { 389 },
201 { 500 },
202 { 778 },
203 { 667 },
204 { 944 },
205 { 722 },
206 { 778 },
207 { 611 },
208 { 778 },
209 { 722 },
210 { 556 },
211 { 667 },
212 { 722 },
213 { 722 },
214 { 1000 },
215 { 722 },
216 { 722 },
217 { 667 },
218 { 333 },
219 { 278 },
220 { 333 },
221 { 581 },
222 { 500 },
223 { 333 },
224 { 500 },
225 { 556 },
226 { 444 },
227 { 556 },
228 { 444 },
229 { 333 },
230 { 500 },
231 { 556 },
232 { 278 },
233 { 333 },
234 { 556 },
235 { 278 },
236 { 833 },
237 { 556 },
238 { 500 },
239 { 556 },
240 { 556 },
241 { 444 },
242 { 389 },
243 { 333 },
244 { 556 },
245 { 500 },
246 { 722 },
247 { 500 },
248 { 500 },
249 { 444 },
250 { 394 },
251 { 220 },
252 { 394 },
253 { 520 },
254 } },
255 { "Times-Italic", {
256 { 250 },
257 { 333 },
258 { 420 },
259 { 500 },
260 { 500 },
261 { 833 },
262 { 778 },
263 { 333 },
264 { 333 },
265 { 333 },
266 { 500 },
267 { 675 },
268 { 250 },
269 { 333 },
270 { 250 },
271 { 278 },
272 { 500 },
273 { 500 },
274 { 500 },
275 { 500 },
276 { 500 },
277 { 500 },
278 { 500 },
279 { 500 },
280 { 500 },
281 { 500 },
282 { 333 },
283 { 333 },
284 { 675 },
285 { 675 },
286 { 675 },
287 { 500 },
288 { 920 },
289 { 611 },
290 { 611 },
291 { 667 },
292 { 722 },
293 { 611 },
294 { 611 },
295 { 722 },
296 { 722 },
297 { 333 },
298 { 444 },
299 { 667 },
300 { 556 },
301 { 833 },
302 { 667 },
303 { 722 },
304 { 611 },
305 { 722 },
306 { 611 },
307 { 500 },
308 { 556 },
309 { 722 },
310 { 611 },
311 { 833 },
312 { 611 },
313 { 556 },
314 { 556 },
315 { 389 },
316 { 278 },
317 { 389 },
318 { 422 },
319 { 500 },
320 { 333 },
321 { 500 },
322 { 500 },
323 { 444 },
324 { 500 },
325 { 444 },
326 { 278 },
327 { 500 },
328 { 500 },
329 { 278 },
330 { 278 },
331 { 444 },
332 { 278 },
333 { 722 },
334 { 500 },
335 { 500 },
336 { 500 },
337 { 500 },
338 { 389 },
339 { 389 },
340 { 278 },
341 { 500 },
342 { 444 },
343 { 667 },
344 { 444 },
345 { 444 },
346 { 389 },
347 { 400 },
348 { 275 },
349 { 400 },
350 { 541 },
351 } },
352 };
353
354 /* These work the buffer used by the header and footer. */
355 #define PS_BUFSLOP 128
356 #define PS_GROWBUF(p, sz) \
357 do if ((p)->engine.ps.psmargcur + (sz) > \
358 (p)->engine.ps.psmargsz) { \
359 (p)->engine.ps.psmargsz += /* CONSTCOND */ \
360 MAX(PS_BUFSLOP, (sz)); \
361 (p)->engine.ps.psmarg = realloc \
362 ((p)->engine.ps.psmarg, \
363 (p)->engine.ps.psmargsz); \
364 if (NULL == (p)->engine.ps.psmarg) { \
365 perror(NULL); \
366 exit(EXIT_FAILURE); \
367 } \
368 } while (/* CONSTCOND */ 0)
369
370
371 static double ps_hspan(const struct termp *,
372 const struct roffsu *);
373 static size_t ps_width(const struct termp *, char);
374 static void ps_advance(struct termp *, size_t);
375 static void ps_begin(struct termp *);
376 static void ps_end(struct termp *);
377 static void ps_endline(struct termp *);
378 static void ps_fclose(struct termp *);
379 static void ps_letter(struct termp *, char);
380 static void ps_pclose(struct termp *);
381 static void ps_pletter(struct termp *, int);
382 static void ps_printf(struct termp *, const char *, ...);
383 static void ps_putchar(struct termp *, char);
384 static void ps_setfont(struct termp *, enum termfont);
385
386
387 void *
388 ps_alloc(char *outopts)
389 {
390 struct termp *p;
391 size_t pagex, pagey, marginx, marginy, lineheight;
392 const char *toks[2];
393 const char *pp;
394 char *v;
395
396 if (NULL == (p = term_alloc(TERMENC_ASCII)))
397 return(NULL);
398
399 p->advance = ps_advance;
400 p->begin = ps_begin;
401 p->end = ps_end;
402 p->endline = ps_endline;
403 p->hspan = ps_hspan;
404 p->letter = ps_letter;
405 p->type = TERMTYPE_PS;
406 p->width = ps_width;
407
408 toks[0] = "paper";
409 toks[1] = NULL;
410
411 pp = NULL;
412
413 while (outopts && *outopts)
414 switch (getsubopt(&outopts, UNCONST(toks), &v)) {
415 case (0):
416 pp = v;
417 break;
418 default:
419 break;
420 }
421
422 /* Default to US letter (millimetres). */
423
424 pagex = 216;
425 pagey = 279;
426
427 /*
428 * The ISO-269 paper sizes can be calculated automatically, but
429 * it would require bringing in -lm for pow() and I'd rather not
430 * do that. So just do it the easy way for now. Since this
431 * only happens once, I'm not terribly concerned.
432 */
433
434 if (pp && strcasecmp(pp, "letter")) {
435 if (0 == strcasecmp(pp, "a3")) {
436 pagex = 297;
437 pagey = 420;
438 } else if (0 == strcasecmp(pp, "a4")) {
439 pagex = 210;
440 pagey = 297;
441 } else if (0 == strcasecmp(pp, "a5")) {
442 pagex = 148;
443 pagey = 210;
444 } else if (0 == strcasecmp(pp, "legal")) {
445 pagex = 216;
446 pagey = 356;
447 } else if (2 != sscanf(pp, "%zux%zu", &pagex, &pagey))
448 fprintf(stderr, "%s: Unknown paper\n", pp);
449 } else if (NULL == pp)
450 pp = "letter";
451
452 /*
453 * This MUST be defined before any PNT2AFM or AFM2PNT
454 * calculations occur.
455 */
456
457 p->engine.ps.scale = 11;
458
459 /* Remember millimetres -> AFM units. */
460
461 pagex = PNT2AFM(p, ((double)pagex * 2.834));
462 pagey = PNT2AFM(p, ((double)pagey * 2.834));
463
464 /* Margins are 1/9 the page x and y. */
465
466 marginx = /* LINTED */
467 (size_t)((double)pagex / 9.0);
468 marginy = /* LINTED */
469 (size_t)((double)pagey / 9.0);
470
471 /* Line-height is 1.4em. */
472
473 lineheight = PNT2AFM(p, ((double)p->engine.ps.scale * 1.4));
474
475 p->engine.ps.width = pagex;
476 p->engine.ps.height = pagey;
477 p->engine.ps.header = pagey - (marginy / 2) - (lineheight / 2);
478 p->engine.ps.top = pagey - marginy;
479 p->engine.ps.footer = (marginy / 2) - (lineheight / 2);
480 p->engine.ps.bottom = marginy;
481 p->engine.ps.left = marginx;
482 p->engine.ps.lineheight = lineheight;
483
484 p->defrmargin = pagex - (marginx * 2);
485 return(p);
486 }
487
488
489 void
490 ps_free(void *arg)
491 {
492 struct termp *p;
493
494 p = (struct termp *)arg;
495
496 if (p->engine.ps.psmarg)
497 free(p->engine.ps.psmarg);
498
499 term_free(p);
500 }
501
502
503 static void
504 ps_printf(struct termp *p, const char *fmt, ...)
505 {
506 va_list ap;
507 int pos;
508
509 va_start(ap, fmt);
510
511 /*
512 * If we're running in regular mode, then pipe directly into
513 * vprintf(). If we're processing margins, then push the data
514 * into our growable margin buffer.
515 */
516
517 if ( ! (PS_MARGINS & p->engine.ps.flags)) {
518 vprintf(fmt, ap);
519 va_end(ap);
520 return;
521 }
522
523 /*
524 * XXX: I assume that the in-margin print won't exceed
525 * PS_BUFSLOP (128 bytes), which is reasonable but still an
526 * assumption that will cause pukeage if it's not the case.
527 */
528
529 PS_GROWBUF(p, PS_BUFSLOP);
530
531 pos = (int)p->engine.ps.psmargcur;
532 vsnprintf(&p->engine.ps.psmarg[pos], PS_BUFSLOP, fmt, ap);
533 p->engine.ps.psmargcur = strlen(p->engine.ps.psmarg);
534
535 va_end(ap);
536 }
537
538
539 static void
540 ps_putchar(struct termp *p, char c)
541 {
542 int pos;
543
544 /* See ps_printf(). */
545
546 if ( ! (PS_MARGINS & p->engine.ps.flags)) {
547 putchar(c);
548 return;
549 }
550
551 PS_GROWBUF(p, 2);
552
553 pos = (int)p->engine.ps.psmargcur++;
554 p->engine.ps.psmarg[pos++] = c;
555 p->engine.ps.psmarg[pos] = '\0';
556 }
557
558
559 /* ARGSUSED */
560 static void
561 ps_end(struct termp *p)
562 {
563
564 /*
565 * At the end of the file, do one last showpage. This is the
566 * same behaviour as groff(1) and works for multiple pages as
567 * well as just one.
568 */
569
570 if ( ! (PS_NEWPAGE & p->engine.ps.flags)) {
571 assert(0 == p->engine.ps.flags);
572 assert('\0' == p->engine.ps.last);
573 assert(p->engine.ps.psmarg && p->engine.ps.psmarg[0]);
574 printf("%s", p->engine.ps.psmarg);
575 p->engine.ps.pages++;
576 printf("showpage\n");
577 }
578
579 printf("%%%%Trailer\n");
580 printf("%%%%Pages: %zu\n", p->engine.ps.pages);
581 printf("%%%%EOF\n");
582 }
583
584
585 static void
586 ps_begin(struct termp *p)
587 {
588 time_t t;
589 int i;
590
591 /*
592 * Print margins into margin buffer. Nothing gets output to the
593 * screen yet, so we don't need to initialise the primary state.
594 */
595
596 if (p->engine.ps.psmarg) {
597 assert(p->engine.ps.psmargsz);
598 p->engine.ps.psmarg[0] = '\0';
599 }
600
601 p->engine.ps.psmargcur = 0;
602 p->engine.ps.flags = PS_MARGINS;
603 p->engine.ps.pscol = p->engine.ps.left;
604 p->engine.ps.psrow = p->engine.ps.header;
605
606 ps_setfont(p, TERMFONT_NONE);
607
608 (*p->headf)(p, p->argf);
609 (*p->endline)(p);
610
611 p->engine.ps.pscol = p->engine.ps.left;
612 p->engine.ps.psrow = p->engine.ps.footer;
613
614 (*p->footf)(p, p->argf);
615 (*p->endline)(p);
616
617 p->engine.ps.flags &= ~PS_MARGINS;
618
619 assert(0 == p->engine.ps.flags);
620 assert(p->engine.ps.psmarg);
621 assert('\0' != p->engine.ps.psmarg[0]);
622
623 /*
624 * Print header and initialise page state. Following this,
625 * stuff gets printed to the screen, so make sure we're sane.
626 */
627
628 t = time(NULL);
629
630 printf("%%!PS-Adobe-3.0\n");
631 printf("%%%%Creator: mandoc-%s\n", VERSION);
632 printf("%%%%CreationDate: %s", ctime(&t));
633 printf("%%%%DocumentData: Clean7Bit\n");
634 printf("%%%%Orientation: Portrait\n");
635 printf("%%%%Pages: (atend)\n");
636 printf("%%%%PageOrder: Ascend\n");
637 printf("%%%%DocumentMedia: Default %zu %zu 0 () ()\n",
638 AFM2PNT(p, p->engine.ps.width),
639 AFM2PNT(p, p->engine.ps.height));
640 printf("%%%%DocumentNeededResources: font");
641 for (i = 0; i < (int)TERMFONT__MAX; i++)
642 printf(" %s", fonts[i].name);
643 printf("\n%%%%EndComments\n");
644
645 printf("%%%%Page: %zu %zu\n",
646 p->engine.ps.pages + 1,
647 p->engine.ps.pages + 1);
648
649 ps_setfont(p, TERMFONT_NONE);
650 p->engine.ps.pscol = p->engine.ps.left;
651 p->engine.ps.psrow = p->engine.ps.top;
652 p->engine.ps.flags |= PS_NEWPAGE;
653 }
654
655
656 static void
657 ps_pletter(struct termp *p, int c)
658 {
659 int f;
660
661 /*
662 * If we're not in a PostScript "word" context, then open one
663 * now at the current cursor.
664 */
665
666 if (PS_NEWPAGE & p->engine.ps.flags)
667 printf("%%%%Page: %zu %zu\n",
668 p->engine.ps.pages + 1,
669 p->engine.ps.pages + 1);
670
671 if ( ! (PS_INLINE & p->engine.ps.flags)) {
672 ps_printf(p, "%zu %zu moveto\n(",
673 AFM2PNT(p, p->engine.ps.pscol),
674 AFM2PNT(p, p->engine.ps.psrow));
675 p->engine.ps.flags |= PS_INLINE;
676 p->engine.ps.flags &= ~PS_NEWPAGE;
677 }
678
679 assert( ! (PS_NEWPAGE & p->engine.ps.flags));
680
681 /*
682 * We need to escape these characters as per the PostScript
683 * specification. We would also escape non-graphable characters
684 * (like tabs), but none of them would get to this point and
685 * it's superfluous to abort() on them.
686 */
687
688 switch (c) {
689 case ('('):
690 /* FALLTHROUGH */
691 case (')'):
692 /* FALLTHROUGH */
693 case ('\\'):
694 ps_putchar(p, '\\');
695 break;
696 default:
697 break;
698 }
699
700 /* Write the character and adjust where we are on the page. */
701
702 f = (int)p->engine.ps.lastf;
703
704 if (c <= 32 || (c - 32 > MAXCHAR)) {
705 ps_putchar(p, ' ');
706 p->engine.ps.pscol += fonts[f].gly[0].wx;
707 return;
708 }
709
710 ps_putchar(p, (char)c);
711 c -= 32;
712 p->engine.ps.pscol += fonts[f].gly[c].wx;
713 }
714
715
716 static void
717 ps_pclose(struct termp *p)
718 {
719
720 /*
721 * Spit out that we're exiting a word context (this is a
722 * "partial close" because we don't check the last-char buffer
723 * or anything).
724 */
725
726 if ( ! (PS_INLINE & p->engine.ps.flags))
727 return;
728
729 ps_printf(p, ") show\n");
730 p->engine.ps.flags &= ~PS_INLINE;
731 }
732
733
734 static void
735 ps_fclose(struct termp *p)
736 {
737
738 /*
739 * Strong closure: if we have a last-char, spit it out after
740 * checking that we're in the right font mode. This will of
741 * course open a new scope, if applicable.
742 *
743 * Following this, close out any scope that's open.
744 */
745
746 if ('\0' != p->engine.ps.last) {
747 if (p->engine.ps.lastf != TERMFONT_NONE) {
748 ps_pclose(p);
749 ps_setfont(p, TERMFONT_NONE);
750 }
751 ps_pletter(p, p->engine.ps.last);
752 p->engine.ps.last = '\0';
753 }
754
755 if ( ! (PS_INLINE & p->engine.ps.flags))
756 return;
757
758 ps_pclose(p);
759 }
760
761
762 static void
763 ps_letter(struct termp *p, char c)
764 {
765 char cc;
766
767 /*
768 * State machine dictates whether to buffer the last character
769 * or not. Basically, encoded words are detected by checking if
770 * we're an "8" and switching on the buffer. Then we put "8" in
771 * our buffer, and on the next charater, flush both character
772 * and buffer. Thus, "regular" words are detected by having a
773 * regular character and a regular buffer character.
774 */
775
776 if ('\0' == p->engine.ps.last) {
777 assert(8 != c);
778 p->engine.ps.last = c;
779 return;
780 } else if (8 == p->engine.ps.last) {
781 assert(8 != c);
782 p->engine.ps.last = '\0';
783 } else if (8 == c) {
784 assert(8 != p->engine.ps.last);
785 if ('_' == p->engine.ps.last) {
786 if (p->engine.ps.lastf != TERMFONT_UNDER) {
787 ps_pclose(p);
788 ps_setfont(p, TERMFONT_UNDER);
789 }
790 } else if (p->engine.ps.lastf != TERMFONT_BOLD) {
791 ps_pclose(p);
792 ps_setfont(p, TERMFONT_BOLD);
793 }
794 p->engine.ps.last = c;
795 return;
796 } else {
797 if (p->engine.ps.lastf != TERMFONT_NONE) {
798 ps_pclose(p);
799 ps_setfont(p, TERMFONT_NONE);
800 }
801 cc = p->engine.ps.last;
802 p->engine.ps.last = c;
803 c = cc;
804 }
805
806 ps_pletter(p, c);
807 }
808
809
810 static void
811 ps_advance(struct termp *p, size_t len)
812 {
813
814 /*
815 * Advance some spaces. This can probably be made smarter,
816 * i.e., to have multiple space-separated words in the same
817 * scope, but this is easier: just close out the current scope
818 * and readjust our column settings.
819 */
820
821 ps_fclose(p);
822 p->engine.ps.pscol += len;
823 }
824
825
826 static void
827 ps_endline(struct termp *p)
828 {
829
830 /* Close out any scopes we have open: we're at eoln. */
831
832 ps_fclose(p);
833
834 /*
835 * If we're in the margin, don't try to recalculate our current
836 * row. XXX: if the column tries to be fancy with multiple
837 * lines, we'll do nasty stuff.
838 */
839
840 if (PS_MARGINS & p->engine.ps.flags)
841 return;
842
843 /* Left-justify. */
844
845 p->engine.ps.pscol = p->engine.ps.left;
846
847 /* If we haven't printed anything, return. */
848
849 if (PS_NEWPAGE & p->engine.ps.flags)
850 return;
851
852 /*
853 * Put us down a line. If we're at the page bottom, spit out a
854 * showpage and restart our row.
855 */
856
857 if (p->engine.ps.psrow >= p->engine.ps.lineheight +
858 p->engine.ps.bottom) {
859 p->engine.ps.psrow -= p->engine.ps.lineheight;
860 return;
861 }
862
863 assert(p->engine.ps.psmarg && p->engine.ps.psmarg[0]);
864 printf("%s", p->engine.ps.psmarg);
865 printf("showpage\n");
866 p->engine.ps.pages++;
867 p->engine.ps.psrow = p->engine.ps.top;
868 assert( ! (PS_NEWPAGE & p->engine.ps.flags));
869 p->engine.ps.flags |= PS_NEWPAGE;
870 }
871
872
873 static void
874 ps_setfont(struct termp *p, enum termfont f)
875 {
876
877 assert(f < TERMFONT__MAX);
878 ps_printf(p, "/%s %zu selectfont\n",
879 fonts[(int)f].name, p->engine.ps.scale);
880 p->engine.ps.lastf = f;
881 }
882
883
884 /* ARGSUSED */
885 static size_t
886 ps_width(const struct termp *p, char c)
887 {
888
889 if (c <= 32 || c - 32 >= MAXCHAR)
890 return(fonts[(int)TERMFONT_NONE].gly[0].wx);
891
892 c -= 32;
893 return(fonts[(int)TERMFONT_NONE].gly[(int)c].wx);
894 }
895
896
897 static double
898 ps_hspan(const struct termp *p, const struct roffsu *su)
899 {
900 double r;
901
902 /*
903 * All of these measurements are derived by converting from the
904 * native measurement to AFM units.
905 */
906
907 switch (su->unit) {
908 case (SCALE_CM):
909 r = PNT2AFM(p, su->scale * 28.34);
910 break;
911 case (SCALE_IN):
912 r = PNT2AFM(p, su->scale * 72);
913 break;
914 case (SCALE_PC):
915 r = PNT2AFM(p, su->scale * 12);
916 break;
917 case (SCALE_PT):
918 r = PNT2AFM(p, su->scale * 100);
919 break;
920 case (SCALE_EM):
921 r = su->scale *
922 fonts[(int)TERMFONT_NONE].gly[109 - 32].wx;
923 break;
924 case (SCALE_MM):
925 r = PNT2AFM(p, su->scale * 2.834);
926 break;
927 case (SCALE_EN):
928 r = su->scale *
929 fonts[(int)TERMFONT_NONE].gly[110 - 32].wx;
930 break;
931 case (SCALE_VS):
932 r = su->scale * p->engine.ps.lineheight;
933 break;
934 default:
935 r = su->scale;
936 break;
937 }
938
939 return(r);
940 }
941