diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-20 17:10:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-20 18:22:26 +0200 |
commit | 764d52045b0a28e071f214fb1334b7a0c05df6bd (patch) | |
tree | 02f5cb1e761745e065fe6b60fea1f4818984dcf3 | |
parent | 37892578e97ea0f0c948116d639797060ac5f21f (diff) |
use fastparser in SvXMLNumFormatContext
which requires making SvXMLStylesContext capable of doing both
fast and slow-parser paths.
Change-Id: I57428b10ac2d67bc233cc978c9a0c0c3755d60e7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101022
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/xmloff/XMLFontStylesContext.hxx | 1 | ||||
-rw-r--r-- | include/xmloff/XMLTextMasterStylesContext.hxx | 1 | ||||
-rw-r--r-- | include/xmloff/xmlnumfi.hxx | 13 | ||||
-rw-r--r-- | include/xmloff/xmlstyle.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlstyli.hxx | 1 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlfmt.cxx | 1 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.hxx | 1 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfi.cxx | 186 | ||||
-rw-r--r-- | xmloff/source/style/xmlstyle.cxx | 35 |
9 files changed, 214 insertions, 29 deletions
diff --git a/include/xmloff/XMLFontStylesContext.hxx b/include/xmloff/XMLFontStylesContext.hxx index b10bf2797b14..3aad7826bcc3 100644 --- a/include/xmloff/XMLFontStylesContext.hxx +++ b/include/xmloff/XMLFontStylesContext.hxx @@ -45,6 +45,7 @@ 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; diff --git a/include/xmloff/XMLTextMasterStylesContext.hxx b/include/xmloff/XMLTextMasterStylesContext.hxx index 12975af36469..45b253759fde 100644 --- a/include/xmloff/XMLTextMasterStylesContext.hxx +++ b/include/xmloff/XMLTextMasterStylesContext.hxx @@ -27,6 +27,7 @@ class XMLOFF_DLLPUBLIC XMLTextMasterStylesContext : public SvXMLStylesContext { protected: + using SvXMLStylesContext::CreateStyleChildContext; virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; diff --git a/include/xmloff/xmlnumfi.hxx b/include/xmloff/xmlnumfi.hxx index e428edc671ce..3170f8b8e7c1 100644 --- a/include/xmloff/xmlnumfi.hxx +++ b/include/xmloff/xmlnumfi.hxx @@ -83,9 +83,8 @@ public: ~SvXMLNumFmtHelper(); SvXMLStyleContext* CreateChildContext( SvXMLImport& rImport, - 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, SvXMLStylesContext& rStyles); SvXMLNumImpData* getData() { return pData.get(); } @@ -154,13 +153,19 @@ class XMLOFF_DLLPUBLIC SvXMLNumFormatContext : public SvXMLStyleContext public: SvXMLNumFormatContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, + sal_uInt16 nPrfx, const OUString& rLName, SvXMLNumImpData* pNewData, SvXMLStylesTokens nNewType, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, SvXMLStylesContext& rStyles ); SvXMLNumFormatContext( SvXMLImport& rImport, + sal_Int32 nElement, + SvXMLNumImpData* pNewData, + SvXMLStylesTokens nNewType, + const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, + SvXMLStylesContext& rStyles ); + SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, diff --git a/include/xmloff/xmlstyle.hxx b/include/xmloff/xmlstyle.hxx index 6ddf51d8872a..e02f2d81a674 100644 --- a/include/xmloff/xmlstyle.hxx +++ b/include/xmloff/xmlstyle.hxx @@ -191,6 +191,10 @@ protected: const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ); + virtual SvXMLStyleContext *CreateStyleChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ); + virtual SvXMLStyleContext *CreateStyleStyleChildContext( XmlStyleFamily nFamily, sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ); diff --git a/sc/source/filter/xml/xmlstyli.hxx b/sc/source/filter/xml/xmlstyli.hxx index 78bab6fdeee2..221ef801a8e9 100644 --- a/sc/source/filter/xml/xmlstyli.hxx +++ b/sc/source/filter/xml/xmlstyli.hxx @@ -169,6 +169,7 @@ public: class ScXMLMasterStylesContext : public SvXMLStylesContext { protected: + using SvXMLStylesContext::CreateStyleChildContext; virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx index 438cf38078ef..559984a60ff2 100644 --- a/sw/source/filter/xml/xmlfmt.cxx +++ b/sw/source/filter/xml/xmlfmt.cxx @@ -754,6 +754,7 @@ class SwXMLStylesContext_Impl : public SvXMLStylesContext protected: + using SvXMLStylesContext::CreateStyleChildContext; virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; diff --git a/xmloff/source/draw/ximpstyl.hxx b/xmloff/source/draw/ximpstyl.hxx index 68927899d2d7..3885d405141b 100644 --- a/xmloff/source/draw/ximpstyl.hxx +++ b/xmloff/source/draw/ximpstyl.hxx @@ -187,6 +187,7 @@ class SdXMLStylesContext : public SvXMLStylesContext XmlStyleFamily nFamily, const OUString& rPrefix) const; protected: + using SvXMLStylesContext::CreateStyleChildContext; virtual SvXMLStyleContext* CreateStyleChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx index 732cfd72d06b..56e05cef65b9 100644 --- a/xmloff/source/style/xmlnumfi.cxx +++ b/xmloff/source/style/xmlnumfi.cxx @@ -1468,6 +1468,143 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, } SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, + sal_Int32 /*nElement*/, + SvXMLNumImpData* pNewData, SvXMLStylesTokens nNewType, + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, + SvXMLStylesContext& rStyles ) : + SvXMLStyleContext( rImport ), + pData( pNewData ), + pStyles( &rStyles ), + aMyConditions(), + nType( nNewType ), + nKey(-1), + nFormatLang( LANGUAGE_SYSTEM ), + bAutoOrder( false ), + bFromSystem( false ), + bTruncate( true ), + bAutoDec( false ), + bAutoInt( false ), + bHasExtraText( false ), + bHasLongDoW( false ), + bHasEra( false ), + bHasDateTime( false ), + bRemoveAfterUse( false ), + eDateDOW( XML_DEA_NONE ), + eDateDay( XML_DEA_NONE ), + eDateMonth( XML_DEA_NONE ), + eDateYear( XML_DEA_NONE ), + eDateHours( XML_DEA_NONE ), + eDateMins( XML_DEA_NONE ), + eDateSecs( XML_DEA_NONE ), + bDateNoDefault( false ) +{ + LanguageTagODF aLanguageTagODF; + css::i18n::NativeNumberXmlAttributes aNatNumAttr; + OUString aSpellout; + bool bAttrBool(false); + + for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) + { + OUString sValue = aIter.toString(); + switch (aIter.getToken()) + { + // attributes for a style + case XML_ELEMENT(STYLE, XML_NAME): + break; + case XML_ELEMENT(NUMBER, XML_RFC_LANGUAGE_TAG): + aLanguageTagODF.maRfcLanguageTag = sValue; + break; + case XML_ELEMENT(NUMBER, XML_LANGUAGE): + aLanguageTagODF.maLanguage = sValue; + break; + case XML_ELEMENT(NUMBER, XML_SCRIPT): + aLanguageTagODF.maScript = sValue; + break; + case XML_ELEMENT(NUMBER, XML_COUNTRY): + aLanguageTagODF.maCountry = sValue; + break; + case XML_ELEMENT(NUMBER, XML_TITLE): + sFormatTitle = sValue; + break; + case XML_ELEMENT(NUMBER, XML_AUTOMATIC_ORDER): + if (::sax::Converter::convertBool( bAttrBool, sValue )) + bAutoOrder = bAttrBool; + break; + case XML_ELEMENT(NUMBER, XML_FORMAT_SOURCE): + SvXMLUnitConverter::convertEnum( bFromSystem, sValue, aFormatSourceMap ); + break; + case XML_ELEMENT(NUMBER, XML_TRUNCATE_ON_OVERFLOW): + if (::sax::Converter::convertBool( bAttrBool, sValue )) + bTruncate = bAttrBool; + break; + case XML_ELEMENT(STYLE, XML_VOLATILE): + // volatile formats can be removed after importing + // if not used in other styles + if (::sax::Converter::convertBool( bAttrBool, sValue )) + bRemoveAfterUse = bAttrBool; + break; + case XML_ELEMENT(NUMBER, XML_TRANSLITERATION_FORMAT): + aNatNumAttr.Format = sValue; + break; + case XML_ELEMENT(LO_EXT, XML_TRANSLITERATION_SPELLOUT): + case XML_ELEMENT(NUMBER, XML_TRANSLITERATION_SPELLOUT): + aSpellout = sValue; + break; + case XML_ELEMENT(NUMBER, XML_TRANSLITERATION_LANGUAGE): + aNatNumAttr.Locale.Language = sValue; + break; + case XML_ELEMENT(NUMBER, XML_TRANSLITERATION_COUNTRY): + aNatNumAttr.Locale.Country = sValue; + break; + case XML_ELEMENT(NUMBER, XML_TRANSLITERATION_STYLE): + aNatNumAttr.Style = sValue; + break; + default: + SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); + } + } + + if (!aLanguageTagODF.isEmpty()) + { + nFormatLang = aLanguageTagODF.getLanguageTag().getLanguageType( false); + if ( nFormatLang == LANGUAGE_DONTKNOW ) + nFormatLang = LANGUAGE_SYSTEM; //! error handling for unknown locales? + } + + if (aNatNumAttr.Format.isEmpty() && aSpellout.isEmpty()) + return; + + LanguageTag aLanguageTag( OUString(), aNatNumAttr.Locale.Language, + OUString(), aNatNumAttr.Locale.Country); + aNatNumAttr.Locale = aLanguageTag.getLocale( false); + + // NatNum12 spell out formula (cardinal, ordinal, ordinal-feminine etc.) + if ( !aSpellout.isEmpty() ) + { + aFormatCode.append( "[NatNum12 " ); + aFormatCode.append( aSpellout ); + } else { + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if ( !pFormatter ) return; + + sal_Int32 nNatNum = pFormatter->GetNatNum()->convertFromXmlAttributes( aNatNumAttr ); + aFormatCode.append( "[NatNum" ); + aFormatCode.append( nNatNum ); + } + + LanguageType eLang = aLanguageTag.getLanguageType( false ); + if ( eLang == LANGUAGE_DONTKNOW ) + eLang = LANGUAGE_SYSTEM; //! error handling for unknown locales? + if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM ) + { + aFormatCode.append( "][$-" ); + // language code in upper hex: + aFormatCode.append(OUString::number(static_cast<sal_uInt16>(eLang), 16).toAsciiUpperCase()); + } + aFormatCode.append( ']' ); +} + +SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference<xml::sax::XAttributeList>& xAttrList, const sal_Int32 nTempKey, LanguageType nLang, @@ -2270,31 +2407,42 @@ SvXMLNumFmtHelper::~SvXMLNumFmtHelper() pData->RemoveVolatileFormats(); } + SvXMLStyleContext* SvXMLNumFmtHelper::CreateChildContext( SvXMLImport& rImport, - sal_uInt16 nPrefix, const OUString& rLocalName, - const uno::Reference<xml::sax::XAttributeList>& xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, SvXMLStylesContext& rStyles ) { - SvXMLStyleContext* pContext = nullptr; - - const SvXMLTokenMap& rTokenMap = pData->GetStylesElemTokenMap(); - SvXMLStylesTokens nToken = static_cast<SvXMLStylesTokens>(rTokenMap.Get( nPrefix, rLocalName )); - switch (nToken) + SvXMLStylesTokens nStyleToken; + switch (nElement) { - case SvXMLStylesTokens::NUMBER_STYLE: - case SvXMLStylesTokens::CURRENCY_STYLE: - case SvXMLStylesTokens::PERCENTAGE_STYLE: - case SvXMLStylesTokens::DATE_STYLE: - case SvXMLStylesTokens::TIME_STYLE: - case SvXMLStylesTokens::BOOLEAN_STYLE: - case SvXMLStylesTokens::TEXT_STYLE: - pContext = new SvXMLNumFormatContext( rImport, nPrefix, rLocalName, - pData.get(), nToken, xAttrList, rStyles ); + case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE): + nStyleToken = SvXMLStylesTokens::NUMBER_STYLE; + break; + case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE): + nStyleToken = SvXMLStylesTokens::CURRENCY_STYLE; + break; + case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE): + nStyleToken = SvXMLStylesTokens::PERCENTAGE_STYLE; break; + case XML_ELEMENT(NUMBER, XML_DATE_STYLE): + nStyleToken = SvXMLStylesTokens::DATE_STYLE; + break; + case XML_ELEMENT(NUMBER, XML_TIME_STYLE): + nStyleToken = SvXMLStylesTokens::TIME_STYLE; + break; + case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE): + nStyleToken = SvXMLStylesTokens::BOOLEAN_STYLE; + break; + case XML_ELEMENT(NUMBER, XML_TEXT_STYLE): + nStyleToken = SvXMLStylesTokens::TEXT_STYLE; + break; + default: + // return NULL if not a data style, caller must handle other elements + return nullptr; } - - // return NULL if not a data style, caller must handle other elements - return pContext; + return new SvXMLNumFormatContext( rImport, nElement, + pData.get(), nStyleToken, xAttrList, rStyles ); } const SvXMLTokenMap& SvXMLNumFmtHelper::GetStylesElemTokenMap() diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx index 3c458b55a43e..03ac41d85077 100644 --- a/xmloff/source/style/xmlstyle.cxx +++ b/xmloff/source/style/xmlstyle.cxx @@ -326,6 +326,11 @@ SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) : inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle ) { +#if OSL_DEBUG_LEVEL > 0 +// for (auto const & xStyle : aStyles) +// if (xStyle->GetFamily() == pStyle->GetFamily() && xStyle->GetName() == pStyle->GetName()) +// assert(false && "duplicate style"); +#endif aStyles.emplace_back(pStyle ); FlushIndex(); @@ -395,18 +400,27 @@ bool SvXMLStylesContext::IsAutomaticStyle() const return mpImpl->IsAutomaticStyle(); } -SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) { SvXMLStyleContext *pStyle = nullptr; if(GetImport().GetDataStylesImport()) { - pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix, - rLocalName, xAttrList, *this); + pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), nElement, + xAttrList, *this); } + return pStyle; +} + +SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = nullptr; + if (!pStyle) { const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap(); @@ -807,8 +821,17 @@ SvXMLStylesContext::~SvXMLStylesContext() } css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext( - sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { + SvXMLStyleContext *pStyle = + CreateStyleChildContext( nElement, xAttrList ); + if( pStyle ) + { + if( !pStyle->IsTransient() ) + mpImpl->AddStyle( pStyle ); + return pStyle; + } + return nullptr; } |