Re: determining character width



On Thu, Jul 11, 2002 at 03:12:18PM -0400, Allin Cottrell wrote:
I want to set the width of a text window in characters rather than
fixing it in pixels.  The idea is to supply the function that creates
the window with a width parameter ("hsize") in characters, then the
function computes on the fly the corresponding width in pixels.

PangoLayout *pl;
int width;

pl = pango_layout_new(gtk_widget_get_pango_context(widget));

pango_layout_set_text(pl, "sample text here", -1);
/* -1 indicates "use strlen() to find length of string. */
pango_layout_get_pixel_size(pl, &width, NULL);
/* NULL because we don't care about height. */

gtk_widget_set_size_request(widget, width, -1);
/* -1 because we don't care about height. */

/* make sure to unref the PangoLayout! */
g_object_unref(G_OBJECT(pl));


Lemme know if you have any problems...

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



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