[cairo] Locking font / pen space
spitzak at gmail.com
Sat Aug 28 09:05:15 PDT 2010
On Aug 28, 2010, at 5:30 AM, Arjen Nienhuis wrote:
> Help me try to understand this please.
> A use case for cairo_lock_font_space() is to draw text of the same
> size while using a different transform:
> // All captions should be the same size
> // draw as tall widget at [0,0] and add a caption
> cairo_scale(cr, 2, 0.5);
> cairo_show_text (cr, "My Tall Widget");
> // draw as narrow widget at [100,0] and add a caption
> cairo_translate(100, 0);
> cairo_scale(0.5, 2);
> cairo_show_text (cr, "My Narrow Widget");
Yes that will draw text the same size as it was being drawn before the
> Now what if I want the text in my_draw_widget() to scale? How would
> that work?
> void my_draw_widget(cr)
> // draw a /!\ symbol
> my_draw_triangle(30,0, 60,50, 0,50);
> cairo_translate(25, 40);
> cairo_set_font_size(cr, 30);
> cairo_show_text (cr, "!");
That will draw text *exactly* the same whether font-lock is on or off.
I think this may be the confusion.
Font-lock will only make a difference if there is a transform (rotate,
scale, etc) between when you set the font and when you use it.
In fact I very much believe almost every current Cairo program will
work correctly whether or not font-lock is on. That is because nobody
ever does transforms between setting the font and printing, because
the current behavior is never what is wanted. There may be some
programs that set the font, don't draw, then transform, then draw,
these would have to be fixed by swapping the transform and font
setting. But just looking at the examples it seems very rare that
programmers write it this way.
> I think I'd rather save the font space in a variable and restore it
> when needed:
> my_label_font_space = cairo_save_font_space(cr);
> void my_draw_label(cr, text)
> cairo_restore_font_space(cr, my_label_font_space);
> cairo_show_text (cr, text);
I can assure you this is NOT what is wanted. This sort of hack can be
done now in Cairo (by building paths and then restoring the transform,
or by loading the identity transform). The purpose of this call is to
get the desired behavior with *fewer* calls!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo