X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=f2b309562c3111455e024c03ff89de8e8d333616;hb=0e48a1995eee1c2babc58523ef0be296e4b1c3e8;hp=2473af7b44b01fcb7d62d45f7b1ce749c7bf4c52;hpb=30440295bc054f37a2a8275acca769cd83bcb780;p=st.git diff --git a/st.c b/st.c index 2473af7..f2b3095 100644 --- a/st.c +++ b/st.c @@ -68,6 +68,7 @@ char *argv0; #define LEN(a) (sizeof(a) / sizeof(a)[0]) #define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) +#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) #define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) @@ -3277,6 +3278,7 @@ xloadfont(Font *f, FcPattern *pattern) { FcPattern *match; FcResult result; + XGlyphInfo extents; match = FcFontMatch(NULL, pattern, &result); if (!match) @@ -3287,6 +3289,10 @@ xloadfont(Font *f, FcPattern *pattern) return 1; } + XftTextExtentsUtf8(xw.dpy, f->match, + (const FcChar8 *) ascii_printable, + LEN(ascii_printable), &extents); + f->set = NULL; f->pattern = FcPatternDuplicate(pattern); @@ -3296,7 +3302,7 @@ xloadfont(Font *f, FcPattern *pattern) f->rbearing = f->match->max_advance_width; f->height = f->ascent + f->descent; - f->width = f->lbearing + f->rbearing; + f->width = DIVCEIL(extents.xOff, LEN(ascii_printable)); return 0; } @@ -3665,7 +3671,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x specs[numspecs].font = frc[f].font; specs[numspecs].glyph = glyphidx; specs[numspecs].x = (short)xp; - specs[numspecs].y = (short)(winy + frc[f].font->ascent); + specs[numspecs].y = (short)yp; xp += runewidth; numspecs++; }