From 3fbc15ce456d0112700e1832e860e06f01eb5c03 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 5 Mar 2013 19:35:42 +0100 Subject: remove the need to explicitly specify font style for font embedding The information can be read from the font data itself now, so this is a bit pointless. It wasn't entirely reliable anyway, as it is also necessary to ensure two font different font files don't overwrite each other. Change-Id: Ie17ab8118e1c08228beb7c749c5c8d6cf3426362 --- xmloff/inc/xmloff/XMLFontAutoStylePool.hxx | 2 +- xmloff/inc/xmloff/xmlimp.hxx | 7 +++++++ xmloff/source/core/xmlimp.cxx | 8 ++++++++ xmloff/source/style/XMLFontAutoStylePool.cxx | 12 +++++------- xmloff/source/style/XMLFontStylesContext.cxx | 21 ++++++--------------- 5 files changed, 27 insertions(+), 23 deletions(-) (limited to 'xmloff') diff --git a/xmloff/inc/xmloff/XMLFontAutoStylePool.hxx b/xmloff/inc/xmloff/XMLFontAutoStylePool.hxx index 1b16725e5a88..ad6a46d81b8e 100644 --- a/xmloff/inc/xmloff/XMLFontAutoStylePool.hxx +++ b/xmloff/inc/xmloff/XMLFontAutoStylePool.hxx @@ -39,7 +39,7 @@ class XMLOFF_DLLPUBLIC XMLFontAutoStylePool : public UniRefBase XMLFontAutoStylePoolNames_Impl m_aNames; bool tryToEmbedFonts; - OUString embedFontFile( const OUString& fontUrl, const char* style ); + OUString embedFontFile( const OUString& fontUrl ); protected: diff --git a/xmloff/inc/xmloff/xmlimp.hxx b/xmloff/inc/xmloff/xmlimp.hxx index 24f1f9799c11..750f56725aaf 100644 --- a/xmloff/inc/xmloff/xmlimp.hxx +++ b/xmloff/inc/xmloff/xmlimp.hxx @@ -138,6 +138,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper6< sal_uInt16 mnImportFlags; sal_uInt16 mnErrorFlags; + std::set< OUString > embeddedFontUrlsKnown; protected: @@ -449,6 +450,12 @@ public: */ bool isGraphicLoadOnDemandSupported() const; + /** + Returns true if the embedded font document URL has already been processed. + Otherwise returns false and consequent calls with the same URL will return true. + */ + bool embeddedFontAlreadyProcessed( const OUString& url ); + virtual void NotifyEmbeddedFontRead() {}; }; diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 9962db56fd89..2edbac4ad084 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -1902,4 +1902,12 @@ SvXMLImport::AddRDFa(uno::Reference i_xObject, i_rAbout, i_rProperty, i_rContent, i_rDatatype); } +bool SvXMLImport::embeddedFontAlreadyProcessed( const OUString& url ) +{ + if( embeddedFontUrlsKnown.count( url ) != 0 ) + return true; + embeddedFontUrlsKnown.insert( url ); + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx index e8c33aafdd71..561814d32c18 100644 --- a/xmloff/source/style/XMLFontAutoStylePool.cxx +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -275,13 +275,11 @@ void XMLFontAutoStylePool::exportXML() if( tryToEmbedFonts ) { std::vector< OUString > fileUrls; - static const char* const styles[] = { "", "b", "i", "bi" }; static const FontWeight weight[] = { WEIGHT_NORMAL, WEIGHT_BOLD, WEIGHT_NORMAL, WEIGHT_BOLD }; static const FontItalic italic[] = { ITALIC_NONE, ITALIC_NONE, ITALIC_NORMAL, ITALIC_NORMAL }; - assert( SAL_N_ELEMENTS( styles ) == SAL_N_ELEMENTS( italic )); - assert( SAL_N_ELEMENTS( styles ) == SAL_N_ELEMENTS( weight )); + assert( SAL_N_ELEMENTS( weight ) == SAL_N_ELEMENTS( italic )); for( unsigned int j = 0; - j < SAL_N_ELEMENTS( styles ); + j < SAL_N_ELEMENTS( weight ); ++j ) { OUString fileUrl = EmbeddedFontsHelper::fontFileUrl( pEntry->GetFamilyName(), pEntry->GetFamily(), @@ -290,7 +288,7 @@ void XMLFontAutoStylePool::exportXML() continue; if( !fontFilesMap.count( fileUrl )) { - OUString docUrl = embedFontFile( fileUrl, styles[ j ] ); + OUString docUrl = embedFontFile( fileUrl ); if( !docUrl.isEmpty()) fontFilesMap[ fileUrl ] = docUrl; else @@ -319,7 +317,7 @@ void XMLFontAutoStylePool::exportXML() } } -OUString XMLFontAutoStylePool::embedFontFile( const OUString& fileUrl, const char* style ) +OUString XMLFontAutoStylePool::embedFontFile( const OUString& fileUrl ) { try { @@ -333,7 +331,7 @@ OUString XMLFontAutoStylePool::embedFontFile( const OUString& fileUrl, const cha OUString name; do { - name = "font" + OUString::number( ++index ) + OUString::createFromAscii( style ) + ".ttf"; + name = "font" + OUString::number( ++index ) + ".ttf"; } while( storage->hasByName( name ) ); uno::Reference< io::XOutputStream > outputStream; outputStream.set( storage->openStreamElement( name, ::embed::ElementModes::WRITE ), UNO_QUERY_THROW ); diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx index f269284f3319..21b9cdb83d45 100644 --- a/xmloff/source/style/XMLFontStylesContext.cxx +++ b/xmloff/source/style/XMLFontStylesContext.cxx @@ -238,18 +238,12 @@ void XMLFontStyleContextFontFaceUri::SetAttribute( sal_uInt16 nPrefixKey, const void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url ) { + if( GetImport().embeddedFontAlreadyProcessed( url )) + { + GetImport().NotifyEmbeddedFontRead(); + return; + } OUString fontName = font.familyName(); - const char* style = ""; - // OOXML needs to know what kind of style the font is (regular, italic, bold, bold-italic), - // and the EmbeddedFontsHelper class is modelled after it. But ODF doesn't (need to) include - // this information, so try to guess from the name (LO encodes the style), otherwise - // go with regular and hope it works. - if( url.endsWithIgnoreAsciiCase( "bi.ttf" )) - style = "bi"; - else if( url.endsWithIgnoreAsciiCase( "b.ttf" )) - style = "b"; - else if( url.endsWithIgnoreAsciiCase( "i.ttf" )) - style = "i"; // If there's any giveMeStreamForThisURL(), then it's well-hidden for me to find it. if( GetImport().IsPackageURL( url )) { @@ -258,15 +252,12 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url ) if( url.indexOf( '/' ) > -1 ) // TODO what if more levels? storage.set( storage->openStorageElement( url.copy( 0, url.indexOf( '/' )), ::embed::ElementModes::READ ), uno::UNO_QUERY_THROW ); - OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, style ); + OUString fileUrl = EmbeddedFontsHelper::fileUrlForTemporaryFont( fontName, "?" ); osl::File file( fileUrl ); switch( file.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_Write )) { case osl::File::E_None: break; // ok - case osl::File::E_EXIST: - GetImport().NotifyEmbeddedFontRead(); - return; // Assume it's already been added correctly. default: SAL_WARN( "xmloff", "Cannot open file for temporary font" ); return; -- cgit