diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-08-23 16:43:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-23 18:57:37 +0200 |
commit | 8d3f88f22e35936577f278b0fcc366c75c403a82 (patch) | |
tree | 257b9c9db782745e92bfcc63a30f20a1cf681957 /xmloff | |
parent | 179909a9ec0ac3c73cc3f797da63ae20c9057636 (diff) |
use fastparser in SdXMLPageMasterContext
Change-Id: Ie4c9419a226eb14e0ff0ded23e2749e68dadcaa9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101241
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/draw/ximpstyl.cxx | 94 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.hxx | 15 |
2 files changed, 44 insertions, 65 deletions
diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index 22a77b320d78..ff2796023d1f 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -309,10 +309,9 @@ void XMLDrawingPageStyleContext::FillPropertySet( SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList>& xAttrList) -: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XmlStyleFamily::SD_PAGEMASTERSTYLECONEXT_ID), + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList>& xAttrList) +: SvXMLStyleContext(rImport, nElement, xAttrList, XmlStyleFamily::SD_PAGEMASTERSTYLECONEXT_ID), mnBorderBottom( 0 ), mnBorderLeft( 0 ), mnBorderRight( 0 ), @@ -324,54 +323,54 @@ SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext( // set family to something special at SvXMLStyleContext // for differences in search-methods - sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for(sal_Int16 i=0; i < nAttrCount; i++) + for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) { - OUString sAttrName = xAttrList->getNameByIndex(i); - OUString aLocalName; - sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName); - OUString sValue = xAttrList->getValueByIndex(i); - const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterStyleAttrTokenMap(); - - switch(rAttrTokenMap.Get(nPrefix, aLocalName)) + OUString sValue = aIter.toString(); + switch(aIter.getToken()) { - case XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP: + case XML_ELEMENT(FO, XML_MARGIN_TOP): + case XML_ELEMENT(FO_COMPAT, XML_MARGIN_TOP): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnBorderTop, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM: + case XML_ELEMENT(FO, XML_MARGIN_BOTTOM): + case XML_ELEMENT(FO_COMPAT, XML_MARGIN_BOTTOM): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnBorderBottom, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT: + case XML_ELEMENT(FO, XML_MARGIN_LEFT): + case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnBorderLeft, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT: + case XML_ELEMENT(FO, XML_MARGIN_RIGHT): + case XML_ELEMENT(FO_COMPAT, XML_MARGIN_RIGHT): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnBorderRight, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH: + case XML_ELEMENT(FO, XML_PAGE_WIDTH): + case XML_ELEMENT(FO_COMPAT, XML_PAGE_WIDTH): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnWidth, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT: + case XML_ELEMENT(FO, XML_PAGE_HEIGHT): + case XML_ELEMENT(FO_COMPAT, XML_PAGE_HEIGHT): { GetSdImport().GetMM100UnitConverter().convertMeasureToCore( mnHeight, sValue); break; } - case XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION: + case XML_ELEMENT(STYLE, XML_PRINT_ORIENTATION): { if( IsXMLToken( sValue, XML_PORTRAIT ) ) meOrientation = view::PaperOrientation_PORTRAIT; @@ -379,6 +378,8 @@ SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext( meOrientation = view::PaperOrientation_LANDSCAPE; break; } + default: + SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); } } } @@ -390,47 +391,29 @@ SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext() SdXMLPageMasterContext::SdXMLPageMasterContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList>& xAttrList) -: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XmlStyleFamily::SD_PAGEMASTERCONEXT_ID) + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList>& xAttrList) +: SvXMLStyleContext(rImport, nElement, xAttrList, XmlStyleFamily::SD_PAGEMASTERCONEXT_ID) { // set family to something special at SvXMLStyleContext // for differences in search-methods - sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for(sal_Int16 i=0; i < nAttrCount; i++) - { - OUString sAttrName = xAttrList->getNameByIndex(i); - OUString aLocalName; - sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName); - const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterAttrTokenMap(); - - switch(rAttrTokenMap.Get(nPrefix, aLocalName)) - { - case XML_TOK_PAGEMASTER_NAME: - { - break; - } - } - } } -SvXMLImportContextRef SdXMLPageMasterContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPageMasterContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLImportContextRef xContext; - - if(nPrefix == XML_NAMESPACE_STYLE && IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES) ) + if(nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES)) { DBG_ASSERT(!mxPageMasterStyle.is(), "PageMasterStyle is set, there seem to be two of them (!)"); - mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nPrefix, rLocalName, xAttrList)); - xContext = mxPageMasterStyle.get(); + mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nElement, xAttrList)); + return mxPageMasterStyle.get(); } + else + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); - return xContext; + return nullptr; } SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext( @@ -914,6 +897,11 @@ SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext( if (pContext) return pContext; } + else if (nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT)) + { + // style:page-master inside office:styles context + return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList); + } // call base class return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList); @@ -929,12 +917,6 @@ SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext( switch(rStyleTokenMap.Get(nPrefix, rLocalName)) { - case XML_TOK_STYLES_PAGE_MASTER: - { - // style:page-master inside office:styles context - pContext = new SdXMLPageMasterContext(GetSdImport(), nPrefix, rLocalName, xAttrList); - break; - } case XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT: { // style:presentation-page-layout inside office:styles context diff --git a/xmloff/source/draw/ximpstyl.hxx b/xmloff/source/draw/ximpstyl.hxx index c85fb2880624..c0290bb6aab0 100644 --- a/xmloff/source/draw/ximpstyl.hxx +++ b/xmloff/source/draw/ximpstyl.hxx @@ -53,9 +53,8 @@ public: SdXMLPageMasterStyleContext( SdXMLImport& 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); virtual ~SdXMLPageMasterStyleContext() override; sal_Int32 GetBorderBottom() const { return mnBorderBottom; } @@ -80,13 +79,11 @@ public: SdXMLPageMasterContext( SdXMLImport& 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); - virtual 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 >& AttrList ) override; const SdXMLPageMasterStyleContext* GetPageMasterStyle() const { return mxPageMasterStyle.get(); } }; |