[cairo] How to measure Fonts

thom_schu at gmx.de thom_schu at gmx.de
Mon Feb 5 00:15:28 PST 2007

Hi there,
I want to draw my own Gtkmm-Widgets using Pango + Cairo.
I started to draw some lines, rectangles ..... everything looked fine.
But then I started to work with fonts and I got confused.

What I wanted to do is to draw a Rectangle and put a String in the
y-middle of that Rectangle :

cairoContext->rectangle(0, 0, 200, 20);
Cairo::TextExtents extents;
cairoContext->get_text_extents("HELLO", extents);
cairoContext->move_to(0, 20-((20-extents.height)/2));

But this doesnt work at all. The font-height is smaller then the value of extends.height.
I also tried with "pangoLayout->get_pixel_size( ....), but get the same result.

I think all this font-stuff is too much for me.
Isnt there an introduction ?
Why does the font look different when I draw with a gtk-draw-method like
window->draw_layout(...) or with pangoLayout->get_line(0)->show_in_cairo_context(cairoContext), the Cairo::Context was created with window->create_cairo_context() ......
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

More information about the cairo mailing list