ren: disable ligatures and pairwise kerning when interpolating diverted text
[neatroff.git] / out.c
blob7b22ee4f41bc95a75c75260072c317dacaae9d31
1 #include <ctype.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include "roff.h"
8 static int out_nl = 1;
10 /* output troff code; newlines may appear only at the end of s */
11 static void out_out(char *s, va_list ap)
13 out_nl = strchr(s, '\n') != NULL;
14 vfprintf(stdout, s, ap);
17 /* output troff code; no preceding newline is necessary */
18 static void outnn(char *s, ...)
20 va_list ap;
21 va_start(ap, s);
22 out_out(s, ap);
23 va_end(ap);
26 /* output troff cmd; should appear after a newline */
27 void out(char *s, ...)
29 va_list ap;
30 if (!out_nl)
31 outnn("\n");
32 va_start(ap, s);
33 out_out(s, ap);
34 va_end(ap);
37 static int o_s = 10;
38 static int o_f = 1;
39 static int o_m = 0;
41 static void out_ps(int n)
43 if (o_s != n) {
44 o_s = n;
45 out("s%d\n", o_s);
49 static void out_ft(int n)
51 if (n >= 0 && o_f != n) {
52 o_f = n;
53 out("f%d\n", o_f);
57 static void out_clr(int n)
59 if (n >= 0 && o_m != n) {
60 o_m = n;
61 out("m%s\n", clr_str(o_m));
65 static int tok_num(char **s, int scale)
67 char tok[ILNLEN];
68 char *d = tok;
69 while (isspace(**s))
70 (*s)++;
71 while (**s && !isspace(**s))
72 *d++ = *(*s)++;
73 *d = '\0';
74 return eval(tok, scale);
77 static void out_draw(char *s)
79 int c = *s++;
80 out("D%c", c);
81 switch (tolower(c)) {
82 case 'l':
83 outnn(" %d", tok_num(&s, 'm'));
84 outnn(" %d", tok_num(&s, 'v'));
85 outnn(" ."); /* dpost requires this */
86 break;
87 case 'c':
88 outnn(" %d", tok_num(&s, 'm'));
89 break;
90 case 'e':
91 outnn(" %d", tok_num(&s, 'm'));
92 outnn(" %d", tok_num(&s, 'v'));
93 break;
94 case 'a':
95 outnn(" %d", tok_num(&s, 'm'));
96 outnn(" %d", tok_num(&s, 'v'));
97 outnn(" %d", tok_num(&s, 'm'));
98 outnn(" %d", tok_num(&s, 'v'));
99 break;
100 case '~':
101 case 'p':
102 outnn(" %d", tok_num(&s, 'm'));
103 outnn(" %d", tok_num(&s, 'v'));
104 while (*s) {
105 outnn(" %d", tok_num(&s, 'm'));
106 outnn(" %d", tok_num(&s, 'v'));
108 break;
110 outnn("\n");
113 static void outg(char *c)
115 if (utf8len((unsigned char) c[0]) == strlen(c))
116 outnn("c%s%s", c, c[1] ? "\n" : "");
117 else
118 out("C%s\n", c[0] == c_ec && c[1] == '(' ? c + 2 : c);
121 static void outc(char *c)
123 struct glyph *g = dev_glyph(c, o_f);
124 int cwid = charwid(o_f, o_s, g ? g->wid : SC_DW);
125 int bwid = charwid_base(o_f, o_s, g ? g->wid : SC_DW);
126 if (dev_getcs(o_f))
127 outnn("h%d", (cwid - bwid) / 2);
128 outg(c);
129 if (dev_getbd(o_f)) {
130 outnn("h%d", dev_getbd(o_f) - 1);
131 outg(c);
132 outnn("h%d", -dev_getbd(o_f) + 1);
134 if (dev_getcs(o_f))
135 outnn("h%d", -(cwid - bwid) / 2);
136 outnn("h%d", cwid);
139 void out_line(char *s)
141 char c[ILNLEN + GNLEN * 4];
142 int t;
143 while ((t = escread(&s, c)) >= 0) {
144 if (!t) {
145 if (c[0] == c_ni || (c[0] == '\\' && c[1] == '\\')) {
146 c[0] = c[1];
147 c[1] = '\0';
149 if (c[0] == '\t' || c[0] == '\x01' || !strcmp(c_hc, c))
150 continue;
151 outc(tr_map(c));
152 continue;
154 switch (t) {
155 case 'D':
156 out_draw(c);
157 break;
158 case 'f':
159 out_ft(dev_pos(c));
160 break;
161 case 'h':
162 outnn("h%d", eval(c, 'm'));
163 break;
164 case 'm':
165 if (!n_cp)
166 out_clr(clr_get(c));
167 break;
168 case 's':
169 out_ps(eval_re(c, o_s, '\0'));
170 break;
171 case 'v':
172 outnn("v%d", eval(c, 'v'));
173 break;
174 case 'X':
175 out("x X %s\n", c);
176 break;