summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-10-28 15:11:36 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-10-29 10:14:16 +0100
commit388735924392027eb6a8e722083e6496b92a40fa (patch)
tree112aaf7591c9fef82d3415fe8e16c0263a1a2383
parente58592414da353aaef9432277d7155fc0c0f0213 (diff)
tdf#137643 alternative solution to activate embedded fonts in one batch
Change-Id: Ib5ffb2b8a31f237d5d2e465bf3f777590e0bfade Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104947 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--include/vcl/embeddedfontshelper.hxx29
-rw-r--r--include/xmloff/xmlimp.hxx12
-rw-r--r--vcl/source/gdi/embeddedfontshelper.cxx28
-rw-r--r--vcl/source/outdev/font.cxx18
-rw-r--r--writerfilter/source/dmapper/FontTable.cxx17
-rw-r--r--writerfilter/source/dmapper/FontTable.hxx9
-rw-r--r--xmloff/source/core/xmlimp.cxx10
-rw-r--r--xmloff/source/style/XMLFontStylesContext.cxx5
8 files changed, 93 insertions, 35 deletions
diff --git a/include/vcl/embeddedfontshelper.hxx b/include/vcl/embeddedfontshelper.hxx
index e1f2e5c28ece..c1c98eaf0694 100644
--- a/include/vcl/embeddedfontshelper.hxx
+++ b/include/vcl/embeddedfontshelper.hxx
@@ -26,6 +26,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
@@ -41,14 +53,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);
@@ -63,13 +76,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
@@ -85,6 +95,11 @@ public:
@internal
*/
static void clearTemporaryFontFiles();
+
+ ~EmbeddedFontsHelper()
+ {
+ activateFonts();
+ }
};
#endif
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index bfc2cbeb028f..48d4425edee1 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;
@@ -582,7 +586,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 03f4092d5ed6..431c140422ce 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 faaff5682df5..e633781ed040 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 e81876e4abdf..1569ebf56e48 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>
@@ -51,6 +52,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;
@@ -76,18 +81,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 5a6bddd4192a..dbb02f0fe29a 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/namespacemap.hxx>
@@ -451,6 +452,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 f8e3184740dd..8f4019985beb 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/xmlnamespace.hxx>
#include <xmloff/xmltoken.hxx>
@@ -327,7 +326,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();
}
@@ -339,7 +338,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();
}