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

Re: Size of text



Hi,

How can we determine the size of the text in terms of
pxiel? 

My gtkmm code looks like this:
Glib::RefPtr<Pango::Layout> pango_layout =
create_pango_layout(ustr);
Pango::FontDescription fd("Courier 400");
pango_layout->set_font_description( fd);              
window_->draw_layout(gc_, 220, 100, pango_layout);

I want to know how big the "ustr" is, so that I can
position it in the right place on the screen
automatically instead of using things like "220" and
"100" here.

Thanks,
Dan


--- Owen Taylor <otaylor@redhat.com> wrote:
> 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
> 
> 
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
>
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


=====
----------------------------------------------------------
Have fun!
__________________________________________________________

__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com



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