[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Math differences between FT_Set_Transform and FT_Glyph_Transform
From: |
Werner LEMBERG |
Subject: |
Re: Math differences between FT_Set_Transform and FT_Glyph_Transform |
Date: |
Tue, 14 Jul 2020 09:42:47 +0200 (CEST) |
Hello Derek,
sorry for the late reply.
> I've been integrating FreeType for text rendering in a game engine
> and have everything I need working, but I recently ran into an
> oddity. When switching from using FT_Set_Transform before loading a
> glyph to FT_Glyph_Transform on the copy of the glyph I render with,
> I noticed that the glyph advances were slightly different between
> the two transform functions, even though both use
> FT_Vector_Transform.
>
> What seems to be going on is that when the advance is transformed in
> FT_Set_Transform, FT_MulFix is multiplying a 26.6 fixed-point value
> (the face advance vector) by a 16.16 value (the matrix), whereas
> FT_Glyph_Transform is multiplying two 16.16 values (the glyph
> advance is 16.16). The side-effect is that when FT_MulFix adds 1/2
> to round the intermediate value, the math is different depending on
> the fixed-point precision of that intermediate value.
>
> The difference is minor (and not visible from what I can tell), but
> I'm seeing a couple off-by-one errors when calculating control boxes
> after transforming with FT_Glyph_Transform.
>
> I’m not really sure this is something that should be fixed, and I
> have a simple workaround by converting the glyph advance to 26.6
> before transforming, then back to 16.16 afterwards. It's definitely
> odd that you can get different values for the advance depending on
> when the transform is applied, though.
>
> I don't really have a question beyond: is my understanding of what's
> going on correct?
Your understanding is correct: `FT_Face::FT_GlyphSlot::advance` is in
26.6 format, while `FT_Glyph::advance` is in 16.16 format, and the
different rounding causes slight differences in the result.
And I agree that there is probably nothing to be fixed except the
documentation, which should mention this difference, and how to
circumvent it if necessary.
David?
By the way, do you have a reason to mix `FT_Set_Transform` with
`FT_Glyph_Transform` to get the same advance widths? Otherwise, the
difference shouldn't be an issue, right?
Werner
- Re: Math differences between FT_Set_Transform and FT_Glyph_Transform,
Werner LEMBERG <=