Re: What replaces gdk_text_extents() ?



Hello Owen and Rikke,
thanks for your help. I decided to use the code that Owen suggested. I
think it works more exactly than Rikke's code when using proportional
fonts and looks at bit easier.
Maybe someone of the developers could add a cross reference from the GDK
manual's Fonts section to the example in the GTK manual in a spare
minute. This would make it easier for newbies like me to find what they
are looking for.

From "Rikke D. Giles" <rgiles telebyte com>:
> I just did this using a PangoFontMetric.
>
> Here's what I did:
>
> PangoLayout *layout;
> PangoContext *context;
> PangoFontMetrics *metrics;
> gchar *text_string;
> gint textx, texty, char_width, string_width;
>
>    layout = gtk_widget_create_pango_layout(widget, NULL);
>
>    text_string = g_strdup_printf(some_text);
>
>    pango_layout_set_text(layout, text_string, -1);
>
>    /* want this text in the center of x-dimension and
>       7/8 down the y dimension of the widget */
>    textx = widget->allocation.width / 2;
>    texty = 7 * widget->allocation.height / 8;
>
>
>    /* find out how wide the characters are to center on textx
> */                 context = gtk_widget_get_pango_context(widget);
>    metrics = pango_context_get_metrics(context,
>        widget->style->font_desc,
>        pango_context_get_language(context));
>    char_width = pango_font_metrics_get_approximate_char_width (metrics);
>    string_width = strlen(text_string) * PANGO_PIXELS(char_width);
>
>    gtk_paint_layout(widget->style, widget->window,
>        GTK_WIDGET_STATE(widget), FALSE,
>        NULL, widget, "widget_name", textx - (string_width/2), texty,
>        layout);
>
>
> I don't know if this is a good way to do this or not, but it worked for
> me.
>
> Cheers,
>
> Rikke
-- 
====================================================================
Peter Krüger

applied software solutions (appss) GmbH
Sandtorstr. 23
D-39106 Magdeburg
Germany

Phone:  +49-(0)391-54486-19388
Fax:    +49-(0)391-54486-19222
email:  krueger appss de
URL:    http://www.appss.de

Managing Director: Uwe Hess, Dietmar Schäfer
Register: HRB12386, AG Mageburg

"Virtual business becomes reality!"

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
====================================================================




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