summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xmloff/table/XMLTableExport.hxx8
-rw-r--r--include/xmloff/xmlexp.hxx1
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx27
-rw-r--r--sc/source/filter/xml/xmlstyle.cxx38
-rw-r--r--sc/source/filter/xml/xmlstyle.hxx14
-rw-r--r--sw/qa/extras/odfexport/data/tdf101710.odtbin0 -> 9350 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx7
-rw-r--r--sw/source/filter/xml/xmlfmt.cxx73
-rw-r--r--sw/source/filter/xml/xmlfmte.cxx2
-rw-r--r--xmloff/source/core/xmlexp.cxx33
-rw-r--r--xmloff/source/table/XMLTableExport.cxx47
-rw-r--r--xmloff/source/text/txtprmap.cxx2
12 files changed, 172 insertions, 80 deletions
diff --git a/include/xmloff/table/XMLTableExport.hxx b/include/xmloff/table/XMLTableExport.hxx
index d8f037efe56a..f49a4236e2d0 100644
--- a/include/xmloff/table/XMLTableExport.hxx
+++ b/include/xmloff/table/XMLTableExport.hxx
@@ -38,6 +38,7 @@
#include <salhelper/simplereferenceobject.hxx>
#include <xmloff/prhdlfac.hxx>
#include <xmloff/xmlexppr.hxx>
+#include <xmloff/styleexp.hxx>
class SvXMLExport;
class SvXMLExportPropertyMapper;
@@ -92,6 +93,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 b14f52a97900..0ff26a843d45 100644
--- a/include/xmloff/xmlexp.hxx
+++ b/include/xmloff/xmlexp.hxx
@@ -401,6 +401,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 59e8088d4acf..b626eb3b72f3 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>
@@ -1957,7 +1958,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);
@@ -1971,29 +1972,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 5283b97f24a7..1dbd6ca451a7 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 3ddb5e9c215a..bff6767bf51a 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
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/tdf101710.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index a7af9a7f3553..6f8a78ac501b 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -2007,6 +2007,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(testTdf129568, "tdf129568.fodt")
{
// Test that export doesn't fail, and that style is imported and in use.
diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx
index 8bee69b3d4f4..b7cfde1e0405 100644
--- a/sw/source/filter/xml/xmlfmt.cxx
+++ b/sw/source/filter/xml/xmlfmt.cxx
@@ -30,6 +30,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/xmlstyle.hxx>
#include <xmloff/txtstyli.hxx>
@@ -391,6 +394,16 @@ SvXMLImportContextRef SwXMLTextStyleContext_Impl::CreateChildContext(
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;
@@ -447,6 +460,64 @@ public:
}
+void SwXMLCellStyleContext::AddDataFormat()
+{
+ if (m_sDataStyleName.isEmpty() || IsDefaultStyle())
+ return;
+
+ const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>(
+ GetStyles()->FindStyleChildContext(XmlStyleFamily::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 )
@@ -750,7 +821,7 @@ SvXMLStyleContext *SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
if (IsAutomaticStyle())
pStyle = new SwXMLItemSetStyleContext_Impl(GetSwImport(), nPrefix, rLocalName, xAttrList, *this, nFamily);
else if (nFamily == XmlStyleFamily::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 ec3f00f60caa..eb38216546d5 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 9ba14a6f4840..0a1f53107d13 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>
@@ -1787,6 +1789,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 1970987f8129..a7d719ff1d75 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>
@@ -142,6 +143,22 @@ 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
+ }
+};
+
+}
XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExportPropertyMapper >& xExportPropertyMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef )
: mrExport( rExp )
@@ -168,7 +185,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
{
@@ -471,7 +488,7 @@ void XMLTableExport::exportTableStyles()
if (mbWriter)
{
sCellStyleName = "CellStyles";
- aStEx.set(new XMLStyleExport(mrExport));
+ aStEx.set(new XMLCellStyleExport(mrExport));
}
else
{
@@ -662,4 +679,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 eaed538c55f4..94835323a693 100644
--- a/xmloff/source/text/txtprmap.cxx
+++ b/xmloff/source/text/txtprmap.cxx
@@ -1014,7 +1014,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