From 2f5695bed5660e32a41786d8b9ab6b4b0775caf1 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 16 Aug 2021 14:41:47 +0200 Subject: Fix printing with unhinted fonts On high-dpi displays or when you explicitly select an unhinted font, we pick a DirectWrite font engine. This hit an uncovered code path on Windows, because we relied on being able to get the HFONT from the font engine. To fix this, we introduce an alternative code path which gets the HFONT based on the DirectWrite font when this font engine is active. [ChangeLog][Windows] Fixed an issue where the characters in printed text would look too small. Pick-to: 6.1 6.2 Fixes: QTBUG-95720 Change-Id: Ifd609e92512e1f25f0ee2aace35cb5ccedf09030 Reviewed-by: Lars Knoll --- src/gui/text/windows/qwindowsfontenginedirectwrite.cpp | 16 ++++++++++++++++ src/gui/text/windows/qwindowsfontenginedirectwrite_p.h | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/gui/text') diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp index 0dac9769ef..55aab15132 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp @@ -337,6 +337,22 @@ QString QWindowsFontEngineDirectWrite::filenameFromFontFile(IDWriteFontFile *fon return ret; } +HFONT QWindowsFontEngineDirectWrite::createHFONT() const +{ + if (m_fontEngineData == nullptr || m_directWriteFontFace == nullptr) + return NULL; + + LOGFONT lf; + HRESULT hr = m_fontEngineData->directWriteGdiInterop->ConvertFontFaceToLOGFONT(m_directWriteFontFace, + &lf); + if (SUCCEEDED(hr)) { + lf.lfHeight = -qRound(fontDef.pixelSize); + return CreateFontIndirect(&lf); + } else { + return NULL; + } +} + void QWindowsFontEngineDirectWrite::initializeHeightMetrics() const { DWRITE_FONT_METRICS metrics; diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite_p.h b/src/gui/text/windows/qwindowsfontenginedirectwrite_p.h index 4d19c3908a..06eb5ae475 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite_p.h +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite_p.h @@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE class QWindowsFontEngineData; -class QWindowsFontEngineDirectWrite : public QFontEngine +class Q_GUI_EXPORT QWindowsFontEngineDirectWrite : public QFontEngine { Q_DISABLE_COPY_MOVE(QWindowsFontEngineDirectWrite) public: @@ -107,6 +107,8 @@ public: bool supportsHorizontalSubPixelPositions() const override; + HFONT createHFONT() const; + QImage alphaMapForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition) override; QImage alphaMapForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition, -- cgit v1.2.3