st-boxdraw_v2-0.8.2.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-boxdraw_v2-0.8.2.diff (18550B)
---
1 From 318ae7fe1bd614cb937c8f43d855a1c2e8e93fd4 Mon Sep 17 00:00:00 2001
2 From: "Avi Halachmi (:avih)" <avihpit@yahoo.com>
3 Date: Wed, 26 Dec 2018 14:51:45 +0200
4 Subject: [PATCH] boxdraw_v2: custom render lines/blocks/braille for perfect
5 alignment
6
7 It seems impossible to ensure that blocks and line drawing glyphs
8 align without visible gaps for all combinations of arbitrary font,
9 size and width/height scale factor.
10
11 This commit adds options to render most of the lines/blocks and
12 braille codepoints without using the font such that they align
13 perfectly regardless of font, size or other configuration values.
14
15 Supported codepoints are U+2500 - U+259F except dashes/diagonals,
16 and U28XX.
17
18 The lines/blocks data is stored as 16-bit values at boxdraw_data.h
19
20 boxdraw/braille are independent, disabled by default at config[.def].h
21 ---
22 Makefile | 3 +-
23 boxdraw.c | 194 ++++++++++++++++++++++++++++++++++++++++++++
24 boxdraw_data.h | 214 +++++++++++++++++++++++++++++++++++++++++++++++++
25 config.def.h | 12 +++
26 st.c | 3 +
27 st.h | 10 +++
28 x.c | 21 +++--
29 7 files changed, 451 insertions(+), 6 deletions(-)
30 create mode 100644 boxdraw.c
31 create mode 100644 boxdraw_data.h
32
33 diff --git a/Makefile b/Makefile
34 index 470ac86..6dfa212 100644
35 --- a/Makefile
36 +++ b/Makefile
37 @@ -4,7 +4,7 @@
38
39 include config.mk
40
41 -SRC = st.c x.c
42 +SRC = st.c x.c boxdraw.c
43 OBJ = $(SRC:.c=.o)
44
45 all: options st
46 @@ -23,6 +23,7 @@ config.h:
47
48 st.o: config.h st.h win.h
49 x.o: arg.h config.h st.h win.h
50 +boxdraw.o: config.h st.h boxdraw_data.h
51
52 $(OBJ): config.h config.mk
53
54 diff --git a/boxdraw.c b/boxdraw.c
55 new file mode 100644
56 index 0000000..28a92d0
57 --- /dev/null
58 +++ b/boxdraw.c
59 @@ -0,0 +1,194 @@
60 +/*
61 + * Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
62 + * MIT/X Consortium License
63 + */
64 +
65 +#include <X11/Xft/Xft.h>
66 +#include "st.h"
67 +#include "boxdraw_data.h"
68 +
69 +/* Rounded non-negative integers division of n / d */
70 +#define DIV(n, d) (((n) + (d) / 2) / (d))
71 +
72 +static Display *xdpy;
73 +static Colormap xcmap;
74 +static XftDraw *xd;
75 +static Visual *xvis;
76 +
77 +static void drawbox(int, int, int, int, XftColor *, XftColor *, ushort);
78 +static void drawboxlines(int, int, int, int, XftColor *, ushort);
79 +
80 +/* public API */
81 +
82 +void
83 +boxdraw_xinit(Display *dpy, Colormap cmap, XftDraw *draw, Visual *vis)
84 +{
85 + xdpy = dpy; xcmap = cmap; xd = draw, xvis = vis;
86 +}
87 +
88 +int
89 +isboxdraw(Rune u)
90 +{
91 + Rune block = u & ~0xff;
92 + return (boxdraw && block == 0x2500 && boxdata[(uint8_t)u]) ||
93 + (boxdraw_braille && block == 0x2800);
94 +}
95 +
96 +/* the "index" is actually the entire shape data encoded as ushort */
97 +ushort
98 +boxdrawindex(const Glyph *g)
99 +{
100 + if (boxdraw_braille && (g->u & ~0xff) == 0x2800)
101 + return BRL | (uint8_t)g->u;
102 + if (boxdraw_bold && (g->mode & ATTR_BOLD))
103 + return BDB | boxdata[(uint8_t)g->u];
104 + return boxdata[(uint8_t)g->u];
105 +}
106 +
107 +void
108 +drawboxes(int x, int y, int cw, int ch, XftColor *fg, XftColor *bg,
109 + const XftGlyphFontSpec *specs, int len)
110 +{
111 + for ( ; len-- > 0; x += cw, specs++)
112 + drawbox(x, y, cw, ch, fg, bg, (ushort)specs->glyph);
113 +}
114 +
115 +/* implementation */
116 +
117 +void
118 +drawbox(int x, int y, int w, int h, XftColor *fg, XftColor *bg, ushort bd)
119 +{
120 + ushort cat = bd & ~(BDB | 0xff); /* mask out bold and data */
121 + if (bd & (BDL | BDA)) {
122 + /* lines (light/double/heavy/arcs) */
123 + drawboxlines(x, y, w, h, fg, bd);
124 +
125 + } else if (cat == BBD) {
126 + /* lower (8-X)/8 block */
127 + int d = DIV((uint8_t)bd * h, 8);
128 + XftDrawRect(xd, fg, x, y + d, w, h - d);
129 +
130 + } else if (cat == BBU) {
131 + /* upper X/8 block */
132 + XftDrawRect(xd, fg, x, y, w, DIV((uint8_t)bd * h, 8));
133 +
134 + } else if (cat == BBL) {
135 + /* left X/8 block */
136 + XftDrawRect(xd, fg, x, y, DIV((uint8_t)bd * w, 8), h);
137 +
138 + } else if (cat == BBR) {
139 + /* right (8-X)/8 block */
140 + int d = DIV((uint8_t)bd * w, 8);
141 + XftDrawRect(xd, fg, x + d, y, w - d, h);
142 +
143 + } else if (cat == BBQ) {
144 + /* Quadrants */
145 + int w2 = DIV(w, 2), h2 = DIV(h, 2);
146 + if (bd & TL)
147 + XftDrawRect(xd, fg, x, y, w2, h2);
148 + if (bd & TR)
149 + XftDrawRect(xd, fg, x + w2, y, w - w2, h2);
150 + if (bd & BL)
151 + XftDrawRect(xd, fg, x, y + h2, w2, h - h2);
152 + if (bd & BR)
153 + XftDrawRect(xd, fg, x + w2, y + h2, w - w2, h - h2);
154 +
155 + } else if (bd & BBS) {
156 + /* Shades - data is 1/2/3 for 25%/50%/75% alpha, respectively */
157 + int d = (uint8_t)bd;
158 + XftColor xfc;
159 + XRenderColor xrc = { .alpha = 0xffff };
160 +
161 + xrc.red = DIV(fg->color.red * d + bg->color.red * (4 - d), 4);
162 + xrc.green = DIV(fg->color.green * d + bg->color.green * (4 - d), 4);
163 + xrc.blue = DIV(fg->color.blue * d + bg->color.blue * (4 - d), 4);
164 +
165 + XftColorAllocValue(xdpy, xvis, xcmap, &xrc, &xfc);
166 + XftDrawRect(xd, &xfc, x, y, w, h);
167 + XftColorFree(xdpy, xvis, xcmap, &xfc);
168 +
169 + } else if (cat == BRL) {
170 + /* braille, each data bit corresponds to one dot at 2x4 grid */
171 + int w1 = DIV(w, 2);
172 + int h1 = DIV(h, 4), h2 = DIV(h, 2), h3 = DIV(3 * h, 4);
173 +
174 + if (bd & 1) XftDrawRect(xd, fg, x, y, w1, h1);
175 + if (bd & 2) XftDrawRect(xd, fg, x, y + h1, w1, h2 - h1);
176 + if (bd & 4) XftDrawRect(xd, fg, x, y + h2, w1, h3 - h2);
177 + if (bd & 8) XftDrawRect(xd, fg, x + w1, y, w - w1, h1);
178 + if (bd & 16) XftDrawRect(xd, fg, x + w1, y + h1, w - w1, h2 - h1);
179 + if (bd & 32) XftDrawRect(xd, fg, x + w1, y + h2, w - w1, h3 - h2);
180 + if (bd & 64) XftDrawRect(xd, fg, x, y + h3, w1, h - h3);
181 + if (bd & 128) XftDrawRect(xd, fg, x + w1, y + h3, w - w1, h - h3);
182 +
183 + }
184 +}
185 +
186 +void
187 +drawboxlines(int x, int y, int w, int h, XftColor *fg, ushort bd)
188 +{
189 + /* s: stem thickness. width/8 roughly matches underscore thickness. */
190 + /* We draw bold as 1.5 * normal-stem and at least 1px thicker. */
191 + /* doubles draw at least 3px, even when w or h < 3. bold needs 6px. */
192 + int mwh = MIN(w, h);
193 + int base_s = MAX(1, DIV(mwh, 8));
194 + int bold = (bd & BDB) && mwh >= 6; /* possibly ignore boldness */
195 + int s = bold ? MAX(base_s + 1, DIV(3 * base_s, 2)) : base_s;
196 + int w2 = DIV(w - s, 2), h2 = DIV(h - s, 2);
197 + /* the s-by-s square (x + w2, y + h2, s, s) is the center texel. */
198 + /* The base length (per direction till edge) includes this square. */
199 +
200 + int light = bd & (LL | LU | LR | LD);
201 + int double_ = bd & (DL | DU | DR | DD);
202 +
203 + if (light) {
204 + /* d: additional (negative) length to not-draw the center */
205 + /* texel - at arcs and avoid drawing inside (some) doubles */
206 + int arc = bd & BDA;
207 + int multi_light = light & (light - 1);
208 + int multi_double = double_ & (double_ - 1);
209 + /* light crosses double only at DH+LV, DV+LH (ref. shapes) */
210 + int d = arc || (multi_double && !multi_light) ? -s : 0;
211 +
212 + if (bd & LL)
213 + XftDrawRect(xd, fg, x, y + h2, w2 + s + d, s);
214 + if (bd & LU)
215 + XftDrawRect(xd, fg, x + w2, y, s, h2 + s + d);
216 + if (bd & LR)
217 + XftDrawRect(xd, fg, x + w2 - d, y + h2, w - w2 + d, s);
218 + if (bd & LD)
219 + XftDrawRect(xd, fg, x + w2, y + h2 - d, s, h - h2 + d);
220 + }
221 +
222 + /* double lines - also align with light to form heavy when combined */
223 + if (double_) {
224 + /*
225 + * going clockwise, for each double-ray: p is additional length
226 + * to the single-ray nearer to the previous direction, and n to
227 + * the next. p and n adjust from the base length to lengths
228 + * which consider other doubles - shorter to avoid intersections
229 + * (p, n), or longer to draw the far-corner texel (n).
230 + */
231 + int dl = bd & DL, du = bd & DU, dr = bd & DR, dd = bd & DD;
232 + if (dl) {
233 + int p = dd ? -s : 0, n = du ? -s : dd ? s : 0;
234 + XftDrawRect(xd, fg, x, y + h2 + s, w2 + s + p, s);
235 + XftDrawRect(xd, fg, x, y + h2 - s, w2 + s + n, s);
236 + }
237 + if (du) {
238 + int p = dl ? -s : 0, n = dr ? -s : dl ? s : 0;
239 + XftDrawRect(xd, fg, x + w2 - s, y, s, h2 + s + p);
240 + XftDrawRect(xd, fg, x + w2 + s, y, s, h2 + s + n);
241 + }
242 + if (dr) {
243 + int p = du ? -s : 0, n = dd ? -s : du ? s : 0;
244 + XftDrawRect(xd, fg, x + w2 - p, y + h2 - s, w - w2 + p, s);
245 + XftDrawRect(xd, fg, x + w2 - n, y + h2 + s, w - w2 + n, s);
246 + }
247 + if (dd) {
248 + int p = dr ? -s : 0, n = dl ? -s : dr ? s : 0;
249 + XftDrawRect(xd, fg, x + w2 + s, y + h2 - p, s, h - h2 + p);
250 + XftDrawRect(xd, fg, x + w2 - s, y + h2 - n, s, h - h2 + n);
251 + }
252 + }
253 +}
254 diff --git a/boxdraw_data.h b/boxdraw_data.h
255 new file mode 100644
256 index 0000000..7890500
257 --- /dev/null
258 +++ b/boxdraw_data.h
259 @@ -0,0 +1,214 @@
260 +/*
261 + * Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
262 + * MIT/X Consortium License
263 + */
264 +
265 +/*
266 + * U+25XX codepoints data
267 + *
268 + * References:
269 + * http://www.unicode.org/charts/PDF/U2500.pdf
270 + * http://www.unicode.org/charts/PDF/U2580.pdf
271 + *
272 + * Test page:
273 + * https://github.com/GNOME/vte/blob/master/doc/boxes.txt
274 + */
275 +
276 +/* Each shape is encoded as 16-bits. Higher bits are category, lower are data */
277 +/* Categories (mutually exclusive except BDB): */
278 +/* For convenience, BDL/BDA/BBS/BDB are 1 bit each, the rest are enums */
279 +#define BDL (1<<8) /* Box Draw Lines (light/double/heavy) */
280 +#define BDA (1<<9) /* Box Draw Arc (light) */
281 +
282 +#define BBD (1<<10) /* Box Block Down (lower) X/8 */
283 +#define BBL (2<<10) /* Box Block Left X/8 */
284 +#define BBU (3<<10) /* Box Block Upper X/8 */
285 +#define BBR (4<<10) /* Box Block Right X/8 */
286 +#define BBQ (5<<10) /* Box Block Quadrants */
287 +#define BRL (6<<10) /* Box Braille (data is lower byte of U28XX) */
288 +
289 +#define BBS (1<<14) /* Box Block Shades */
290 +#define BDB (1<<15) /* Box Draw is Bold */
291 +
292 +/* (BDL/BDA) Light/Double/Heavy x Left/Up/Right/Down/Horizontal/Vertical */
293 +/* Heavy is light+double (literally drawing light+double align to form heavy) */
294 +#define LL (1<<0)
295 +#define LU (1<<1)
296 +#define LR (1<<2)
297 +#define LD (1<<3)
298 +#define LH (LL+LR)
299 +#define LV (LU+LD)
300 +
301 +#define DL (1<<4)
302 +#define DU (1<<5)
303 +#define DR (1<<6)
304 +#define DD (1<<7)
305 +#define DH (DL+DR)
306 +#define DV (DU+DD)
307 +
308 +#define HL (LL+DL)
309 +#define HU (LU+DU)
310 +#define HR (LR+DR)
311 +#define HD (LD+DD)
312 +#define HH (HL+HR)
313 +#define HV (HU+HD)
314 +
315 +/* (BBQ) Quadrants Top/Bottom x Left/Right */
316 +#define TL (1<<0)
317 +#define TR (1<<1)
318 +#define BL (1<<2)
319 +#define BR (1<<3)
320 +
321 +/* Data for U+2500 - U+259F except dashes/diagonals */
322 +static const unsigned short boxdata[256] = {
323 + /* light lines */
324 + [0x00] = BDL + LH, /* light horizontal */
325 + [0x02] = BDL + LV, /* light vertical */
326 + [0x0c] = BDL + LD + LR, /* light down and right */
327 + [0x10] = BDL + LD + LL, /* light down and left */
328 + [0x14] = BDL + LU + LR, /* light up and right */
329 + [0x18] = BDL + LU + LL, /* light up and left */
330 + [0x1c] = BDL + LV + LR, /* light vertical and right */
331 + [0x24] = BDL + LV + LL, /* light vertical and left */
332 + [0x2c] = BDL + LH + LD, /* light horizontal and down */
333 + [0x34] = BDL + LH + LU, /* light horizontal and up */
334 + [0x3c] = BDL + LV + LH, /* light vertical and horizontal */
335 + [0x74] = BDL + LL, /* light left */
336 + [0x75] = BDL + LU, /* light up */
337 + [0x76] = BDL + LR, /* light right */
338 + [0x77] = BDL + LD, /* light down */
339 +
340 + /* heavy [+light] lines */
341 + [0x01] = BDL + HH,
342 + [0x03] = BDL + HV,
343 + [0x0d] = BDL + HR + LD,
344 + [0x0e] = BDL + HD + LR,
345 + [0x0f] = BDL + HD + HR,
346 + [0x11] = BDL + HL + LD,
347 + [0x12] = BDL + HD + LL,
348 + [0x13] = BDL + HD + HL,
349 + [0x15] = BDL + HR + LU,
350 + [0x16] = BDL + HU + LR,
351 + [0x17] = BDL + HU + HR,
352 + [0x19] = BDL + HL + LU,
353 + [0x1a] = BDL + HU + LL,
354 + [0x1b] = BDL + HU + HL,
355 + [0x1d] = BDL + HR + LV,
356 + [0x1e] = BDL + HU + LD + LR,
357 + [0x1f] = BDL + HD + LR + LU,
358 + [0x20] = BDL + HV + LR,
359 + [0x21] = BDL + HU + HR + LD,
360 + [0x22] = BDL + HD + HR + LU,
361 + [0x23] = BDL + HV + HR,
362 + [0x25] = BDL + HL + LV,
363 + [0x26] = BDL + HU + LD + LL,
364 + [0x27] = BDL + HD + LU + LL,
365 + [0x28] = BDL + HV + LL,
366 + [0x29] = BDL + HU + HL + LD,
367 + [0x2a] = BDL + HD + HL + LU,
368 + [0x2b] = BDL + HV + HL,
369 + [0x2d] = BDL + HL + LD + LR,
370 + [0x2e] = BDL + HR + LL + LD,
371 + [0x2f] = BDL + HH + LD,
372 + [0x30] = BDL + HD + LH,
373 + [0x31] = BDL + HD + HL + LR,
374 + [0x32] = BDL + HR + HD + LL,
375 + [0x33] = BDL + HH + HD,
376 + [0x35] = BDL + HL + LU + LR,
377 + [0x36] = BDL + HR + LU + LL,
378 + [0x37] = BDL + HH + LU,
379 + [0x38] = BDL + HU + LH,
380 + [0x39] = BDL + HU + HL + LR,
381 + [0x3a] = BDL + HU + HR + LL,
382 + [0x3b] = BDL + HH + HU,
383 + [0x3d] = BDL + HL + LV + LR,
384 + [0x3e] = BDL + HR + LV + LL,
385 + [0x3f] = BDL + HH + LV,
386 + [0x40] = BDL + HU + LH + LD,
387 + [0x41] = BDL + HD + LH + LU,
388 + [0x42] = BDL + HV + LH,
389 + [0x43] = BDL + HU + HL + LD + LR,
390 + [0x44] = BDL + HU + HR + LD + LL,
391 + [0x45] = BDL + HD + HL + LU + LR,
392 + [0x46] = BDL + HD + HR + LU + LL,
393 + [0x47] = BDL + HH + HU + LD,
394 + [0x48] = BDL + HH + HD + LU,
395 + [0x49] = BDL + HV + HL + LR,
396 + [0x4a] = BDL + HV + HR + LL,
397 + [0x4b] = BDL + HV + HH,
398 + [0x78] = BDL + HL,
399 + [0x79] = BDL + HU,
400 + [0x7a] = BDL + HR,
401 + [0x7b] = BDL + HD,
402 + [0x7c] = BDL + HR + LL,
403 + [0x7d] = BDL + HD + LU,
404 + [0x7e] = BDL + HL + LR,
405 + [0x7f] = BDL + HU + LD,
406 +
407 + /* double [+light] lines */
408 + [0x50] = BDL + DH,
409 + [0x51] = BDL + DV,
410 + [0x52] = BDL + DR + LD,
411 + [0x53] = BDL + DD + LR,
412 + [0x54] = BDL + DR + DD,
413 + [0x55] = BDL + DL + LD,
414 + [0x56] = BDL + DD + LL,
415 + [0x57] = BDL + DL + DD,
416 + [0x58] = BDL + DR + LU,
417 + [0x59] = BDL + DU + LR,
418 + [0x5a] = BDL + DU + DR,
419 + [0x5b] = BDL + DL + LU,
420 + [0x5c] = BDL + DU + LL,
421 + [0x5d] = BDL + DL + DU,
422 + [0x5e] = BDL + DR + LV,
423 + [0x5f] = BDL + DV + LR,
424 + [0x60] = BDL + DV + DR,
425 + [0x61] = BDL + DL + LV,
426 + [0x62] = BDL + DV + LL,
427 + [0x63] = BDL + DV + DL,
428 + [0x64] = BDL + DH + LD,
429 + [0x65] = BDL + DD + LH,
430 + [0x66] = BDL + DD + DH,
431 + [0x67] = BDL + DH + LU,
432 + [0x68] = BDL + DU + LH,
433 + [0x69] = BDL + DH + DU,
434 + [0x6a] = BDL + DH + LV,
435 + [0x6b] = BDL + DV + LH,
436 + [0x6c] = BDL + DH + DV,
437 +
438 + /* (light) arcs */
439 + [0x6d] = BDA + LD + LR,
440 + [0x6e] = BDA + LD + LL,
441 + [0x6f] = BDA + LU + LL,
442 + [0x70] = BDA + LU + LR,
443 +
444 + /* Lower (Down) X/8 block (data is 8 - X) */
445 + [0x81] = BBD + 7, [0x82] = BBD + 6, [0x83] = BBD + 5, [0x84] = BBD + 4,
446 + [0x85] = BBD + 3, [0x86] = BBD + 2, [0x87] = BBD + 1, [0x88] = BBD + 0,
447 +
448 + /* Left X/8 block (data is X) */
449 + [0x89] = BBL + 7, [0x8a] = BBL + 6, [0x8b] = BBL + 5, [0x8c] = BBL + 4,
450 + [0x8d] = BBL + 3, [0x8e] = BBL + 2, [0x8f] = BBL + 1,
451 +
452 + /* upper 1/2 (4/8), 1/8 block (X), right 1/2, 1/8 block (8-X) */
453 + [0x80] = BBU + 4, [0x94] = BBU + 1,
454 + [0x90] = BBR + 4, [0x95] = BBR + 7,
455 +
456 + /* Quadrants */
457 + [0x96] = BBQ + BL,
458 + [0x97] = BBQ + BR,
459 + [0x98] = BBQ + TL,
460 + [0x99] = BBQ + TL + BL + BR,
461 + [0x9a] = BBQ + TL + BR,
462 + [0x9b] = BBQ + TL + TR + BL,
463 + [0x9c] = BBQ + TL + TR + BR,
464 + [0x9d] = BBQ + TR,
465 + [0x9e] = BBQ + BL + TR,
466 + [0x9f] = BBQ + BL + TR + BR,
467 +
468 + /* Shades, data is an alpha value in 25% units (1/4, 1/2, 3/4) */
469 + [0x91] = BBS + 1, [0x92] = BBS + 2, [0x93] = BBS + 3,
470 +
471 + /* U+2504 - U+250B, U+254C - U+254F: unsupported (dashes) */
472 + /* U+2571 - U+2573: unsupported (diagonals) */
473 +};
474 diff --git a/config.def.h b/config.def.h
475 index 0e01717..e3654a9 100644
476 --- a/config.def.h
477 +++ b/config.def.h
478 @@ -56,6 +56,18 @@ static unsigned int blinktimeout = 800;
479 */
480 static unsigned int cursorthickness = 2;
481
482 +/*
483 + * 1: render most of the lines/blocks characters without using the font for
484 + * perfect alignment between cells (U2500 - U259F except dashes/diagonals).
485 + * Bold affects lines thickness if boxdraw_bold is not 0. Italic is ignored.
486 + * 0: disable (render all U25XX glyphs normally from the font).
487 + */
488 +const int boxdraw = 0;
489 +const int boxdraw_bold = 0;
490 +
491 +/* braille (U28XX): 1: render as adjacent "pixels", 0: use font */
492 +const int boxdraw_braille = 0;
493 +
494 /*
495 * bell volume. It must be a value between -100 and 100. Use 0 for disabling
496 * it
497 diff --git a/st.c b/st.c
498 index b8e6077..d65f722 100644
499 --- a/st.c
500 +++ b/st.c
501 @@ -1230,6 +1230,9 @@ tsetchar(Rune u, Glyph *attr, int x, int y)
502 term.dirty[y] = 1;
503 term.line[y][x] = *attr;
504 term.line[y][x].u = u;
505 +
506 + if (isboxdraw(u))
507 + term.line[y][x].mode |= ATTR_BOXDRAW;
508 }
509
510 void
511 diff --git a/st.h b/st.h
512 index 38c61c4..9275632 100644
513 --- a/st.h
514 +++ b/st.h
515 @@ -33,6 +33,7 @@ enum glyph_attribute {
516 ATTR_WRAP = 1 << 8,
517 ATTR_WIDE = 1 << 9,
518 ATTR_WDUMMY = 1 << 10,
519 + ATTR_BOXDRAW = 1 << 11,
520 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
521 };
522
523 @@ -110,6 +111,14 @@ void *xmalloc(size_t);
524 void *xrealloc(void *, size_t);
525 char *xstrdup(char *);
526
527 +int isboxdraw(Rune);
528 +ushort boxdrawindex(const Glyph *);
529 +#ifdef XFT_VERSION
530 +/* only exposed to x.c, otherwise we'll need Xft.h for the types */
531 +void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *);
532 +void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int);
533 +#endif
534 +
535 /* config.h globals */
536 extern char *utmp;
537 extern char *stty_args;
538 @@ -120,3 +129,4 @@ extern char *termname;
539 extern unsigned int tabspaces;
540 extern unsigned int defaultfg;
541 extern unsigned int defaultbg;
542 +extern const int boxdraw, boxdraw_bold, boxdraw_braille;
543 diff --git a/x.c b/x.c
544 index 0422421..c740bed 100644
545 --- a/x.c
546 +++ b/x.c
547 @@ -1118,6 +1118,8 @@ xinit(int cols, int rows)
548 xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
549 if (xsel.xtarget == None)
550 xsel.xtarget = XA_STRING;
551 +
552 + boxdraw_xinit(xw.dpy, xw.cmap, xw.draw, xw.vis);
553 }
554
555 int
556 @@ -1164,8 +1166,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
557 yp = winy + font->ascent;
558 }
559
560 - /* Lookup character index with default font. */
561 - glyphidx = XftCharIndex(xw.dpy, font->match, rune);
562 + if (mode & ATTR_BOXDRAW) {
563 + /* minor shoehorning: boxdraw uses only this ushort */
564 + glyphidx = boxdrawindex(&glyphs[i]);
565 + } else {
566 + /* Lookup character index with default font. */
567 + glyphidx = XftCharIndex(xw.dpy, font->match, rune);
568 + }
569 if (glyphidx) {
570 specs[numspecs].font = font->match;
571 specs[numspecs].glyph = glyphidx;
572 @@ -1372,8 +1379,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
573 r.width = width;
574 XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
575
576 - /* Render the glyphs. */
577 - XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
578 + if (base.mode & ATTR_BOXDRAW) {
579 + drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
580 + } else {
581 + /* Render the glyphs. */
582 + XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
583 + }
584
585 /* Render underline and strikethrough. */
586 if (base.mode & ATTR_UNDERLINE) {
587 @@ -1416,7 +1427,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
588 /*
589 * Select the right color for the right mode.
590 */
591 - g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
592 + g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE|ATTR_BOXDRAW;
593
594 if (IS_SET(MODE_REVERSE)) {
595 g.mode |= ATTR_REVERSE;
596 --
597 2.17.1
598