From a5085d7f6ac0ee4e066431ec9a99b7e0f13d2d0c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 25 May 2021 11:32:31 +0200 Subject: minor: Clean up areMetricsTooLarge() conditions This amends e2bdff3555f8c2a275c7bbcf964d939a5f489100. 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 b7e436738756b1d5d7a45201b7a7204d7fe128a1 it was turned back into 16.6 again. But this was accidentally reverted as part of a bad conflict resolution in afb326f07109da0035112e6f56e683e37b8a5d72. 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 --- src/gui/text/freetype/qfontengine_ft.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp index ae1e139251..12ba46b7ed 100644 --- a/src/gui/text/freetype/qfontengine_ft.cpp +++ b/src/gui/text/freetype/qfontengine_ft.cpp @@ -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; -- cgit v1.2.3