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

Michael Stahl mstahl at redhat.com
Fri Sep 22 18:42:51 UTC 2017


 vcl/inc/unx/fontmanager.hxx                 |    4 +++-
 vcl/inc/unx/gendata.hxx                     |   10 +++++++++-
 vcl/unx/generic/fontmanager/fontmanager.cxx |   24 ++++++++++++++++++------
 3 files changed, 30 insertions(+), 8 deletions(-)

New commits:
commit ca8a4c81a4194cfaa526bd8071a2243aad0f3461
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Sep 22 11:20:01 2017 +0200

    vcl: [loplugin:badstatics] pManager
    
    Move this to class GenericUnixSalData, which is deleted on shutdown.
    
    Change-Id: I6366c12f255bfeca737b22259c3f58ffa2c6222c
    Reviewed-on: https://gerrit.libreoffice.org/42632
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx
index 0dd0cc87b412..47ea4348bdcc 100644
--- a/vcl/inc/unx/fontmanager.hxx
+++ b/vcl/inc/unx/fontmanager.hxx
@@ -45,6 +45,7 @@
 class FontSubsetInfo;
 class FontConfigFontOptions;
 class FontSelectPattern;
+class GenericUnixSalData;
 
 namespace psp {
 class PPDParser;
@@ -200,8 +201,9 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
     DECL_LINK( autoInstallFontLangSupport, Timer*, void );
 #endif
     PrintFontManager();
-    ~PrintFontManager();
 public:
+    ~PrintFontManager();
+    friend class ::GenericUnixSalData;
     static PrintFontManager& get(); // one instance only
 
     // There may be multiple font ids for font collections
diff --git a/vcl/inc/unx/gendata.hxx b/vcl/inc/unx/gendata.hxx
index db19b0cf0420..55a9aaf4ba8c 100644
--- a/vcl/inc/unx/gendata.hxx
+++ b/vcl/inc/unx/gendata.hxx
@@ -14,7 +14,10 @@
 
 #include <saldatabasic.hxx>
 
+#include <memory>
+
 class SalGenericDisplay;
+namespace psp { class PrintFontManager; }
 
 enum GenericUnixSalDataType { SAL_DATA_GTK, SAL_DATA_GTK3,
                               SAL_DATA_TDE3, SAL_DATA_KDE3, SAL_DATA_KDE4,
@@ -31,8 +34,13 @@ class VCL_DLLPUBLIC GenericUnixSalData : public SalData
     OUString      m_aHostname;
     // for transient storage of unicode strings eg. 'u123' by input methods
     OUString      m_aUnicodeEntry;
+
+    friend class psp::PrintFontManager;
+    std::unique_ptr<psp::PrintFontManager> m_pPrintFontManager;
+
  public:
-    GenericUnixSalData( GenericUnixSalDataType t, SalInstance *pInstance ) : SalData(), m_eType( t ), m_pDisplay( nullptr ) { m_pInstance = pInstance; SetSalData( this ); }
+    GenericUnixSalData(GenericUnixSalDataType const t, SalInstance *const pInstance);
+    virtual ~GenericUnixSalData() override;
     virtual void Dispose() {}
 
     SalGenericDisplay *GetDisplay() const { return m_pDisplay; }
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 6726deeefb90..c7ff4c1f5e45 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -30,6 +30,7 @@
 #include "impfontcharmap.hxx"
 #include "svdata.hxx"
 #include "unx/geninst.h"
+#include "unx/gendata.hxx"
 #include <vcl/strhelper.hxx>
 #include <vcl/ppdparser.hxx>
 #include <vcl/embeddedfontshelper.hxx>
@@ -111,19 +112,30 @@ PrintFontManager::PrintFont::PrintFont()
 {
 }
 
+GenericUnixSalData::GenericUnixSalData(GenericUnixSalDataType const t, SalInstance *const pInstance)
+    : m_eType(t), m_pDisplay(nullptr), m_pPrintFontManager(nullptr)
+{
+    m_pInstance = pInstance; SetSalData(this);
+}
+
+GenericUnixSalData::~GenericUnixSalData()
+{
+}
+
 /*
  *  one instance only
  */
 PrintFontManager& PrintFontManager::get()
 {
-    static PrintFontManager* pManager = nullptr;
-    if( ! pManager )
+    GenericUnixSalData *const pSalData(GetGenericUnixSalData());
+    assert(pSalData);
+
+    if (!pSalData->m_pPrintFontManager)
     {
-        static PrintFontManager theManager;
-        pManager = &theManager;
-        pManager->initialize();
+        pSalData->m_pPrintFontManager.reset( new PrintFontManager );
+        pSalData->m_pPrintFontManager->initialize();
     }
-    return *pManager;
+    return *pSalData->m_pPrintFontManager;
 }
 
 /*


More information about the Libreoffice-commits mailing list