From: Dana Jansens Date: Wed, 4 Jun 2003 22:23:55 +0000 (+0000) Subject: better font layout X-Git-Tag: gl-oldtheme~43 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=5481c48383168e7e1858d630ed23fee0b62c996f;p=dana%2Fopenbox.git better font layout --- diff --git a/render2/font.c b/render2/font.c index 3a37c824..0bf2997b 100644 --- a/render2/font.c +++ b/render2/font.c @@ -58,7 +58,7 @@ void RrFontRenderString(struct RrSurface *sur, struct RrFont *font, { struct GlftColor col; int fh = RrFontHeight(font); - int l, m; + int l, mw, mh; GString *text; int shortened = 0; @@ -81,16 +81,18 @@ void RrFontRenderString(struct RrSurface *sur, struct RrFont *font, text = g_string_new(string); l = g_utf8_strlen(text->str, -1); - m = RrFontMeasureString(font, text->str); + GlftMeasureString(font->font, text->str, strlen(text->str), &mw, &mh); if (font->elipses > w) l = 0; /* nothing fits.. */ else { - while (l && m > w) { + while (l && mw > w) { shortened = 1; /* remove a character from the middle */ text = g_string_erase(text, l-- / 2, 1); /* if the elipses are too large, don't show them at all */ - m = RrFontMeasureString(font, text->str) + font->elipses; + GlftMeasureString(font->font, text->str, strlen(text->str), + &mw, &mh); + mw += font->elipses; } if (shortened) { text = g_string_insert(text, (l + 1) / 2, ELIPSES); @@ -99,6 +101,10 @@ void RrFontRenderString(struct RrSurface *sur, struct RrFont *font, } if (!l) return; + /* center in the font's height's area based on the measured height of the + specific string */ + y += (fh - mh) / 2; + switch (layout) { case RR_TOP_LEFT: case RR_LEFT: @@ -107,12 +113,12 @@ void RrFontRenderString(struct RrSurface *sur, struct RrFont *font, case RR_TOP: case RR_CENTER: case RR_BOTTOM: - x += (w - m) / 2; + x += (w - mw) / 2; break; case RR_TOP_RIGHT: case RR_RIGHT: case RR_BOTTOM_RIGHT: - x += w - m; + x += w - mw; break; }