From ec7fee968f5f1a842b7d2fe670de1d517ecca308 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 17 Aug 2016 11:45:59 +0200 Subject: 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 Reviewed-by: Friedemann Kleint --- .../platforms/windows/qwindowsfontenginedirectwrite.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp') diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index c5831dd2e1..04a08d892a 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -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; -- cgit v1.2.3