diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-11-20 02:34:26 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-11-20 02:35:17 +0100 |
commit | 64d4275b60d50a87fb2bf4dd45be3c28902cec52 (patch) | |
tree | 6fbd008b39e473acd357d08bcca0035be1b96ff3 | |
parent | 16a7e944ab1b318fafb7dd48d48379168403d2e8 (diff) |
vcl: fix artificial bold and italic on Windows
Move creating DWFontFace to WinFontInstance so that it get proper font
synthesis settings.
Regression from:
commit a80239ede3236c84d7a05d0fbc0f299811fee6c0
Author: Khaled Hosny <khaled@aliftype.com>
Date: Sat Nov 19 03:03:15 2022 +0200
vcl: move creating DWFontFace to WinFontFace
Change-Id: Ifba947d8908a37972d723028258500b10ec24cd4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142982
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/inc/font/PhysicalFontFace.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 2 | ||||
-rw-r--r-- | vcl/inc/unx/freetype_glyphcache.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/win/salgdi.h | 4 | ||||
-rw-r--r-- | vcl/inc/win/winlayout.hxx | 3 | ||||
-rw-r--r-- | vcl/quartz/ctfonts.cxx | 2 | ||||
-rw-r--r-- | vcl/skia/win/gdiimpl.cxx | 2 | ||||
-rw-r--r-- | vcl/source/font/LogicalFontInstance.cxx | 2 | ||||
-rw-r--r-- | vcl/source/font/PhysicalFontFace.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/glyphs/freetype_glyphcache.cxx | 2 | ||||
-rw-r--r-- | vcl/win/gdi/DWriteTextRenderer.cxx | 2 | ||||
-rw-r--r-- | vcl/win/gdi/salfont.cxx | 63 |
12 files changed, 47 insertions, 41 deletions
diff --git a/vcl/inc/font/PhysicalFontFace.hxx b/vcl/inc/font/PhysicalFontFace.hxx index 6e99ae4a098c..96f2533f22fe 100644 --- a/vcl/inc/font/PhysicalFontFace.hxx +++ b/vcl/inc/font/PhysicalFontFace.hxx @@ -194,7 +194,7 @@ public: return nullptr; } - virtual const std::vector<hb_variation_t>& GetVariations() const; + virtual const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const; protected: mutable hb_face_t* mpHbFace; diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index 79ea9e32e0d6..4812404bbc6e 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -72,7 +72,7 @@ public: hb_blob_t* GetHbTable(hb_tag_t nTag) const override; - const std::vector<hb_variation_t>& GetVariations() const override; + const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const override; private: CTFontDescriptorRef mxFontDescriptor; diff --git a/vcl/inc/unx/freetype_glyphcache.hxx b/vcl/inc/unx/freetype_glyphcache.hxx index 4cf982c50a12..5bc1632ccee6 100644 --- a/vcl/inc/unx/freetype_glyphcache.hxx +++ b/vcl/inc/unx/freetype_glyphcache.hxx @@ -101,7 +101,7 @@ public: virtual hb_face_t* GetHbFace() const override; virtual hb_blob_t* GetHbTable(hb_tag_t nTag) const override; - const std::vector<hb_variation_t>& GetVariations() const override; + const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const override; }; class SAL_DLLPUBLIC_RTTI FreetypeFontInstance final : public LogicalFontInstance diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 999bb39a1812..f26f1d40f0c9 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -72,11 +72,9 @@ public: BYTE GetCharSet() const { return meWinCharSet; } BYTE GetPitchAndFamily() const { return mnPitchAndFamily; } - IDWriteFontFace* GetDWFontFace() const; - hb_blob_t* GetHbTable(hb_tag_t nTag) const override; - const std::vector<hb_variation_t>& GetVariations() const override; + const std::vector<hb_variation_t>& GetVariations(const LogicalFontInstance&) const override; private: sal_IntPtr mnId; diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx index 702bf7bf0b2a..fb8e5a1c6e43 100644 --- a/vcl/inc/win/winlayout.hxx +++ b/vcl/inc/win/winlayout.hxx @@ -54,6 +54,8 @@ public: bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override; + IDWriteFontFace* GetDWFontFace() const; + private: explicit WinFontInstance(const WinFontFace&, const vcl::font::FontSelectPattern&); @@ -65,6 +67,7 @@ private: float m_fScale; bool m_bIsCJKVerticalFont; sal_Int32 m_nTmDescent; + mutable sal::systools::COMReference<IDWriteFontFace> mxDWFontFace; }; class TextOutRenderer diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx index c2f6a8a55c00..92fd35fa2cee 100644 --- a/vcl/quartz/ctfonts.cxx +++ b/vcl/quartz/ctfonts.cxx @@ -268,7 +268,7 @@ hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const return pBlob; } -const std::vector<hb_variation_t>& CoreTextFontFace::GetVariations() const +const std::vector<hb_variation_t>& CoreTextFontFace::GetVariations(const LogicalFontInstance&) const { CTFontRef pFont = CTFontCreateWithFontDescriptor(mxFontDescriptor, 0.0, nullptr); diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx index a9df26cb53a1..d063b440cf31 100644 --- a/vcl/skia/win/gdiimpl.cxx +++ b/vcl/skia/win/gdiimpl.cxx @@ -135,7 +135,7 @@ WinSkiaSalGraphicsImpl::createDirectWriteTypeface(const WinFontInstance* pWinFon if (!dwriteFontMgr) return nullptr; - IDWriteFontFace* fontFace = pWinFont->GetFontFace()->GetDWFontFace(); + IDWriteFontFace* fontFace = pWinFont->GetDWFontFace(); if (!fontFace) return nullptr; diff --git a/vcl/source/font/LogicalFontInstance.cxx b/vcl/source/font/LogicalFontInstance.cxx index c3a7c6726537..cf2fd332802e 100644 --- a/vcl/source/font/LogicalFontInstance.cxx +++ b/vcl/source/font/LogicalFontInstance.cxx @@ -63,7 +63,7 @@ hb_font_t* LogicalFontInstance::InitHbFont() hb_font_set_scale(pHbFont, nUPEM, nUPEM); hb_ot_font_set_funcs(pHbFont); - auto aVariations = pFace->GetVariations(); + auto aVariations = pFace->GetVariations(*this); if (!aVariations.empty()) hb_font_set_variations(pHbFont, aVariations.data(), aVariations.size()); diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx index d0670f51a1e2..cf9849162d15 100644 --- a/vcl/source/font/PhysicalFontFace.cxx +++ b/vcl/source/font/PhysicalFontFace.cxx @@ -510,7 +510,7 @@ OUString PhysicalFontFace::GetName(NameID aNameID, const LanguageTag& rLanguageT return sName; } -const std::vector<hb_variation_t>& PhysicalFontFace::GetVariations() const +const std::vector<hb_variation_t>& PhysicalFontFace::GetVariations(const LogicalFontInstance&) const { if (!mxVariations) { diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index 4d430e6d8f9a..4cc30ea3c21a 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -367,7 +367,7 @@ hb_blob_t* FreetypeFontFace::GetHbTable(hb_tag_t nTag) const return hb_face_reference_table(mpHbFace, nTag); } -const std::vector<hb_variation_t>& FreetypeFontFace::GetVariations() const +const std::vector<hb_variation_t>& FreetypeFontFace::GetVariations(const LogicalFontInstance&) const { if (!mxVariations) { diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx index c09eeb410199..b7d7c03e9995 100644 --- a/vcl/win/gdi/DWriteTextRenderer.cxx +++ b/vcl/win/gdi/DWriteTextRenderer.cxx @@ -288,7 +288,7 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa IDWriteFontFace* D2DWriteTextOutRenderer::GetDWriteFace(const WinFontInstance& rWinFont, float* lfSize) const { - auto pFontFace = rWinFont.GetFontFace()->GetDWFontFace(); + auto pFontFace = rWinFont.GetDWFontFace(); if (pFontFace) { LOGFONTW aLogFont; diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 8719829ee8d4..7139aa038163 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -539,39 +539,13 @@ rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const vcl::f return new WinFontInstance(*this, rFSD); } -IDWriteFontFace* WinFontFace::GetDWFontFace() const -{ - if (!mxDWFontFace) - { - IDWriteGdiInterop* pDWriteGdiInterop; - WinSalGraphics::getDWriteFactory(nullptr, &pDWriteGdiInterop); - - HDC hDC(::GetDC(nullptr)); - HFONT hFont = ::CreateFontIndirectW(&maLogFont); - HFONT hOldFont = ::SelectFont(hDC, hFont); - - HRESULT hr = pDWriteGdiInterop->CreateFontFaceFromHdc(hDC, &mxDWFontFace); - if (FAILED(hr)) - { - SAL_WARN("vcl.fonts", "HRESULT 0x" << OUString::number(hr, 16) << ": " - << WindowsErrorStringFromHRESULT(hr)); - mxDWFontFace = nullptr; - } - - ::SelectFont(hDC, hOldFont); - ::DeleteFont(hFont); - ::ReleaseDC(nullptr, hDC); - } - - return mxDWFontFace; -} - -const std::vector<hb_variation_t>& WinFontFace::GetVariations() const +const std::vector<hb_variation_t>& +WinFontFace::GetVariations(const LogicalFontInstance& rFont) const { if (!mxVariations) { mxVariations.emplace(); - auto pDWFontFace = WinFontFace::GetDWFontFace(); + auto pDWFontFace = static_cast<const WinFontInstance&>(rFont).GetDWFontFace(); if (pDWFontFace) { sal::systools::COMReference<IDWriteFontFace5> xDWFontFace5; @@ -1424,4 +1398,35 @@ bool WinFontInstance::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& return true; } +IDWriteFontFace* WinFontInstance::GetDWFontFace() const +{ + if (!mxDWFontFace) + { + assert(m_pGraphics); + HDC hDC = m_pGraphics->getHDC(); + const HFONT hOrigFont = static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT)); + const HFONT hFont = GetHFONT(); + if (hFont != hOrigFont) + SelectObject(hDC, hFont); + + const ::comphelper::ScopeGuard aFontRestoreScopeGuard([hFont, hOrigFont, hDC]() { + if (hFont != hOrigFont) + SelectObject(hDC, hOrigFont); + }); + + IDWriteGdiInterop* pDWriteGdiInterop; + WinSalGraphics::getDWriteFactory(nullptr, &pDWriteGdiInterop); + + HRESULT hr = pDWriteGdiInterop->CreateFontFaceFromHdc(hDC, &mxDWFontFace); + if (FAILED(hr)) + { + SAL_WARN("vcl.fonts", "HRESULT 0x" << OUString::number(hr, 16) << ": " + << WindowsErrorStringFromHRESULT(hr)); + mxDWFontFace = nullptr; + } + } + + return mxDWFontFace; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |