diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2020-02-21 02:35:55 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-03-03 18:22:37 +0100 |
commit | c98cd883be11ff931ae903469f56cfd5b5f4fd66 (patch) | |
tree | 81c6ffb4a33538aaae42ef61cbcc372d2bd6d539 /xmloff | |
parent | 9691219ae7dce548d24952e335109d546b295a9a (diff) |
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.stahl@cib.de>
(cherry picked from commit 59ace23c367f83491a37e844d16f7d716eff6346)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89774
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmlexp.cxx | 33 | ||||
-rw-r--r-- | xmloff/source/table/XMLTableExport.cxx | 48 | ||||
-rw-r--r-- | xmloff/source/text/txtprmap.cxx | 2 |
3 files changed, 80 insertions, 3 deletions
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx index 59dcf10f60a5..a314b6a39670 100644 --- a/xmloff/source/core/xmlexp.cxx +++ b/xmloff/source/core/xmlexp.cxx @@ -68,6 +68,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> @@ -1779,6 +1781,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 1703542d0cf0..42d482a1c8a5 100644 --- a/xmloff/source/table/XMLTableExport.cxx +++ b/xmloff/source/table/XMLTableExport.cxx @@ -31,6 +31,7 @@ #include <com/sun/star/table/XColumnRowRange.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> @@ -138,6 +139,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 ) @@ -165,7 +183,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 { @@ -468,7 +486,7 @@ void XMLTableExport::exportTableStyles() if (mbWriter) { sCellStyleName = "CellStyles"; - aStEx.set(new XMLStyleExport(mrExport)); + aStEx.set(new XMLCellStyleExport(mrExport)); } else { @@ -659,4 +677,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 5340ffd80e16..ebd91ebc3062 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -1010,7 +1010,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 |