Re: Font style in widget->size_request





On Tue, Mar 24, 2009 at 2:18 PM, David Brigada <brigad rpi edu> wrote:
Hello,

I am writing a graph widget for use in GTK+ applications.  I'm trying to calculate the minimum size for the widget from the text along the axes of the graph.  I use Cairo to draw the text, so I'm using the cairo_text_extents functions to calculate their sizes.

However, I'm running into a problem where widget->style->font_desc does not seem to be returning a valid Pango font description.  When I call pango_font_description_get_size on the font_desc, it returns 10 * PANGO_SCALE, which seems to be a default value when the style isn't initialized.  This causes my function to assume the incorrect font size when calculating its size request.  I tried calling gtk_widget_ensure_style on my widget before accessing the font_desc element, but that does not help.

at some point the development of GTK (i don't recall precisely where, but roughly in the vicinity of GTK 2.10), a change was made to the way styles "bind" to widgets. the key change was that a widget that is not attached to a GtkWindow doesn't have a style (yet).

i have several examples in my code where i need to do style-based size computation, and so I create a dummy GtkWindow, pack some (temporary, representative) widget into it (I do not show the window), then use ensure_style, and then do the computation, and then delete them both. the critical change was adding the widget to the (dummy) window. it was initially a very irritating change, but in the end a pretty trivial code change.

---p





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