aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyusei Yamaguchi <mandel59@gmail.com>2016-03-08 12:26:04 +0900
committerChristoph Lohmann <20h@r-36.net>2016-03-08 13:46:42 +0100
commit034a5c8a09e23ce0a410d0c608dd7e050b83681e (patch)
tree6e5baa21a777ccac547125653c4389ecc18b6e6c
parent30440295bc054f37a2a8275acca769cd83bcb780 (diff)
downloadst-patched-034a5c8a09e23ce0a410d0c608dd7e050b83681e.tar.bz2
st-patched-034a5c8a09e23ce0a410d0c608dd7e050b83681e.tar.xz
st-patched-034a5c8a09e23ce0a410d0c608dd7e050b83681e.zip
Measure the single advance width with a heuristic method
This fix is needed to use dual-width fonts, which have double-width glyphs (e.g. CJK unified ideographs). Signed-off-by: Ryusei Yamaguchi <mandel59@gmail.com> Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r--config.def.h8
-rw-r--r--st.c8
2 files changed, 15 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h
index fd09d72..a1e7d5a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -417,3 +417,11 @@ static uint selmasks[] = {
417 [SEL_RECTANGULAR] = Mod1Mask, 417 [SEL_RECTANGULAR] = Mod1Mask,
418}; 418};
419 419
420/*
421 * Printable characters in ASCII, used to estimate the advance width
422 * of single wide characters.
423 */
424static char ascii_printable[] =
425 " !\"#$%&'()*+,-./0123456789:;<=>?"
426 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
427 "`abcdefghijklmnopqrstuvwxyz{|}~";
diff --git a/st.c b/st.c
index 2473af7..ca126d7 100644
--- a/st.c
+++ b/st.c
@@ -68,6 +68,7 @@ char *argv0;
68#define LEN(a) (sizeof(a) / sizeof(a)[0]) 68#define LEN(a) (sizeof(a) / sizeof(a)[0])
69#define DEFAULT(a, b) (a) = (a) ? (a) : (b) 69#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
70#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) 70#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
71#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
71#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') 72#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
72#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) 73#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
73#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) 74#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
@@ -3277,6 +3278,7 @@ xloadfont(Font *f, FcPattern *pattern)
3277{ 3278{
3278 FcPattern *match; 3279 FcPattern *match;
3279 FcResult result; 3280 FcResult result;
3281 XGlyphInfo extents;
3280 3282
3281 match = FcFontMatch(NULL, pattern, &result); 3283 match = FcFontMatch(NULL, pattern, &result);
3282 if (!match) 3284 if (!match)
@@ -3287,6 +3289,10 @@ xloadfont(Font *f, FcPattern *pattern)
3287 return 1; 3289 return 1;
3288 } 3290 }
3289 3291
3292 XftTextExtentsUtf8(xw.dpy, f->match,
3293 (const FcChar8 *) ascii_printable,
3294 LEN(ascii_printable), &extents);
3295
3290 f->set = NULL; 3296 f->set = NULL;
3291 f->pattern = FcPatternDuplicate(pattern); 3297 f->pattern = FcPatternDuplicate(pattern);
3292 3298
@@ -3296,7 +3302,7 @@ xloadfont(Font *f, FcPattern *pattern)
3296 f->rbearing = f->match->max_advance_width; 3302 f->rbearing = f->match->max_advance_width;
3297 3303
3298 f->height = f->ascent + f->descent; 3304 f->height = f->ascent + f->descent;
3299 f->width = f->lbearing + f->rbearing; 3305 f->width = DIVCEIL(extents.xOff, LEN(ascii_printable));
3300 3306
3301 return 0; 3307 return 0;
3302} 3308}