From a9d191857372847fe198cb6036a9db2877289b4b Mon Sep 17 00:00:00 2001 From: David Tardon Date: Mon, 5 Jan 2015 16:45:25 +0100 Subject: read embedded fonts from Flat ODF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic94608f4afac9d8ac05ec3140d195b0526e9420a (cherry picked from commit 0a0496858905622374f9880b21b35ac1943c7a19) Reviewed-on: https://gerrit.libreoffice.org/13751 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- xmloff/source/style/XMLFontStylesContext.cxx | 27 ++++++++++++++++++++--- xmloff/source/style/XMLFontStylesContext_impl.hxx | 8 +++++++ 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'xmloff') diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx index 5f7dfa87855d..373e116bf9a8 100644 --- a/xmloff/source/style/XMLFontStylesContext.cxx +++ b/xmloff/source/style/XMLFontStylesContext.cxx @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -33,6 +35,7 @@ #include "fonthdl.hxx" #include #include +#include using namespace ::com::sun::star; @@ -251,6 +254,12 @@ SvXMLImportContext * XMLFontStyleContextFontFaceUri::CreateChildContext( { if( nPrefix == XML_NAMESPACE_SVG && IsXMLToken( rLocalName, XML_FONT_FACE_FORMAT )) return new XMLFontStyleContextFontFaceFormat( GetImport(), nPrefix, rLocalName, xAttrList, *this ); + if( linkPath.isEmpty() && ( nPrefix == XML_NAMESPACE_OFFICE ) && IsXMLToken( rLocalName, XML_BINARY_DATA ) ) + { + mxBase64Stream.set( new comphelper::OSequenceOutputStream( maFontData ) ); + if( mxBase64Stream.is() ) + return new XMLBase64ImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxBase64Stream ); + } return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); } @@ -276,9 +285,9 @@ const char* EOT_FORMAT = "embedded-opentype"; void XMLFontStyleContextFontFaceUri::EndElement() { - if( linkPath.getLength() == 0 ) + if( ( linkPath.getLength() == 0 ) && ( maFontData.getLength() == 0 ) ) { - SAL_WARN( "xmloff", "svg:font-face-uri tag with no link; ignoring." ); + SAL_WARN( "xmloff", "svg:font-face-uri tag with no link or base64 data; ignoring." ); return; } bool eot; @@ -298,7 +307,10 @@ void XMLFontStyleContextFontFaceUri::EndElement() SAL_WARN( "xmloff", "Unknown format of embedded font; assuming TTF." ); eot = false; } - handleEmbeddedFont( linkPath, eot ); + if ( maFontData.getLength() == 0 ) + handleEmbeddedFont( linkPath, eot ); + else + handleEmbeddedFont( maFontData, eot ); } void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url, bool eot ) @@ -328,6 +340,15 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url, bo SAL_WARN( "xmloff", "External URL for font file not handled." ); } +void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const ::css::uno::Sequence< sal_Int8 >& rData, const bool eot ) +{ + 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 ) ) + GetImport().NotifyEmbeddedFontRead(); + xInput->closeInput(); +} + SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, diff --git a/xmloff/source/style/XMLFontStylesContext_impl.hxx b/xmloff/source/style/XMLFontStylesContext_impl.hxx index 3938aa670659..a1cfc1161c9e 100644 --- a/xmloff/source/style/XMLFontStylesContext_impl.hxx +++ b/xmloff/source/style/XMLFontStylesContext_impl.hxx @@ -22,6 +22,10 @@ #include +namespace com { namespace sun { namespace star { namespace io { + class XOutputStream; +} } } } + /// Handles class XMLFontStyleContextFontFace : public SvXMLStyleContext { @@ -91,7 +95,11 @@ class XMLFontStyleContextFontFaceUri : public SvXMLStyleContext const XMLFontStyleContextFontFace& font; OUString format; OUString linkPath; + ::css::uno::Sequence< sal_Int8 > maFontData; + ::css::uno::Reference< ::css::io::XOutputStream > mxBase64Stream; + void handleEmbeddedFont( const OUString& url, bool eot ); + void handleEmbeddedFont( const ::css::uno::Sequence< sal_Int8 >& rData, bool eot ); public: TYPEINFO_OVERRIDE(); -- cgit v1.2.3