vcl/inc/win/DWriteTextRenderer.hxx | 15 +++++++++++++++ vcl/inc/win/winlayout.hxx | 2 ++ vcl/win/gdi/DWriteTextRenderer.cxx | 28 ++++++++++------------------ vcl/win/gdi/winlayout.cxx | 8 ++++++++ 4 files changed, 35 insertions(+), 18 deletions(-)
New commits: commit 14c76305c6ebbaa765caf45db409a10cf99c5cea Author: Mike Kaganski <[email protected]> AuthorDate: Mon Apr 8 11:12:01 2024 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Apr 8 11:12:01 2024 +0500 Revert "Exclude getHScale from DirectWrite font rendering" This reverts commit 36e8e419d022a9c43302efe5e702a704dea39e76. diff --git a/vcl/inc/win/DWriteTextRenderer.hxx b/vcl/inc/win/DWriteTextRenderer.hxx index a655df6459ea..67094052ebb5 100644 --- a/vcl/inc/win/DWriteTextRenderer.hxx +++ b/vcl/inc/win/DWriteTextRenderer.hxx @@ -72,6 +72,21 @@ private: D2DTextAntiAliasMode meTextAntiAliasMode; }; +/** + * Sets and unsets the needed DirectWrite transform to support the font's horizontal scaling and + * rotation. + */ +class WinFontTransformGuard +{ +public: + WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, float fHScale, const GenericSalLayout& rLayout, const D2D1_POINT_2F& rBaseline, bool bIsVertical); + ~WinFontTransformGuard(); + +private: + ID2D1RenderTarget* mpRenderTarget; + D2D1::Matrix3x2F maTransform; +}; + #endif // INCLUDED_VCL_INC_WIN_DWRITERENDERER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx index ac70e42b66cf..0f253230c1b4 100644 --- a/vcl/inc/win/winlayout.hxx +++ b/vcl/inc/win/winlayout.hxx @@ -36,6 +36,8 @@ class WinFontInstance : public LogicalFontInstance public: ~WinFontInstance() override; + float getHScale() const; + void SetGraphics(WinSalGraphics*); WinSalGraphics* GetGraphics() const { return m_pGraphics; } diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx index 321587db8137..b7d7c03e9995 100644 --- a/vcl/win/gdi/DWriteTextRenderer.cxx +++ b/vcl/win/gdi/DWriteTextRenderer.cxx @@ -97,20 +97,6 @@ HRESULT checkResult(HRESULT hr, const char* file, size_t line) #endif -// Sets and unsets the needed DirectWrite transform to support the font's rotation. -class WinFontTransformGuard -{ -public: - WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, - const GenericSalLayout& rLayout, const D2D1_POINT_2F& rBaseline, - bool bIsVertical); - ~WinFontTransformGuard(); - -private: - ID2D1RenderTarget* mpRenderTarget; - D2D1::Matrix3x2F maTransform; -}; - } // end anonymous namespace D2DWriteTextOutRenderer::D2DWriteTextOutRenderer(bool bRenderingModeNatural) @@ -232,6 +218,7 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa } const WinFontInstance& rWinFont = static_cast<const WinFontInstance&>(rLayout.GetFont()); + float fHScale = rWinFont.getHScale(); float lfEmHeight = 0; IDWriteFontFace* pFontFace = GetDWriteFace(rWinFont, &lfEmHeight); @@ -264,11 +251,11 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart)) { UINT16 glyphIndices[] = { static_cast<UINT16>(pGlyph->glyphId()) }; - FLOAT glyphAdvances[] = { static_cast<FLOAT>(pGlyph->newWidth()) }; + FLOAT glyphAdvances[] = { static_cast<FLOAT>(pGlyph->newWidth()) / fHScale }; DWRITE_GLYPH_OFFSET glyphOffsets[] = { { 0.0f, 0.0f }, }; - D2D1_POINT_2F baseline = { static_cast<FLOAT>(aPos.getX() - bounds.Left()), + D2D1_POINT_2F baseline = { static_cast<FLOAT>(aPos.getX() - bounds.Left()) / fHScale, static_cast<FLOAT>(aPos.getY() - bounds.Top()) }; - WinFontTransformGuard aTransformGuard(mpRT, rLayout, baseline, pGlyph->IsVertical()); + WinFontTransformGuard aTransformGuard(mpRT, fHScale, rLayout, baseline, pGlyph->IsVertical()); DWRITE_GLYPH_RUN glyphs = { pFontFace, lfEmHeight, @@ -319,7 +306,7 @@ IDWriteFontFace* D2DWriteTextOutRenderer::GetDWriteFace(const WinFontInstance& r return pFontFace; } -WinFontTransformGuard::WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, +WinFontTransformGuard::WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, float fHScale, const GenericSalLayout& rLayout, const D2D1_POINT_2F& rBaseline, bool bIsVertical) @@ -327,6 +314,11 @@ WinFontTransformGuard::WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, { pRenderTarget->GetTransform(&maTransform); D2D1::Matrix3x2F aTransform = maTransform; + if (fHScale != 1.0f) + { + aTransform + = aTransform * D2D1::Matrix3x2F::Scale(D2D1::Size(fHScale, 1.0f), D2D1::Point2F(0, 0)); + } Degree10 angle = rLayout.GetOrientation(); diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index f7ac7f5ff851..3865f2ebed66 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -147,6 +147,14 @@ WinFontInstance::~WinFontInstance() ::DeleteFont(m_hFont); } +float WinFontInstance::getHScale() const +{ + const vcl::font::FontSelectPattern& rPattern = GetFontSelectPattern(); + if (!rPattern.mnHeight || !rPattern.mnWidth) + return 1.0; + return rPattern.mnWidth * GetAverageWidthFactor() / rPattern.mnHeight; +} + void WinFontInstance::ImplInitHbFont(hb_font_t* /*pHbFont*/) { assert(m_pGraphics);
