]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.282 2020/09/02 16:40:36 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 #include <sys/types.h>
30 #include "mandoc_aux.h"
35 static size_t cond_width(const struct termp
*, int, int *);
36 static void adjbuf(struct termp_col
*, size_t);
37 static void bufferc(struct termp
*, char);
38 static void encode(struct termp
*, const char *, size_t);
39 static void encode1(struct termp
*, int);
40 static void endline(struct termp
*);
41 static void term_field(struct termp
*, size_t, size_t);
42 static void term_fill(struct termp
*, size_t *, size_t *,
47 term_setcol(struct termp
*p
, size_t maxtcol
)
49 if (maxtcol
> p
->maxtcol
) {
50 p
->tcols
= mandoc_recallocarray(p
->tcols
,
51 p
->maxtcol
, maxtcol
, sizeof(*p
->tcols
));
54 p
->lasttcol
= maxtcol
- 1;
59 term_free(struct termp
*p
)
61 for (p
->tcol
= p
->tcols
; p
->tcol
< p
->tcols
+ p
->maxtcol
; p
->tcol
++)
69 term_begin(struct termp
*p
, term_margin head
,
70 term_margin foot
, const struct roff_meta
*arg
)
80 term_end(struct termp
*p
)
87 * Flush a chunk of text. By default, break the output line each time
88 * the right margin is reached, and continue output on the next line
89 * at the same offset as the chunk itself. By default, also break the
90 * output line at the end of the chunk. There are many flags modifying
91 * this behaviour, see the comments in the body of the function.
94 term_flushln(struct termp
*p
)
96 size_t vbl
; /* Number of blanks to prepend to the output. */
97 size_t vbr
; /* Actual visual position of the end of field. */
98 size_t vfield
; /* Desired visual field width. */
99 size_t vtarget
; /* Desired visual position of the right margin. */
100 size_t ic
; /* Character position in the input buffer. */
101 size_t nbr
; /* Number of characters to print in this field. */
104 * Normally, start writing at the left margin, but with the
105 * NOPAD flag, start writing at the current position instead.
108 vbl
= (p
->flags
& TERMP_NOPAD
) || p
->tcol
->offset
< p
->viscol
?
109 0 : p
->tcol
->offset
- p
->viscol
;
110 if (p
->minbl
&& vbl
< p
->minbl
)
113 if ((p
->flags
& TERMP_MULTICOL
) == 0)
116 /* Loop over output lines. */
119 vfield
= p
->tcol
->rmargin
> p
->viscol
+ vbl
?
120 p
->tcol
->rmargin
- p
->viscol
- vbl
: 0;
123 * Normally, break the line at the the right margin
124 * of the field, but with the NOBREAK flag, only
125 * break it at the max right margin of the screen,
126 * and with the BRNEVER flag, never break it at all.
129 vtarget
= (p
->flags
& TERMP_NOBREAK
) == 0 ? vfield
:
130 p
->maxrmargin
> p
->viscol
+ vbl
?
131 p
->maxrmargin
- p
->viscol
- vbl
: 0;
134 * Figure out how much text will fit in the field.
135 * If there is whitespace only, print nothing.
138 term_fill(p
, &nbr
, &vbr
,
139 p
->flags
& TERMP_BRNEVER
? SIZE_MAX
: vtarget
);
144 * With the CENTER or RIGHT flag, increase the indentation
145 * to center the text between the left and right margins
146 * or to adjust it to the right margin, respectively.
150 if (p
->flags
& TERMP_CENTER
)
151 vbl
+= (vtarget
- vbr
) / 2;
152 else if (p
->flags
& TERMP_RIGHT
)
153 vbl
+= vtarget
- vbr
;
156 /* Finally, print the field content. */
158 term_field(p
, vbl
, nbr
);
161 * If there is no text left in the field, exit the loop.
162 * If the BRTRSP flag is set, consider trailing
163 * whitespace significant when deciding whether
164 * the field fits or not.
167 for (ic
= p
->tcol
->col
; ic
< p
->tcol
->lastcol
; ic
++) {
168 switch (p
->tcol
->buf
[ic
]) {
170 if (p
->flags
& TERMP_BRTRSP
)
171 vbr
= term_tab_next(vbr
);
174 if (p
->flags
& TERMP_BRTRSP
)
175 vbr
+= (*p
->width
)(p
, ' ');
185 if (ic
== p
->tcol
->lastcol
)
189 * At the location of an automtic line break, input
190 * space characters are consumed by the line break.
193 while (p
->tcol
->col
< p
->tcol
->lastcol
&&
194 p
->tcol
->buf
[p
->tcol
->col
] == ' ')
198 * In multi-column mode, leave the rest of the text
199 * in the buffer to be handled by a subsequent
200 * invocation, such that the other columns of the
201 * table can be handled first.
202 * In single-column mode, simply break the line.
205 if (p
->flags
& TERMP_MULTICOL
)
212 * Normally, start the next line at the same indentation
213 * as this one, but with the BRIND flag, start it at the
214 * right margin instead. This is used together with
215 * NOBREAK for the tags in various kinds of tagged lists.
218 vbl
= p
->flags
& TERMP_BRIND
?
219 p
->tcol
->rmargin
: p
->tcol
->offset
;
222 /* Reset output state in preparation for the next field. */
224 p
->col
= p
->tcol
->col
= p
->tcol
->lastcol
= 0;
225 p
->minbl
= p
->trailspace
;
226 p
->flags
&= ~(TERMP_BACKAFTER
| TERMP_BACKBEFORE
| TERMP_NOPAD
);
228 if (p
->flags
& TERMP_MULTICOL
)
232 * The HANG flag means that the next field
233 * always follows on the same line.
234 * The NOBREAK flag means that the next field
235 * follows on the same line unless the field was overrun.
236 * Normally, break the line at the end of each field.
239 if ((p
->flags
& TERMP_HANG
) == 0 &&
240 ((p
->flags
& TERMP_NOBREAK
) == 0 ||
241 vbr
+ term_len(p
, p
->trailspace
) > vfield
))
246 * Store the number of input characters to print in this field in *nbr
247 * and their total visual width to print in *vbr.
248 * If there is only whitespace in the field, both remain zero.
249 * The desired visual width of the field is provided by vtarget.
250 * If the first word is longer, the field will be overrun.
253 term_fill(struct termp
*p
, size_t *nbr
, size_t *vbr
, size_t vtarget
)
255 size_t ic
; /* Character position in the input buffer. */
256 size_t vis
; /* Visual position of the current character. */
257 size_t vn
; /* Visual position of the next character. */
258 int breakline
; /* Break at the end of this word. */
259 int graph
; /* Last character was non-blank. */
261 *nbr
= *vbr
= vis
= 0;
262 breakline
= graph
= 0;
263 for (ic
= p
->tcol
->col
; ic
< p
->tcol
->lastcol
; ic
++) {
264 switch (p
->tcol
->buf
[ic
]) {
265 case '\b': /* Escape \o (overstrike) or backspace markup. */
267 vis
-= (*p
->width
)(p
, p
->tcol
->buf
[ic
- 1]);
270 case '\t': /* Normal ASCII whitespace. */
272 case ASCII_BREAK
: /* Escape \: (breakpoint). */
273 switch (p
->tcol
->buf
[ic
]) {
275 vn
= term_tab_next(vis
);
278 vn
= vis
+ (*p
->width
)(p
, ' ');
286 /* Can break at the end of a word. */
287 if (breakline
|| vn
> vtarget
)
297 case '\n': /* Escape \p (break at the end of the word). */
301 case ASCII_HYPH
: /* Breakable hyphen. */
304 * We are about to decide whether to break the
305 * line or not, so we no longer need this hyphen
306 * to be marked as breakable. Put back a real
307 * hyphen such that we get the correct width.
309 p
->tcol
->buf
[ic
] = '-';
310 vis
+= (*p
->width
)(p
, '-');
319 case ASCII_NBRSP
: /* Non-breakable space. */
320 p
->tcol
->buf
[ic
] = ' ';
322 default: /* Printable character. */
324 vis
+= (*p
->width
)(p
, p
->tcol
->buf
[ic
]);
325 if (vis
> vtarget
&& *nbr
> 0)
333 * If the last word extends to the end of the field without any
334 * trailing whitespace, the loop could not check yet whether it
335 * can remain on this line. So do the check now.
338 if (graph
&& (vis
<= vtarget
|| *nbr
== 0)) {
345 * Print the contents of one field
346 * with an indentation of vbl visual columns,
347 * and an input string length of nbr characters.
350 term_field(struct termp
*p
, size_t vbl
, size_t nbr
)
352 size_t ic
; /* Character position in the input buffer. */
353 size_t vis
; /* Visual position of the current character. */
354 size_t dv
; /* Visual width of the current character. */
355 size_t vn
; /* Visual position of the next character. */
358 for (ic
= p
->tcol
->col
; ic
< nbr
; ic
++) {
361 * To avoid the printing of trailing whitespace,
362 * do not print whitespace right away, only count it.
365 switch (p
->tcol
->buf
[ic
]) {
370 vn
= term_tab_next(vis
);
376 dv
= (*p
->width
)(p
, ' ');
385 * We found a non-blank character to print,
386 * so write preceding white space now.
390 (*p
->advance
)(p
, vbl
);
395 /* Print the character and adjust the visual position. */
397 (*p
->letter
)(p
, p
->tcol
->buf
[ic
]);
398 if (p
->tcol
->buf
[ic
] == '\b') {
399 dv
= (*p
->width
)(p
, p
->tcol
->buf
[ic
- 1]);
403 dv
= (*p
->width
)(p
, p
->tcol
->buf
[ic
]);
412 endline(struct termp
*p
)
414 if ((p
->flags
& (TERMP_NEWMC
| TERMP_ENDMC
)) == TERMP_ENDMC
) {
416 p
->flags
&= ~TERMP_ENDMC
;
419 if (p
->viscol
&& p
->maxrmargin
>= p
->viscol
)
420 (*p
->advance
)(p
, p
->maxrmargin
- p
->viscol
+ 1);
421 p
->flags
|= TERMP_NOBUF
| TERMP_NOSPACE
;
423 p
->flags
&= ~(TERMP_NOBUF
| TERMP_NEWMC
);
431 * A newline only breaks an existing line; it won't assert vertical
432 * space. All data in the output buffer is flushed prior to the newline
436 term_newln(struct termp
*p
)
439 p
->flags
|= TERMP_NOSPACE
;
440 if (p
->tcol
->lastcol
|| p
->viscol
)
445 * Asserts a vertical space (a full, empty line-break between lines).
446 * Note that if used twice, this will cause two blank spaces and so on.
447 * All data in the output buffer is flushed prior to the newline
451 term_vspace(struct termp
*p
)
463 /* Swap current and previous font; for \fP and .ft P */
465 term_fontlast(struct termp
*p
)
470 p
->fontl
= p
->fontq
[p
->fonti
];
471 p
->fontq
[p
->fonti
] = f
;
474 /* Set font, save current, discard previous; for \f, .ft, .B etc. */
476 term_fontrepl(struct termp
*p
, enum termfont f
)
479 p
->fontl
= p
->fontq
[p
->fonti
];
480 p
->fontq
[p
->fonti
] = f
;
483 /* Set font, save previous. */
485 term_fontpush(struct termp
*p
, enum termfont f
)
488 p
->fontl
= p
->fontq
[p
->fonti
];
489 if (++p
->fonti
== p
->fontsz
) {
491 p
->fontq
= mandoc_reallocarray(p
->fontq
,
492 p
->fontsz
, sizeof(*p
->fontq
));
494 p
->fontq
[p
->fonti
] = f
;
497 /* Flush to make the saved pointer current again. */
499 term_fontpopq(struct termp
*p
, int i
)
507 /* Pop one font off the stack. */
509 term_fontpop(struct termp
*p
)
517 * Handle pwords, partial words, which may be either a single word or a
518 * phrase that cannot be broken down (such as a literal string). This
519 * handles word styling.
522 term_word(struct termp
*p
, const char *word
)
525 const char nbrsp
[2] = { ASCII_NBRSP
, 0 };
526 const char *seq
, *cp
;
528 size_t csz
, lsz
, ssz
;
531 if ((p
->flags
& TERMP_NOBUF
) == 0) {
532 if ((p
->flags
& TERMP_NOSPACE
) == 0) {
533 if ((p
->flags
& TERMP_KEEP
) == 0) {
535 if (p
->flags
& TERMP_SENTENCE
)
538 bufferc(p
, ASCII_NBRSP
);
540 if (p
->flags
& TERMP_PREKEEP
)
541 p
->flags
|= TERMP_KEEP
;
542 if (p
->flags
& TERMP_NONOSPACE
)
543 p
->flags
|= TERMP_NOSPACE
;
545 p
->flags
&= ~TERMP_NOSPACE
;
546 p
->flags
&= ~(TERMP_SENTENCE
| TERMP_NONEWLINE
);
550 while ('\0' != *word
) {
552 if (TERMP_NBRWORD
& p
->flags
) {
558 ssz
= strcspn(word
, "\\ ");
560 ssz
= strcspn(word
, "\\");
561 encode(p
, word
, ssz
);
567 esc
= mandoc_escape(&word
, &seq
, &sz
);
570 uc
= mchars_num2uc(seq
+ 1, sz
- 1);
572 case ESCAPE_NUMBERED
:
573 uc
= mchars_num2char(seq
, sz
);
578 if (p
->enc
== TERMENC_ASCII
) {
579 cp
= mchars_spec2str(seq
, sz
, &ssz
);
583 uc
= mchars_spec2cp(seq
, sz
);
591 case ESCAPE_FONTBOLD
:
592 term_fontrepl(p
, TERMFONT_BOLD
);
594 case ESCAPE_FONTITALIC
:
595 term_fontrepl(p
, TERMFONT_UNDER
);
598 term_fontrepl(p
, TERMFONT_BI
);
602 case ESCAPE_FONTROMAN
:
603 term_fontrepl(p
, TERMFONT_NONE
);
605 case ESCAPE_FONTPREV
:
612 if (p
->flags
& TERMP_BACKAFTER
)
613 p
->flags
&= ~TERMP_BACKAFTER
;
614 else if (*word
== '\0')
615 p
->flags
|= (TERMP_NOSPACE
| TERMP_NONEWLINE
);
618 if (p
->type
== TERMTYPE_PDF
)
620 else if (p
->type
== TERMTYPE_PS
)
622 else if (p
->enc
== TERMENC_ASCII
)
623 encode(p
, "ascii", 5);
625 encode(p
, "utf8", 4);
633 if (a2roffsu(seq
, &su
, SCALE_EM
) == NULL
)
635 uc
+= term_hen(p
, &su
);
638 bufferc(p
, ASCII_NBRSP
);
639 else if (p
->col
> (size_t)(-uc
))
644 if (p
->tcol
->offset
> (size_t)(-uc
)) {
646 p
->tcol
->offset
+= uc
;
648 p
->ti
-= p
->tcol
->offset
;
654 if ((cp
= a2roffsu(seq
, &su
, SCALE_EM
)) == NULL
)
656 uc
= term_hen(p
, &su
);
658 if (p
->tcol
->rmargin
<= p
->tcol
->offset
)
660 lsz
= p
->tcol
->rmargin
- p
->tcol
->offset
;
665 else if (*cp
== '\\') {
667 esc
= mandoc_escape(&seq
, &cp
, &sz
);
670 uc
= mchars_num2uc(cp
+ 1, sz
- 1);
672 case ESCAPE_NUMBERED
:
673 uc
= mchars_num2char(cp
, sz
);
676 uc
= mchars_spec2cp(cp
, sz
);
687 if (uc
< 0x20 || (uc
> 0x7E && uc
< 0xA0))
689 if (p
->enc
== TERMENC_ASCII
) {
690 cp
= ascii_uc2str(uc
);
691 csz
= term_strlen(p
, cp
);
694 csz
= (*p
->width
)(p
, uc
);
696 if (p
->enc
== TERMENC_ASCII
)
703 case ESCAPE_SKIPCHAR
:
704 p
->flags
|= TERMP_BACKAFTER
;
706 case ESCAPE_OVERSTRIKE
:
710 mandoc_escape(&seq
, NULL
, NULL
);
715 if (p
->flags
& TERMP_BACKBEFORE
)
716 p
->flags
|= TERMP_BACKAFTER
;
718 p
->flags
|= TERMP_BACKBEFORE
;
721 /* Trim trailing backspace/blank pair. */
722 if (p
->tcol
->lastcol
> 2 &&
723 (p
->tcol
->buf
[p
->tcol
->lastcol
- 1] == ' ' ||
724 p
->tcol
->buf
[p
->tcol
->lastcol
- 1] == '\t'))
725 p
->tcol
->lastcol
-= 2;
726 if (p
->col
> p
->tcol
->lastcol
)
727 p
->col
= p
->tcol
->lastcol
;
734 * Common handling for Unicode and numbered
735 * character escape sequences.
738 if (p
->enc
== TERMENC_ASCII
) {
739 cp
= ascii_uc2str(uc
);
740 encode(p
, cp
, strlen(cp
));
742 if ((uc
< 0x20 && uc
!= 0x09) ||
743 (uc
> 0x7E && uc
< 0xA0))
748 p
->flags
&= ~TERMP_NBRWORD
;
752 adjbuf(struct termp_col
*c
, size_t sz
)
756 while (c
->maxcols
<= sz
)
758 c
->buf
= mandoc_reallocarray(c
->buf
, c
->maxcols
, sizeof(*c
->buf
));
762 bufferc(struct termp
*p
, char c
)
764 if (p
->flags
& TERMP_NOBUF
) {
768 if (p
->col
+ 1 >= p
->tcol
->maxcols
)
769 adjbuf(p
->tcol
, p
->col
+ 1);
770 if (p
->tcol
->lastcol
<= p
->col
|| (c
!= ' ' && c
!= ASCII_NBRSP
))
771 p
->tcol
->buf
[p
->col
] = c
;
772 if (p
->tcol
->lastcol
< ++p
->col
)
773 p
->tcol
->lastcol
= p
->col
;
778 * Do this for a single (probably unicode) value.
779 * Does not check for non-decorated glyphs.
782 encode1(struct termp
*p
, int c
)
786 if (p
->flags
& TERMP_NOBUF
) {
791 if (p
->col
+ 7 >= p
->tcol
->maxcols
)
792 adjbuf(p
->tcol
, p
->col
+ 7);
794 f
= (c
== ASCII_HYPH
|| c
> 127 || isgraph(c
)) ?
795 p
->fontq
[p
->fonti
] : TERMFONT_NONE
;
797 if (p
->flags
& TERMP_BACKBEFORE
) {
798 if (p
->tcol
->buf
[p
->col
- 1] == ' ' ||
799 p
->tcol
->buf
[p
->col
- 1] == '\t')
802 p
->tcol
->buf
[p
->col
++] = '\b';
803 p
->flags
&= ~TERMP_BACKBEFORE
;
805 if (f
== TERMFONT_UNDER
|| f
== TERMFONT_BI
) {
806 p
->tcol
->buf
[p
->col
++] = '_';
807 p
->tcol
->buf
[p
->col
++] = '\b';
809 if (f
== TERMFONT_BOLD
|| f
== TERMFONT_BI
) {
811 p
->tcol
->buf
[p
->col
++] = '-';
813 p
->tcol
->buf
[p
->col
++] = c
;
814 p
->tcol
->buf
[p
->col
++] = '\b';
816 if (p
->tcol
->lastcol
<= p
->col
|| (c
!= ' ' && c
!= ASCII_NBRSP
))
817 p
->tcol
->buf
[p
->col
] = c
;
818 if (p
->tcol
->lastcol
< ++p
->col
)
819 p
->tcol
->lastcol
= p
->col
;
820 if (p
->flags
& TERMP_BACKAFTER
) {
821 p
->flags
|= TERMP_BACKBEFORE
;
822 p
->flags
&= ~TERMP_BACKAFTER
;
827 encode(struct termp
*p
, const char *word
, size_t sz
)
831 if (p
->flags
& TERMP_NOBUF
) {
832 for (i
= 0; i
< sz
; i
++)
833 (*p
->letter
)(p
, word
[i
]);
837 if (p
->col
+ 2 + (sz
* 5) >= p
->tcol
->maxcols
)
838 adjbuf(p
->tcol
, p
->col
+ 2 + (sz
* 5));
840 for (i
= 0; i
< sz
; i
++) {
841 if (ASCII_HYPH
== word
[i
] ||
842 isgraph((unsigned char)word
[i
]))
845 if (p
->tcol
->lastcol
<= p
->col
||
846 (word
[i
] != ' ' && word
[i
] != ASCII_NBRSP
))
847 p
->tcol
->buf
[p
->col
] = word
[i
];
851 * Postpone the effect of \z while handling
852 * an overstrike sequence from ascii_uc2str().
855 if (word
[i
] == '\b' &&
856 (p
->flags
& TERMP_BACKBEFORE
)) {
857 p
->flags
&= ~TERMP_BACKBEFORE
;
858 p
->flags
|= TERMP_BACKAFTER
;
862 if (p
->tcol
->lastcol
< p
->col
)
863 p
->tcol
->lastcol
= p
->col
;
867 term_setwidth(struct termp
*p
, const char *wstr
)
887 if (a2roffsu(wstr
, &su
, SCALE_MAX
) != NULL
)
888 width
= term_hspan(p
, &su
);
892 (*p
->setwidth
)(p
, iop
, width
);
896 term_len(const struct termp
*p
, size_t sz
)
899 return (*p
->width
)(p
, ' ') * sz
;
903 cond_width(const struct termp
*p
, int c
, int *skip
)
910 return (*p
->width
)(p
, c
);
914 term_strlen(const struct termp
*p
, const char *cp
)
918 const char *seq
, *rhs
;
920 static const char rej
[] = { '\\', ASCII_NBRSP
, ASCII_HYPH
,
924 * Account for escaped sequences within string length
925 * calculations. This follows the logic in term_word() as we
926 * must calculate the width of produced strings.
931 while ('\0' != *cp
) {
932 rsz
= strcspn(cp
, rej
);
933 for (i
= 0; i
< rsz
; i
++)
934 sz
+= cond_width(p
, *cp
++, &skip
);
940 esc
= mandoc_escape(&cp
, &seq
, &ssz
);
943 uc
= mchars_num2uc(seq
+ 1, ssz
- 1);
945 case ESCAPE_NUMBERED
:
946 uc
= mchars_num2char(seq
, ssz
);
951 if (p
->enc
== TERMENC_ASCII
) {
952 rhs
= mchars_spec2str(seq
, ssz
, &rsz
);
956 uc
= mchars_spec2cp(seq
, ssz
);
958 sz
+= cond_width(p
, uc
, &skip
);
965 if (p
->type
== TERMTYPE_PDF
) {
968 } else if (p
->type
== TERMTYPE_PS
) {
971 } else if (p
->enc
== TERMENC_ASCII
) {
979 case ESCAPE_SKIPCHAR
:
982 case ESCAPE_OVERSTRIKE
:
987 mandoc_escape(&seq
, NULL
, NULL
);
990 i
= (*p
->width
)(p
, *seq
++);
1001 * Common handling for Unicode and numbered
1002 * character escape sequences.
1006 if (p
->enc
== TERMENC_ASCII
) {
1007 rhs
= ascii_uc2str(uc
);
1010 if ((uc
< 0x20 && uc
!= 0x09) ||
1011 (uc
> 0x7E && uc
< 0xA0))
1013 sz
+= cond_width(p
, uc
, &skip
);
1024 * Common handling for all escape sequences
1025 * printing more than one character.
1028 for (i
= 0; i
< rsz
; i
++)
1029 sz
+= (*p
->width
)(p
, *rhs
++);
1032 sz
+= cond_width(p
, ' ', &skip
);
1036 sz
+= cond_width(p
, '-', &skip
);
1048 term_vspan(const struct termp
*p
, const struct roffsu
*su
)
1055 r
= su
->scale
/ 40.0;
1058 r
= su
->scale
* 6.0 / 2.54;
1061 r
= su
->scale
* 65536.0 / 40.0;
1064 r
= su
->scale
* 6.0;
1067 r
= su
->scale
* 0.006;
1073 r
= su
->scale
/ 12.0;
1077 r
= su
->scale
* 0.6;
1085 ri
= r
> 0.0 ? r
+ 0.4995 : r
- 0.4995;
1086 return ri
< 66 ? ri
: 1;
1090 * Convert a scaling width to basic units, rounding towards 0.
1093 term_hspan(const struct termp
*p
, const struct roffsu
*su
)
1096 return (*p
->hspan
)(p
, su
);
1100 * Convert a scaling width to basic units, rounding to closest.
1103 term_hen(const struct termp
*p
, const struct roffsu
*su
)
1107 if ((bu
= (*p
->hspan
)(p
, su
)) >= 0)
1108 return (bu
+ 11) / 24;
1110 return -((-bu
+ 11) / 24);