aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2016-03-09 17:11:57 +0100
committerChristoph Lohmann <20h@r-36.net>2016-03-09 22:01:25 +0100
commit39964614b742c4ec98a326762d98470cb987a45b (patch)
tree49873bc7690c3a6f298162f029a4361c3748c327
parent0e48a1995eee1c2babc58523ef0be296e4b1c3e8 (diff)
downloadst-patched-39964614b742c4ec98a326762d98470cb987a45b.tar.bz2
st-patched-39964614b742c4ec98a326762d98470cb987a45b.tar.xz
st-patched-39964614b742c4ec98a326762d98470cb987a45b.zip
st: Fix off-by-one error when calculating character width.
LEN(str) is one larger than strlen(str) because it also counts the zero terminator. The original code would include the .notdef glyph (since it'll try to encode character 0, which gets encoded to the .notdef glyph) when measuring the average dimensions of printable ascii characters. This causes problems with fonts like GNU Unifont where the .notdef glyph is not the same width as the usual half-width characters. Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r--st.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/st.c b/st.c
index f2b3095..839136d 100644
--- a/st.c
+++ b/st.c
@@ -3291,7 +3291,7 @@ xloadfont(Font *f, FcPattern *pattern)
3291 3291
3292 XftTextExtentsUtf8(xw.dpy, f->match, 3292 XftTextExtentsUtf8(xw.dpy, f->match,
3293 (const FcChar8 *) ascii_printable, 3293 (const FcChar8 *) ascii_printable,
3294 LEN(ascii_printable), &extents); 3294 strlen(ascii_printable), &extents);
3295 3295
3296 f->set = NULL; 3296 f->set = NULL;
3297 f->pattern = FcPatternDuplicate(pattern); 3297 f->pattern = FcPatternDuplicate(pattern);
@@ -3302,7 +3302,7 @@ xloadfont(Font *f, FcPattern *pattern)
3302 f->rbearing = f->match->max_advance_width; 3302 f->rbearing = f->match->max_advance_width;
3303 3303
3304 f->height = f->ascent + f->descent; 3304 f->height = f->ascent + f->descent;
3305 f->width = DIVCEIL(extents.xOff, LEN(ascii_printable)); 3305 f->width = DIVCEIL(extents.xOff, strlen(ascii_printable));
3306 3306
3307 return 0; 3307 return 0;
3308} 3308}