diff options
author | David Tardon <dtardon@redhat.com> | 2015-01-05 16:45:25 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-01-05 18:59:08 +0100 |
commit | 0a0496858905622374f9880b21b35ac1943c7a19 (patch) | |
tree | 6c735ec620553877368b80be50f42bdbf16abe2b /xmloff | |
parent | 02266c33f23cd9fa59b73db3ef88e32c24106587 (diff) |
read embedded fonts from Flat ODF
Change-Id: Ic94608f4afac9d8ac05ec3140d195b0526e9420a
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/style/XMLFontStylesContext.cxx | 27 | ||||
-rw-r--r-- | xmloff/source/style/XMLFontStylesContext_impl.hxx | 8 |
2 files changed, 32 insertions, 3 deletions
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 <com/sun/star/awt/FontPitch.hpp> #include <com/sun/star/embed/ElementModes.hpp> +#include <comphelper/seqstream.hxx> + #include <osl/file.hxx> #include <vcl/embeddedfontshelper.hxx> @@ -33,6 +35,7 @@ #include "fonthdl.hxx" #include <xmloff/xmlimp.hxx> #include <xmloff/maptype.hxx> +#include <xmloff/XMLBase64ImportContext.hxx> 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 <xmloff/xmlstyle.hxx> +namespace com { namespace sun { namespace star { namespace io { + class XOutputStream; +} } } } + /// Handles <style:font-face> 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(); |