[GtkGLExt] width of strings compiled with gdk_gl_use_pango_font?
- From: David Morse <dcmorse gmail com>
- To: gtkglext-list gnome org
- Subject: [GtkGLExt] width of strings compiled with gdk_gl_use_pango_font?
- Date: Wed, 13 Jul 2005 00:10:51 -0400
Hi,
I'm porting, and gdk_gl_use_pango_font works perfectly for me.
What I can't figure out how to do is calculate the width/height of a
certain string in a given font. Some nice person suggested I use
pango layouts (see code below), but I don't think he realized that I
wasn't going through the usual gdk font rendering engine, instead I
was going to glCallLists().
I've measured the below function on the string "GAME OVER" with the
font "lucida Bold 34". Pango Layout predicts:
width 302 (pixels?)
height 53 (pixels?)
ascent 31(pixels?)
Screen capture and measuring in the Gimp shows:
width ~219 pixels
height unmeasurable
ascent 25 pixels,
These differ BADLY, but at least the error seems to be proportional,
like I"m missing some conversion factor.
So to come to the question:
1) Is this the right approach for measuring font-string-widths?
2a) if so, why is it wrong?
2b) if not, what way is the right way? (hopefully not glGetting the
glRasterpos2i after drawing each character in the font - blech!)
/* coco_font_string_dimensions:
Sets w and h to be the bounding box for the specified string, taking
into account multi-line issues. Ascent is not multi-line aware, (what
would that mean?), it simply is set to the ascent of the font as a
whole. nchars_or_minus_one is -1 if string is null terminated. */
void
coco_font_string_dimensions__internal( const char *string, int
nchars_or_minus_one,
struct coco_font *font,
int *w, int *h, int *ascent )
{
PangoRectangle rect;
struct coco_pango_font_stuff *pfstuff = font->implementation_datum;
if (w||h)
{
pango_layout_set_text( pfstuff->layout, string, nchars_or_minus_one );
pango_layout_get_pixel_extents( pfstuff->layout, NULL, &rect );
if (w) *w = rect.width;
if (h) *h = rect.height;
/* avoid leaving the layout around with a stale pointer to
possibly de-allocated memory */
pango_layout_set_text( pfstuff->layout, "", 0 );
}
if (ascent)
*ascent
= PANGO_PIXELS( pango_font_metrics_get_ascent( pfstuff->metrics ) );
}
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]