iMeasure the single advance width with a heuristic method - st - Simple Terminal Err gopher.r-36.net 70 i Err gopher.r-36.net 70 1Log /scm/st//log.gph gopher.r-36.net 70 1Files /scm/st//files.gph gopher.r-36.net 70 1Refs /scm/st//refs.gph gopher.r-36.net 70 1README /scm/st//file/README.gph gopher.r-36.net 70 1LICENSE /scm/st//file/LICENSE.gph gopher.r-36.net 70 i--- Err gopher.r-36.net 70 1commit 034a5c8a09e23ce0a410d0c608dd7e050b83681e /scm/st//commit/034a5c8a09e23ce0a410d0c608dd7e050b83681e.gph gopher.r-36.net 70 1parent 30440295bc054f37a2a8275acca769cd83bcb780 /scm/st//commit/30440295bc054f37a2a8275acca769cd83bcb780.gph gopher.r-36.net 70 hAuthor: Ryusei Yamaguchi URL:mailto:mandel59@gmail.com gopher.r-36.net 70 iDate: Tue, 8 Mar 2016 12:26:04 +0900 Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iMeasure the single advance width with a heuristic method Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iThis fix is needed to use dual-width fonts, which have double-width Err gopher.r-36.net 70 iglyphs (e.g. CJK unified ideographs). Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iSigned-off-by: Ryusei Yamaguchi Err gopher.r-36.net 70 iSigned-off-by: Christoph Lohmann <20h@r-36.net> Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iDiffstat: Err gopher.r-36.net 70 i config.def.h | 8 ++++++++ Err gopher.r-36.net 70 i st.c | 8 +++++++- Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i2 files changed, 15 insertions(+), 1 deletion(-) Err gopher.r-36.net 70 i--- Err gopher.r-36.net 70 1diff --git a/config.def.h b/config.def.h /scm/st//file/config.def.h.gph gopher.r-36.net 70 i@@ -417,3 +417,11 @@ static uint selmasks[] = { Err gopher.r-36.net 70 i [SEL_RECTANGULAR] = Mod1Mask, Err gopher.r-36.net 70 i }; Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i+/* Err gopher.r-36.net 70 i+ * Printable characters in ASCII, used to estimate the advance width Err gopher.r-36.net 70 i+ * of single wide characters. Err gopher.r-36.net 70 i+ */ Err gopher.r-36.net 70 i+static char ascii_printable[] = Err gopher.r-36.net 70 i+ " !\"#$%&'()*+,-./0123456789:;<=>?" Err gopher.r-36.net 70 i+ "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" Err gopher.r-36.net 70 i+ "`abcdefghijklmnopqrstuvwxyz{|}~"; Err gopher.r-36.net 70 1diff --git a/st.c b/st.c /scm/st//file/st.c.gph gopher.r-36.net 70 i@@ -68,6 +68,7 @@ char *argv0; Err gopher.r-36.net 70 i #define LEN(a) (sizeof(a) / sizeof(a)[0]) Err gopher.r-36.net 70 i #define DEFAULT(a, b) (a) = (a) ? (a) : (b) Err gopher.r-36.net 70 i #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) Err gopher.r-36.net 70 i+#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) Err gopher.r-36.net 70 i #define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') Err gopher.r-36.net 70 i #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) Err gopher.r-36.net 70 i #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) Err gopher.r-36.net 70 i@@ -3277,6 +3278,7 @@ xloadfont(Font *f, FcPattern *pattern) Err gopher.r-36.net 70 i { Err gopher.r-36.net 70 i FcPattern *match; Err gopher.r-36.net 70 i FcResult result; Err gopher.r-36.net 70 i+ XGlyphInfo extents; Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i match = FcFontMatch(NULL, pattern, &result); Err gopher.r-36.net 70 i if (!match) Err gopher.r-36.net 70 i@@ -3287,6 +3289,10 @@ xloadfont(Font *f, FcPattern *pattern) Err gopher.r-36.net 70 i return 1; Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i+ XftTextExtentsUtf8(xw.dpy, f->match, Err gopher.r-36.net 70 i+ (const FcChar8 *) ascii_printable, Err gopher.r-36.net 70 i+ LEN(ascii_printable), &extents); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i f->set = NULL; Err gopher.r-36.net 70 i f->pattern = FcPatternDuplicate(pattern); Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i@@ -3296,7 +3302,7 @@ xloadfont(Font *f, FcPattern *pattern) Err gopher.r-36.net 70 i f->rbearing = f->match->max_advance_width; Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i f->height = f->ascent + f->descent; Err gopher.r-36.net 70 i- f->width = f->lbearing + f->rbearing; Err gopher.r-36.net 70 i+ f->width = DIVCEIL(extents.xOff, LEN(ascii_printable)); Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i return 0; Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 .