From: Dana Jansens Date: Mon, 17 Mar 2003 06:41:40 +0000 (+0000) Subject: measure the font's height instead of listening to Xft X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=a4838c740cd52d4405fab019b73d118d02599c56;p=chaz%2Fopenbox measure the font's height instead of listening to Xft --- diff --git a/render/font.c b/render/font.c index a55cb77a..67fd1b7d 100644 --- a/render/font.c +++ b/render/font.c @@ -23,6 +23,22 @@ void font_startup(void) #endif } +static void measure_height(ObFont *f) +{ + XGlyphInfo info; + char *str; + + /* XXX add some extended UTF8 characters in here? */ + str = "12345678900-qwertyuiopasdfghjklzxcvbnm" + "!@#$%^&*()_+QWERTYUIOPASDFGHJKLZXCVBNM" + "`~[]\\;',./{}|:\"<>?"; + + XftTextExtentsUtf8(ob_display, f->xftfont, + (FcChar8*)str, strlen(str), &info); + g_message("measured: %d", info.height); + f->height = (signed) info.height; +} + ObFont *font_open(char *fontstring) { ObFont *out; @@ -31,6 +47,7 @@ ObFont *font_open(char *fontstring) if ((xf = XftFontOpenName(ob_display, ob_screen, fontstring))) { out = malloc(sizeof(ObFont)); out->xftfont = xf; + measure_height(out); return out; } g_warning(_("Unable to load font: %s\n"), fontstring); @@ -39,6 +56,7 @@ ObFont *font_open(char *fontstring) if ((xf = XftFontOpenName(ob_display, ob_screen, "fixed"))) { out = malloc(sizeof(ObFont)); out->xftfont = xf; + measure_height(out); return out; } g_warning(_("Unable to load font: %s\n"), "fixed"); @@ -64,7 +82,7 @@ int font_measure_string(ObFont *f, const char *str, int shadow, int offset) int font_height(ObFont *f, int shadow, int offset) { - return (signed) f->xftfont->height + (shadow ? offset : 0); + return f->height + (shadow ? offset : 0); } int font_max_char_width(ObFont *f) @@ -93,7 +111,9 @@ void font_draw(XftDraw *d, TextureText *t) c.pixel = t->color->pixel; c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet - XftDrawStringUtf8(d, &c, t->font->xftfont, x, t->font->xftfont->ascent + y, + XftDrawStringUtf8(d, &c, t->font->xftfont, x, + t->font->xftfont->ascent + y - + (t->font->xftfont->height - t->font->height) / 2, (FcChar8*)t->string, strlen(t->string)); return; } diff --git a/render/render.h b/render/render.h index 9cd1bd73..dfbf4f12 100644 --- a/render/render.h +++ b/render/render.h @@ -99,6 +99,7 @@ typedef struct Surface { typedef struct { XftFont *xftfont; + int height; } ObFont; typedef enum {