]> git.cameronkatri.com Git - mandoc.git/blob - term.c
To make the code more readable, delete 283 /* FALLTHROUGH */ comments
[mandoc.git] / term.c
1 /* $Id: term.c,v 1.253 2015/10/12 00:08:16 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "mandoc.h"
29 #include "mandoc_aux.h"
30 #include "out.h"
31 #include "term.h"
32 #include "main.h"
33
34 static size_t cond_width(const struct termp *, int, int *);
35 static void adjbuf(struct termp *p, size_t);
36 static void bufferc(struct termp *, char);
37 static void encode(struct termp *, const char *, size_t);
38 static void encode1(struct termp *, int);
39
40
41 void
42 term_free(struct termp *p)
43 {
44
45 free(p->buf);
46 free(p->fontq);
47 free(p);
48 }
49
50 void
51 term_begin(struct termp *p, term_margin head,
52 term_margin foot, const struct roff_meta *arg)
53 {
54
55 p->headf = head;
56 p->footf = foot;
57 p->argf = arg;
58 (*p->begin)(p);
59 }
60
61 void
62 term_end(struct termp *p)
63 {
64
65 (*p->end)(p);
66 }
67
68 /*
69 * Flush a chunk of text. By default, break the output line each time
70 * the right margin is reached, and continue output on the next line
71 * at the same offset as the chunk itself. By default, also break the
72 * output line at the end of the chunk.
73 * The following flags may be specified:
74 *
75 * - TERMP_NOBREAK: Do not break the output line at the right margin,
76 * but only at the max right margin. Also, do not break the output
77 * line at the end of the chunk, such that the next call can pad to
78 * the next column. However, if less than p->trailspace blanks,
79 * which can be 0, 1, or 2, remain to the right margin, the line
80 * will be broken.
81 * - TERMP_BRTRSP: Consider trailing whitespace significant
82 * when deciding whether the chunk fits or not.
83 * - TERMP_BRIND: If the chunk does not fit and the output line has
84 * to be broken, start the next line at the right margin instead
85 * of at the offset. Used together with TERMP_NOBREAK for the tags
86 * in various kinds of tagged lists.
87 * - TERMP_DANGLE: Do not break the output line at the right margin,
88 * append the next chunk after it even if this one is too long.
89 * To be used together with TERMP_NOBREAK.
90 * - TERMP_HANG: Like TERMP_DANGLE, and also suppress padding before
91 * the next chunk if this column is not full.
92 */
93 void
94 term_flushln(struct termp *p)
95 {
96 size_t i; /* current input position in p->buf */
97 int ntab; /* number of tabs to prepend */
98 size_t vis; /* current visual position on output */
99 size_t vbl; /* number of blanks to prepend to output */
100 size_t vend; /* end of word visual position on output */
101 size_t bp; /* visual right border position */
102 size_t dv; /* temporary for visual pos calculations */
103 size_t j; /* temporary loop index for p->buf */
104 size_t jhy; /* last hyph before overflow w/r/t j */
105 size_t maxvis; /* output position of visible boundary */
106
107 /*
108 * First, establish the maximum columns of "visible" content.
109 * This is usually the difference between the right-margin and
110 * an indentation, but can be, for tagged lists or columns, a
111 * small set of values.
112 *
113 * The following unsigned-signed subtractions look strange,
114 * but they are actually correct. If the int p->overstep
115 * is negative, it gets sign extended. Subtracting that
116 * very large size_t effectively adds a small number to dv.
117 */
118 dv = p->rmargin > p->offset ? p->rmargin - p->offset : 0;
119 maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
120
121 if (p->flags & TERMP_NOBREAK) {
122 dv = p->maxrmargin > p->offset ?
123 p->maxrmargin - p->offset : 0;
124 bp = (int)dv > p->overstep ?
125 dv - (size_t)p->overstep : 0;
126 } else
127 bp = maxvis;
128
129 /*
130 * Calculate the required amount of padding.
131 */
132 vbl = p->offset + p->overstep > p->viscol ?
133 p->offset + p->overstep - p->viscol : 0;
134
135 vis = vend = 0;
136 i = 0;
137
138 while (i < p->col) {
139 /*
140 * Handle literal tab characters: collapse all
141 * subsequent tabs into a single huge set of spaces.
142 */
143 ntab = 0;
144 while (i < p->col && '\t' == p->buf[i]) {
145 vend = (vis / p->tabwidth + 1) * p->tabwidth;
146 vbl += vend - vis;
147 vis = vend;
148 ntab++;
149 i++;
150 }
151
152 /*
153 * Count up visible word characters. Control sequences
154 * (starting with the CSI) aren't counted. A space
155 * generates a non-printing word, which is valid (the
156 * space is printed according to regular spacing rules).
157 */
158
159 for (j = i, jhy = 0; j < p->col; j++) {
160 if (' ' == p->buf[j] || '\t' == p->buf[j])
161 break;
162
163 /* Back over the the last printed character. */
164 if (8 == p->buf[j]) {
165 assert(j);
166 vend -= (*p->width)(p, p->buf[j - 1]);
167 continue;
168 }
169
170 /* Regular word. */
171 /* Break at the hyphen point if we overrun. */
172 if (vend > vis && vend < bp &&
173 (ASCII_HYPH == p->buf[j] ||
174 ASCII_BREAK == p->buf[j]))
175 jhy = j;
176
177 /*
178 * Hyphenation now decided, put back a real
179 * hyphen such that we get the correct width.
180 */
181 if (ASCII_HYPH == p->buf[j])
182 p->buf[j] = '-';
183
184 vend += (*p->width)(p, p->buf[j]);
185 }
186
187 /*
188 * Find out whether we would exceed the right margin.
189 * If so, break to the next line.
190 */
191 if (vend > bp && 0 == jhy && vis > 0) {
192 vend -= vis;
193 (*p->endline)(p);
194 p->viscol = 0;
195 if (TERMP_BRIND & p->flags) {
196 vbl = p->rmargin;
197 vend += p->rmargin;
198 vend -= p->offset;
199 } else
200 vbl = p->offset;
201
202 /* use pending tabs on the new line */
203
204 if (0 < ntab)
205 vbl += ntab * p->tabwidth;
206
207 /*
208 * Remove the p->overstep width.
209 * Again, if p->overstep is negative,
210 * sign extension does the right thing.
211 */
212
213 bp += (size_t)p->overstep;
214 p->overstep = 0;
215 }
216
217 /* Write out the [remaining] word. */
218 for ( ; i < p->col; i++) {
219 if (vend > bp && jhy > 0 && i > jhy)
220 break;
221 if ('\t' == p->buf[i])
222 break;
223 if (' ' == p->buf[i]) {
224 j = i;
225 while (i < p->col && ' ' == p->buf[i])
226 i++;
227 dv = (i - j) * (*p->width)(p, ' ');
228 vbl += dv;
229 vend += dv;
230 break;
231 }
232 if (ASCII_NBRSP == p->buf[i]) {
233 vbl += (*p->width)(p, ' ');
234 continue;
235 }
236 if (ASCII_BREAK == p->buf[i])
237 continue;
238
239 /*
240 * Now we definitely know there will be
241 * printable characters to output,
242 * so write preceding white space now.
243 */
244 if (vbl) {
245 (*p->advance)(p, vbl);
246 p->viscol += vbl;
247 vbl = 0;
248 }
249
250 (*p->letter)(p, p->buf[i]);
251 if (8 == p->buf[i])
252 p->viscol -= (*p->width)(p, p->buf[i-1]);
253 else
254 p->viscol += (*p->width)(p, p->buf[i]);
255 }
256 vis = vend;
257 }
258
259 /*
260 * If there was trailing white space, it was not printed;
261 * so reset the cursor position accordingly.
262 */
263 if (vis > vbl)
264 vis -= vbl;
265 else
266 vis = 0;
267
268 p->col = 0;
269 p->overstep = 0;
270 p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
271
272 if ( ! (TERMP_NOBREAK & p->flags)) {
273 p->viscol = 0;
274 (*p->endline)(p);
275 return;
276 }
277
278 if (TERMP_HANG & p->flags) {
279 p->overstep += (int)(p->offset + vis - p->rmargin +
280 p->trailspace * (*p->width)(p, ' '));
281
282 /*
283 * If we have overstepped the margin, temporarily move
284 * it to the right and flag the rest of the line to be
285 * shorter.
286 * If there is a request to keep the columns together,
287 * allow negative overstep when the column is not full.
288 */
289 if (p->trailspace && p->overstep < 0)
290 p->overstep = 0;
291 return;
292
293 } else if (TERMP_DANGLE & p->flags)
294 return;
295
296 /* Trailing whitespace is significant in some columns. */
297 if (vis && vbl && (TERMP_BRTRSP & p->flags))
298 vis += vbl;
299
300 /* If the column was overrun, break the line. */
301 if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) {
302 (*p->endline)(p);
303 p->viscol = 0;
304 }
305 }
306
307 /*
308 * A newline only breaks an existing line; it won't assert vertical
309 * space. All data in the output buffer is flushed prior to the newline
310 * assertion.
311 */
312 void
313 term_newln(struct termp *p)
314 {
315
316 p->flags |= TERMP_NOSPACE;
317 if (p->col || p->viscol)
318 term_flushln(p);
319 }
320
321 /*
322 * Asserts a vertical space (a full, empty line-break between lines).
323 * Note that if used twice, this will cause two blank spaces and so on.
324 * All data in the output buffer is flushed prior to the newline
325 * assertion.
326 */
327 void
328 term_vspace(struct termp *p)
329 {
330
331 term_newln(p);
332 p->viscol = 0;
333 if (0 < p->skipvsp)
334 p->skipvsp--;
335 else
336 (*p->endline)(p);
337 }
338
339 /* Swap current and previous font; for \fP and .ft P */
340 void
341 term_fontlast(struct termp *p)
342 {
343 enum termfont f;
344
345 f = p->fontl;
346 p->fontl = p->fontq[p->fonti];
347 p->fontq[p->fonti] = f;
348 }
349
350 /* Set font, save current, discard previous; for \f, .ft, .B etc. */
351 void
352 term_fontrepl(struct termp *p, enum termfont f)
353 {
354
355 p->fontl = p->fontq[p->fonti];
356 p->fontq[p->fonti] = f;
357 }
358
359 /* Set font, save previous. */
360 void
361 term_fontpush(struct termp *p, enum termfont f)
362 {
363
364 p->fontl = p->fontq[p->fonti];
365 if (++p->fonti == p->fontsz) {
366 p->fontsz += 8;
367 p->fontq = mandoc_reallocarray(p->fontq,
368 p->fontsz, sizeof(enum termfont *));
369 }
370 p->fontq[p->fonti] = f;
371 }
372
373 /* Flush to make the saved pointer current again. */
374 void
375 term_fontpopq(struct termp *p, int i)
376 {
377
378 assert(i >= 0);
379 if (p->fonti > i)
380 p->fonti = i;
381 }
382
383 /* Pop one font off the stack. */
384 void
385 term_fontpop(struct termp *p)
386 {
387
388 assert(p->fonti);
389 p->fonti--;
390 }
391
392 /*
393 * Handle pwords, partial words, which may be either a single word or a
394 * phrase that cannot be broken down (such as a literal string). This
395 * handles word styling.
396 */
397 void
398 term_word(struct termp *p, const char *word)
399 {
400 const char nbrsp[2] = { ASCII_NBRSP, 0 };
401 const char *seq, *cp;
402 int sz, uc;
403 size_t ssz;
404 enum mandoc_esc esc;
405
406 if ( ! (TERMP_NOSPACE & p->flags)) {
407 if ( ! (TERMP_KEEP & p->flags)) {
408 bufferc(p, ' ');
409 if (TERMP_SENTENCE & p->flags)
410 bufferc(p, ' ');
411 } else
412 bufferc(p, ASCII_NBRSP);
413 }
414 if (TERMP_PREKEEP & p->flags)
415 p->flags |= TERMP_KEEP;
416
417 if ( ! (p->flags & TERMP_NONOSPACE))
418 p->flags &= ~TERMP_NOSPACE;
419 else
420 p->flags |= TERMP_NOSPACE;
421
422 p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
423 p->skipvsp = 0;
424
425 while ('\0' != *word) {
426 if ('\\' != *word) {
427 if (TERMP_NBRWORD & p->flags) {
428 if (' ' == *word) {
429 encode(p, nbrsp, 1);
430 word++;
431 continue;
432 }
433 ssz = strcspn(word, "\\ ");
434 } else
435 ssz = strcspn(word, "\\");
436 encode(p, word, ssz);
437 word += (int)ssz;
438 continue;
439 }
440
441 word++;
442 esc = mandoc_escape(&word, &seq, &sz);
443 if (ESCAPE_ERROR == esc)
444 continue;
445
446 switch (esc) {
447 case ESCAPE_UNICODE:
448 uc = mchars_num2uc(seq + 1, sz - 1);
449 break;
450 case ESCAPE_NUMBERED:
451 uc = mchars_num2char(seq, sz);
452 if (uc < 0)
453 continue;
454 break;
455 case ESCAPE_SPECIAL:
456 if (p->enc == TERMENC_ASCII) {
457 cp = mchars_spec2str(p->symtab,
458 seq, sz, &ssz);
459 if (cp != NULL)
460 encode(p, cp, ssz);
461 } else {
462 uc = mchars_spec2cp(p->symtab, seq, sz);
463 if (uc > 0)
464 encode1(p, uc);
465 }
466 continue;
467 case ESCAPE_FONTBOLD:
468 term_fontrepl(p, TERMFONT_BOLD);
469 continue;
470 case ESCAPE_FONTITALIC:
471 term_fontrepl(p, TERMFONT_UNDER);
472 continue;
473 case ESCAPE_FONTBI:
474 term_fontrepl(p, TERMFONT_BI);
475 continue;
476 case ESCAPE_FONT:
477 case ESCAPE_FONTROMAN:
478 term_fontrepl(p, TERMFONT_NONE);
479 continue;
480 case ESCAPE_FONTPREV:
481 term_fontlast(p);
482 continue;
483 case ESCAPE_NOSPACE:
484 if (p->flags & TERMP_BACKAFTER)
485 p->flags &= ~TERMP_BACKAFTER;
486 else if (*word == '\0')
487 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
488 continue;
489 case ESCAPE_SKIPCHAR:
490 p->flags |= TERMP_BACKAFTER;
491 continue;
492 case ESCAPE_OVERSTRIKE:
493 cp = seq + sz;
494 while (seq < cp) {
495 if (*seq == '\\') {
496 mandoc_escape(&seq, NULL, NULL);
497 continue;
498 }
499 encode1(p, *seq++);
500 if (seq < cp) {
501 if (p->flags & TERMP_BACKBEFORE)
502 p->flags |= TERMP_BACKAFTER;
503 else
504 p->flags |= TERMP_BACKBEFORE;
505 }
506 }
507 /* Trim trailing backspace/blank pair. */
508 if (p->col > 2 && p->buf[p->col - 1] == ' ')
509 p->col -= 2;
510 continue;
511 default:
512 continue;
513 }
514
515 /*
516 * Common handling for Unicode and numbered
517 * character escape sequences.
518 */
519
520 if (p->enc == TERMENC_ASCII) {
521 cp = ascii_uc2str(uc);
522 encode(p, cp, strlen(cp));
523 } else {
524 if ((uc < 0x20 && uc != 0x09) ||
525 (uc > 0x7E && uc < 0xA0))
526 uc = 0xFFFD;
527 encode1(p, uc);
528 }
529 }
530 p->flags &= ~TERMP_NBRWORD;
531 }
532
533 static void
534 adjbuf(struct termp *p, size_t sz)
535 {
536
537 if (0 == p->maxcols)
538 p->maxcols = 1024;
539 while (sz >= p->maxcols)
540 p->maxcols <<= 2;
541
542 p->buf = mandoc_reallocarray(p->buf, p->maxcols, sizeof(int));
543 }
544
545 static void
546 bufferc(struct termp *p, char c)
547 {
548
549 if (p->col + 1 >= p->maxcols)
550 adjbuf(p, p->col + 1);
551
552 p->buf[p->col++] = c;
553 }
554
555 /*
556 * See encode().
557 * Do this for a single (probably unicode) value.
558 * Does not check for non-decorated glyphs.
559 */
560 static void
561 encode1(struct termp *p, int c)
562 {
563 enum termfont f;
564
565 if (p->col + 7 >= p->maxcols)
566 adjbuf(p, p->col + 7);
567
568 f = (c == ASCII_HYPH || isgraph(c)) ?
569 p->fontq[p->fonti] : TERMFONT_NONE;
570
571 if (p->flags & TERMP_BACKBEFORE) {
572 if (p->buf[p->col - 1] == ' ')
573 p->col--;
574 else
575 p->buf[p->col++] = 8;
576 p->flags &= ~TERMP_BACKBEFORE;
577 }
578 if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
579 p->buf[p->col++] = '_';
580 p->buf[p->col++] = 8;
581 }
582 if (TERMFONT_BOLD == f || TERMFONT_BI == f) {
583 if (ASCII_HYPH == c)
584 p->buf[p->col++] = '-';
585 else
586 p->buf[p->col++] = c;
587 p->buf[p->col++] = 8;
588 }
589 p->buf[p->col++] = c;
590 if (p->flags & TERMP_BACKAFTER) {
591 p->flags |= TERMP_BACKBEFORE;
592 p->flags &= ~TERMP_BACKAFTER;
593 }
594 }
595
596 static void
597 encode(struct termp *p, const char *word, size_t sz)
598 {
599 size_t i;
600
601 if (p->col + 2 + (sz * 5) >= p->maxcols)
602 adjbuf(p, p->col + 2 + (sz * 5));
603
604 for (i = 0; i < sz; i++) {
605 if (ASCII_HYPH == word[i] ||
606 isgraph((unsigned char)word[i]))
607 encode1(p, word[i]);
608 else
609 p->buf[p->col++] = word[i];
610 }
611 }
612
613 void
614 term_setwidth(struct termp *p, const char *wstr)
615 {
616 struct roffsu su;
617 int iop, width;
618
619 iop = 0;
620 width = 0;
621 if (NULL != wstr) {
622 switch (*wstr) {
623 case '+':
624 iop = 1;
625 wstr++;
626 break;
627 case '-':
628 iop = -1;
629 wstr++;
630 break;
631 default:
632 break;
633 }
634 if (a2roffsu(wstr, &su, SCALE_MAX))
635 width = term_hspan(p, &su);
636 else
637 iop = 0;
638 }
639 (*p->setwidth)(p, iop, width);
640 }
641
642 size_t
643 term_len(const struct termp *p, size_t sz)
644 {
645
646 return (*p->width)(p, ' ') * sz;
647 }
648
649 static size_t
650 cond_width(const struct termp *p, int c, int *skip)
651 {
652
653 if (*skip) {
654 (*skip) = 0;
655 return 0;
656 } else
657 return (*p->width)(p, c);
658 }
659
660 size_t
661 term_strlen(const struct termp *p, const char *cp)
662 {
663 size_t sz, rsz, i;
664 int ssz, skip, uc;
665 const char *seq, *rhs;
666 enum mandoc_esc esc;
667 static const char rej[] = { '\\', ASCII_NBRSP, ASCII_HYPH,
668 ASCII_BREAK, '\0' };
669
670 /*
671 * Account for escaped sequences within string length
672 * calculations. This follows the logic in term_word() as we
673 * must calculate the width of produced strings.
674 */
675
676 sz = 0;
677 skip = 0;
678 while ('\0' != *cp) {
679 rsz = strcspn(cp, rej);
680 for (i = 0; i < rsz; i++)
681 sz += cond_width(p, *cp++, &skip);
682
683 switch (*cp) {
684 case '\\':
685 cp++;
686 esc = mandoc_escape(&cp, &seq, &ssz);
687 if (ESCAPE_ERROR == esc)
688 continue;
689
690 rhs = NULL;
691
692 switch (esc) {
693 case ESCAPE_UNICODE:
694 uc = mchars_num2uc(seq + 1, ssz - 1);
695 break;
696 case ESCAPE_NUMBERED:
697 uc = mchars_num2char(seq, ssz);
698 if (uc < 0)
699 continue;
700 break;
701 case ESCAPE_SPECIAL:
702 if (p->enc == TERMENC_ASCII) {
703 rhs = mchars_spec2str(p->symtab,
704 seq, ssz, &rsz);
705 if (rhs != NULL)
706 break;
707 } else {
708 uc = mchars_spec2cp(p->symtab,
709 seq, ssz);
710 if (uc > 0)
711 sz += cond_width(p, uc, &skip);
712 }
713 continue;
714 case ESCAPE_SKIPCHAR:
715 skip = 1;
716 continue;
717 case ESCAPE_OVERSTRIKE:
718 rsz = 0;
719 rhs = seq + ssz;
720 while (seq < rhs) {
721 if (*seq == '\\') {
722 mandoc_escape(&seq, NULL, NULL);
723 continue;
724 }
725 i = (*p->width)(p, *seq++);
726 if (rsz < i)
727 rsz = i;
728 }
729 sz += rsz;
730 continue;
731 default:
732 continue;
733 }
734
735 /*
736 * Common handling for Unicode and numbered
737 * character escape sequences.
738 */
739
740 if (rhs == NULL) {
741 if (p->enc == TERMENC_ASCII) {
742 rhs = ascii_uc2str(uc);
743 rsz = strlen(rhs);
744 } else {
745 if ((uc < 0x20 && uc != 0x09) ||
746 (uc > 0x7E && uc < 0xA0))
747 uc = 0xFFFD;
748 sz += cond_width(p, uc, &skip);
749 continue;
750 }
751 }
752
753 if (skip) {
754 skip = 0;
755 break;
756 }
757
758 /*
759 * Common handling for all escape sequences
760 * printing more than one character.
761 */
762
763 for (i = 0; i < rsz; i++)
764 sz += (*p->width)(p, *rhs++);
765 break;
766 case ASCII_NBRSP:
767 sz += cond_width(p, ' ', &skip);
768 cp++;
769 break;
770 case ASCII_HYPH:
771 sz += cond_width(p, '-', &skip);
772 cp++;
773 break;
774 default:
775 break;
776 }
777 }
778
779 return sz;
780 }
781
782 int
783 term_vspan(const struct termp *p, const struct roffsu *su)
784 {
785 double r;
786 int ri;
787
788 switch (su->unit) {
789 case SCALE_BU:
790 r = su->scale / 40.0;
791 break;
792 case SCALE_CM:
793 r = su->scale * 6.0 / 2.54;
794 break;
795 case SCALE_FS:
796 r = su->scale * 65536.0 / 40.0;
797 break;
798 case SCALE_IN:
799 r = su->scale * 6.0;
800 break;
801 case SCALE_MM:
802 r = su->scale * 0.006;
803 break;
804 case SCALE_PC:
805 r = su->scale;
806 break;
807 case SCALE_PT:
808 r = su->scale / 12.0;
809 break;
810 case SCALE_EN:
811 case SCALE_EM:
812 r = su->scale * 0.6;
813 break;
814 case SCALE_VS:
815 r = su->scale;
816 break;
817 default:
818 abort();
819 }
820 ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
821 return ri < 66 ? ri : 1;
822 }
823
824 /*
825 * Convert a scaling width to basic units, rounding down.
826 */
827 int
828 term_hspan(const struct termp *p, const struct roffsu *su)
829 {
830
831 return (*p->hspan)(p, su);
832 }