add readme, return and update boxdraw, improve latency
This commit is contained in:
		
							parent
							
								
									39d5aae8fb
								
							
						
					
					
						commit
						b63af87e4c
					
				
					 4 changed files with 182 additions and 77 deletions
				
			
		
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					st-patches
 | 
				
			||||||
 | 
					==========
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A personal set of st configuration and patches because why the fuck not.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Includes:
 | 
				
			||||||
 | 
					* [st-boxdraw_v2-0.8.2.diff](https://st.suckless.org/patches/boxdraw/) - draw beautiful pseudo graphic lines instead of whatever your font provides
 | 
				
			||||||
 | 
					* st-bright-bold-text.patch - make non-colored bold text brigh
 | 
				
			||||||
 | 
					* st-disable-bold-italic-fonts.patch - actually disable bold, italic or bold italic font styles
 | 
				
			||||||
 | 
					* st-disable-intensity-styles.patch - disable so called "intensity styles", do not make colored bold text bright
 | 
				
			||||||
 | 
					* makest - a simple script to apply all the patches and build st
 | 
				
			||||||
 | 
					* config.h - my config
 | 
				
			||||||
							
								
								
									
										16
									
								
								config.h
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								config.h
									
										
									
									
									
								
							| 
						 | 
					@ -46,8 +46,8 @@ static unsigned int tripleclicktimeout = 600;
 | 
				
			||||||
int allowaltscreen = 1;
 | 
					int allowaltscreen = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* frames per second st should at maximum draw to the screen */
 | 
					/* frames per second st should at maximum draw to the screen */
 | 
				
			||||||
static unsigned int xfps = 60;
 | 
					static unsigned int xfps = 300;
 | 
				
			||||||
static unsigned int actionfps = 30;
 | 
					static unsigned int actionfps = 150;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * blinking timeout (set to 0 to disable blinking) for the terminal blinking
 | 
					 * blinking timeout (set to 0 to disable blinking) for the terminal blinking
 | 
				
			||||||
| 
						 | 
					@ -60,6 +60,18 @@ static unsigned int blinktimeout = 0;
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static unsigned int cursorthickness = 1;
 | 
					static unsigned int cursorthickness = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 1: render most of the lines/blocks characters without using the font for
 | 
				
			||||||
 | 
					 *    perfect alignment between cells (U2500 - U259F except dashes/diagonals).
 | 
				
			||||||
 | 
					 *    Bold affects lines thickness if boxdraw_bold is not 0. Italic is ignored.
 | 
				
			||||||
 | 
					 * 0: disable (render all U25XX glyphs normally from the font).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					const int boxdraw = 1;
 | 
				
			||||||
 | 
					const int boxdraw_bold = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* braille (U28XX):  1: render as adjacent "pixels",  0: use font */
 | 
				
			||||||
 | 
					const int boxdraw_braille = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * bell volume. It must be a value between -100 and 100. Use 0 for disabling
 | 
					 * bell volume. It must be a value between -100 and 100. Use 0 for disabling
 | 
				
			||||||
 * it
 | 
					 * it
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								makest
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								makest
									
										
									
									
									
								
							| 
						 | 
					@ -4,7 +4,7 @@ ST_REPO=https://git.suckless.org/st
 | 
				
			||||||
ST_SRC=$PWD/st
 | 
					ST_SRC=$PWD/st
 | 
				
			||||||
ST_CFG=$PWD/config.h
 | 
					ST_CFG=$PWD/config.h
 | 
				
			||||||
PATCHLIST=(
 | 
					PATCHLIST=(
 | 
				
			||||||
    #st-boxdraw.patch
 | 
					    st-boxdraw_v2-0.8.2.patch
 | 
				
			||||||
    st-bright-bold-text.patch
 | 
					    st-bright-bold-text.patch
 | 
				
			||||||
    st-disable-bold-italic-fonts.patch
 | 
					    st-disable-bold-italic-fonts.patch
 | 
				
			||||||
    st-disable-intensity-styles.patch
 | 
					    st-disable-intensity-styles.patch
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,35 +1,37 @@
 | 
				
			||||||
From 1630b7016d26c266d004f38ecfef2c4b708aa9a6 Mon Sep 17 00:00:00 2001
 | 
					From 318ae7fe1bd614cb937c8f43d855a1c2e8e93fd4 Mon Sep 17 00:00:00 2001
 | 
				
			||||||
From: "Avi Halachmi (:avih)" <avihpit@yahoo.com>
 | 
					From: "Avi Halachmi (:avih)" <avihpit@yahoo.com>
 | 
				
			||||||
Date: Fri, 26 Oct 2018 13:11:20 +0300
 | 
					Date: Wed, 26 Dec 2018 14:51:45 +0200
 | 
				
			||||||
Subject: [PATCH] boxdraw: custom-draw U+25XX lines/blocks to align seamlessly
 | 
					Subject: [PATCH] boxdraw_v2: custom render lines/blocks/braille for perfect
 | 
				
			||||||
 | 
					 alignment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
It seems impossible to ensure that blocks and line drawing glyphs
 | 
					It seems impossible to ensure that blocks and line drawing glyphs
 | 
				
			||||||
align without visible gaps for all combinations of arbitrary font,
 | 
					align without visible gaps for all combinations of arbitrary font,
 | 
				
			||||||
size and width/height scale factor.
 | 
					size and width/height scale factor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This commit adds an option to custom-draw (without using the font)
 | 
					This commit adds options to render most of the lines/blocks and
 | 
				
			||||||
most of the lines/blocks codepoints such that they're rendered
 | 
					braille codepoints without using the font such that they align
 | 
				
			||||||
identically (per size) and align perfectly regardless of font, size
 | 
					perfectly regardless of font, size or other configuration values.
 | 
				
			||||||
or chscale/cwscale configuration values.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
138 shapes are supported (U+2500 - U+259F except dashes, diagonals
 | 
					Supported codepoints are U+2500 - U+259F except dashes/diagonals,
 | 
				
			||||||
and shades), composited as 16-bit values at boxdraw_data.h .
 | 
					and U28XX.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
See links and references at boxdraw_data.h
 | 
					The lines/blocks data is stored as 16-bit values at boxdraw_data.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					boxdraw/braille are independent, disabled by default at config[.def].h
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
 Makefile       |   3 +-
 | 
					 Makefile       |   3 +-
 | 
				
			||||||
 boxdraw.c      | 141 ++++++++++++++++++++++++++++++++++
 | 
					 boxdraw.c      | 194 ++++++++++++++++++++++++++++++++++++++++++++
 | 
				
			||||||
 boxdraw_data.h | 202 +++++++++++++++++++++++++++++++++++++++++++++++++
 | 
					 boxdraw_data.h | 214 +++++++++++++++++++++++++++++++++++++++++++++++++
 | 
				
			||||||
 config.def.h   |   8 ++
 | 
					 config.def.h   |  12 +++
 | 
				
			||||||
 st.c           |   3 +
 | 
					 st.c           |   3 +
 | 
				
			||||||
 st.h           |   9 +++
 | 
					 st.h           |  10 +++
 | 
				
			||||||
 x.c            |  19 +++--
 | 
					 x.c            |  21 +++--
 | 
				
			||||||
 7 files changed, 379 insertions(+), 6 deletions(-)
 | 
					 7 files changed, 451 insertions(+), 6 deletions(-)
 | 
				
			||||||
 create mode 100644 boxdraw.c
 | 
					 create mode 100644 boxdraw.c
 | 
				
			||||||
 create mode 100644 boxdraw_data.h
 | 
					 create mode 100644 boxdraw_data.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
diff --git a/Makefile b/Makefile
 | 
					diff --git a/Makefile b/Makefile
 | 
				
			||||||
index 0b3cecd..8d3af33 100644
 | 
					index 470ac86..6dfa212 100644
 | 
				
			||||||
--- a/Makefile
 | 
					--- a/Makefile
 | 
				
			||||||
+++ b/Makefile
 | 
					+++ b/Makefile
 | 
				
			||||||
@@ -4,7 +4,7 @@
 | 
					@@ -4,7 +4,7 @@
 | 
				
			||||||
| 
						 | 
					@ -51,72 +53,96 @@ index 0b3cecd..8d3af33 100644
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
diff --git a/boxdraw.c b/boxdraw.c
 | 
					diff --git a/boxdraw.c b/boxdraw.c
 | 
				
			||||||
new file mode 100644
 | 
					new file mode 100644
 | 
				
			||||||
index 0000000..357250f
 | 
					index 0000000..28a92d0
 | 
				
			||||||
--- /dev/null
 | 
					--- /dev/null
 | 
				
			||||||
+++ b/boxdraw.c
 | 
					+++ b/boxdraw.c
 | 
				
			||||||
@@ -0,0 +1,141 @@
 | 
					@@ -0,0 +1,194 @@
 | 
				
			||||||
 | 
					+/*
 | 
				
			||||||
 | 
					+ * Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
 | 
				
			||||||
 | 
					+ * MIT/X Consortium License
 | 
				
			||||||
 | 
					+ */
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
+#include <X11/Xft/Xft.h>
 | 
					+#include <X11/Xft/Xft.h>
 | 
				
			||||||
+#include "st.h"
 | 
					+#include "st.h"
 | 
				
			||||||
+#include "boxdraw_data.h"
 | 
					+#include "boxdraw_data.h"
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+static void drawbox(XftDraw *, int, int, int, int, XftColor *, ushort);
 | 
					+/* Rounded non-negative integers division of n / d  */
 | 
				
			||||||
+static void drawboxlines(XftDraw *, int, int, int, int, XftColor *, ushort);
 | 
					+#define DIV(n, d) (((n) + (d) / 2) / (d))
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+static Display *xdpy;
 | 
				
			||||||
 | 
					+static Colormap xcmap;
 | 
				
			||||||
 | 
					+static XftDraw *xd;
 | 
				
			||||||
 | 
					+static Visual *xvis;
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+static void drawbox(int, int, int, int, XftColor *, XftColor *, ushort);
 | 
				
			||||||
 | 
					+static void drawboxlines(int, int, int, int, XftColor *, ushort);
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* public API */
 | 
					+/* public API */
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+int
 | 
					+void
 | 
				
			||||||
+isboxdraw(const Glyph *g)
 | 
					+boxdraw_xinit(Display *dpy, Colormap cmap, XftDraw *draw, Visual *vis)
 | 
				
			||||||
+{
 | 
					+{
 | 
				
			||||||
+	return (g->u & ~0xff) == 0x2500 &&
 | 
					+	xdpy = dpy; xcmap = cmap; xd = draw, xvis = vis;
 | 
				
			||||||
+	       boxdata[(uint8_t)g->u] != 0 &&
 | 
					+}
 | 
				
			||||||
+	       (g->mode & ATTR_ITALIC) == 0;
 | 
					+
 | 
				
			||||||
 | 
					+int
 | 
				
			||||||
 | 
					+isboxdraw(Rune u)
 | 
				
			||||||
 | 
					+{
 | 
				
			||||||
 | 
					+	Rune block = u & ~0xff;
 | 
				
			||||||
 | 
					+	return (boxdraw && block == 0x2500 && boxdata[(uint8_t)u]) ||
 | 
				
			||||||
 | 
					+	       (boxdraw_braille && block == 0x2800);
 | 
				
			||||||
+}
 | 
					+}
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* the "index" is actually the entire shape data encoded as ushort */
 | 
					+/* the "index" is actually the entire shape data encoded as ushort */
 | 
				
			||||||
+ushort
 | 
					+ushort
 | 
				
			||||||
+boxdrawindex(const Glyph *g)
 | 
					+boxdrawindex(const Glyph *g)
 | 
				
			||||||
+{
 | 
					+{
 | 
				
			||||||
+	return boxdata[(uint8_t)g->u] | ((g->mode & ATTR_BOLD) ? BDB : 0);
 | 
					+	if (boxdraw_braille && (g->u & ~0xff) == 0x2800)
 | 
				
			||||||
 | 
					+		return BRL | (uint8_t)g->u;
 | 
				
			||||||
 | 
					+	if (boxdraw_bold && (g->mode & ATTR_BOLD))
 | 
				
			||||||
 | 
					+		return BDB | boxdata[(uint8_t)g->u];
 | 
				
			||||||
 | 
					+	return boxdata[(uint8_t)g->u];
 | 
				
			||||||
+}
 | 
					+}
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+void
 | 
					+void
 | 
				
			||||||
+drawboxes(XftDraw *xd, int x, int y, int cw, int ch, XftColor *fg,
 | 
					+drawboxes(int x, int y, int cw, int ch, XftColor *fg, XftColor *bg,
 | 
				
			||||||
+          const XftGlyphFontSpec *specs, int len)
 | 
					+          const XftGlyphFontSpec *specs, int len)
 | 
				
			||||||
+{
 | 
					+{
 | 
				
			||||||
+	for ( ; len-- > 0; x += cw, specs++)
 | 
					+	for ( ; len-- > 0; x += cw, specs++)
 | 
				
			||||||
+		drawbox(xd, x, y, cw, ch, fg, (ushort)specs->glyph);
 | 
					+		drawbox(x, y, cw, ch, fg, bg, (ushort)specs->glyph);
 | 
				
			||||||
+}
 | 
					+}
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* implementation */
 | 
					+/* implementation */
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+void
 | 
					+void
 | 
				
			||||||
+drawbox(XftDraw *xd, int x, int y, int w, int h, XftColor *fg, ushort bd)
 | 
					+drawbox(int x, int y, int w, int h, XftColor *fg, XftColor *bg, ushort bd)
 | 
				
			||||||
+{
 | 
					+{
 | 
				
			||||||
 | 
					+	ushort cat = bd & ~(BDB | 0xff);  /* mask out bold and data */
 | 
				
			||||||
+	if (bd & (BDL | BDA)) {
 | 
					+	if (bd & (BDL | BDA)) {
 | 
				
			||||||
+		/* lines (light/double/heavy/arcs) */
 | 
					+		/* lines (light/double/heavy/arcs) */
 | 
				
			||||||
+		drawboxlines(xd, x, y, w, h, fg, bd);
 | 
					+		drawboxlines(x, y, w, h, fg, bd);
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	} else if (bd & BBD) {
 | 
					+	} else if (cat == BBD) {
 | 
				
			||||||
+		/* lower (8-X)/8 block */
 | 
					+		/* lower (8-X)/8 block */
 | 
				
			||||||
+		int d = ((uint8_t)bd * h + 4) / 8;
 | 
					+		int d = DIV((uint8_t)bd * h, 8);
 | 
				
			||||||
+		XftDrawRect(xd, fg, x, y + d, w, h - d);
 | 
					+		XftDrawRect(xd, fg, x, y + d, w, h - d);
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	} else if (bd & BBU) {
 | 
					+	} else if (cat == BBU) {
 | 
				
			||||||
+		/* upper X/8 block */
 | 
					+		/* upper X/8 block */
 | 
				
			||||||
+		XftDrawRect(xd, fg, x, y, w, ((uint8_t)bd * h + 4) / 8);
 | 
					+		XftDrawRect(xd, fg, x, y, w, DIV((uint8_t)bd * h, 8));
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	} else if (bd & BBL) {
 | 
					+	} else if (cat == BBL) {
 | 
				
			||||||
+		/* left X/8 block */
 | 
					+		/* left X/8 block */
 | 
				
			||||||
+		XftDrawRect(xd, fg, x, y, ((uint8_t)bd * w + 4) / 8, h);
 | 
					+		XftDrawRect(xd, fg, x, y, DIV((uint8_t)bd * w, 8), h);
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	} else if (bd & BBR) {
 | 
					+	} else if (cat == BBR) {
 | 
				
			||||||
+		/* right (8-X)/8 block */
 | 
					+		/* right (8-X)/8 block */
 | 
				
			||||||
+		int d = ((uint8_t)bd * w + 4) / 8;
 | 
					+		int d = DIV((uint8_t)bd * w, 8);
 | 
				
			||||||
+		XftDrawRect(xd, fg, x + d, y, w - d, h);
 | 
					+		XftDrawRect(xd, fg, x + d, y, w - d, h);
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	} else if (bd & BBQ) {
 | 
					+	} else if (cat == BBQ) {
 | 
				
			||||||
+		/* Quadrants */
 | 
					+		/* Quadrants */
 | 
				
			||||||
+		int w2 = (w + 1) / 2, h2 = (h + 1) / 2;
 | 
					+		int w2 = DIV(w, 2), h2 = DIV(h, 2);
 | 
				
			||||||
+		if (bd & TL)
 | 
					+		if (bd & TL)
 | 
				
			||||||
+			XftDrawRect(xd, fg, x, y, w2, h2);
 | 
					+			XftDrawRect(xd, fg, x, y, w2, h2);
 | 
				
			||||||
+		if (bd & TR)
 | 
					+		if (bd & TR)
 | 
				
			||||||
| 
						 | 
					@ -125,20 +151,49 @@ index 0000000..357250f
 | 
				
			||||||
+			XftDrawRect(xd, fg, x, y + h2, w2, h - h2);
 | 
					+			XftDrawRect(xd, fg, x, y + h2, w2, h - h2);
 | 
				
			||||||
+		if (bd & BR)
 | 
					+		if (bd & BR)
 | 
				
			||||||
+			XftDrawRect(xd, fg, x + w2, y + h2, w - w2, h - h2);
 | 
					+			XftDrawRect(xd, fg, x + w2, y + h2, w - w2, h - h2);
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+	} else if (bd & BBS) {
 | 
				
			||||||
 | 
					+		/* Shades - data is 1/2/3 for 25%/50%/75% alpha, respectively */
 | 
				
			||||||
 | 
					+		int d = (uint8_t)bd;
 | 
				
			||||||
 | 
					+		XftColor xfc;
 | 
				
			||||||
 | 
					+		XRenderColor xrc = { .alpha = 0xffff };
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+		xrc.red = DIV(fg->color.red * d + bg->color.red * (4 - d), 4);
 | 
				
			||||||
 | 
					+		xrc.green = DIV(fg->color.green * d + bg->color.green * (4 - d), 4);
 | 
				
			||||||
 | 
					+		xrc.blue = DIV(fg->color.blue * d + bg->color.blue * (4 - d), 4);
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+		XftColorAllocValue(xdpy, xvis, xcmap, &xrc, &xfc);
 | 
				
			||||||
 | 
					+		XftDrawRect(xd, &xfc, x, y, w, h);
 | 
				
			||||||
 | 
					+		XftColorFree(xdpy, xvis, xcmap, &xfc);
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+	} else if (cat == BRL) {
 | 
				
			||||||
 | 
					+		/* braille, each data bit corresponds to one dot at 2x4 grid */
 | 
				
			||||||
 | 
					+		int w1 = DIV(w, 2);
 | 
				
			||||||
 | 
					+		int h1 = DIV(h, 4), h2 = DIV(h, 2), h3 = DIV(3 * h, 4);
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+		if (bd & 1)   XftDrawRect(xd, fg, x, y, w1, h1);
 | 
				
			||||||
 | 
					+		if (bd & 2)   XftDrawRect(xd, fg, x, y + h1, w1, h2 - h1);
 | 
				
			||||||
 | 
					+		if (bd & 4)   XftDrawRect(xd, fg, x, y + h2, w1, h3 - h2);
 | 
				
			||||||
 | 
					+		if (bd & 8)   XftDrawRect(xd, fg, x + w1, y, w - w1, h1);
 | 
				
			||||||
 | 
					+		if (bd & 16)  XftDrawRect(xd, fg, x + w1, y + h1, w - w1, h2 - h1);
 | 
				
			||||||
 | 
					+		if (bd & 32)  XftDrawRect(xd, fg, x + w1, y + h2, w - w1, h3 - h2);
 | 
				
			||||||
 | 
					+		if (bd & 64)  XftDrawRect(xd, fg, x, y + h3, w1, h - h3);
 | 
				
			||||||
 | 
					+		if (bd & 128) XftDrawRect(xd, fg, x + w1, y + h3, w - w1, h - h3);
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
+	}
 | 
					+	}
 | 
				
			||||||
+}
 | 
					+}
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+void
 | 
					+void
 | 
				
			||||||
+drawboxlines(XftDraw *xd, int x, int y, int w, int h, XftColor *fg, ushort bd)
 | 
					+drawboxlines(int x, int y, int w, int h, XftColor *fg, ushort bd)
 | 
				
			||||||
+{
 | 
					+{
 | 
				
			||||||
+	/* s: stem thickness. width/8 roughly matches underscore thickness. */
 | 
					+	/* s: stem thickness. width/8 roughly matches underscore thickness. */
 | 
				
			||||||
+	/* We draw bold as 1.5 * normal-stem and at least 1px thicker.      */
 | 
					+	/* We draw bold as 1.5 * normal-stem and at least 1px thicker.      */
 | 
				
			||||||
+	/* doubles draw at least 3px, even when w or h < 3. bold needs 6px. */
 | 
					+	/* doubles draw at least 3px, even when w or h < 3. bold needs 6px. */
 | 
				
			||||||
+	int mwh = MIN(w, h);
 | 
					+	int mwh = MIN(w, h);
 | 
				
			||||||
+	int base_s = MAX(1, (mwh + 4) / 8);
 | 
					+	int base_s = MAX(1, DIV(mwh, 8));
 | 
				
			||||||
+	int bold = (bd & BDB) && mwh >= 6;  /* possibly ignore boldness */
 | 
					+	int bold = (bd & BDB) && mwh >= 6;  /* possibly ignore boldness */
 | 
				
			||||||
+	int s = bold ? MAX(base_s + 1, (3 * base_s + 1) / 2) : base_s;
 | 
					+	int s = bold ? MAX(base_s + 1, DIV(3 * base_s, 2)) : base_s;
 | 
				
			||||||
+	int w2 = (w - s + 1) / 2, h2 = (h - s + 1) / 2;
 | 
					+	int w2 = DIV(w - s, 2), h2 = DIV(h - s, 2);
 | 
				
			||||||
+	/* the s-by-s square (x + w2, y + h2, s, s) is the center texel.    */
 | 
					+	/* the s-by-s square (x + w2, y + h2, s, s) is the center texel.    */
 | 
				
			||||||
+	/* The base length (per direction till edge) includes this square.  */
 | 
					+	/* The base length (per direction till edge) includes this square.  */
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
| 
						 | 
					@ -198,10 +253,15 @@ index 0000000..357250f
 | 
				
			||||||
+}
 | 
					+}
 | 
				
			||||||
diff --git a/boxdraw_data.h b/boxdraw_data.h
 | 
					diff --git a/boxdraw_data.h b/boxdraw_data.h
 | 
				
			||||||
new file mode 100644
 | 
					new file mode 100644
 | 
				
			||||||
index 0000000..ee78cdc
 | 
					index 0000000..7890500
 | 
				
			||||||
--- /dev/null
 | 
					--- /dev/null
 | 
				
			||||||
+++ b/boxdraw_data.h
 | 
					+++ b/boxdraw_data.h
 | 
				
			||||||
@@ -0,0 +1,202 @@
 | 
					@@ -0,0 +1,214 @@
 | 
				
			||||||
 | 
					+/*
 | 
				
			||||||
 | 
					+ * Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
 | 
				
			||||||
 | 
					+ * MIT/X Consortium License
 | 
				
			||||||
 | 
					+ */
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
+/*
 | 
					+/*
 | 
				
			||||||
+ * U+25XX codepoints data
 | 
					+ * U+25XX codepoints data
 | 
				
			||||||
+ *
 | 
					+ *
 | 
				
			||||||
| 
						 | 
					@ -215,13 +275,18 @@ index 0000000..ee78cdc
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* Each shape is encoded as 16-bits. Higher bits are category, lower are data */
 | 
					+/* Each shape is encoded as 16-bits. Higher bits are category, lower are data */
 | 
				
			||||||
+/* Categories (mutually exclusive except BDB): */
 | 
					+/* Categories (mutually exclusive except BDB): */
 | 
				
			||||||
 | 
					+/* For convenience, BDL/BDA/BBS/BDB are 1 bit each, the rest are enums */
 | 
				
			||||||
+#define BDL (1<<8)   /* Box Draw Lines (light/double/heavy) */
 | 
					+#define BDL (1<<8)   /* Box Draw Lines (light/double/heavy) */
 | 
				
			||||||
+#define BDA (1<<9)   /* Box Draw Arc (light) */
 | 
					+#define BDA (1<<9)   /* Box Draw Arc (light) */
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
+#define BBD (1<<10)  /* Box Block Down (lower) X/8 */
 | 
					+#define BBD (1<<10)  /* Box Block Down (lower) X/8 */
 | 
				
			||||||
+#define BBL (1<<11)  /* Box Block Left X/8 */
 | 
					+#define BBL (2<<10)  /* Box Block Left X/8 */
 | 
				
			||||||
+#define BBU (1<<12)  /* Box Block Upper X/8 */
 | 
					+#define BBU (3<<10)  /* Box Block Upper X/8 */
 | 
				
			||||||
+#define BBR (1<<13)  /* Box Block Right X/8 */
 | 
					+#define BBR (4<<10)  /* Box Block Right X/8 */
 | 
				
			||||||
+#define BBQ (1<<14)  /* Box Block Quadrants */
 | 
					+#define BBQ (5<<10)  /* Box Block Quadrants */
 | 
				
			||||||
 | 
					+#define BRL (6<<10)  /* Box Braille (data is lower byte of U28XX) */
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+#define BBS (1<<14)  /* Box Block Shades */
 | 
				
			||||||
+#define BDB (1<<15)  /* Box Draw is Bold */
 | 
					+#define BDB (1<<15)  /* Box Draw is Bold */
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* (BDL/BDA) Light/Double/Heavy x Left/Up/Right/Down/Horizontal/Vertical      */
 | 
					+/* (BDL/BDA) Light/Double/Heavy x Left/Up/Right/Down/Horizontal/Vertical      */
 | 
				
			||||||
| 
						 | 
					@ -253,7 +318,7 @@ index 0000000..ee78cdc
 | 
				
			||||||
+#define BL (1<<2)
 | 
					+#define BL (1<<2)
 | 
				
			||||||
+#define BR (1<<3)
 | 
					+#define BR (1<<3)
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+/* 138 shapes are supported: U+2500 - U+259F except dashes/diagonals/shades */
 | 
					+/* Data for U+2500 - U+259F except dashes/diagonals */
 | 
				
			||||||
+static const unsigned short boxdata[256] = {
 | 
					+static const unsigned short boxdata[256] = {
 | 
				
			||||||
+	/* light lines */
 | 
					+	/* light lines */
 | 
				
			||||||
+	[0x00] = BDL + LH,       /* light horizontal */
 | 
					+	[0x00] = BDL + LH,       /* light horizontal */
 | 
				
			||||||
| 
						 | 
					@ -400,45 +465,51 @@ index 0000000..ee78cdc
 | 
				
			||||||
+	[0x9e] = BBQ + BL + TR,
 | 
					+	[0x9e] = BBQ + BL + TR,
 | 
				
			||||||
+	[0x9f] = BBQ + BL + TR + BR,
 | 
					+	[0x9f] = BBQ + BL + TR + BR,
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
 | 
					+	/* Shades, data is an alpha value in 25% units (1/4, 1/2, 3/4) */
 | 
				
			||||||
 | 
					+	[0x91] = BBS + 1, [0x92] = BBS + 2, [0x93] = BBS + 3,
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
+	/* U+2504 - U+250B, U+254C - U+254F: unsupported (dashes) */
 | 
					+	/* U+2504 - U+250B, U+254C - U+254F: unsupported (dashes) */
 | 
				
			||||||
+	/* U+2571 - U+2573: unsupported (diagonals) */
 | 
					+	/* U+2571 - U+2573: unsupported (diagonals) */
 | 
				
			||||||
+	/* U+2591 - U+2593: unsupported (shades) */
 | 
					 | 
				
			||||||
+};
 | 
					+};
 | 
				
			||||||
diff --git a/config.def.h b/config.def.h
 | 
					diff --git a/config.def.h b/config.def.h
 | 
				
			||||||
index 823e79f..018cbe4 100644
 | 
					index 0e01717..e3654a9 100644
 | 
				
			||||||
--- a/config.def.h
 | 
					--- a/config.def.h
 | 
				
			||||||
+++ b/config.def.h
 | 
					+++ b/config.def.h
 | 
				
			||||||
@@ -56,6 +56,14 @@ static unsigned int blinktimeout = 800;
 | 
					@@ -56,6 +56,18 @@ static unsigned int blinktimeout = 800;
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
 static unsigned int cursorthickness = 2;
 | 
					 static unsigned int cursorthickness = 2;
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
+/*
 | 
					+/*
 | 
				
			||||||
+ * 1: custom-draw (without using the font) most of the lines/blocks characters
 | 
					+ * 1: render most of the lines/blocks characters without using the font for
 | 
				
			||||||
+ *    for gapless alignment between cells. This includes all the codepoints at
 | 
					+ *    perfect alignment between cells (U2500 - U259F except dashes/diagonals).
 | 
				
			||||||
+ *    U+2500 - U+259F except dashes, diagonals and shades.
 | 
					+ *    Bold affects lines thickness if boxdraw_bold is not 0. Italic is ignored.
 | 
				
			||||||
+ * 0: disable (render all glyphs normally from the font).
 | 
					+ * 0: disable (render all U25XX glyphs normally from the font).
 | 
				
			||||||
+ */
 | 
					+ */
 | 
				
			||||||
+const int boxdraw = 0;
 | 
					+const int boxdraw = 0;
 | 
				
			||||||
 | 
					+const int boxdraw_bold = 0;
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+/* braille (U28XX):  1: render as adjacent "pixels",  0: use font */
 | 
				
			||||||
 | 
					+const int boxdraw_braille = 0;
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
 /*
 | 
					 /*
 | 
				
			||||||
  * bell volume. It must be a value between -100 and 100. Use 0 for disabling
 | 
					  * bell volume. It must be a value between -100 and 100. Use 0 for disabling
 | 
				
			||||||
  * it
 | 
					  * it
 | 
				
			||||||
diff --git a/st.c b/st.c
 | 
					diff --git a/st.c b/st.c
 | 
				
			||||||
index 46cf2da..7ee136a 100644
 | 
					index b8e6077..d65f722 100644
 | 
				
			||||||
--- a/st.c
 | 
					--- a/st.c
 | 
				
			||||||
+++ b/st.c
 | 
					+++ b/st.c
 | 
				
			||||||
@@ -1228,6 +1228,9 @@ tsetchar(Rune u, Glyph *attr, int x, int y)
 | 
					@@ -1230,6 +1230,9 @@ tsetchar(Rune u, Glyph *attr, int x, int y)
 | 
				
			||||||
 	term.dirty[y] = 1;
 | 
					 	term.dirty[y] = 1;
 | 
				
			||||||
 	term.line[y][x] = *attr;
 | 
					 	term.line[y][x] = *attr;
 | 
				
			||||||
 	term.line[y][x].u = u;
 | 
					 	term.line[y][x].u = u;
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+	if (boxdraw && isboxdraw(&term.line[y][x]))
 | 
					+	if (isboxdraw(u))
 | 
				
			||||||
+		term.line[y][x].mode |= ATTR_BOXDRAW;
 | 
					+		term.line[y][x].mode |= ATTR_BOXDRAW;
 | 
				
			||||||
 }
 | 
					 }
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
 void
 | 
					 void
 | 
				
			||||||
diff --git a/st.h b/st.h
 | 
					diff --git a/st.h b/st.h
 | 
				
			||||||
index 38c61c4..fc68c3b 100644
 | 
					index 38c61c4..9275632 100644
 | 
				
			||||||
--- a/st.h
 | 
					--- a/st.h
 | 
				
			||||||
+++ b/st.h
 | 
					+++ b/st.h
 | 
				
			||||||
@@ -33,6 +33,7 @@ enum glyph_attribute {
 | 
					@@ -33,6 +33,7 @@ enum glyph_attribute {
 | 
				
			||||||
| 
						 | 
					@ -449,30 +520,40 @@ index 38c61c4..fc68c3b 100644
 | 
				
			||||||
 	ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
 | 
					 	ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
 | 
				
			||||||
 };
 | 
					 };
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
@@ -110,6 +111,13 @@ void *xmalloc(size_t);
 | 
					@@ -110,6 +111,14 @@ void *xmalloc(size_t);
 | 
				
			||||||
 void *xrealloc(void *, size_t);
 | 
					 void *xrealloc(void *, size_t);
 | 
				
			||||||
 char *xstrdup(char *);
 | 
					 char *xstrdup(char *);
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
+int isboxdraw(const Glyph *);
 | 
					+int isboxdraw(Rune);
 | 
				
			||||||
+ushort boxdrawindex(const Glyph *);
 | 
					+ushort boxdrawindex(const Glyph *);
 | 
				
			||||||
+#ifdef XFT_VERSION
 | 
					+#ifdef XFT_VERSION
 | 
				
			||||||
+/* only exposed to x.c, otherwise we'll need Xft.h for the types */
 | 
					+/* only exposed to x.c, otherwise we'll need Xft.h for the types */
 | 
				
			||||||
+void drawboxes(XftDraw *, int, int, int, int, XftColor *, const XftGlyphFontSpec *, int);
 | 
					+void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *);
 | 
				
			||||||
 | 
					+void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int);
 | 
				
			||||||
+#endif
 | 
					+#endif
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
 /* config.h globals */
 | 
					 /* config.h globals */
 | 
				
			||||||
 extern char *utmp;
 | 
					 extern char *utmp;
 | 
				
			||||||
 extern char *stty_args;
 | 
					 extern char *stty_args;
 | 
				
			||||||
@@ -120,3 +128,4 @@ extern char *termname;
 | 
					@@ -120,3 +129,4 @@ extern char *termname;
 | 
				
			||||||
 extern unsigned int tabspaces;
 | 
					 extern unsigned int tabspaces;
 | 
				
			||||||
 extern unsigned int defaultfg;
 | 
					 extern unsigned int defaultfg;
 | 
				
			||||||
 extern unsigned int defaultbg;
 | 
					 extern unsigned int defaultbg;
 | 
				
			||||||
+extern const int boxdraw;
 | 
					+extern const int boxdraw, boxdraw_bold, boxdraw_braille;
 | 
				
			||||||
diff --git a/x.c b/x.c
 | 
					diff --git a/x.c b/x.c
 | 
				
			||||||
index 00cb6b1..730f525 100644
 | 
					index 0422421..c740bed 100644
 | 
				
			||||||
--- a/x.c
 | 
					--- a/x.c
 | 
				
			||||||
+++ b/x.c
 | 
					+++ b/x.c
 | 
				
			||||||
@@ -1164,8 +1164,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
 | 
					@@ -1118,6 +1118,8 @@ xinit(int cols, int rows)
 | 
				
			||||||
 | 
					 	xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
 | 
				
			||||||
 | 
					 	if (xsel.xtarget == None)
 | 
				
			||||||
 | 
					 		xsel.xtarget = XA_STRING;
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					+	boxdraw_xinit(xw.dpy, xw.cmap, xw.draw, xw.vis);
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 int
 | 
				
			||||||
 | 
					@@ -1164,8 +1166,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
 | 
				
			||||||
 			yp = winy + font->ascent;
 | 
					 			yp = winy + font->ascent;
 | 
				
			||||||
 		}
 | 
					 		}
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
| 
						 | 
					@ -488,14 +569,14 @@ index 00cb6b1..730f525 100644
 | 
				
			||||||
 		if (glyphidx) {
 | 
					 		if (glyphidx) {
 | 
				
			||||||
 			specs[numspecs].font = font->match;
 | 
					 			specs[numspecs].font = font->match;
 | 
				
			||||||
 			specs[numspecs].glyph = glyphidx;
 | 
					 			specs[numspecs].glyph = glyphidx;
 | 
				
			||||||
@@ -1372,8 +1377,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
 | 
					@@ -1372,8 +1379,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
 | 
				
			||||||
 	r.width = width;
 | 
					 	r.width = width;
 | 
				
			||||||
 	XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
 | 
					 	XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
-	/* Render the glyphs. */
 | 
					-	/* Render the glyphs. */
 | 
				
			||||||
-	XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
 | 
					-	XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
 | 
				
			||||||
+	if (base.mode & ATTR_BOXDRAW) {
 | 
					+	if (base.mode & ATTR_BOXDRAW) {
 | 
				
			||||||
+		drawboxes(xw.draw, winx, winy, width / len, win.ch, fg, specs, len);
 | 
					+		drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
 | 
				
			||||||
+	} else {
 | 
					+	} else {
 | 
				
			||||||
+		/* Render the glyphs. */
 | 
					+		/* Render the glyphs. */
 | 
				
			||||||
+		XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
 | 
					+		XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
 | 
				
			||||||
| 
						 | 
					@ -503,7 +584,7 @@ index 00cb6b1..730f525 100644
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
 	/* Render underline and strikethrough. */
 | 
					 	/* Render underline and strikethrough. */
 | 
				
			||||||
 	if (base.mode & ATTR_UNDERLINE) {
 | 
					 	if (base.mode & ATTR_UNDERLINE) {
 | 
				
			||||||
@@ -1416,7 +1425,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
 | 
					@@ -1416,7 +1427,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
 | 
				
			||||||
 	/*
 | 
					 	/*
 | 
				
			||||||
 	 * Select the right color for the right mode.
 | 
					 	 * Select the right color for the right mode.
 | 
				
			||||||
 	 */
 | 
					 	 */
 | 
				
			||||||
| 
						 | 
					@ -513,5 +594,5 @@ index 00cb6b1..730f525 100644
 | 
				
			||||||
 	if (IS_SET(MODE_REVERSE)) {
 | 
					 	if (IS_SET(MODE_REVERSE)) {
 | 
				
			||||||
 		g.mode |= ATTR_REVERSE;
 | 
					 		g.mode |= ATTR_REVERSE;
 | 
				
			||||||
-- 
 | 
					-- 
 | 
				
			||||||
2.19.1
 | 
					2.17.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue