From 763fb35d9d9461a6927fbcc9551eb8a166cdb677 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 13 Jun 2022 12:35:37 +0200 Subject: [PATCH] CoreText: Fix fonts with synthetic stretch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a font is synthetically condensed / expanded, we need to scale the advances as well as the bounding boxes for the glyph cache. The logic is adapted from DirectWrite font engine, where the same scaling is already in place. [ChangeLog][macOS] Fixed a bug where synthetically stretched fonts would get the wrong advances and sometimes glyphs would be clipped. Fixes: QTBUG-103838 Change-Id: I09fc87b245d1f2de980c10ad9253b9a83571f714 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 992a318d391db397d6fec78532ce9e60af098e58) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/coretext/qfontengine_coretext.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/text/coretext/qfontengine_coretext.mm b/src/gui/text/coretext/qfontengine_coretext.mm index f15b413c11a..89166489926 100644 --- a/src/gui/text/coretext/qfontengine_coretext.mm +++ b/src/gui/text/coretext/qfontengine_coretext.mm @@ -503,7 +503,11 @@ glyph_metrics_t QCoreTextFontEngine::alphaMapBoundingBox(glyph_t glyph, const QF return QFontEngine::alphaMapBoundingBox(glyph, subPixelPosition, matrix, format); glyph_metrics_t br = boundingBox(glyph); - qcoretextfontengine_scaleMetrics(br, matrix); + + QTransform xform = matrix; + if (fontDef.stretch != 100 && fontDef.stretch != QFont::AnyStretch) + xform.scale(fontDef.stretch / 100.0, 1.0); + qcoretextfontengine_scaleMetrics(br, xform); // Normalize width and height if (br.width < 0) @@ -848,8 +852,9 @@ void QCoreTextFontEngine::loadAdvancesForGlyphs(QVarLengthArray &cgGlyp QVarLengthArray advances(numGlyphs); CTFontGetAdvancesForGlyphs(ctfont, kCTFontOrientationHorizontal, cgGlyphs.data(), advances.data(), numGlyphs); + qreal stretch = fontDef.stretch != QFont::AnyStretch ? fontDef.stretch / 100.0 : 1.0; for (int i = 0; i < numGlyphs; ++i) - glyphs->advances[i] = QFixed::fromReal(advances[i].width); + glyphs->advances[i] = QFixed::fromReal(advances[i].width * stretch); } QFontEngine::FaceId QCoreTextFontEngine::faceId() const