Re: Font Sizes



thumper plover net writes:
A while ago I asked about how to set the size (in lines) of a text
view.  Havoc filed bug 62103 about the unimplemented height_lines and
width_columns properties.  This bug has been marked resolved and it
says I should use textview->style->font_desc to get the size of the
font and size the widget using that info.

Well the reason I closed the bug is that having the size feature on
the text view itself isn't right, because you don't want to change the
text view's size request, you want to change the default size of the
window containing the text view.

So now my question is, given a PangoFontDescription, how do I figure
out the width/height (in pixels) of text rendered in that font?

I'm guessing maybe I need to make a PangoFontMetrics and calculate
ascent + descent + pixels_above_lines + pixels_below_lines?  If that's
correct, how do I get the PangoFontMetrics?

Have a look at gtk/gtkentry.c source code, it looks something like
this:

  PangoFontMetrics *metrics;
  PangoContext *context;
  
  context = gtk_widget_get_pango_context (widget);
  metrics = pango_context_get_metrics (context,
                                       widget->style->font_desc,
                                       pango_context_get_language (context));

  ascent = pango_font_metrics_get_ascent (metrics);
  descent = pango_font_metrics_get_descent (metrics);

There's an "approximate_char_width" metric as well IIRC.

Havoc



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