sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-boxdraw_v2-0.8.5.diff (17960B)


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