[cairo] How to get extents of transformed graphics
Andreas Falkenhahn
andreas at falkenhahn.com
Sat Sep 17 13:31:35 UTC 2022
On 17.09.2022 at 13:47 Uli Schlachter wrote:
> Okay, so I have finally taken a look at this. Actually, I only looked at
> the demo program in the bug report and not this mailing list thread
> (half the conversation seems to happen outside of the mailing list...?).
Oops, yeah, looks like Michal didn't CC the mailing list at all.
> Could someone please tell me why the conclusion was that this is a bug
> in cairo? If I understood the thread correctly, the conclusion was just
> "this happens on Ubuntu, but not on Darwin", but I cannot find anything
> saying that this is a bug.
> What I think is going on: Font hinting!
> When you draw some text, "magic happens" to make it more readable. This
> magic includes moving stuff slightly so that things end up a bit more
> aligned to the pixel grid. Thus, this can change the extents of the text.
Yes, this makes very much sense and explains the fact that it works on
Darwin but not on Ubuntu because the font backend is probably different
between the two.
I can confirm that when disabling font hinting all my problems with the
extents of transformed text are gone so it definitely isn't a bug, but a
feature ;)
> Attached is another variation that makes the problem go away: Instead of
> scaling the extents with a factor of 4.6, I ask cairo for the extents
> after the scaling was applied.
Argh, that's depressing. It's what I wanted to do first but for some
reason I misunderstood the Cairo manual which says that cairo_fill_extents()
returns values in "user coordinates". This made me think that it does *not*
take any transformation into account but apparently that thought is just
plain wrong.
It's a bit frustrating that nobody corrected this misconception because I
actually started my very first email on 28th August with it. I wrote:
"Is there any way to get the *exact* extents of transformed graphics? AFAICS,
cairo_fill_extents() is in user coordinates, i.e. it doesn't take any transformation
settings into account."
If someone had just said "Hey, cairo_fill_extents() *does* take the transformation
settings into account" it would have spared me a lot of trouble :-(
--
Best regards,
Andreas Falkenhahn mailto:andreas at falkenhahn.com
More information about the cairo
mailing list