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>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2022-10-19 14:39:38 +02:00
parent 2decbe0417
commit cdd7163c60

View File

@ -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 {