CoreText: Fix fonts with synthetic stretch
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ø <tor.arne.vestbo@qt.io> (cherry picked from commit 992a318d391db397d6fec78532ce9e60af098e58) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
97d7042c45
commit
763fb35d9d
@ -503,7 +503,11 @@ glyph_metrics_t QCoreTextFontEngine::alphaMapBoundingBox(glyph_t glyph, const QF
|
|||||||
return QFontEngine::alphaMapBoundingBox(glyph, subPixelPosition, matrix, format);
|
return QFontEngine::alphaMapBoundingBox(glyph, subPixelPosition, matrix, format);
|
||||||
|
|
||||||
glyph_metrics_t br = boundingBox(glyph);
|
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
|
// Normalize width and height
|
||||||
if (br.width < 0)
|
if (br.width < 0)
|
||||||
@ -848,8 +852,9 @@ void QCoreTextFontEngine::loadAdvancesForGlyphs(QVarLengthArray<CGGlyph> &cgGlyp
|
|||||||
QVarLengthArray<CGSize> advances(numGlyphs);
|
QVarLengthArray<CGSize> advances(numGlyphs);
|
||||||
CTFontGetAdvancesForGlyphs(ctfont, kCTFontOrientationHorizontal, cgGlyphs.data(), advances.data(), 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)
|
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
|
QFontEngine::FaceId QCoreTextFontEngine::faceId() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user