minor: Clean up areMetricsTooLarge() conditions

This amends e2bdff3555.

The linearAdvance property has some history. First it was
a 16 bit value (allowing for 10.6 fixed point numbers). Then
it was turned into 22 bits to fit the 16 bits of Freetype
integer parts into it (16.6). Then back to 10.6. Then in
b7e4367387 it was turned
back into 16.6 again. But this was accidentally reverted
as part of a bad conflict resolution in
afb326f071.

Since there was no check for it, we would sometimes overflow
the linearAdvance, but only in the rare cases where the
width and height did not also overflow. Specifically this
is the case for whitespace, which always has a width of 0
regardless of the advance.

This change just moves the linearAdvance condition in
together with the other checks to avoid fragmentation, and
also adds this fun story to the commit log.

Pick-to: 6.1 5.15
Change-Id: Iaac09942f4c50d1aced4a160b6eabb11eb8e6373
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2021-05-25 11:32:31 +02:00
parent 810e755c18
commit a5085d7f6a

View File

@ -903,7 +903,7 @@ int QFontEngineFT::loadFlags(QGlyphSet *set, GlyphFormat format, int flags,
static inline bool areMetricsTooLarge(const QFontEngineFT::GlyphInfo &info)
{
// false if exceeds QFontEngineFT::Glyph metrics
return info.width > 0xFF || info.height > 0xFF;
return info.width > 0xFF || info.height > 0xFF || info.linearAdvance > 0x7FFF;
}
static inline void transformBoundingBox(int *left, int *top, int *right, int *bottom, FT_Matrix *matrix)
@ -1052,7 +1052,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph,
// If any of the metrics are too large to fit, don't cache them
// Also, avoid integer overflow when linearAdvance is to large to fit in a signed short
if (areMetricsTooLarge(info) || info.linearAdvance > 0x7FFF)
if (areMetricsTooLarge(info))
return nullptr;
g = new Glyph;