dpost.ps: increase linewidth to match groff
[troff.git] / tbl / tu.c
blob242fb09ec3d0344d8f53534f227fcdc857756b9f
1 /* tu.c: draws horizontal lines */
2 #include <string.h>
3 #include "t.h"
5 void
6 makeline(int i, int c, int lintype)
8 int cr, type, shortl;
10 type = thish(i, c);
11 if (type == 0)
12 return;
13 shortl = (table[i][c].col[0] == '\\');
14 if (c > 0 && !shortl && thish(i, c - 1) == type)
15 return;
16 if (shortl == 0)
17 for (cr = c; cr < ncol && (ctype(i, cr) == 's' || type == thish(i, cr)); cr++)
19 else
20 for (cr = c + 1; cr < ncol && ctype(i, cr) == 's'; cr++)
22 drawline(i, c, cr - 1, lintype, 0, shortl);
26 void
27 fullwide(int i, int lintype)
29 int cr, cl;
31 if (!pr1403)
32 fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
33 cr = 0;
34 while (cr < ncol) {
35 cl = cr;
36 while (i > 0 && vspand(prev(i), cl, 1))
37 cl++;
38 for (cr = cl; cr < ncol; cr++)
39 if (i > 0 && vspand(prev(i), cr, 1))
40 break;
41 if (cl < ncol)
42 drawline(i, cl, (cr < ncol ? cr - 1 : cr), lintype, 1, 0);
44 fprintf(tabout, "\n");
45 if (!pr1403)
46 fprintf(tabout, ".vs \\n(%du\n", SVS);
50 void
51 drawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
53 char *exhr, *exhl, *lnch;
54 int lcount, ln, linpos, oldpos, nodata;
56 lcount = 0;
57 exhr = exhl = "";
58 switch (lintype) {
59 case '-':
60 lcount = 1;
61 break;
62 case '=':
63 lcount = pr1403 ? 1 : 2;
64 break;
65 case SHORTLINE:
66 lcount = 1;
67 break;
69 if (lcount <= 0)
70 return;
71 nodata = cr - cl >= ncol || noheight || allh(i);
72 if (!nodata)
73 fprintf(tabout, "\\v'-.5m'");
74 for (ln = oldpos = 0; ln < lcount; ln++) {
75 linpos = 2 * ln - lcount + 1;
76 if (linpos != oldpos)
77 fprintf(tabout, "\\v'%dp'", linpos - oldpos);
78 oldpos = linpos;
79 if (shortl == 0) {
80 tohcol(cl);
81 if (lcount > 1) {
82 switch (interv(i, cl)) {
83 case TOP:
84 exhl = ln == 0 ? "1p" : "-1p";
85 break;
86 case BOT:
87 exhl = ln == 1 ? "1p" : "-1p";
88 break;
89 case THRU:
90 exhl = "1p";
91 break;
93 if (exhl[0])
94 fprintf(tabout, "\\h'%s'", exhl);
95 } else if (lcount == 1) {
96 switch (interv(i, cl)) {
97 case TOP:
98 case BOT:
99 exhl = "-1p";
100 break;
101 case THRU:
102 exhl = "1p";
103 break;
105 if (exhl[0])
106 fprintf(tabout, "\\h'%s'", exhl);
108 if (lcount > 1) {
109 switch (interv(i, cr + 1)) {
110 case TOP:
111 exhr = ln == 0 ? "-1p" : "+1p";
112 break;
113 case BOT:
114 exhr = ln == 1 ? "-1p" : "+1p";
115 break;
116 case THRU:
117 exhr = "-1p";
118 break;
120 } else if (lcount == 1) {
121 switch (interv(i, cr + 1)) {
122 case TOP:
123 case BOT:
124 exhr = "+1p";
125 break;
126 case THRU:
127 exhr = "-1p";
128 break;
131 } else
132 fprintf(tabout, "\\h'|\\n(%2su'", reg(cl, CLEFT));
133 fprintf(tabout, "\\s\\n(%d", LSIZE);
134 if (linsize)
135 fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
136 if (shortl)
137 fprintf(tabout, "\\l'|\\n(%2su'", reg(cr, CRIGHT));
138 else
140 lnch = "\\(ul";
141 if (pr1403)
142 lnch = lintype == 2 ? "=" : "\\(ru";
143 if (cr + 1 >= ncol)
144 fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr, lnch);
145 else
146 fprintf(tabout, "\\l'(|\\n(%2su+|\\n(%2su)/2u%s%s'", reg(cr, CRIGHT),
147 reg(cr + 1, CLEFT), exhr, lnch);
149 if (linsize)
150 fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
151 fprintf(tabout, "\\s0");
153 if (oldpos != 0)
154 fprintf(tabout, "\\v'%dp'", -oldpos);
155 if (!nodata)
156 fprintf(tabout, "\\v'+.5m'");
160 void
161 getstop(void)
163 int i, c, k, junk, stopp;
165 stopp = 1;
166 for (i = 0; i < MAXLIN; i++)
167 linestop[i] = 0;
168 for (i = 0; i < nlin; i++)
169 for (c = 0; c < ncol; c++) {
170 k = left(i, c, &junk);
171 if (k >= 0 && linestop[k] == 0)
172 linestop[k] = ++stopp;
174 if (boxflg || allflg || dboxflg)
175 linestop[0] = 1;
180 left(int i, int c, int *lwidp)
182 int kind, li, lj;
183 /* returns -1 if no line to left */
184 /* returns number of line where it starts */
185 /* stores into lwid the kind of line */
186 *lwidp = 0;
187 if (i < 0)
188 return(-1);
189 kind = lefdata(i, c);
190 if (kind == 0)
191 return(-1);
192 if (i + 1 < nlin)
193 if (lefdata(next(i), c) == kind)
194 return(-1);
195 li = i;
196 while (i >= 0 && lefdata(i, c) == kind)
197 i = prev(li = i);
198 if (prev(li) == -1)
199 li = 0;
200 *lwidp = kind;
201 for (lj = i + 1; lj < li; lj++)
202 if (instead[lj] && strcmp(instead[lj], ".TH") == 0)
203 return(li);
204 for (i = i + 1; i < li; i++)
205 if (fullbot[i])
206 li = i;
207 return(li);
212 lefdata(int i, int c)
214 int ck;
216 if (i >= nlin)
217 i = nlin - 1;
218 if (ctype(i, c) == 's') {
219 for (ck = c; ctype(i, ck) == 's'; ck--)
221 if (thish(i, ck) == 0)
222 return(0);
224 i = stynum[i];
225 i = lefline[c][i];
226 if (i > 0)
227 return(i);
228 if (dboxflg && c == 0)
229 return(2);
230 if (allflg)
231 return(1);
232 if (boxflg && c == 0)
233 return(1);
234 return(0);
239 next(int i)
241 while (i + 1 < nlin) {
242 i++;
243 if (!fullbot[i] && !instead[i])
244 break;
246 return(i);
251 prev(int i)
253 while (--i >= 0 && (fullbot[i] || instead[i]))
255 return(i);