Re: determining character width



On Thu, Jul 11, 2002 at 04:32:17PM -0400, Allin Cottrell wrote:
Thank you, this is certainly heading in the right direction, but I'd
really like to get the fixed width of a single monospaced glyph as a
unit (so as to be able to multiply up by the desired with in
characters).  Comparing gtk-1.2 and gtk-2.0,

    gdk_char_width(fixed_font, 'X');

returns 7, while

    pango_layout_set_text(pl, "X", 1);
    pango_layout_get_pixel_size(pl, &width, NULL);

returns 9 (with the same font, Lucida Typewriter, in both cases).  If
I multiply up 9 times the max number of characters on a row (e.g. 78),
I get too wide a window.

I'm reaching here, but it seems possible that the extra space is because
the character is in isolation.  Perhaps try:

char *x_times_78 = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
pango_layout_set_text(pl, x_times_78, 1);


    width = pango_font_metrics_get_approximate_char_width(pfm);
It returns 8.  ;-)

Well, the function does claim to be "approximate"... ;)

-- 
      Evan Martin
martine cs washington edu
  http://neugierig.org



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