From beede51bca1a43befe42499ad784af57d2450162 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 30 Jan 2020 10:01:09 +0100 Subject: Fix rendering offset when using DirectWrite engine When rendering the glyphs into the texture, we need to translate by the margins (this is accounted for later). The visible symptom for this was that when the DirectWrite engine was used all glyphs would be two pixels to the left (which could be seen when placing a cursor at the glyph for instance, and sometimes the edge of the glyph was clipped). Change-Id: Ife72ae8b5663cf43448ae0f8323a459210609b4d Reviewed-by: Simon Hausmann Reviewed-by: Allan Sandfeld Jensen --- .../fontdatabases/windows/qwindowsfontenginedirectwrite.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index 5c999f455e..f84ee3dcaa 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -696,7 +696,7 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, &transform, renderMode, DWRITE_MEASURING_MODE_NATURAL, - 0.0, 0.0, + margin, margin, &glyphAnalysis ); @@ -997,6 +997,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph DWRITE_RENDERING_MODE renderMode = hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); + const int margin = glyphMargin(QFontEngine::Format_A32); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( &glyphRun, @@ -1004,7 +1005,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph &transform, renderMode, DWRITE_MEASURING_MODE_NATURAL, - 0.0, 0.0, + margin, margin, &glyphAnalysis ); @@ -1013,8 +1014,6 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); glyphAnalysis->Release(); - int margin = glyphMargin(QFontEngine::Format_A32); - return glyph_metrics_t(rect.left - margin, rect.top - margin, rect.right - rect.left + margin * 2, -- cgit v1.2.3 From 07e5a05dcb91720a88122e4aba9d8ce6bfbd14ad Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 30 Jan 2020 07:56:02 +0100 Subject: Suppress deprecation warnings for QFont::ForceIntegerMetrics This flag has been deprecated, but until we remove it completely we need to continue supporting it, so we just suppress the warnings for now. Change-Id: I464e1cce42f78af76d46ec12eeb3e8d53d64d6a3 Reviewed-by: Friedemann Kleint --- .../fontdatabases/freetype/qfontengine_ft.cpp | 9 +++++++ .../fontdatabases/mac/qfontengine_coretext.mm | 30 ++++++++++++++++++++++ .../windows/qwindowsfontenginedirectwrite.cpp | 27 +++++++++++++++++++ 3 files changed, 66 insertions(+) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp index 64ceb69c23..8273041549 100644 --- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp +++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp @@ -1334,7 +1334,10 @@ void QFontEngineFT::doKerning(QGlyphLayout *g, QFontEngine::ShaperFlags flags) c } } +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (shouldUseDesignMetrics(flags) && !(fontDef.styleStrategy & QFont::ForceIntegerMetrics)) +QT_WARNING_POP flags |= DesignMetrics; else flags &= ~DesignMetrics; @@ -1649,7 +1652,10 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlag if (face) unlockFace(); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { +QT_WARNING_POP for (int i = 0; i < glyphs->numGlyphs; ++i) glyphs->advances[i] = glyphs->advances[i].round(); } @@ -1729,7 +1735,10 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph) overall.width = g->width; overall.height = g->height; overall.xoff = g->advance; +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) +QT_WARNING_POP overall.xoff = overall.xoff.round(); if (!cacheEnabled && g != &emptyGlyph) delete g; diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index 30c80ebd86..ce793dfafa 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -345,7 +345,10 @@ bool QCoreTextFontEngine::stringToCMap(const QChar *str, int len, QGlyphLayout * glyph_metrics_t QCoreTextFontEngine::boundingBox(const QGlyphLayout &glyphs) { QFixed w; +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED bool round = fontDef.styleStrategy & QFont::ForceIntegerMetrics; +QT_WARNING_POP for (int i = 0; i < glyphs.numGlyphs; ++i) { w += round ? glyphs.effectiveAdvance(i).round() @@ -371,7 +374,10 @@ glyph_metrics_t QCoreTextFontEngine::boundingBox(glyph_t glyph) ret.xoff = QFixed::fromReal(advances[0].width); ret.yoff = QFixed::fromReal(advances[0].height); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { +QT_WARNING_POP ret.xoff = ret.xoff.round(); ret.yoff = ret.yoff.round(); } @@ -381,9 +387,12 @@ glyph_metrics_t QCoreTextFontEngine::boundingBox(glyph_t glyph) QFixed QCoreTextFontEngine::ascent() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) ? QFixed::fromReal(CTFontGetAscent(ctfont)).round() : QFixed::fromReal(CTFontGetAscent(ctfont)); +QT_WARNING_POP } QFixed QCoreTextFontEngine::capHeight() const @@ -392,7 +401,10 @@ QFixed QCoreTextFontEngine::capHeight() const if (c <= 0) return calculatedCapHeight(); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) +QT_WARNING_POP c = c.round(); return c; @@ -401,28 +413,40 @@ QFixed QCoreTextFontEngine::capHeight() const QFixed QCoreTextFontEngine::descent() const { QFixed d = QFixed::fromReal(CTFontGetDescent(ctfont)); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) +QT_WARNING_POP d = d.round(); return d; } QFixed QCoreTextFontEngine::leading() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) ? QFixed::fromReal(CTFontGetLeading(ctfont)).round() : QFixed::fromReal(CTFontGetLeading(ctfont)); +QT_WARNING_POP } QFixed QCoreTextFontEngine::xHeight() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) ? QFixed::fromReal(CTFontGetXHeight(ctfont)).round() : QFixed::fromReal(CTFontGetXHeight(ctfont)); +QT_WARNING_POP } QFixed QCoreTextFontEngine::averageCharWidth() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return (fontDef.styleStrategy & QFont::ForceIntegerMetrics) ? avgCharWidth.round() : avgCharWidth; +QT_WARNING_POP } qreal QCoreTextFontEngine::maxCharWidth() const @@ -917,8 +941,11 @@ void QCoreTextFontEngine::loadAdvancesForGlyphs(QVarLengthArray &cgGlyp for (int i = 0; i < numGlyphs; ++i) { QFixed advance = QFixed::fromReal(advances[i].width); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED glyphs->advances[i] = fontDef.styleStrategy & QFont::ForceIntegerMetrics ? advance.round() : advance; +QT_WARNING_POP } } @@ -1027,7 +1054,10 @@ QFontEngine::Properties QCoreTextFontEngine::properties() const result.capHeight = QFixed::fromReal(CTFontGetCapHeight(ctfont) * scale); result.lineWidth = QFixed::fromReal(CTFontGetUnderlineThickness(ctfont) * scale); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { +QT_WARNING_POP result.ascent = result.ascent.round(); result.descent = result.descent.round(); result.leading = result.leading.round(); diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index f84ee3dcaa..e8f9cfb2a8 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -487,7 +487,10 @@ void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEn qreal stretch = fontDef.stretch != QFont::AnyStretch ? fontDef.stretch / 100.0 : 1.0; for (int i = 0; i < glyphs->numGlyphs; ++i) glyphs->advances[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth * stretch); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { +QT_WARNING_POP for (int i = 0; i < glyphs->numGlyphs; ++i) glyphs->advances[i] = glyphs->advances[i].round(); } @@ -531,7 +534,10 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(const QGlyphLayout &g if (glyphs.numGlyphs == 0) return glyph_metrics_t(); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED bool round = fontDef.styleStrategy & QFont::ForceIntegerMetrics; +QT_WARNING_POP QFixed w = 0; for (int i = 0; i < glyphs.numGlyphs; ++i) { @@ -557,7 +563,10 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(glyph_t g) QFixed topSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.topSideBearing); QFixed bottomSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.bottomSideBearing); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { +QT_WARNING_POP advanceWidth = advanceWidth.round(); advanceHeight = advanceHeight.round(); } @@ -579,9 +588,12 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(glyph_t g) QFixed QWindowsFontEngineDirectWrite::ascent() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_ascent.round() : m_ascent; +QT_WARNING_POP } QFixed QWindowsFontEngineDirectWrite::capHeight() const @@ -589,37 +601,52 @@ QFixed QWindowsFontEngineDirectWrite::capHeight() const if (m_capHeight <= 0) return calculatedCapHeight(); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_capHeight.round() : m_capHeight; +QT_WARNING_POP } QFixed QWindowsFontEngineDirectWrite::descent() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_descent.round() : m_descent; +QT_WARNING_POP } QFixed QWindowsFontEngineDirectWrite::leading() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_lineGap.round() : m_lineGap; +QT_WARNING_POP } QFixed QWindowsFontEngineDirectWrite::xHeight() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_xHeight.round() : m_xHeight; +QT_WARNING_POP } qreal QWindowsFontEngineDirectWrite::maxCharWidth() const { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED return fontDef.styleStrategy & QFont::ForceIntegerMetrics ? m_maxAdvanceWidth.round().toReal() : m_maxAdvanceWidth.toReal(); +QT_WARNING_POP } QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) -- cgit v1.2.3