summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorBrennan Vincent <brennanv@email.arizona.edu>2013-10-05 16:50:24 -0700
committerCaolán McNamara <caolanm@redhat.com>2013-11-13 14:37:53 +0000
commit5ce50b8d171c9d86d2175dd35b1e7ef23255e895 (patch)
treede6bd12da7446ec1efe1f377f5f0e031cc59e83d /xmloff
parent4f1e4c05a9b67fbc67ea4279793a61af46444dad (diff)
Respect svg:font-face-format element.
Call libeot to parse font if value "embedded-opentype" is found. Change-Id: I03a072fd4db47d151a3934e959ad17c1e24fcf09 Reviewed-on: https://gerrit.libreoffice.org/6144 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmltoken.cxx1
-rw-r--r--xmloff/source/style/XMLFontStylesContext.cxx67
-rw-r--r--xmloff/source/style/XMLFontStylesContext_impl.hxx33
3 files changed, 97 insertions, 4 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 40511048b7a9..dedb2b48ec49 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -2486,6 +2486,7 @@ namespace xmloff { namespace token {
TOKEN( "font-face", XML_FONT_FACE ),
TOKEN( "font-face-src", XML_FONT_FACE_SRC ),
TOKEN( "font-face-uri", XML_FONT_FACE_URI ),
+ TOKEN( "font-face-format", XML_FONT_FACE_FORMAT ),
TOKEN( "font-adornments", XML_FONT_ADORNMENTS ),
TOKEN( "inch", XML_INCH ),
TOKEN( "space-after", XML_SPACE_AFTER ),
diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx
index 33f998a2579c..29f480864a29 100644
--- a/xmloff/source/style/XMLFontStylesContext.cxx
+++ b/xmloff/source/style/XMLFontStylesContext.cxx
@@ -190,6 +190,26 @@ OUString XMLFontStyleContextFontFace::familyName() const
return ret;
}
+TYPEINIT1( XMLFontStyleContextFontFaceFormat, SvXMLStyleContext );
+
+XMLFontStyleContextFontFaceFormat::XMLFontStyleContextFontFaceFormat( SvXMLImport& rImport,
+ sal_uInt16 nPrfx, const OUString& rLName,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::sax::XAttributeList > &xAttrList,
+ XMLFontStyleContextFontFaceUri& _uri )
+ : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList)
+ , uri(_uri)
+{
+}
+
+void XMLFontStyleContextFontFaceFormat::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
+ const OUString& rValue )
+{
+ if( nPrefixKey == XML_NAMESPACE_SVG && IsXMLToken( rLocalName, XML_STRING ))
+ uri.SetFormat(rValue);
+ else
+ SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
+}
TYPEINIT1( XMLFontStyleContextFontFaceSrc, SvXMLImportContext );
@@ -224,16 +244,57 @@ XMLFontStyleContextFontFaceUri::XMLFontStyleContextFontFaceUri( SvXMLImport& rIm
{
}
+SvXMLImportContext * XMLFontStyleContextFontFaceUri::CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
+{
+ if( nPrefix == XML_NAMESPACE_SVG && IsXMLToken( rLocalName, XML_FONT_FACE_FORMAT ))
+ return new XMLFontStyleContextFontFaceFormat( GetImport(), nPrefix, rLocalName, xAttrList, *this );
+ return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
+}
+
void XMLFontStyleContextFontFaceUri::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
const OUString& rValue )
{
if( nPrefixKey == XML_NAMESPACE_XLINK && IsXMLToken( rLocalName, XML_HREF ))
- handleEmbeddedFont( rValue );
+ linkPath = rValue;
else
SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
}
-void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url )
+void XMLFontStyleContextFontFaceUri::SetFormat( const OUString& rFormat )
+{
+ format = rFormat;
+}
+void XMLFontStyleContextFontFaceUri::EndElement()
+{
+ if( linkPath.getLength() == 0 )
+ {
+ SAL_WARN( "xmloff", "svg:font-face-uri tag with no link; ignoring." );
+ return;
+ }
+ bool eot;
+ // Assume by default that the font is not compressed.
+ if( format.getLength() == 0
+ || format.equalsAscii( OPENTYPE_FORMAT )
+ || format.equalsAscii( TRUETYPE_FORMAT ))
+ {
+ eot = false;
+ }
+ else if( format.equalsAscii( EOT_FORMAT ))
+ {
+ eot = true;
+ }
+ else
+ {
+ SAL_WARN( "xmloff", "Unknown format of embedded font; assuming TTF." );
+ eot = false;
+ }
+ handleEmbeddedFont( linkPath, eot );
+}
+
+void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url, bool eot )
{
if( GetImport().embeddedFontAlreadyProcessed( url ))
{
@@ -252,7 +313,7 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const OUString& url )
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, "?" ))
+ if( EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, "?", std::vector< unsigned char >(), eot ))
GetImport().NotifyEmbeddedFontRead();
inputStream->closeInput();
}
diff --git a/xmloff/source/style/XMLFontStylesContext_impl.hxx b/xmloff/source/style/XMLFontStylesContext_impl.hxx
index 81e1b7afdaa2..6ad621f265e3 100644
--- a/xmloff/source/style/XMLFontStylesContext_impl.hxx
+++ b/xmloff/source/style/XMLFontStylesContext_impl.hxx
@@ -88,8 +88,16 @@ public:
/// Handles <style:font-face-uri>
class XMLFontStyleContextFontFaceUri : public SvXMLStyleContext
{
+ // the CSS2 standard ( http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#referencing )
+ // defines these format strings.
+ const char* OPENTYPE_FORMAT = "opentype";
+ const char* TRUETYPE_FORMAT = "truetype";
+ const char* EOT_FORMAT = "embedded-opentype";
+
const XMLFontStyleContextFontFace& font;
- void handleEmbeddedFont( const OUString& url );
+ OUString format;
+ OUString linkPath;
+ void handleEmbeddedFont( const OUString& url, bool eot );
public:
TYPEINFO();
@@ -102,6 +110,29 @@ public:
virtual void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
const OUString& rValue );
+ void SetFormat( const OUString& rFormat );
+ void EndElement();
+ SvXMLImportContext * CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
+};
+
+/// Handles <svg:font-face-format>
+class XMLFontStyleContextFontFaceFormat : public SvXMLStyleContext
+{
+ XMLFontStyleContextFontFaceUri& uri;
+public:
+ TYPEINFO();
+
+ XMLFontStyleContextFontFaceFormat( SvXMLImport& rImport, sal_uInt16 nPrfx,
+ const OUString& rLName,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
+ XMLFontStyleContextFontFaceUri& uri );
+
+ void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName,
+ const OUString& rValue );
};
#endif