diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-25 08:35:28 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-25 11:17:38 +0200 |
commit | 9f514aae04933b6bc677c178e982cabb9be7ab14 (patch) | |
tree | 1efed716b239cb432963a8c1f80100b81414c3b5 | |
parent | e8acd00ba910cae2b91ee396048381e3897c6776 (diff) |
use fastparser in XMLFontStylesContext
Change-Id: I122216400ae5f97bc2a757146f84f146ba92afb2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101303
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/xmloff/XMLFontStylesContext.hxx | 5 | ||||
-rw-r--r-- | xmloff/source/style/XMLFontStylesContext.cxx | 95 | ||||
-rw-r--r-- | xmloff/source/style/XMLFontStylesContext_impl.hxx | 46 |
3 files changed, 68 insertions, 78 deletions
diff --git a/include/xmloff/XMLFontStylesContext.hxx b/include/xmloff/XMLFontStylesContext.hxx index 3aad7826bcc3..3094ac191365 100644 --- a/include/xmloff/XMLFontStylesContext.hxx +++ b/include/xmloff/XMLFontStylesContext.hxx @@ -46,9 +46,8 @@ class XMLOFF_DLLPUBLIC XMLFontStylesContext final : public SvXMLStylesContext rtl_TextEncoding eDfltEncoding; using SvXMLStylesContext::CreateStyleChildContext; - virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual SvXMLStyleContext *CreateStyleChildContext( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; public: diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx index e17b79bd6ecb..7a9d36a7cac5 100644 --- a/xmloff/source/style/XMLFontStylesContext.cxx +++ b/xmloff/source/style/XMLFontStylesContext.cxx @@ -85,10 +85,10 @@ static const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap() XMLFontStyleContextFontFace::XMLFontStyleContextFontFace( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const Reference< XAttributeList > & xAttrList, + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList, XMLFontStylesContext& rStyles ) : - SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ), + SvXMLStyleContext( rImport, nElement, xAttrList, XML_STYLE_FAMILY_FONT ), xStyles( &rStyles ) { aFamilyName <<= OUString(); @@ -176,13 +176,15 @@ void XMLFontStyleContextFontFace::FillProperties( } } -SvXMLImportContextRef XMLFontStyleContextFontFace::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFontStyleContextFontFace::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & ) { - if( nPrefix == XML_NAMESPACE_SVG && IsXMLToken( rLocalName, XML_FONT_FACE_SRC )) - return new XMLFontStyleContextFontFaceSrc( GetImport(), nPrefix, rLocalName, *this ); + if( nElement == XML_ELEMENT(SVG, XML_FONT_FACE_SRC) || + nElement == XML_ELEMENT(SVG_COMPAT, XML_FONT_FACE_SRC) ) + return new XMLFontStyleContextFontFaceSrc( GetImport(), *this ); + else + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); return nullptr; } @@ -195,10 +197,10 @@ OUString XMLFontStyleContextFontFace::familyName() const XMLFontStyleContextFontFaceFormat::XMLFontStyleContextFontFaceFormat( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLFontStyleContextFontFaceUri& _uri ) - : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList) + : SvXMLStyleContext( rImport, nElement, xAttrList) , uri(_uri) { } @@ -214,46 +216,51 @@ void XMLFontStyleContextFontFaceFormat::SetAttribute( sal_uInt16 nPrefixKey, con XMLFontStyleContextFontFaceSrc::XMLFontStyleContextFontFaceSrc( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, const XMLFontStyleContextFontFace& _font ) - : SvXMLImportContext( rImport, nPrfx, rLName ) + : SvXMLImportContext( rImport ) , font( _font ) { } -SvXMLImportContextRef XMLFontStyleContextFontFaceSrc::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFontStyleContextFontFaceSrc::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) { - if( nPrefix == XML_NAMESPACE_SVG && IsXMLToken( rLocalName, XML_FONT_FACE_URI )) - return new XMLFontStyleContextFontFaceUri( GetImport(), nPrefix, rLocalName, xAttrList, font ); + if( nElement == XML_ELEMENT(SVG, XML_FONT_FACE_URI) || + nElement == XML_ELEMENT(SVG_COMPAT, XML_FONT_FACE_URI) ) + return new XMLFontStyleContextFontFaceUri( GetImport(), nElement, xAttrList, font ); + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); return nullptr; } XMLFontStyleContextFontFaceUri::XMLFontStyleContextFontFaceUri( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const XMLFontStyleContextFontFace& _font ) - : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList ) + : SvXMLStyleContext( rImport, nElement, xAttrList ) , font( _font ) { } -SvXMLImportContextRef XMLFontStyleContextFontFaceUri::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFontStyleContextFontFaceUri::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) { - 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 ) ) + if( nElement == XML_ELEMENT(SVG, XML_FONT_FACE_FORMAT) ) + return new XMLFontStyleContextFontFaceFormat( GetImport(), nElement, xAttrList, *this ); + else if( nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA) ) { - mxBase64Stream.set( new comphelper::OSequenceOutputStream( maFontData ) ); - if( mxBase64Stream.is() ) - return new XMLBase64ImportContext( GetImport(), nPrefix, rLocalName, xAttrList, mxBase64Stream ); + assert(linkPath.isEmpty()); + if( linkPath.isEmpty() ) + { + mxBase64Stream.set( new comphelper::OSequenceOutputStream( maFontData ) ); + if( mxBase64Stream.is() ) + return new XMLBase64ImportContext( GetImport(), mxBase64Stream ); + } } + else + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); return nullptr; } @@ -277,7 +284,7 @@ const char OPENTYPE_FORMAT[] = "opentype"; const char TRUETYPE_FORMAT[] = "truetype"; const char EOT_FORMAT[] = "embedded-opentype"; -void XMLFontStyleContextFontFaceUri::EndElement() +void XMLFontStyleContextFontFaceUri::endFastElement(sal_Int32 ) { if( ( linkPath.getLength() == 0 ) && ( !maFontData.hasElements() ) ) { @@ -344,24 +351,14 @@ void XMLFontStyleContextFontFaceUri::handleEmbeddedFont( const ::css::uno::Seque } SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) { - SvXMLStyleContext *pStyle; - if( XML_NAMESPACE_STYLE == nPrefix && - IsXMLToken( rLocalName, XML_FONT_FACE ) ) - { - pStyle = new XMLFontStyleContextFontFace( GetImport(), nPrefix, - rLocalName, xAttrList, *this ); - } - else + if( nElement == XML_ELEMENT(STYLE, XML_FONT_FACE) ) { - pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix, - rLocalName, xAttrList ); + return new XMLFontStyleContextFontFace( GetImport(), nElement, xAttrList, *this ); } - - return pStyle; + return SvXMLStylesContext::CreateStyleChildContext( nElement, xAttrList ); } diff --git a/xmloff/source/style/XMLFontStylesContext_impl.hxx b/xmloff/source/style/XMLFontStylesContext_impl.hxx index 854523e9a15b..b9c56ad8114c 100644 --- a/xmloff/source/style/XMLFontStylesContext_impl.hxx +++ b/xmloff/source/style/XMLFontStylesContext_impl.hxx @@ -45,10 +45,10 @@ class XMLFontStyleContextFontFace : public SvXMLStyleContext public: - XMLFontStyleContextFontFace( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, + XMLFontStyleContextFontFace( SvXMLImport& rImport, + sal_Int32 nElement, const css::uno::Reference< - css::xml::sax::XAttributeList > & xAttrList, + css::xml::sax::XFastAttributeList > & xAttrList, XMLFontStylesContext& rStyles ); virtual ~XMLFontStyleContextFontFace() override; @@ -64,10 +64,9 @@ public: OUString familyName() const; - SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; }; /// Handles <style:font-face-src> @@ -77,14 +76,14 @@ class XMLFontStyleContextFontFaceSrc : public SvXMLImportContext public: - XMLFontStyleContextFontFaceSrc( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, + XMLFontStyleContextFontFaceSrc( SvXMLImport& rImport, const XMLFontStyleContextFontFace& font ); - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; }; /// Handles <style:font-face-uri> @@ -101,20 +100,17 @@ class XMLFontStyleContextFontFaceUri : public SvXMLStyleContext public: - XMLFontStyleContextFontFaceUri( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< - css::xml::sax::XAttributeList > & xAttrList, + XMLFontStyleContextFontFaceUri( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const XMLFontStyleContextFontFace& font ); virtual void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue ) override; void SetFormat( const OUString& rFormat ); - void EndElement() override; - SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + void SAL_CALL endFastElement(sal_Int32 nElement) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; }; /// Handles <svg:font-face-format> @@ -123,10 +119,8 @@ class XMLFontStyleContextFontFaceFormat : public SvXMLStyleContext XMLFontStyleContextFontFaceUri& uri; public: - XMLFontStyleContextFontFaceFormat( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< - css::xml::sax::XAttributeList > & xAttrList, + XMLFontStyleContextFontFaceFormat( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, XMLFontStyleContextFontFaceUri& uri ); void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, |