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

Re: Size of text



On Wed, 2003-04-23 at 10:09, François-Xavier Coudert wrote:
> Hello,
> 
> I'm developping an application with Gtk+ 2.0, and I'm fighting with
> Pango (mostly due to the lack of a tutorial or basic help other than
> API).
> 
> I want to draw text on a pixmap, and I'd like to be able to scale it by
> a given factor. I tried pango_attr_size_new, but can't make it work. I
> would expect the following code:
> 
> gint
> button_press_event (GtkWidget * widget, GdkEventButton * event)
> {
>   PangoLayout *p_layout;
>   PangoAttribute *p_attr;
>   PangoAttrList *p_list;
> 
>   p_layout = gtk_widget_create_pango_layout (widget, "Text");
>   p_list = pango_attr_list_new ();
>   p_attr = pango_attr_size_new ((int) (10000 * (1 + ((double) i) / 5)));
>   printf ("%d\n", (int) (10000 * (1 + ((double) i) / 5)));
>   pango_attr_list_insert (p_list, p_attr);
>   pango_layout_set_attributes (p_layout, p_list);
> 
>   gdk_draw_layout (widget->window, widget->style->black_gc, 60 * i + 10,
>                    10, p_layout);
>   i++;
> 
>   return TRUE;
> }
> 
> 
> to display "Text" every time I click, with its size increasing, but the
> size is always the same (the default size), though the (int) (10000 * (1
> + ((double) i) / 5)) factor is increasing.
> 
> I think I miss something trivial, but can't figure out what. Can someone
> help me?

You have the same problem that everybody using PangoAttrList has (so,
clearly an API-design problem).

PangoAttrList isn't a list of of attributes to apply to the whole
layout, but rather a list of attributes applied to ranges of text.
When you create a new PangoAttribute, the range for it is [0,0], 
so, you need to do:
 
 p_attr->start_index = 0;
 p_attr->end_index = strlen ("Text");

(Remember to call pango_attr_list_unref() after
pango_Layout_set_attributes())

Regards,
                                                Owen





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