[cairo] [PATCH] ft: correct abs(distance) to fabs(distance)

Matt Sealey matt at genesi-usa.com
Fri Mar 22 12:19:21 PDT 2013


On Thu, Mar 21, 2013 at 3:50 PM, Behdad Esfahbod <behdad at behdad.org> wrote:
> Hi Matt,
>
> On 13-03-20 03:12 PM, Matt Sealey wrote:
>> Previous commit a8f1b45 ([FT] Prefer downscaling bitmap glyphs to upscaling)
>> modified the behavior of Cairo's FT font backend but it seems accidentally
>> used abs() with a 'double' type argument. The compiler almost silently
>> converts the double to signed integer and then we get the absolute value
>> of that signed integer as a signed integer result cast into a double.
>
> Oops.
>
>
>> The net effect is that min_distance loses precision (fractional part is
>> discarded by the compiler's conversion of double -> int) and in some cases
>> observed here some fonts do not render correctly if there was any scaling
>> involved that actually had a fractional value.
>
> Pushing this out.  Though I fail to see how it can cause fonts to not render
> correctly.  Worst harm it can do is that the wrong strike will be chosen, if
> there are strikes very close in size.  Right?

My best guess is that it was not entirely Cairo's fault, and that one
of the apps, or a combination of GTK, Cairo, FT, Pango, Harfbuzz or so
was relying on everything being perfect at the Cairo side, and also
doing it's own handling on the FT_Face. With the font being scaled
weirdly by Cairo (i.e. not as expected) some math didn't match and it
started going haywire with the actual rendering.

The net effect was that some fonts were a little smaller (in fact,
some so small they were unreadable) and the advances weren't correct
so we got characters laid on top of each other (as in a 20-character
filename string being rendered in a 16x8 box).

It's not an easily reproduceable environment, we're using pretty much
ancient 2009/2010 versions of the GNOME2 desktop vs. brand new Cairo
and Pixman, so there could be bugs fixed in the past 3 or 4 years
upstream that make this never happen in real life for anyone doing any
real development.

All I could tell without spending far more time than I have to work on
it is that at Cairo ToT, it broke, I reverted your patch, it worked
again, I reverted my revert and made a one-line fix, and it stayed
fixed..

--
Matt Sealey <matt at genesi-usa.com>
Product Development Analyst, Genesi USA, Inc.


More information about the cairo mailing list