[cairo] Locking font / pen space
Andrea Canciani
ranma42 at gmail.com
Mon Aug 30 11:19:45 PDT 2010
On Mon, Aug 30, 2010 at 7:45 PM, Behdad Esfahbod <behdad at behdad.org> wrote:
> On 08/30/10 12:41, Andrea Canciani wrote:
>> On Mon, Aug 30, 2010 at 6:01 PM, Behdad Esfahbod <behdad at behdad.org> wrote:
>>> On 08/27/10 16:37, Bill Spitzak wrote:
>>>>
>>>> I would prefer it to not be reset by changing the font/pen.
>>>
>>> Resetting is needed to preserve backward compatibility with old code. Say, I
>>> have a library function foo_draw(cairo_t *cr). foo_draw sets font, stroke,
>>> etc, then magnifies depending on a requested magnification level, and draws.
>>> This should not break, ever. If the caller locks the font space and the lock
>>> doesn't release upon setting the font by foo_draw(), that function breaks.
>>
>> You could say that the caller should _unlock before calling foo_draw().
>
> You can say all you want in the docs. Still, foo_draw() will be considered
> "buggy" because it makes assumptions about the state the cairo_t is in.
It just behaves respecting the state set in the cairo_t it receives as input.
>
>> This might be a good idea anyway, since the caller doesn't know if foo_draw
>> will reset it or not.
>
> So, when calling any cairo drawing function you have to reset everything?
> Because you don't know...
No, you just reset what you don't want to affect that function behaviour.
If you call that function with lock on it is because you want it to
modify that function
behaviour (just like changing the ctm would change the output of foo_draw())
>
> cairo drawing functions are typically organized like this:
>
> cairo_save()
> ...set whatever we use...
> ...draw...
> cairo_restore()
>
> The caller doesn't need to make any assumption, neither does the callee.
There are quite a lot of underlying assumptions: calls to cairo_restore()s
and cairo_save()s are "balanced parentheses" in draw etc etc
Andrea
More information about the cairo
mailing list