1 /* generating troff output */
11 /* output troff code; newlines may appear only at the end of s */
12 static void out_out(char *s
, va_list ap
)
14 out_nl
= strchr(s
, '\n') != NULL
;
15 vfprintf(stdout
, s
, ap
);
18 /* output troff code; no preceding newline is necessary */
19 static void outnn(char *s
, ...)
27 /* output troff cmd; should appear after a newline */
28 void out(char *s
, ...)
42 static void out_ps(int n
)
50 static void out_ft(int n
)
52 if (n
>= 0 && o_f
!= n
) {
58 static void out_clr(int n
)
60 if (n
>= 0 && o_m
!= n
) {
62 out("m%s\n", clr_str(o_m
));
66 static int tok_num(char **s
, int scale
)
72 while (**s
&& !isspace(**s
))
75 return eval(tok
, scale
);
78 static void out_draw(char *s
)
84 outnn(" %d", tok_num(&s
, 'm'));
85 outnn(" %d", tok_num(&s
, 'v'));
86 outnn(" ."); /* dpost requires this */
89 outnn(" %d", tok_num(&s
, 'm'));
92 outnn(" %d", tok_num(&s
, 'm'));
93 outnn(" %d", tok_num(&s
, 'v'));
96 outnn(" %d", tok_num(&s
, 'm'));
97 outnn(" %d", tok_num(&s
, 'v'));
98 outnn(" %d", tok_num(&s
, 'm'));
99 outnn(" %d", tok_num(&s
, 'v'));
103 outnn(" %d", tok_num(&s
, 'm'));
104 outnn(" %d", tok_num(&s
, 'v'));
106 outnn(" %d", tok_num(&s
, 'm'));
107 outnn(" %d", tok_num(&s
, 'v'));
114 static void outg(char *c
, int fn
, int sz
)
121 outnn("c%s%s", c
, c
[1] ? "\n" : "");
123 out("C%s\n", c
[0] == c_ec
&& c
[1] == '(' ? c
+ 2 : c
);
128 static void outc(char *c
)
130 struct glyph
*g
= dev_glyph(c
, o_f
);
131 struct font
*fn
= dev_font(o_f
);
135 cwid
= font_gwid(g
->font
, dev_font(o_f
), o_s
, g
->wid
);
136 bwid
= font_wid(g
->font
, o_s
, g
->wid
);
137 if (font_mapped(g
->font
, c
))
140 outnn("h%d", (cwid
- bwid
) / 2);
141 outg(c
, dev_fontpos(g
->font
), font_zoom(g
->font
, o_s
));
142 if (font_getbd(fn
)) {
143 outnn("h%d", font_getbd(fn
) - 1);
144 outg(c
, dev_fontpos(g
->font
), font_zoom(g
->font
, o_s
));
145 outnn("h%d", -font_getbd(fn
) + 1);
148 outnn("h%d", -(cwid
- bwid
) / 2);
152 void out_line(char *s
)
154 char c
[ILNLEN
+ GNLEN
* 4];
156 while ((t
= escread(&s
, c
)) >= 0) {
158 if (c
[0] == c_ni
|| (c
[0] == '\\' && c
[1] == '\\')) {
162 if (c
[0] == '\t' || c
[0] == '\x01' || c_hymark(c
))
175 outnn("h%d", eval(c
, 'm'));
185 outnn("v%d", eval(c
, 'v'));