vcl/win/gdi/winlayout.cxx |   23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

New commits:
commit 792d07c7f2816f1afdbed1d0b8129e3f1aecf8d7
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Fri Oct 19 09:45:54 2018 +0000
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Fri Oct 19 22:53:46 2018 +0200

    WIN fix CacheGlyphToAtlas resource handling
    
    Use :comphelper::ScopeGuard to handle cleanup.
    And actually restore the original font on the correct DC.
    
    Change-Id: Ib59d430636b470486da2f8e5e34ed8d71b57aac2
    Reviewed-on: https://gerrit.libreoffice.org/62010
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 35303fc5c8a5..efbbd0c1edb3 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -23,6 +23,7 @@
 #include <sal/log.hxx>
 
 #include <comphelper/windowserrorstring.hxx>
+#include <comphelper/scopeguard.hxx>
 
 #include <opengl/texture.hxx>
 #include <opengl/win/gdiimpl.hxx>
@@ -48,11 +49,11 @@
 #include <shlwapi.h>
 #include <winver.h>
 
-GlobalOpenGLGlyphCache * GlobalOpenGLGlyphCache::get() {
-    SalData * data = GetSalData();
-    if (!data->m_pGlobalOpenGLGlyphCache) {
+GlobalOpenGLGlyphCache * GlobalOpenGLGlyphCache::get()
+{
+    SalData *data = GetSalData();
+    if (!data->m_pGlobalOpenGLGlyphCache)
         data->m_pGlobalOpenGLGlyphCache.reset(new GlobalOpenGLGlyphCache);
-    }
     return data->m_pGlobalOpenGLGlyphCache.get();
 }
 
@@ -67,12 +68,15 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT 
hFont, int nGlyphIndex, S
         SAL_WARN("vcl.gdi", "CreateCompatibleDC failed: " << 
WindowsErrorString(GetLastError()));
         return false;
     }
-    HFONT hOrigFont = static_cast<HFONT>(SelectObject(aHDC.get(), hFont));
+
+    const HFONT hOrigFont = static_cast<HFONT>(SelectObject(aHDC.get(), 
hFont));
     if (hOrigFont == nullptr)
     {
         SAL_WARN("vcl.gdi", "SelectObject failed: " << 
WindowsErrorString(GetLastError()));
         return false;
     }
+    const ::comphelper::ScopeGuard aHFONTrestoreScopeGuard(
+        [&aHDC,hOrigFont]() { SelectFont(aHDC.get(), hOrigFont); });
 
     // For now we assume DWrite is present and we won't bother with fallback 
paths.
     D2DWriteTextOutRenderer * pTxt = dynamic_cast<D2DWriteTextOutRenderer 
*>(&TextOutRenderer::get(true));
@@ -86,6 +90,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, 
int nGlyphIndex, S
         SAL_WARN("vcl.gdi", "Binding of font failed. The font might not be 
supported by DirectWrite.");
         return false;
     }
+    const ::comphelper::ScopeGuard aFontReleaseScopeGuard([&pTxt]() { 
pTxt->ReleaseFont(); });
 
     std::vector<WORD> aGlyphIndices(1);
     aGlyphIndices[0] = nGlyphIndex;
@@ -158,10 +163,7 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT 
hFont, int nGlyphIndex, S
 
     ID2D1SolidColorBrush* pBrush = nullptr;
     if 
(!SUCCEEDED(pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), 
&pBrush)))
-    {
-        pTxt->ReleaseFont();
         return false;
-    }
 
     D2D1_POINT_2F baseline = {
         static_cast<FLOAT>(aElement.getExtraOffset()),
@@ -194,12 +196,9 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT 
hFont, int nGlyphIndex, S
         break;
     default:
         SAL_WARN("vcl.gdi", "DrawGlyphRun-EndDraw failed: " << 
WindowsErrorString(GetLastError()));
-        SelectFont(aDC.getCompatibleHDC(), hOrigFont);
         return false;
     }
 
-    pTxt->ReleaseFont();
-
     if (!OpenGLGlyphCache::ReserveTextureSpace(aElement, nBitmapWidth, 
nBitmapHeight))
         return false;
     if (!aDC.copyToTexture(aElement.maTexture))
@@ -207,8 +206,6 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT 
hFont, int nGlyphIndex, S
 
     maOpenGLGlyphCache.PutDrawElementInCache(aElement, nGlyphIndex);
 
-    SelectFont(aDC.getCompatibleHDC(), hOrigFont);
-
     return true;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to