Support stretch when using DirectWrite font engine
The DirectWrite font we get when converting the GDI font does not respect the stretch we have set, as this is an attribute of the text layout in DirectWrite and not the font description. To compensate for this, we scale advances and glyphs in the engine if the stretch is different from 100%. [ChangeLog][QtGui][Windows] Fixed stretch when combined with either no or vertical hinting preference or a device pixel ratio different from 1. Task-number: QTBUG-54494 Change-Id: Icc06d1457191782d1a281c99da2da3081a82c542 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
0d99452339
commit
ec7fee968f
@ -351,8 +351,9 @@ void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEn
|
||||
glyphIndices.size(),
|
||||
glyphMetrics.data());
|
||||
if (SUCCEEDED(hr)) {
|
||||
qreal stretch = fontDef.stretch / 100.0;
|
||||
for (int i = 0; i < glyphs->numGlyphs; ++i)
|
||||
glyphs->advances[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth);
|
||||
glyphs->advances[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth * stretch);
|
||||
if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
|
||||
for (int i = 0; i < glyphs->numGlyphs; ++i)
|
||||
glyphs->advances[i] = glyphs->advances[i].round();
|
||||
@ -509,7 +510,7 @@ bool QWindowsFontEngineDirectWrite::supportsSubPixelPositions() const
|
||||
QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
|
||||
QFixed subPixelPosition,
|
||||
int margin,
|
||||
const QTransform &xform)
|
||||
const QTransform &originalTransform)
|
||||
{
|
||||
UINT16 glyphIndex = t;
|
||||
FLOAT glyphAdvance = 0;
|
||||
@ -528,6 +529,10 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t,
|
||||
glyphRun.bidiLevel = 0;
|
||||
glyphRun.glyphOffsets = &glyphOffset;
|
||||
|
||||
QTransform xform = originalTransform;
|
||||
if (fontDef.stretch != 100)
|
||||
xform.scale(fontDef.stretch / 100.0, 1.0);
|
||||
|
||||
DWRITE_MATRIX transform;
|
||||
transform.dx = subPixelPosition.toReal();
|
||||
transform.dy = 0;
|
||||
@ -664,10 +669,15 @@ QString QWindowsFontEngineDirectWrite::fontNameSubstitute(const QString &familyN
|
||||
|
||||
glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph,
|
||||
QFixed subPixelPosition,
|
||||
const QTransform &matrix,
|
||||
const QTransform &originalTransform,
|
||||
GlyphFormat format)
|
||||
{
|
||||
Q_UNUSED(format);
|
||||
|
||||
QTransform matrix = originalTransform;
|
||||
if (fontDef.stretch != 100)
|
||||
matrix.scale(fontDef.stretch / 100.0, 1.0);
|
||||
|
||||
glyph_metrics_t bbox = QFontEngine::boundingBox(glyph, matrix); // To get transformed advance
|
||||
|
||||
UINT16 glyphIndex = glyph;
|
||||
|
Loading…
Reference in New Issue
Block a user