Re: GTK & Pango string measurement
- From: Wesley Smith <wesley hoke gmail com>
- To: Ken Resander <kresander yahoo com>
- Cc: gtk-list gnome org
- Subject: Re: GTK & Pango string measurement
- Date: Wed, 16 Sep 2009 01:07:08 -0700
In the situation I'm talking about, there is no GtkWidget object so
your technique won't work. This is the code I'm going off of
actually. Thus my question is how can I get a pango context from a
On Tue, Sep 15, 2009 at 11:16 PM, Ken Resander <kresander yahoo com> wrote:
> I also had a similar problem. Here is how I ended up doing it...
> extern GttWidget * curdlg; // of current dialog
> void gettextwdht ( char * family , int ptsize , int weight , bool normalstyle ,
> char * stringtomeasure ,
> int * wdret , int * htret )
> PangoFontDescription * fd = pango_font_description_new ( );
> pango_font_description_set_family (fd, family );
> pango_font_description_set_style (fd, normalstyle ? PANGO_STYLE_NORMAL :
> PANGO_STYLE_ITALIC );
> pango_font_description_set_variant (fd, PANGO_VARIANT_NORMAL);
> pango_font_description_set_weight (fd, (PangoWeight)weight );
> pango_font_description_set_stretch (fd, PANGO_STRETCH_NORMAL);
> pango_font_description_set_size (fd, ptsize * PANGO_SCALE);
> PangoContext * context = gtk_widget_get_pango_context ( curdlg ) ;
> PangoLayout * layout = pango_layout_new ( context );
> pango_layout_set_text ( layout, stringtomeasure, -1 );
> pango_layout_set_font_description ( layout, fd );
> pango_layout_get_pixel_size (layout, wdret , htret );
> g_object_unref ( layout );
> You can 'borrow' any widget for this (I think). It worked with a dialog widget for me.
> I really wanted a PangoContext that is not associated with a widget, so the calculations can be carried out totally 'offline'. I could not see how to do that.
> If anyone knows, I would be interested in finding out.
> P.S. The code shown above combines getting a font and measuring it. The actual code I am using splits these into two steps for efficiency.
> I'm banging my head trying to figure out how to measure the text width
> of a string to be displayed in a GtkCelRendererText. From the code
> I've found, I need a PangoContext and GtkCelRendererText has plenty of
> Pango properties but none that return a PangoContext. In addition,
> GtkCelRendererText is not a GtkWidget, so I can't use
> gtk_widget_get_pango_context(). I'm at a loss as to how to do this.
> Any ideas?
> Get your new Email address!
> Grab the Email name you've always wanted before someone else does!
> gtk-list mailing list
> gtk-list gnome org
] [Thread Prev