Rebased ref, commits from common ancestor:
commit 2fb1514255b4783a180d614abbd5b7f53e55ab9b
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Thu Sep 6 14:04:25 2018 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Thu Sep 6 14:48:38 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

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 bf9b2149163e..cd0611750fb4 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 )
@@ -1586,7 +1583,7 @@ private:
 ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData)
 {
     m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT();
-    m_rData.mpWinFontEntry[0]->UnsetHFONT();
+    m_rData.mpWinFontEntry[0]->SetHFONT(nullptr);
 }
 
 ScopedFont::~ScopedFont()
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)
commit 9324e87991644e6ca4887086f1cf17ada25b045f
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Thu Sep 6 14:00:29 2018 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Thu Sep 6 14:42:00 2018 +0200

    WIN drop mhFonts[MAX_FALLBACK]
    
    Everything now uses the HFONT from WinFontInstance, so there
    is no need for the additional fallback array.
    
    Change-Id: I15a197b262633569cb95c37689561db5323e1115

diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 32a104bef88e..243d2cdc8fc5 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -156,19 +156,6 @@ private:
     bool                    mbScreen : 1;           // is Screen compatible
     HWND                    mhWnd;              // Window-Handle, when 
Window-Graphics
 
-    /** HFONT lifecycle
-     *
-     * The HFONT has to be shared between mhFonts and mpWinFontEntry.
-     * As mpWinFontEntry is reference counted and just freed in SetFont, the 
HFONT is
-     * transferred from mhFonts to the mpWinFontEntry.
-     *
-     * We need the mhFonts list, as embedded fonts don't have a corresponding 
WinFontInstance
-     * so for these there is just the mhFonts entry.
-     *
-     * The HFONT object can just be assigned to mhFonts _or_ mpWinFontEntry!
-     **/
-
-    HFONT                   mhFonts[ MAX_FALLBACK ];        // Font + Fallbacks
     rtl::Reference<WinFontInstance>
                             mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the 
most recent font instance
     HRGN                    mhRegion;           // vcl::Region Handle
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index bed9c7a22376..bf9b2149163e 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -913,22 +913,17 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
     // return early if there is no new font
     if( !pFont )
     {
-        // deselect still active font
-        if (mhDefFont)
-        {
-            ::SelectFont(getHDC(), mhDefFont);
-            mhDefFont = nullptr;
-        }
+        if (!mpWinFontEntry[nFallbackLevel].is())
+            return;
+
+        // select original DC font
+        assert(mhDefFont);
+        ::SelectFont(getHDC(), mhDefFont);
+        mhDefFont = nullptr;
+
         // release no longer referenced font handles
         for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
-        {
-            if( mhFonts[i] )
-            {
-                ::DeleteFont( mhFonts[i] );
-                mhFonts[ i ] = nullptr;
-            }
             mpWinFontEntry[i] = nullptr;
-        }
         return;
     }
 
@@ -953,16 +948,8 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
     else
     {
         // release no longer referenced font handles
-        for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
-        {
-            if( mhFonts[i] )
-            {
-                ::DeleteFont( mhFonts[i] );
-                mhFonts[i] = nullptr;
-            }
-            if (i > nFallbackLevel)
-                mpWinFontEntry[i] = nullptr;
-        }
+        for( int i = nFallbackLevel + 1; mpWinFontEntry[i].is() && i < 
MAX_FALLBACK; ++i )
+            mpWinFontEntry[i] = nullptr;
     }
 
     // now the font is live => update font face
@@ -973,8 +960,8 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
 void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int 
nFallbackLevel )
 {
     // temporarily change the HDC to the font in the fallback level
-    assert(!mhFonts[nFallbackLevel] && mpWinFontEntry[nFallbackLevel]);
-    const HFONT hOldFont = SelectFont(getHDC(), 
mpWinFontEntry[nFallbackLevel]->GetHFONT());
+    rtl::Reference<WinFontInstance> pFontInstance = 
mpWinFontEntry[nFallbackLevel];
+    const HFONT hOldFont = SelectFont(getHDC(), pFontInstance->GetHFONT());
 
     wchar_t aFaceName[LF_FACESIZE+60];
     if( GetTextFaceW( getHDC(), SAL_N_ELEMENTS(aFaceName), aFaceName ) )
@@ -985,7 +972,7 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& 
rxFontMetric, int nFa
     const RawFontData aHheaRawData(getHDC(), nHheaTag);
     const RawFontData aOS2RawData(getHDC(), nOS2Tag);
 
-    
rxFontMetric->SetMinKashida(mpWinFontEntry[nFallbackLevel]->GetKashidaWidth());
+    rxFontMetric->SetMinKashida(pFontInstance->GetKashidaWidth());
 
     // get the font metric
     OUTLINETEXTMETRICW aOutlineMetric;
@@ -1006,7 +993,7 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& 
rxFontMetric, int nFa
     rxFontMetric->SetSlant( 0 );
 
     // transformation dependent font metrics
-    
rxFontMetric->SetWidth(static_cast<int>(mpWinFontEntry[nFallbackLevel]->GetScale()
 * aWinMetric.tmAveCharWidth));
+    rxFontMetric->SetWidth(static_cast<int>(pFontInstance->GetScale() * 
aWinMetric.tmAveCharWidth));
 
     const std::vector<uint8_t> rHhea(aHheaRawData.get(), aHheaRawData.get() + 
aHheaRawData.size());
     const std::vector<uint8_t> rOS2(aOS2RawData.get(), aOS2RawData.get() + 
aOS2RawData.size());
@@ -1598,16 +1585,8 @@ private:
 
 ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData)
 {
-    if (m_rData.mpWinFontEntry[0])
-    {
-        m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT();
-        m_rData.mpWinFontEntry[0]->UnsetHFONT();
-    }
-    else
-    {
-        m_hOrigFont = m_rData.mhFonts[0];
-        m_rData.mhFonts[0] = nullptr; // avoid deletion of current font
-    }
+    m_hOrigFont = m_rData.mpWinFontEntry[0]->GetHFONT();
+    m_rData.mpWinFontEntry[0]->UnsetHFONT();
 }
 
 ScopedFont::~ScopedFont()
@@ -1615,11 +1594,8 @@ ScopedFont::~ScopedFont()
     if( m_hOrigFont )
     {
         // restore original font, destroy temporary font
-        HFONT hTempFont = m_rData.mhFonts[0];
-        if (m_rData.mpWinFontEntry[0])
-            m_rData.mpWinFontEntry[0]->SetHFONT(m_hOrigFont);
-        else
-            m_rData.mhFonts[0] = m_hOrigFont;
+        HFONT hTempFont = m_rData.mpWinFontEntry[0]->GetHFONT();
+        m_rData.mpWinFontEntry[0]->SetHFONT(m_hOrigFont);
         SelectObject( m_rData.getHDC(), m_hOrigFont );
         DeleteObject( hTempFont );
     }
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index 46155bbef3dc..24188e42517d 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -620,12 +620,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, 
bool bScreen, HWND hW
         mpImpl.reset(new WinOpenGLSalGraphicsImpl(*this, pProvider));
     else
         mpImpl.reset(new WinSalGraphicsImpl(*this));
-
-    for( int i = 0; i < MAX_FALLBACK; ++i )
-    {
-        mhFonts[ i ] = nullptr;
-        mpWinFontEntry[ i ] = nullptr;
-    }
 }
 
 WinSalGraphics::~WinSalGraphics()
commit a34d574647d68880e6583418c30f339a9d3c9aab
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Thu Sep 6 13:46:28 2018 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Thu Sep 6 14:41:17 2018 +0200

    tdf#119302 WIN better font scale handling
    
    Moves the scale factor into the LogicalFontInstance and uses the
    Glyphs font fallback level to use the correct font and scale.
    
    Probably the glyphs should be using a rtl::Reference to the
    LogcalFontInstance instead of the fallback level. I don't know if
    glyphs are evicted from the cache, if the fallback changes. There
    is now an assert and all places will use 1.0 as the default
    scaling factor, so LO should at least not crash.
    
    Change-Id: I9dd4fc3a5b5924fc379b48a7f71c9eed26b4779d

diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 51d14cb7ddda..32a104bef88e 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -171,8 +171,6 @@ private:
     HFONT                   mhFonts[ MAX_FALLBACK ];        // Font + Fallbacks
     rtl::Reference<WinFontInstance>
                             mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the 
most recent font instance
-    float                   mfFontScale[ MAX_FALLBACK ];        // allows 
metrics emulation of huge font sizes
-    float                   mfCurrentFontScale;
     HRGN                    mhRegion;           // vcl::Region Handle
     HPEN                    mhDefPen;           // DefaultPen
     HBRUSH                  mhDefBrush;         // DefaultBrush
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 598d90c60588..066f7b587f6d 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -156,6 +156,8 @@ public:
 
     void SetHFONT(const HFONT);
     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
@@ -167,6 +169,7 @@ private:
     virtual hb_font_t* ImplInitHbFont() override;
 
     HFONT m_hFont;
+    float m_fScale;
     GlyphCache maGlyphCache;
 };
 
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 8c1a6651bbd5..bed9c7a22376 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -919,7 +919,6 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
             ::SelectFont(getHDC(), mhDefFont);
             mhDefFont = nullptr;
         }
-        mfCurrentFontScale = mfFontScale[nFallbackLevel];
         // release no longer referenced font handles
         for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
         {
@@ -933,25 +932,24 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
         return;
     }
 
-    mpWinFontEntry[ nFallbackLevel ] = static_cast<WinFontInstance*>(pFont);
+    WinFontInstance *pFontInstance = static_cast<WinFontInstance*>(pFont);
+    mpWinFontEntry[ nFallbackLevel ] = pFontInstance;
 
     HFONT hOldFont = nullptr;
-    HFONT hNewFont = mpWinFontEntry[ nFallbackLevel ]->GetHFONT();
+    HFONT hNewFont = pFontInstance->GetHFONT();
     if (!hNewFont)
     {
-        hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), 
pFont->GetFontFace(), mfFontScale[ nFallbackLevel ], hOldFont);
+        float fFontScale = 1.0;
+        hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), 
pFont->GetFontFace(), fFontScale, hOldFont);
         mpWinFontEntry[ nFallbackLevel ]->SetHFONT(hNewFont);
+        mpWinFontEntry[ nFallbackLevel ]->SetScale(fFontScale);
     }
     else
         hOldFont = ::SelectFont( getHDC(), hNewFont );
 
-    mfCurrentFontScale = mfFontScale[nFallbackLevel];
-
+    // keep default font
     if( !mhDefFont )
-    {
-        // keep default font
         mhDefFont = hOldFont;
-    }
     else
     {
         // release no longer referenced font handles
@@ -968,7 +966,7 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
     }
 
     // now the font is live => update font face
-    const WinFontFace* pFontFace = static_cast<const 
WinFontFace*>(mpWinFontEntry[nFallbackLevel]->GetFontFace());
+    const WinFontFace* pFontFace = static_cast<const 
WinFontFace*>(pFontInstance->GetFontFace());
     pFontFace->UpdateFromHDC(getHDC());
 }
 
@@ -1008,7 +1006,7 @@ void WinSalGraphics::GetFontMetric( 
ImplFontMetricDataRef& rxFontMetric, int nFa
     rxFontMetric->SetSlant( 0 );
 
     // transformation dependent font metrics
-    rxFontMetric->SetWidth(static_cast<int>( mfFontScale[nFallbackLevel] * 
aWinMetric.tmAveCharWidth ));
+    
rxFontMetric->SetWidth(static_cast<int>(mpWinFontEntry[nFallbackLevel]->GetScale()
 * aWinMetric.tmAveCharWidth));
 
     const std::vector<uint8_t> rHhea(aHheaRawData.get(), aHheaRawData.get() + 
aHheaRawData.size());
     const std::vector<uint8_t> rOS2(aOS2RawData.get(), aOS2RawData.get() + 
aOS2RawData.size());
@@ -1361,7 +1359,18 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& 
rGlyph, tools::Rectangle
         return true;
     }
 
+    rtl::Reference<WinFontInstance> pFont = 
mpWinFontEntry[rGlyph.mnFallbackLevel];
+    assert(pFont.is());
+
     HDC hDC = getHDC();
+    HFONT hFont = static_cast<HFONT>(GetCurrentObject(hDC, OBJ_FONT));
+    float fFontScale = 1.0;
+    if (pFont.is())
+    {
+        if (hFont != pFont->GetHFONT())
+            SelectObject(hDC, pFont->GetHFONT());
+        fFontScale = pFont->GetScale();
+    }
 
     // use unity matrix
     MAT2 aMat;
@@ -1375,15 +1384,17 @@ bool WinSalGraphics::GetGlyphBoundRect(const GlyphItem& 
rGlyph, tools::Rectangle
     aGM.gmptGlyphOrigin.x = aGM.gmptGlyphOrigin.y = 0;
     aGM.gmBlackBoxX = aGM.gmBlackBoxY = 0;
     DWORD nSize = ::GetGlyphOutlineW(hDC, rGlyph.maGlyphId, nGGOFlags, &aGM, 
0, nullptr, &aMat);
+    if (pFont.is() && hFont != pFont->GetHFONT())
+        SelectObject(hDC, hFont);
     if( nSize == GDI_ERROR )
         return false;
 
     rRect = tools::Rectangle( Point( +aGM.gmptGlyphOrigin.x, 
-aGM.gmptGlyphOrigin.y ),
         Size( aGM.gmBlackBoxX, aGM.gmBlackBoxY ) );
-    rRect.SetLeft(static_cast<int>( mfCurrentFontScale * rRect.Left() ));
-    rRect.SetRight(static_cast<int>( mfCurrentFontScale * rRect.Right() ) + 1);
-    rRect.SetTop(static_cast<int>( mfCurrentFontScale * rRect.Top() ));
-    rRect.SetBottom(static_cast<int>( mfCurrentFontScale * rRect.Bottom() ) + 
1);
+    rRect.SetLeft(static_cast<int>( fFontScale * rRect.Left() ));
+    rRect.SetRight(static_cast<int>( fFontScale * rRect.Right() ) + 1);
+    rRect.SetTop(static_cast<int>( fFontScale * rRect.Top() ));
+    rRect.SetBottom(static_cast<int>( fFontScale * rRect.Bottom() ) + 1);
 
     g_BoundRectCache.insert({rGlyph.maGlyphId, rRect});
 
@@ -1563,7 +1574,10 @@ bool WinSalGraphics::GetGlyphOutline(const GlyphItem& 
rGlyph,
     // rescaling needed for the tools::PolyPolygon conversion
     if( rB2DPolyPoly.count() )
     {
-        const double fFactor(mfCurrentFontScale/256);
+        rtl::Reference<WinFontInstance> pFont = 
mpWinFontEntry[rGlyph.mnFallbackLevel];
+        assert(pFont.is());
+        float fFontScale = pFont.is() ? pFont->GetScale() : 1.0;
+        const double fFactor(fFontScale/256);
         
rB2DPolyPoly.transform(basegfx::utils::createScaleB2DHomMatrix(fFactor, 
fFactor));
     }
 
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index 78961ddaa8ba..46155bbef3dc 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -608,7 +608,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, 
bool bScreen, HWND hW
     mbWindow(eType == WinSalGraphics::WINDOW),
     mbScreen(bScreen),
     mhWnd(hWnd),
-    mfCurrentFontScale(1.0),
     mhRegion(nullptr),
     mhDefPen(nullptr),
     mhDefBrush(nullptr),
@@ -626,7 +625,6 @@ WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, 
bool bScreen, HWND hW
     {
         mhFonts[ i ] = nullptr;
         mpWinFontEntry[ i ] = nullptr;
-        mfFontScale[ i ] = 1.0;
     }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to