diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-05-26 08:58:45 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-05-27 14:41:52 +0200 |
commit | 8b0f5763b2f7fa8985b4982cd9b54934942b4ea0 (patch) | |
tree | 12719f403b38e8c96342b6613060751aaf44a25a /src/platformsupport | |
parent | dfc5a1035607d433acdb64b0798bc6d8d9cad729 (diff) |
Fix various offset issues with DirectWrite font engine
This reverts commit 318a991907b6c08f52786160bafea1e30d3ad9bd
and its follow-up commit beede51bca1a43befe42499ad784af57d2450162.
This fix was incorrect and caused regressions elsewhere (QTBUG-84357)
The issue in QTBUG-71928 (offsets on emojis) turned out to be much
simpler: The emojis are expected to be drawn without any margin,
but since we retrieved the margin for A32 there would be a mismatch
between the margin used for positioning and the actual margin in the
returned QImage from the font engine.
Passing the correct margin in bitmapForGlyph() fixes this.
But reverting these fixes reintroduces a clipping bug when using
software rendering in Qt Quick: QTBUG-80180. This needs to be addressed
in Qt Quick. It also exposes an existing issue with positioning in
Qt Quick NativeRendering: QTBUG-84454.
In addition, it caused an assert when running with ClearType disabled,
which turned out to be because we were using the A32 margin in the
A8 case in the DirectWrite engine. This was also the cause of
QTBUG-50024 before, which is now also fixed.
However, it also needs to work with Qt Quick, where the text is currently
offset by margin * dpr and glyphs are clipped with the software renderer,
possibly because of the offset in position.
Task-number: QTBUG-71928
Task-number: QTBUG-84042
Task-number: QTBUG-80180
Task-number: QTBUG-84454
Fixes: QTBUG-84357
Fixes: QTBUG-50024
Pick-to: 5.15
Change-Id: I2c8f9f9e7dfb34d492e9833a02fa0c93e6a19513
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r-- | src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index 6c9d4b29a0..6070d59a3e 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -649,7 +649,7 @@ QT_WARNING_POP QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) { - QImage im = alphaRGBMapForGlyph(glyph, subPixelPosition, t); + QImage im = imageForGlyph(glyph, subPixelPosition, glyphMargin(Format_A8), t); QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8); @@ -723,7 +723,7 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, &transform, renderMode, measureMode, - margin, margin, + 0.0, 0.0, &glyphAnalysis ); @@ -731,6 +731,9 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, RECT rect; glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); + if (rect.top == rect.bottom || rect.left == rect.right) + return QImage(); + QRect boundingRect = QRect(QPoint(rect.left - margin, rect.top - margin), QPoint(rect.right + margin, @@ -1025,7 +1028,6 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); DWRITE_MEASURING_MODE measureMode = renderModeToMeasureMode(renderMode); - const int margin = glyphMargin(QFontEngine::Format_A32); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( &glyphRun, @@ -1033,7 +1035,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph &transform, renderMode, measureMode, - margin, margin, + 0.0, 0.0, &glyphAnalysis ); @@ -1042,8 +1044,10 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); glyphAnalysis->Release(); - return glyph_metrics_t(rect.left - margin, - rect.top - margin, + int margin = glyphMargin(format); + + return glyph_metrics_t(rect.left, + rect.top, rect.right - rect.left + margin * 2, rect.bottom - rect.top + margin * 2, bbox.xoff, bbox.yoff); @@ -1054,7 +1058,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph QImage QWindowsFontEngineDirectWrite::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t, const QColor &color) { - return imageForGlyph(glyph, subPixelPosition, glyphMargin(QFontEngine::Format_A32), t, color); + return imageForGlyph(glyph, subPixelPosition, glyphMargin(QFontEngine::Format_ARGB), t, color); } QT_END_NAMESPACE |