[cairo] How to get extents of transformed graphics

Uli Schlachter psychon at znc.in
Sat Sep 17 11:47:50 UTC 2022


Hi,

Am 17.09.22 um 13:18 schrieb Andreas Falkenhahn:
> On 16.09.2022 at 17:00 Michal Sudolsky wrote:
> 
>> That was on darwin. I am getting the same result as you on ubuntu.
>> I would assume that this is a bug. Are you planning to report it on gitlab?
> 
> Thanks for confirming the issue. I've now opened an issue on gitlab about
> it here: https://gitlab.freedesktop.org/cairo/cairo/-/issues/591
> 
> So hopefully this will get fixed...
> 
> Thanks again for your feedback and the useful demo program! (I've
> included it in the gitlib ticket).

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...?).

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.

For this reason, doing any kind of transformation (besides translation) 
on text extents is wrong (I would not be surprised if even rotations 
were affected due to subpixel order business).

What I understand from the test program:

- You get some font extents for the letter "C"
- Then you scale the font extents and the ctm by 4.6
- The assumption is that the extents and a letter "C" still correspond 
to each other

However, for reasons that I do not understand myself in this specific 
example, the two do not correspond. In the bug report I already replied 
that disabling hinting makes the difference go away.

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.

Cheers,
Uli
-- 
"Because I'm in pain," he says. "That's the only way I get your attention."
He picks up the box. "Don't worry, Katniss. It'll pass."
He leaves before I can answer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tmp.png
Type: image/png
Size: 7490 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20220917/ca3a0587/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 1174 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20220917/ca3a0587/attachment-0001.c>


More information about the cairo mailing list