[Libreoffice-commits] core.git: vcl/inc vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Sep 7 18:27:33 UTC 2018


 vcl/inc/win/salgdi.h      |    3 ++-
 vcl/inc/win/winlayout.hxx |    8 +++++---
 vcl/win/gdi/salfont.cxx   |   11 ++++-------
 vcl/win/gdi/winlayout.cxx |   26 +++++++++++++++++---------
 4 files changed, 28 insertions(+), 20 deletions(-)

New commits:
commit 7cb3e475f2fb0162c7290414509de4fb8fe57e30
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Thu Sep 6 14:04:25 2018 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Fri Sep 7 20:27:01 2018 +0200

    WIN add SalGraphics* to WinFontInstance
    
    HFONT lookup in ImplDoSetFont depends on the mbVirDev of the
    WinSalGraphics. Since we need too look up HFONTs for SalLayout
    without changing the corresponding SalGraphics, add a pointer
    to the WinFontInstance.
    
    Change-Id: Idb6573ce7267f0019c2183be47621d0eaef8e57b
    Reviewed-on: https://gerrit.libreoffice.org/60093
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 243d2cdc8fc5..9f30f57ecac8 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -170,9 +170,10 @@ private:
 
     bool CacheGlyphs(const GenericSalLayout& rLayout);
     bool DrawCachedGlyphs(const GenericSalLayout& rLayout);
-    HFONT ImplDoSetFont(FontSelectPattern const & i_rFont, const PhysicalFontFace * i_pFontFace, float& o_rFontScale, HFONT& o_rOldFont);
 
 public:
+    HFONT ImplDoSetFont(FontSelectPattern const & i_rFont, const PhysicalFontFace * i_pFontFace, float& o_rFontScale, HFONT& o_rOldFont);
+
     HDC getHDC() const { return mhLocalDC; }
     void setHDC(HDC aNew) { mhLocalDC = aNew; }
 
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 066f7b587f6d..161b3666e06a 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -154,20 +154,22 @@ public:
     GlyphCache& GetGlyphCache() { return maGlyphCache; }
     bool hasHScale() const;
 
-    void SetHFONT(const HFONT);
+    void SetGraphics(WinSalGraphics*);
+    WinSalGraphics* GetGraphics() const { return m_pGraphics; }
+
     HFONT GetHFONT() const { return m_hFont; }
-    void SetScale(float fScale) { m_fScale = fScale; }
     float GetScale() const { return m_fScale; }
 
     // Prevent deletion of the HFONT in the WinFontInstance destructor
     // Used for the ScopedFont handling
-    void UnsetHFONT() { m_hFont = nullptr; }
+    void SetHFONT(HFONT hFont) { m_hFont = hFont; }
 
 private:
     explicit WinFontInstance(const PhysicalFontFace&, const FontSelectPattern&);
 
     virtual hb_font_t* ImplInitHbFont() override;
 
+    WinSalGraphics *m_pGraphics;
     HFONT m_hFont;
     float m_fScale;
     GlyphCache maGlyphCache;
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index e2734052c9c0..15a95ee98668 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -934,13 +934,10 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, int nFallbackLevel)
     HFONT hNewFont = pFontInstance->GetHFONT();
     if (!hNewFont)
     {
-        float fFontScale = 1.0;
-        hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), pFont->GetFontFace(), fFontScale, hOldFont);
-        mpWinFontEntry[ nFallbackLevel ]->SetHFONT(hNewFont);
-        mpWinFontEntry[ nFallbackLevel ]->SetScale(fFontScale);
+        pFontInstance->SetGraphics(this);
+        hNewFont = pFontInstance->GetHFONT();
     }
-    else
-        hOldFont = ::SelectFont( getHDC(), hNewFont );
+    hOldFont = ::SelectFont(getHDC(), hNewFont);
 
     // keep default font
     if( !mhDefFont )
@@ -1588,7 +1585,7 @@ ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData), m_hOrigFont(null
     if (m_rData.mpWinFontEntry[0])
     {
         m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT();
-        m_rData.mpWinFontEntry[0]->UnsetHFONT();
+        m_rData.mpWinFontEntry[0]->SetHFONT(nullptr);
     }
 }
 
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 3800fcd9adc3..a1d76c8026a4 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -307,13 +307,16 @@ std::unique_ptr<SalLayout> WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs
 
     assert(mpWinFontEntry[nFallbackLevel]->GetFontFace());
 
+    mpWinFontEntry[nFallbackLevel]->SetGraphics(this);
     GenericSalLayout *aLayout = new GenericSalLayout(*mpWinFontEntry[nFallbackLevel]);
     return std::unique_ptr<SalLayout>(aLayout);
 }
 
 WinFontInstance::WinFontInstance(const PhysicalFontFace& rPFF, const FontSelectPattern& rFSP)
     : LogicalFontInstance(rPFF, rFSP)
+    , m_pGraphics(nullptr)
     , m_hFont(nullptr)
+    , m_fScale(1.0f)
 {
 }
 
@@ -335,8 +338,12 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
 {
     sal_uLong nLength = 0;
     unsigned char* pBuffer = nullptr;
-    HFONT hFont = static_cast<HFONT>(pUserData);
-    HDC hDC = GetDC(nullptr);
+    WinFontInstance* pFont = static_cast<WinFontInstance*>(pUserData);
+    HDC hDC = pFont->GetGraphics()->getHDC();
+    HFONT hFont = pFont->GetHFONT();
+    assert(hDC);
+    assert(hFont);
+
     HGDIOBJ hOrigFont = SelectObject(hDC, hFont);
     nLength = ::GetFontData(hDC, OSL_NETDWORD(nTableTag), 0, nullptr, 0);
     if (nLength > 0 && nLength != GDI_ERROR)
@@ -345,7 +352,6 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
         ::GetFontData(hDC, OSL_NETDWORD(nTableTag), 0, pBuffer, nLength);
     }
     SelectObject(hDC, hOrigFont);
-    ReleaseDC(nullptr, hDC);
 
     hb_blob_t* pBlob = nullptr;
     if (pBuffer != nullptr)
@@ -356,8 +362,8 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
 
 hb_font_t* WinFontInstance::ImplInitHbFont()
 {
-    assert(m_hFont);
-    hb_font_t* pHbFont = InitHbFont(hb_face_create_for_tables(getFontTable, m_hFont, nullptr));
+    assert(m_pGraphics);
+    hb_font_t* pHbFont = InitHbFont(hb_face_create_for_tables(getFontTable, this, nullptr));
 
     // Calculate the AverageWidthFactor, see LogicalFontInstance::GetScale().
     if (GetFontSelectPattern().mnWidth)
@@ -373,14 +379,13 @@ hb_font_t* WinFontInstance::ImplInitHbFont()
         aLogFont.lfWidth = 0;
 
         // Get the font metrics.
+        HDC hDC = m_pGraphics->getHDC();
         HFONT hNewFont = CreateFontIndirectW(&aLogFont);
-        HDC hDC = GetDC(nullptr);
         HGDIOBJ hOrigFont = SelectObject(hDC, hNewFont);
         TEXTMETRICW aFontMetric;
         GetTextMetricsW(hDC, &aFontMetric);
         SelectObject(hDC, hOrigFont);
         DeleteObject(hNewFont);
-        ReleaseDC(nullptr, hDC);
 
         SetAverageWidthFactor(nUPEM / aFontMetric.tmAveCharWidth);
     }
@@ -388,12 +393,15 @@ hb_font_t* WinFontInstance::ImplInitHbFont()
     return pHbFont;
 }
 
-void WinFontInstance::SetHFONT(const HFONT hFont)
+void WinFontInstance::SetGraphics(WinSalGraphics *pGraphics)
 {
     ReleaseHbFont();
     if (m_hFont)
         ::DeleteFont(m_hFont);
-    m_hFont = hFont;
+    m_pGraphics = pGraphics;
+    HFONT hOrigFont;
+    m_hFont = m_pGraphics->ImplDoSetFont(GetFontSelectPattern(), GetFontFace(), m_fScale, hOrigFont);
+    SelectObject(m_pGraphics->getHDC(), hOrigFont);
 }
 
 bool WinSalGraphics::CacheGlyphs(const GenericSalLayout& rLayout)


More information about the Libreoffice-commits mailing list