[hackers] [st] st: Fix off-by-one error when calculating character width. || Tor Andersson

From: <git_AT_suckless.org>
Date: Wed, 9 Mar 2016 22:01:42 +0100 (CET)

commit 39964614b742c4ec98a326762d98470cb987a45b
Author: Tor Andersson <tor_AT_ccxvii.net>
AuthorDate: Wed Mar 9 17:11:57 2016 +0100
Commit: Christoph Lohmann <20h_AT_r-36.net>
CommitDate: Wed Mar 9 22:01:25 2016 +0100

    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_AT_r-36.net>

diff --git a/st.c b/st.c
index f2b3095..839136d 100644
--- a/st.c
+++ b/st.c
_AT_@ -3291,7 +3291,7 @@ xloadfont(Font *f, FcPattern *pattern)
 
         XftTextExtentsUtf8(xw.dpy, f->match,
                 (const FcChar8 *) ascii_printable,
- LEN(ascii_printable), &extents);
+ strlen(ascii_printable), &extents);
 
         f->set = NULL;
         f->pattern = FcPatternDuplicate(pattern);
_AT_@ -3302,7 +3302,7 @@ xloadfont(Font *f, FcPattern *pattern)
         f->rbearing = f->match->max_advance_width;
 
         f->height = f->ascent + f->descent;
- f->width = DIVCEIL(extents.xOff, LEN(ascii_printable));
+ f->width = DIVCEIL(extents.xOff, strlen(ascii_printable));
 
         return 0;
 }
Received on Wed Mar 09 2016 - 22:01:42 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 09 2016 - 22:12:12 CET