From 19057bca87abf09ec6701c1d28084faa24ba9c3f Mon Sep 17 00:00:00 2001
From: Adrien Ollier <adr.ollier@hotmail.fr>
Date: Thu, 9 May 2019 19:41:35 +0200
Subject: tdf#74702 partial cleanup of OutDevType
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

makes OutputDevice::ImplClearFontData clean

Change-Id: Iee0683bd4567f85e20d5017b8eaa8a46490678db
Signed-off-by: Adrien Ollier <adr.ollier@hotmail.fr>
Reviewed-on: https://gerrit.libreoffice.org/72084
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
---
 include/vcl/outdev.hxx             |  5 ++++-
 include/vcl/window.hxx             |  2 ++
 vcl/source/gdi/pdfwriter_impl.hxx  |  3 +++
 vcl/source/gdi/pdfwriter_impl2.cxx | 10 ++++++++++
 vcl/source/outdev/font.cxx         | 17 -----------------
 vcl/source/outdev/outdev.cxx       |  4 ++++
 vcl/source/window/window3.cxx      |  7 +++++++
 7 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 15491e8d2807..52b5602d69b0 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1274,13 +1274,16 @@ protected:
     virtual void                SetFontOrientation( LogicalFontInstance* const pFontInstance ) const;
     virtual long                GetFontExtLeading() const;
 
+    virtual void ImplClearFontData(bool bNewFontLists);
+    void ReleaseFontCache();
+    void ReleaseFontCollection();
+
 private:
 
     typedef void ( OutputDevice::* FontUpdateHandler_t )( bool );
 
     SAL_DLLPRIVATE bool         ImplNewFont() const;
 
-    SAL_DLLPRIVATE void         ImplClearFontData( bool bNewFontLists );
     SAL_DLLPRIVATE void         ImplRefreshFontData( bool bNewFontLists );
     SAL_DLLPRIVATE static void  ImplUpdateFontDataForAllFrames( FontUpdateHandler_t pHdl, bool bNewFontLists );
 
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 3b28f9a503a0..433ace0b73c9 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -741,6 +741,8 @@ protected:
 
     virtual void                        InitClipRegion() override;
 
+    void ImplClearFontData(bool bNewFontLists) override;
+
     // FIXME: this is a hack to workaround missing layout functionality
     SAL_DLLPRIVATE void                 ImplAdjustNWFSizes();
 
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 923454d424be..b5a0f5ff87e1 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -593,6 +593,9 @@ public:
 
     static void convertLineInfoToExtLineInfo( const LineInfo& rIn, PDFWriter::ExtLineInfo& rOut );
 
+protected:
+    void ImplClearFontData(bool bNewFontLists) override;
+
 private:
     MapMode                             m_aMapMode; // PDFWriterImpl scaled units
     std::vector< PDFPage >              m_aPages;
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index 5e5c0e5fbf6a..5db8a6b1677c 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -2015,4 +2015,14 @@ static bool lcl_canUsePDFAxialShading(const Gradient& rGradient) {
     return rGradient.GetSteps() <= 0;
 }
 
+void PDFWriterImpl::ImplClearFontData(bool bNewFontLists)
+{
+    VirtualDevice::ImplClearFontData(bNewFontLists);
+    if (bNewFontLists && AcquireGraphics())
+    {
+        ReleaseFontCollection();
+        ReleaseFontCache();
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 22fd7b4e0d9c..0467f2f7c1ae 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -513,23 +513,6 @@ void OutputDevice::ImplClearFontData( const bool bNewFontLists )
     {
         if (mxFontCollection && mxFontCollection != pSVData->maGDIData.mxScreenFontList)
             mxFontCollection->Clear();
-
-        if (GetOutDevType() == OUTDEV_PDF)
-        {
-            mxFontCollection.reset();
-            mxFontCache.reset();
-        }
-    }
-
-    // also update child windows if needed
-    if ( GetOutDevType() == OUTDEV_WINDOW )
-    {
-        vcl::Window* pChild = static_cast<vcl::Window*>(this)->mpWindowImpl->mpFirstChild;
-        while ( pChild )
-        {
-            pChild->ImplClearFontData( true );
-            pChild = pChild->mpWindowImpl->mpNext;
-        }
     }
 }
 
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index ef512a80d6e4..a7fa60287a29 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -729,4 +729,8 @@ bool OutputDevice::DrawEPS( const Point& rPoint, const Size& rSize,
     return bDrawn;
 }
 
+void OutputDevice::ReleaseFontCache() { mxFontCache.reset(); }
+
+void OutputDevice::ReleaseFontCollection() { mxFontCollection.reset(); }
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/window3.cxx b/vcl/source/window/window3.cxx
index 283aee05918e..492839f05415 100644
--- a/vcl/source/window/window3.cxx
+++ b/vcl/source/window/window3.cxx
@@ -20,6 +20,7 @@
 #include <vcl/window.hxx>
 #include <vcl/waitobj.hxx>
 #include <vcl/button.hxx>
+#include <window.h>
 
 WaitObject::~WaitObject()
 {
@@ -58,6 +59,12 @@ void Window::ImplAdjustNWFSizes()
     }
 }
 
+void Window::ImplClearFontData(bool bNewFontLists)
+{
+    OutputDevice::ImplClearFontData(bNewFontLists);
+    for (Window* pChild = mpWindowImpl->mpFirstChild; pChild; pChild = pChild->mpWindowImpl->mpNext)
+        pChild->ImplClearFontData(bNewFontLists);
+}
 } /* namespace vcl */
 
 
-- 
cgit