include/xmloff/table/XMLTableExport.hxx | 8 +++ include/xmloff/xmlexp.hxx | 1 sc/source/filter/xml/xmlexprt.cxx | 27 +--------- sc/source/filter/xml/xmlstyle.cxx | 38 -------------- sc/source/filter/xml/xmlstyle.hxx | 14 ----- sw/qa/extras/odfexport/data/tdf101710.odt |binary sw/qa/extras/odfexport/odfexport.cxx | 7 ++ sw/source/filter/xml/xmlfmt.cxx | 77 +++++++++++++++++++++++++++++- sw/source/filter/xml/xmlfmte.cxx | 2 xmloff/source/core/xmlexp.cxx | 33 ++++++++++++ xmloff/source/table/XMLTableExport.cxx | 48 +++++++++++++++++- xmloff/source/text/txtprmap.cxx | 2 12 files changed, 177 insertions(+), 80 deletions(-)
New commits: commit 8cf4c3157348edb9e4e0c453436b26f7200ecb6c Author: Maxim Monastirsky <momonas...@gmail.com> AuthorDate: Fri Feb 21 02:35:55 2020 +0200 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Wed Mar 4 13:08:23 2020 +0100 tdf#101710 Fix invalid style:data-style-name attribute There were two problems with this attribute: 1. It was written in style:table-cell-properties instead of in style:style. 2. It was referencing a number format id, instead of a style name. Moreover, the data style wasn't even exported as part of office:styles (if at all). Both import and export were affected. For export, it was easily possible to reuse some related stuff from Calc, so that stuff was moved into xmloff and used from there (there are no logic changes for Calc). For import, loading of the invalid attribute was kept for compat reasons. Although it's only useful for automatic number formats, as the data styles weren't exported properly anyway (e.g. see the document attached in bugzilla). Conflicts: sw/qa/extras/odfexport/odfexport.cxx sw/source/filter/xml/xmlfmt.cxx xmloff/source/table/XMLTableExport.cxx Change-Id: I8b70ad205972fada6f3845837d6ed5928d7d6406 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89551 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@cib.de> (cherry picked from commit 59ace23c367f83491a37e844d16f7d716eff6346) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89774 (cherry picked from commit c98cd883be11ff931ae903469f56cfd5b5f4fd66) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89906 diff --git a/include/xmloff/table/XMLTableExport.hxx b/include/xmloff/table/XMLTableExport.hxx index 1d6655e50712..d6fd1890a993 100644 --- a/include/xmloff/table/XMLTableExport.hxx +++ b/include/xmloff/table/XMLTableExport.hxx @@ -41,6 +41,7 @@ #include <salhelper/simplereferenceobject.hxx> #include <xmloff/xmlprmap.hxx> #include <xmloff/xmlexppr.hxx> +#include <xmloff/styleexp.hxx> class SvXMLExport; class SvXMLExportPropertyMapper; @@ -95,6 +96,13 @@ private: }; +class XMLOFF_DLLPUBLIC XMLCellStyleExport final : public XMLStyleExport +{ + using XMLStyleExport::XMLStyleExport; + virtual void exportStyleAttributes(const css::uno::Reference<css::style::XStyle>& rStyle) override; + virtual void exportStyleContent(const css::uno::Reference<css::style::XStyle>& rStyle) override; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/xmloff/xmlexp.hxx b/include/xmloff/xmlexp.hxx index 7bed9eb22643..76dfcc69d953 100644 --- a/include/xmloff/xmlexp.hxx +++ b/include/xmloff/xmlexp.hxx @@ -403,6 +403,7 @@ public: // Export the document. virtual ErrCode exportDoc( enum ::xmloff::token::XMLTokenEnum eClass = ::xmloff::token::XML_TOKEN_INVALID ); + void collectDataStyles(bool bFromUsedStyles); virtual void addDataStyle(const sal_Int32 nNumberFormat, bool bTimeFormat = false ); virtual void exportDataStyles(); virtual void exportAutoDataStyles(); diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 28f85c97fd75..67aff4ab9677 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -101,6 +101,7 @@ #include <xmloff/XMLEventExport.hxx> #include <xmloff/xmlprmap.hxx> #include <xmloff/ProgressBarHelper.hxx> +#include <xmloff/table/XMLTableExport.hxx> #include <sax/tools/converter.hxx> #include <tools/fldunit.hxx> @@ -1954,7 +1955,7 @@ void ScXMLExport::ExportStyles_( bool bUsed ) sal_Int32 nShapesCount(0); CollectSharedData(nTableCount, nShapesCount); } - rtl::Reference<ScXMLStyleExport> aStylesExp(new ScXMLStyleExport(*this, GetAutoStylePool().get())); + rtl::Reference<XMLCellStyleExport> aStylesExp(new XMLCellStyleExport(*this, GetAutoStylePool().get())); if (GetModel().is()) { uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY); @@ -1968,29 +1969,7 @@ void ScXMLExport::ExportStyles_( bool bUsed ) GetShapeExport()->ExportGraphicDefaults(); } } - uno::Reference <style::XStyleFamiliesSupplier> xStyleFamiliesSupplier (GetModel(), uno::UNO_QUERY); - if (xStyleFamiliesSupplier.is()) - { - uno::Reference <container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies()); - if (xStylesFamilies.is()) - { - uno::Reference <container::XIndexAccess> xCellStyles(xStylesFamilies->getByName("CellStyles"), uno::UNO_QUERY); - if (xCellStyles.is()) - { - sal_Int32 nCount(xCellStyles->getCount()); - for (sal_Int32 i = 0; i < nCount; ++i) - { - uno::Reference <beans::XPropertySet> xCellProperties(xCellStyles->getByIndex(i), uno::UNO_QUERY); - if (xCellProperties.is()) - { - sal_Int32 nNumberFormat = 0; - if (xCellProperties->getPropertyValue(SC_UNONAME_NUMFMT) >>= nNumberFormat) - addDataStyle(nNumberFormat); - } - } - } - } - } + collectDataStyles(false); } exportDataStyles(); diff --git a/sc/source/filter/xml/xmlstyle.cxx b/sc/source/filter/xml/xmlstyle.cxx index a8ca7bbdce59..ab21410a8e15 100644 --- a/sc/source/filter/xml/xmlstyle.cxx +++ b/sc/source/filter/xml/xmlstyle.cxx @@ -792,44 +792,6 @@ ScXMLAutoStylePoolP::~ScXMLAutoStylePoolP() { } -void ScXMLStyleExport::exportStyleAttributes( - const css::uno::Reference< css::style::XStyle > & rStyle ) -{ - uno::Reference< beans::XPropertySet > xPropSet( rStyle, uno::UNO_QUERY ); - if (xPropSet.is()) - { - uno::Reference< beans::XPropertySetInfo > xPropSetInfo(xPropSet->getPropertySetInfo()); - OUString sNumberFormat("NumberFormat"); - if( xPropSetInfo->hasPropertyByName( sNumberFormat ) ) - { - uno::Reference< beans::XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); - if( xPropState.is() && (beans::PropertyState_DIRECT_VALUE == - xPropState->getPropertyState( sNumberFormat )) ) - { - sal_Int32 nNumberFormat = 0; - if (xPropSet->getPropertyValue( sNumberFormat ) >>= nNumberFormat) - GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, - GetExport().getDataStyleName(nNumberFormat) ); - } - } - } -} - -void ScXMLStyleExport::exportStyleContent( const css::uno::Reference<css::style::XStyle > & /* rStyle */ ) -{ -} - -ScXMLStyleExport::ScXMLStyleExport( - SvXMLExport& rExp, - SvXMLAutoStylePoolP *pAutoStyleP ) - : XMLStyleExport(rExp, pAutoStyleP) -{ -} - -ScXMLStyleExport::~ScXMLStyleExport() -{ -} - XMLScPropHdlFactory::XMLScPropHdlFactory() : XMLPropertyHandlerFactory() { diff --git a/sc/source/filter/xml/xmlstyle.hxx b/sc/source/filter/xml/xmlstyle.hxx index 36a42737cf24..0980d62de2ac 100644 --- a/sc/source/filter/xml/xmlstyle.hxx +++ b/sc/source/filter/xml/xmlstyle.hxx @@ -24,7 +24,6 @@ #include <xmloff/xmlaustp.hxx> #include <xmloff/xmltypes.hxx> #include <xmloff/prhdlfac.hxx> -#include <xmloff/styleexp.hxx> #include <xmloff/xmlexppr.hxx> #include <xmloff/contextid.hxx> #include <xmloff/xmlprhdl.hxx> @@ -206,19 +205,6 @@ public: virtual ~ScXMLAutoStylePoolP() override; }; -class ScXMLStyleExport : public XMLStyleExport -{ - virtual void exportStyleAttributes( - const css::uno::Reference< css::style::XStyle > & rStyle ) override; - virtual void exportStyleContent( - const css::uno::Reference< css::style::XStyle > & rStyle ) override; -public: - ScXMLStyleExport( - SvXMLExport& rExp, - SvXMLAutoStylePoolP *pAutoStyleP ); - virtual ~ScXMLStyleExport() override; -}; - class XMLScPropHdlFactory : public XMLPropertyHandlerFactory { public: diff --git a/sw/qa/extras/odfexport/data/tdf101710.odt b/sw/qa/extras/odfexport/data/tdf101710.odt new file mode 100644 index 000000000000..50ab736070aa Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf101710.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 4e92701e385e..4b8cef0525c9 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -1991,6 +1991,13 @@ DECLARE_ODFEXPORT_TEST(testTableStyles5, "table_styles_5.odt") } +DECLARE_ODFEXPORT_TEST(testTdf101710, "tdf101710.odt") +{ + // Test that number format of cell styles can be imported and exported. + uno::Reference<beans::XPropertySet> xStyle(getStyles("CellStyles")->getByName("Test Style.11"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(10104), getProperty<sal_uInt32>(xStyle, "NumberFormat")); +} + DECLARE_ODFEXPORT_TEST(testImageMimetype, "image-mimetype.odt") { // Test that the loext:mimetype attribute is written for exported images, tdf#109202 diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx index 9f9423f04ac7..f5600b7bd9ec 100644 --- a/sw/source/filter/xml/xmlfmt.cxx +++ b/sw/source/filter/xml/xmlfmt.cxx @@ -35,6 +35,9 @@ #include <unoprnms.hxx> #include <fmtpdsc.hxx> #include <pagedesc.hxx> +#include <xmloff/maptype.hxx> +#include <xmloff/xmlnumfi.hxx> +#include <xmloff/xmlprmap.hxx> #include <xmloff/xmlnmspe.hxx> #include <xmloff/i18nmap.hxx> #include <xmloff/xmltkmap.hxx> @@ -389,6 +392,20 @@ SvXMLImportContextRef SwXMLTextStyleContext_Impl::CreateChildContext( return xContext; } +namespace { + +class SwXMLCellStyleContext : public XMLPropStyleContext +{ + OUString m_sDataStyleName; + void AddDataFormat(); +public: + using XMLPropStyleContext::XMLPropStyleContext; + virtual void FillPropertySet(const css::uno::Reference<css::beans::XPropertySet>& rPropSet) override; + virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue) override; +}; + +} + class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext { OUString sMasterPageName; @@ -443,6 +460,64 @@ public: bool ResolveDataStyleName(); }; +void SwXMLCellStyleContext::AddDataFormat() +{ + if (m_sDataStyleName.isEmpty() || IsDefaultStyle()) + return; + + const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>( + GetStyles()->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, true)); + + if (!pStyle) + { + SAL_WARN("sw.xml", "not possible to get data style " << m_sDataStyleName); + return; + } + + sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey(); + if (nNumberFormat < 0) + return; + + rtl::Reference<SvXMLImportPropertyMapper> xPropertyMapper(GetStyles()->GetImportPropertyMapper(GetFamily())); + if (!xPropertyMapper.is()) + { + SAL_WARN("sw.xml", "there is no import prop mapper"); + return; + } + + const rtl::Reference<XMLPropertySetMapper>& xPropertySetMapper(xPropertyMapper->getPropertySetMapper()); + sal_Int32 nIndex = xPropertySetMapper->GetEntryIndex(XML_NAMESPACE_STYLE, GetXMLToken(XML_DATA_STYLE_NAME), 0); + if (nIndex < 0) + { + SAL_WARN("sw.xml", "could not find id for " << GetXMLToken(XML_DATA_STYLE_NAME)); + return; + } + + auto aIter = std::find_if(GetProperties().begin(), GetProperties().end(), + [&nIndex](const XMLPropertyState& rProp) { + return rProp.mnIndex == nIndex; + }); + + if (aIter != GetProperties().end()) + aIter->maValue <<= nNumberFormat; + else + GetProperties().push_back(XMLPropertyState(nIndex, makeAny(nNumberFormat))); +} + +void SwXMLCellStyleContext::FillPropertySet(const css::uno::Reference<css::beans::XPropertySet>& rPropSet) +{ + AddDataFormat(); + XMLPropStyleContext::FillPropertySet(rPropSet); +} + +void SwXMLCellStyleContext::SetAttribute(sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue) +{ + if (IsXMLToken(rLocalName, XML_DATA_STYLE_NAME)) + m_sDataStyleName = rValue; + else + XMLPropStyleContext::SetAttribute(nPrefixKey, rLocalName, rValue); +} + void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue ) @@ -744,7 +819,7 @@ SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext( if (IsAutomaticStyle()) pStyle = new SwXMLItemSetStyleContext_Impl(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily); else if (nFamily == XML_STYLE_FAMILY_TABLE_CELL) // Real cell styles are used for table-template import. - pStyle = new XMLPropStyleContext(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily); + pStyle = new SwXMLCellStyleContext(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily); else SAL_WARN("sw.xml", "Context does not exists for non automatic table, column or row style."); break; diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx index 642e9d1d93fd..209cdd5a3904 100644 --- a/sw/source/filter/xml/xmlfmte.cxx +++ b/sw/source/filter/xml/xmlfmte.cxx @@ -165,6 +165,8 @@ void SwXMLExport::ExportStyles_( bool bUsed ) GetTextParagraphExport()->exportTextStyles( bUsed ,IsShowProgress() ); + collectDataStyles(true); + exportDataStyles(); GetShapeExport()->GetShapeTableExport()->exportTableStyles(); //page defaults GetPageExport()->exportDefaultStyle(); diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx index c6746b3ea51b..0e7891e0b495 100644 --- a/xmloff/source/core/xmlexp.cxx +++ b/xmloff/source/core/xmlexp.cxx @@ -71,6 +71,8 @@ #include <XMLImageMapExport.hxx> #include <XMLBase64Export.hxx> #include <xmloff/xmlerror.hxx> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/lang/ServiceNotRegisteredException.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -1821,6 +1823,37 @@ sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::vector< SettingsGroup return 0; } +void SvXMLExport::collectDataStyles(bool bFromUsedStyles) +{ + Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(GetModel(), uno::UNO_QUERY); + if (!xStyleFamiliesSupplier.is()) + return; + + Reference<container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies()); + if (!xStylesFamilies.is()) + return; + + Reference<container::XIndexAccess> xCellStyles(xStylesFamilies->getByName("CellStyles"), uno::UNO_QUERY); + if (!xCellStyles.is()) + return; + + sal_Int32 nCount(xCellStyles->getCount()); + for (sal_Int32 i = 0; i < nCount; ++i) + { + Reference<style::XStyle> xStyle(xCellStyles->getByIndex(i), uno::UNO_QUERY); + if (bFromUsedStyles && !xStyle->isInUse()) + continue; + + Reference<beans::XPropertySet> xCellProperties(xStyle, uno::UNO_QUERY); + if (xCellProperties.is()) + { + sal_Int32 nNumberFormat = 0; + if (xCellProperties->getPropertyValue("NumberFormat") >>= nNumberFormat) + addDataStyle(nNumberFormat); + } + } +} + void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ ) { if(mpNumExport) diff --git a/xmloff/source/table/XMLTableExport.cxx b/xmloff/source/table/XMLTableExport.cxx index 228ce12d1233..597cf2570a1b 100644 --- a/xmloff/source/table/XMLTableExport.cxx +++ b/xmloff/source/table/XMLTableExport.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/table/CellContentType.hpp> #include <com/sun/star/table/XMergeableCell.hpp> #include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -144,6 +145,23 @@ sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName ) return nMax; } +namespace { + +class XMLCellExportPropertyMapper : public SvXMLExportPropertyMapper +{ +public: + using SvXMLExportPropertyMapper::SvXMLExportPropertyMapper; + /** this method is called for every item that has the + MID_FLAG_SPECIAL_ITEM_EXPORT flag set */ + virtual void handleSpecialItem(SvXMLAttributeList&, const XMLPropertyState&, const SvXMLUnitConverter&, + const SvXMLNamespaceMap&, const std::vector<XMLPropertyState>*, sal_uInt32) const override + { + // the SpecialItem NumberFormat must not be handled by this method + } +}; + +} + // class XMLTableExport XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExportPropertyMapper >& xExportPropertyMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef ) @@ -174,7 +192,7 @@ XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExp if (mbWriter) { - mxCellExportPropertySetMapper = new SvXMLExportPropertyMapper(new XMLTextPropertySetMapper(TextPropMap::CELL, true)); + mxCellExportPropertySetMapper = new XMLCellExportPropertyMapper(new XMLTextPropertySetMapper(TextPropMap::CELL, true)); } else { @@ -477,7 +495,7 @@ void XMLTableExport::exportTableStyles() if (mbWriter) { sCellStyleName = "CellStyles"; - aStEx.set(new XMLStyleExport(mrExport)); + aStEx.set(new XMLCellStyleExport(mrExport)); } else { @@ -672,4 +690,30 @@ void XMLTableExport::exportTableTemplates() } } +void XMLCellStyleExport::exportStyleContent(const Reference<XStyle>& /*rStyle*/) +{ +} + +void XMLCellStyleExport::exportStyleAttributes(const Reference<XStyle>& rStyle) +{ + Reference<XPropertySet> xPropSet(rStyle, UNO_QUERY); + if (xPropSet.is()) + { + Reference<XPropertySetInfo> xPropSetInfo(xPropSet->getPropertySetInfo()); + const OUString sNumberFormat("NumberFormat"); + if (xPropSetInfo->hasPropertyByName(sNumberFormat)) + { + Reference<XPropertyState> xPropState(xPropSet, UNO_QUERY); + if (xPropState.is() && (PropertyState_DIRECT_VALUE == + xPropState->getPropertyState(sNumberFormat))) + { + sal_Int32 nNumberFormat = 0; + if (xPropSet->getPropertyValue(sNumberFormat) >>= nNumberFormat) + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, + GetExport().getDataStyleName(nNumberFormat)); + } + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index 2cd5005dfc64..cf33122ac8e0 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -1007,7 +1007,7 @@ XMLPropertyMapEntry const aXMLCellPropMap[] = MC_E( "BottomBorderDistance", FO, PADDING_BOTTOM, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), MC_E( "VertOrient", STYLE, VERTICAL_ALIGN, XML_TYPE_TEXT_VERTICAL_POS, 0 ), MC_E( "WritingMode", STYLE, WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT, 0 ), - MC_E( "NumberFormat", STYLE, DATA_STYLE_NAME, XML_TYPE_NUMBER, 0 ), + MC_E( "NumberFormat", STYLE, DATA_STYLE_NAME, XML_TYPE_NUMBER|MID_FLAG_SPECIAL_ITEM_EXPORT, 0 ), // paragraph properties MP_E( "ParaAdjust", FO, TEXT_ALIGN, XML_TYPE_TEXT_ADJUST, 0 ), // text properties _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits