[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - include/vcl include/xmloff vcl/source writerfilter/source xmloff/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 30 12:41:27 UTC 2020


 include/vcl/embeddedfontshelper.hxx          |   29 ++++++++++++++++++++-------
 include/xmloff/xmlimp.hxx                    |   12 ++++++++++-
 vcl/source/gdi/embeddedfontshelper.cxx       |   28 +++++++++++++++++++++++++-
 vcl/source/outdev/font.cxx                   |   18 ----------------
 writerfilter/source/dmapper/FontTable.cxx    |   17 +++++++++++++--
 writerfilter/source/dmapper/FontTable.hxx    |    9 ++++++--
 xmloff/source/core/xmlimp.cxx                |   10 +++++++++
 xmloff/source/style/XMLFontStylesContext.cxx |    5 +---
 8 files changed, 93 insertions(+), 35 deletions(-)

New commits:
commit 1e9f63fd0d6e8c4e5c92c1379a3792bc09ade97a
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Oct 28 15:11:36 2020 +0000
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Fri Oct 30 13:40:52 2020 +0100

    tdf#137643 alternative solution to activate embedded fonts in one batch
    
    Change-Id: Ib5ffb2b8a31f237d5d2e465bf3f777590e0bfade
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104957
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/include/vcl/embeddedfontshelper.hxx b/include/vcl/embeddedfontshelper.hxx
index 19ec9b1e1076..54123d76a1af 100644
--- a/include/vcl/embeddedfontshelper.hxx
+++ b/include/vcl/embeddedfontshelper.hxx
@@ -25,6 +25,18 @@ namespace com::sun::star::uno { template <typename > class Reference; }
 */
 class VCL_DLLPUBLIC EmbeddedFontsHelper
 {
+private:
+    std::vector<std::pair<OUString, OUString>> m_aAccumulatedFonts;
+
+    /**
+      Adds the given font to the list of known fonts. The font is used only until application
+      exit.
+
+      @param fontName name of the font (e.g. 'Times New Roman')
+      @param fileUrl URL of the font file
+    */
+    static void activateFont( const OUString& fontName, const OUString& fileUrl );
+
 public:
     /// Specification of what kind of operation is allowed when embedding a font
     enum class FontRights
@@ -40,14 +52,15 @@ public:
         FontWeight weight, FontPitch pitch, FontRights rights );
 
     /**
-      Reads a font from the input stream, saves it to a temporary font file and activates the font.
+      Reads a font from the input stream, saves it to a temporary font file and adds it to the list of
+      fonts that activateFonts will activate.
       @param stream stream of font data
       @param fontName name of the font (e.g. 'Times New Roman')
       @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
       @param key key to xor the data with, from the start until the key's length (not repeated)
       @param eot whether the data is compressed in Embedded OpenType format
     */
-    static bool addEmbeddedFont( const css::uno::Reference< css::io::XInputStream >& stream,
+    bool addEmbeddedFont( const css::uno::Reference< css::io::XInputStream >& stream,
         const OUString& fontName, const char* extra,
         std::vector< unsigned char > key, bool eot = false);
 
@@ -62,13 +75,10 @@ public:
     static OUString fileUrlForTemporaryFont( const OUString& fontName, const char* extra );
 
     /**
-      Adds the given font to the list of known fonts. The font is used only until application
+      Adds the accumulated fonts to the list of known fonts. The fonts are used only until application
       exit.
-
-      @param fontName name of the font (e.g. 'Times New Roman')
-      @param fileUrl URL of the font file
     */
-    static void activateFont( const OUString& fontName, const OUString& fileUrl );
+    void activateFonts();
 
     /**
       Returns if the restrictions specified in the font (if present) allow embedding
@@ -84,6 +94,11 @@ public:
       @internal
     */
     static void clearTemporaryFontFiles();
+
+    ~EmbeddedFontsHelper()
+    {
+        activateFonts();
+    }
 };
 
 #endif
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 351a05887ebd..7f08609189ab 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -74,7 +74,7 @@ namespace xmloff {
 namespace xmloff::token {
     class FastTokenHandler;
 }
-
+class EmbeddedFontsHelper;
 class ProgressBarHelper;
 class SvXMLNamespaceMap;
 class SvXMLImport_Impl;
@@ -246,6 +246,10 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public cppu::WeakImplHelper<
 
     css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator;
 
+    // tdf#69060 & tdf#137643 import embedded fonts and activate them in a
+    // batch in EmbeddedFontsHelper's dtor
+    std::unique_ptr<EmbeddedFontsHelper> mxEmbeddedFontHelper;
+
 protected:
     bool                        mbIsFormsSupported;
     bool                        mbIsTableShapeSupported;
@@ -585,7 +589,13 @@ public:
     */
     bool embeddedFontAlreadyProcessed( const OUString& url );
 
+    // see EmbeddedFontsHelper::addEmbeddedFont
+    bool addEmbeddedFont( const css::uno::Reference< css::io::XInputStream >& stream,
+        const OUString& fontName, const char* extra,
+        std::vector< unsigned char > key, bool eot);
+
     virtual void NotifyEmbeddedFontRead() {};
+
     // something referencing a macro/script was imported
     void NotifyMacroEventRead();
 
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
index c5ab8914eb17..e59f940718bc 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -156,10 +156,36 @@ bool EmbeddedFontsHelper::addEmbeddedFont( const uno::Reference< io::XInputStrea
         osl::File::remove( fileUrl );
         return false;
     }
-    EmbeddedFontsHelper::activateFont( fontName, fileUrl );
+    m_aAccumulatedFonts.emplace_back(std::make_pair(fontName, fileUrl));
     return true;
 }
 
+namespace
+{
+    struct UpdateFontsGuard
+    {
+        UpdateFontsGuard()
+        {
+            OutputDevice::ImplClearAllFontData(true);
+        }
+
+        ~UpdateFontsGuard()
+        {
+            OutputDevice::ImplRefreshAllFontData(true);
+        }
+    };
+}
+
+void EmbeddedFontsHelper::activateFonts()
+{
+    if (m_aAccumulatedFonts.empty())
+        return;
+    UpdateFontsGuard aUpdateFontsGuard;
+    for (const auto& rEntry : m_aAccumulatedFonts)
+        EmbeddedFontsHelper::activateFont(rEntry.first, rEntry.second);
+    m_aAccumulatedFonts.clear();
+}
+
 OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName, const char* extra )
 {
     OUString path = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 57ebcb40939c..cf50830dc163 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -135,26 +135,8 @@ Size OutputDevice::GetDevFontSize( const vcl::Font& rFont, int nSizeIndex ) cons
     return aSize;
 }
 
-namespace
-{
-    struct UpdateFontsGuard
-    {
-        UpdateFontsGuard()
-        {
-            OutputDevice::ImplClearAllFontData(true);
-        }
-
-        ~UpdateFontsGuard()
-        {
-            OutputDevice::ImplRefreshAllFontData(true);
-        }
-    };
-}
-
 bool OutputDevice::AddTempDevFont( const OUString& rFileURL, const OUString& rFontName )
 {
-    UpdateFontsGuard aUpdateFontsGuard;
-
     ImplInitFontList();
 
     if( !mpGraphics && !AcquireGraphics() )
diff --git a/writerfilter/source/dmapper/FontTable.cxx b/writerfilter/source/dmapper/FontTable.cxx
index 3c74e97d0adc..c98177db5959 100644
--- a/writerfilter/source/dmapper/FontTable.cxx
+++ b/writerfilter/source/dmapper/FontTable.cxx
@@ -32,6 +32,7 @@ namespace writerfilter::dmapper
 
 struct FontTable_Impl
 {
+    std::unique_ptr<EmbeddedFontsHelper> xEmbeddedFontHelper;
     std::vector< FontEntry::Pointer_t > aFontEntries;
     FontEntry::Pointer_t pCurrentEntry;
     FontTable_Impl() {}
@@ -115,7 +116,7 @@ void FontTable::lcl_sprm(Sprm& rSprm)
             writerfilter::Reference< Properties >::Pointer_t pProperties = rSprm.getProps();
             if( pProperties )
             {
-                EmbeddedFontHandler handler( m_pImpl->pCurrentEntry->sFontName,
+                EmbeddedFontHandler handler(*this, m_pImpl->pCurrentEntry->sFontName,
                     nSprmId == NS_ooxml::LN_CT_Font_embedRegular ? ""
                     : nSprmId == NS_ooxml::LN_CT_Font_embedBold ? "b"
                     : nSprmId == NS_ooxml::LN_CT_Font_embedItalic ? "i"
@@ -222,8 +223,18 @@ sal_uInt32 FontTable::size()
     return m_pImpl->aFontEntries.size();
 }
 
-EmbeddedFontHandler::EmbeddedFontHandler( const OUString& _fontName, const char* _style )
+bool FontTable::addEmbeddedFont(const css::uno::Reference<css::io::XInputStream>& stream,
+                                const OUString& fontName, const char* extra,
+                                std::vector<unsigned char> key)
+{
+    if (!m_pImpl->xEmbeddedFontHelper)
+        m_pImpl->xEmbeddedFontHelper.reset(new EmbeddedFontsHelper);
+    return m_pImpl->xEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key);
+}
+
+EmbeddedFontHandler::EmbeddedFontHandler(FontTable& rFontTable, const OUString& _fontName, const char* _style )
 : LoggedProperties("EmbeddedFontHandler")
+, fontTable( rFontTable )
 , fontName( _fontName )
 , style( _style )
 {
@@ -252,7 +263,7 @@ EmbeddedFontHandler::~EmbeddedFontHandler()
             key[ i + 16 ] = val;
         }
     }
-    EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, style, key );
+    fontTable.addEmbeddedFont( inputStream, fontName, style, key );
     inputStream->closeInput();
 }
 
diff --git a/writerfilter/source/dmapper/FontTable.hxx b/writerfilter/source/dmapper/FontTable.hxx
index a2f03fff3b03..edb8b1480662 100644
--- a/writerfilter/source/dmapper/FontTable.hxx
+++ b/writerfilter/source/dmapper/FontTable.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FONTTABLE_HXX
 
 #include <memory>
+#include <vector>
 #include "LoggedResources.hxx"
 #include <com/sun/star/io/XInputStream.hpp>
 
@@ -52,6 +53,10 @@ class FontTable : public LoggedProperties, public LoggedTable
     sal_uInt32          size();
     FontEntry::Pointer_t  getFontEntry(sal_uInt32 nIndex);
 
+    bool addEmbeddedFont(const css::uno::Reference<css::io::XInputStream>& stream,
+                         const OUString& fontName, const char* extra,
+                         std::vector<unsigned char> key);
+
  private:
     // Properties
     virtual void lcl_attribute(Id Name, Value & val) override;
@@ -77,18 +82,18 @@ class FontTable : public LoggedProperties, public LoggedTable
                                ::writerfilter::Reference<Stream>::Pointer_t ref) override;
     virtual void lcl_startShape(css::uno::Reference<css::drawing::XShape> const& xShape) override;
     virtual void lcl_endShape( ) override;
-
 };
 typedef tools::SvRef< FontTable >          FontTablePtr;
 
 class EmbeddedFontHandler : public LoggedProperties
 {
 public:
-    EmbeddedFontHandler( const OUString& fontName, const char* style );
+    EmbeddedFontHandler(FontTable& rFontTable, const OUString& fontName, const char* style);
     virtual ~EmbeddedFontHandler() override;
 private:
     virtual void lcl_attribute( Id name, Value& val ) override;
     virtual void lcl_sprm( Sprm& rSprm ) override;
+    FontTable& fontTable;
     OUString fontName;
     const char* const style;
     OUString fontKey;
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 1e77eca85928..0c9e9d06cfd4 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -23,6 +23,7 @@
 #include <sal/log.hxx>
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
 #include <tools/urlobj.hxx>
+#include <vcl/embeddedfontshelper.hxx>
 #include <vcl/graph.hxx>
 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
 #include <xmloff/nmspmap.hxx>
@@ -444,6 +445,15 @@ SvXMLImport::~SvXMLImport() throw ()
     cleanup();
 }
 
+bool SvXMLImport::addEmbeddedFont(const css::uno::Reference< css::io::XInputStream >& stream,
+                                  const OUString& fontName, const char* extra,
+                                  std::vector<unsigned char> key, bool eot)
+{
+    if (!mxEmbeddedFontHelper)
+        mxEmbeddedFontHelper.reset(new EmbeddedFontsHelper);
+    return mxEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key, eot);
+}
+
 namespace
 {
     class theSvXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLImportUnoTunnelId> {};
diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx
index ad706d987c96..eb3ed7b45666 100644
--- a/xmloff/source/style/XMLFontStylesContext.cxx
+++ b/xmloff/source/style/XMLFontStylesContext.cxx
@@ -28,7 +28,6 @@
 #include <comphelper/seqstream.hxx>
 
 #include <sal/log.hxx>
-#include <vcl/embeddedfontshelper.hxx>
 
 #include <xmloff/xmlnmspe.hxx>
 #include <xmloff/xmltoken.hxx>
@@ -326,7 +325,7 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url, bo
         uno::Reference< io::XInputStream > inputStream;
         inputStream.set( storage->openStreamElement( url.copy( url.indexOf( '/' ) + 1 ), ::embed::ElementModes::READ ),
             UNO_QUERY_THROW );
-        if( EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, "?", std::vector< unsigned char >(), eot ))
+        if (GetImport().addEmbeddedFont(inputStream, fontName, "?", std::vector< unsigned char >(), eot))
             GetImport().NotifyEmbeddedFontRead();
         inputStream->closeInput();
     }
@@ -338,7 +337,7 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const ::css::uno::Seque
 {
     const uno::Reference< io::XInputStream > xInput( new comphelper::SequenceInputStream( rData ) );
     const OUString fontName = font.familyName();
-    if( EmbeddedFontsHelper::addEmbeddedFont( xInput, fontName, "?", std::vector< unsigned char >(), eot ) )
+    if (GetImport().addEmbeddedFont(xInput, fontName, "?", std::vector< unsigned char >(), eot))
         GetImport().NotifyEmbeddedFontRead();
     xInput->closeInput();
 }


More information about the Libreoffice-commits mailing list