diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-10-19 14:39:38 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-10-20 16:05:25 +0200 |
commit | cdd7163c6071ac2020a1750cf2820ecea057abe4 (patch) | |
tree | 71be710b1883e0003af69476d8be6ed37fe9346b /src/gui/text | |
parent | 2decbe04170842c23119dc752d45f51021773836 (diff) |
macOS: Fix synthetic bold on scaled painters
Bold synthesizing on macOS works by redrawing the text at a
subpixel offset. However, since the text position is given
in user space (pre-transformed) we need to scale the offset
by the current matrix, otherwise you can get large gaps between
the two instances of the text.
[ChangeLog][macOS] Fixed an issue with synthetic bold on
fonts when the painter had a scale
Fixes: QTBUG-103215
Change-Id: Idf0ae3da75a55825cbb5598561ef8fd9a512c6a5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/coretext/qfontengine_coretext.mm | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/gui/text/coretext/qfontengine_coretext.mm b/src/gui/text/coretext/qfontengine_coretext.mm index 32f7ed2094..599a7f08c3 100644 --- a/src/gui/text/coretext/qfontengine_coretext.mm +++ b/src/gui/text/coretext/qfontengine_coretext.mm @@ -362,6 +362,7 @@ bool QCoreTextFontEngine::hasColorGlyphs() const return glyphFormat == QFontEngine::Format_ARGB; } +Q_GUI_EXPORT extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight) { QVarLengthArray<QFixedPoint> positions; @@ -406,7 +407,15 @@ void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextIt CTFontDrawGlyphs(ctfont, cgGlyphs.data(), cgPositions.data(), glyphs.size(), ctx); if (synthesisFlags & QFontEngine::SynthesizedBold) { - CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(), + QTransform matrix(cgMatrix.a, cgMatrix.b, cgMatrix.c, cgMatrix.d, cgMatrix.tx, cgMatrix.ty); + + qreal boldOffset = 0.5 * lineThickness().toReal(); + qreal scale; + qt_scaleForTransform(matrix, &scale); + boldOffset *= scale; + + CGContextSetTextPosition(ctx, + positions[0].x.toReal() + boldOffset, positions[0].y.toReal()); CTFontDrawGlyphs(ctfont, cgGlyphs.data(), cgPositions.data(), glyphs.size(), ctx); } @@ -753,7 +762,13 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, const QFixedPoint &subP CTFontDrawGlyphs(ctfont, &cgGlyph, &CGPointZero, 1, ctx); if (synthesisFlags & QFontEngine::SynthesizedBold) { - CGContextSetTextPosition(ctx, pos_x + 0.5 * lineThickness().toReal(), pos_y); + qreal boldOffset = 0.5 * lineThickness().toReal(); + + qreal scale; + qt_scaleForTransform(matrix, &scale); + boldOffset *= scale; + + CGContextSetTextPosition(ctx, pos_x + boldOffset, pos_y); CTFontDrawGlyphs(ctfont, &cgGlyph, &CGPointZero, 1, ctx); } } else { |