st-boxdraw_v2-0.8.5.diff 18 KB

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