vcl/win/gdi/salfont.cxx |   38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

New commits:
commit 7e7a1ff3926e86705199aa9814089e90f01c02ed
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Tue Sep 4 17:24:03 2018 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Tue Sep 4 19:20:53 2018 +0200

    tdf#119340 WIN don't always re-init the HFONT
    
    After all the LogicalFontInstance refactoring, its FontSelectData
    is now immutable, so the HFONT will never need to be changed.
    Therefore we can skip the HFONT lookup in WinSalGraphics::SetFont,
    if the WinFontInstance already has it set.
    
    All the HFONT handling (basically WinSalGraphics::ImplDoSetFont)
    should be moved to the WinFontInstance to further clean this up.
    
    Change-Id: I1c9a9e3414677d77f0f007d7ace653bb53b8474d
    Reviewed-on: https://gerrit.libreoffice.org/59988
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 969cefd17279..8c1a6651bbd5 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -851,11 +851,6 @@ HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern 
const & i_rFont,
     g_BoundRectCache.clear();
     HFONT hNewFont = nullptr;
 
-    HDC hdcScreen = nullptr;
-    if( mbVirDev )
-        // only required for virtual devices, see below for details
-        hdcScreen = GetDC(nullptr);
-
     LOGFONTW aLogFont;
     ImplGetLogFontFromFontSelect( getHDC(), i_rFont, i_pFontFace, aLogFont );
 
@@ -878,8 +873,12 @@ HFONT WinSalGraphics::ImplDoSetFont(FontSelectPattern 
const & i_rFont,
         aLogFont.lfWidth = +MAXFONTHEIGHT;
         aLogFont.lfHeight = FRound( aLogFont.lfHeight / o_rFontScale );
     }
-
     hNewFont = ::CreateFontIndirectW( &aLogFont );
+
+    HDC hdcScreen = nullptr;
+    if( mbVirDev )
+        // only required for virtual devices, see below for details
+        hdcScreen = GetDC(nullptr);
     if( hdcScreen )
     {
         // select font into screen hdc first to get an antialiased font
@@ -934,12 +933,18 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
         return;
     }
 
-    // WinSalGraphics::GetEmbedFontData does not set mpFontInstance
-    // since it is interested in font file data only.
-    mpWinFontEntry[ nFallbackLevel ] = 
reinterpret_cast<WinFontInstance*>(pFont);
+    mpWinFontEntry[ nFallbackLevel ] = static_cast<WinFontInstance*>(pFont);
 
     HFONT hOldFont = nullptr;
-    HFONT hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), 
pFont->GetFontFace(), mfFontScale[ nFallbackLevel ], hOldFont);
+    HFONT hNewFont = mpWinFontEntry[ nFallbackLevel ]->GetHFONT();
+    if (!hNewFont)
+    {
+        hNewFont = ImplDoSetFont(pFont->GetFontSelectPattern(), 
pFont->GetFontFace(), mfFontScale[ nFallbackLevel ], hOldFont);
+        mpWinFontEntry[ nFallbackLevel ]->SetHFONT(hNewFont);
+    }
+    else
+        hOldFont = ::SelectFont( getHDC(), hNewFont );
+
     mfCurrentFontScale = mfFontScale[nFallbackLevel];
 
     if( !mhDefFont )
@@ -962,16 +967,9 @@ void WinSalGraphics::SetFont(LogicalFontInstance* pFont, 
int nFallbackLevel)
         }
     }
 
-    // store new font in correct layer
-    if (mpWinFontEntry[nFallbackLevel])
-    {
-        mpWinFontEntry[nFallbackLevel]->SetHFONT(hNewFont);
-        // now the font is live => update font face
-        const WinFontFace* pFontFace = static_cast<const 
WinFontFace*>(mpWinFontEntry[nFallbackLevel]->GetFontFace());
-        pFontFace->UpdateFromHDC(getHDC());
-    }
-    else
-        mhFonts[ nFallbackLevel ] = hNewFont;
+    // now the font is live => update font face
+    const WinFontFace* pFontFace = static_cast<const 
WinFontFace*>(mpWinFontEntry[nFallbackLevel]->GetFontFace());
+    pFontFace->UpdateFromHDC(getHDC());
 }
 
 void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int 
nFallbackLevel )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to