gdk_text_overall_height



Hi !

I encountered the problem to determine the exakt height of the
bounding rectangle of a string, and found out that "gdk_text_measure"
does all the necessary work, but only returns the width.

Therefore, if nobody objects, I'd like to commit something like the
following:

gint
gdk_text_overall_height (GdkFont     *font,
                         const gchar *text,
                         gint         text_length)
{
  GdkFontPrivate *private;
  XCharStruct overall;
  XFontStruct *xfont;
  XFontSet    fontset;
  XRectangle  ink, log;
  int direction;
  int font_ascent;
  int font_descent;
  gint height;

  g_return_val_if_fail (font != NULL, -1);
  g_return_val_if_fail (text != NULL, -1);

  private = (GdkFontPrivate*) font;

  switch (font->type)
    {
    case GDK_FONT_FONT:
      xfont = (XFontStruct *) private->xfont;
      if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
        {
          XTextExtents (xfont, text, text_length,
                        &direction, &font_ascent, &font_descent,
                        &overall);
        }
      else
        {
          XTextExtents16 (xfont, (XChar2b *) text, text_length / 2,
                          &direction, &font_ascent, &font_descent,
                          &overall);
        }
      height = overall.ascent + overall.descent;
      break;
    case GDK_FONT_FONTSET:
      fontset = (XFontSet) private->xfont;
      XmbTextExtents (fontset, text, text_length, &ink, &log);
      height = log.height;
      break;
    default:
      height = 0;
    }
  return height;
}


Or should we modify "gdk_text_measure" to return more information ? 

bye,
   Stefan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]