summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-03-17 06:41:40 +0000
committerDana Jansens <danakj@orodu.net>2003-03-17 06:41:40 +0000
commita4838c740cd52d4405fab019b73d118d02599c56 (patch)
tree4bf1c700afd36e06a5257d091e563045e885e546 /render
parent5d62948cc5ace4dfa4c2543a53e9f7f7d9a86fff (diff)
measure the font's height instead of listening to Xft
Diffstat (limited to 'render')
-rw-r--r--render/font.c24
-rw-r--r--render/render.h1
2 files changed, 23 insertions, 2 deletions
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 {