[cairo] Locking font / pen space

Arjen Nienhuis a.g.nienhuis at gmail.com
Sat Aug 28 05:30:10 PDT 2010


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
cairo_lock_font_space(cr);

// draw as tall widget at [0,0] and add a caption
cairo_save(cr);
cairo_scale(cr, 2, 0.5);
my_draw_widget(cr);
cairo_show_text (cr, "My Tall Widget");
cairo_restore(cr);

// draw as narrow widget at [100,0] and add a caption
cairo_save(cr);
cairo_translate(100, 0);
cairo_scale(0.5, 2);
my_draw_widget(cr);
cairo_show_text (cr, "My Narrow Widget");
cairo_restore(cr);

Right?

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
    cairo_save(cr);
    my_draw_triangle(30,0, 60,50, 0,50);
    cairo_translate(25, 40);
    cairo_set_font_size(cr, 30);
    cairo_show_text (cr, "!");
    cairo_restore(cr);
}

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_save(cr);
    cairo_restore_font_space(cr, my_label_font_space);
    cairo_show_text (cr, text);
    cairo_restore(cr);
}

Groeten, Arjen

On Fri, Aug 27, 2010 at 9:45 PM, Behdad Esfahbod <behdad at behdad.org> wrote:

> It occured to me last night that instead of changing the behavior of font /
> pen space locking at the they are set, we can add two new calls:
>
>  cairo_lock_font_space()
>  cairo_lock_pen_space()
>
> These two will record the ctm at the time of the call to be used for text /
> stroke until the font-space / pen-space is set again (perhaps implicitly by
> cairo_restore()).
>
> May want to add the unlock() versions too.  I don't like the fact that the
> unlock is not mandatory, but I think I can live with this API and have more
> confidence in it than I have in changing the semantics of existing API.
>
> behdad
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100828/ced57745/attachment.html>


More information about the cairo mailing list