sd/qa/unit/data/odg/tablestyles.fodg | 34 ++++++++++++++++++++++++++ sd/qa/unit/export-tests.cxx | 35 +++++++++++++++++++++++++++ xmloff/source/table/XMLTableExport.cxx | 14 ++++++++++- xmloff/source/table/XMLTableImport.cxx | 42 ++++++++++++++++++++++++++++++++- 4 files changed, 123 insertions(+), 2 deletions(-)
New commits: commit 6f32f1a12be06c4da92b807d8a35cb079984e26a Author: Maxim Monastirsky <momonas...@gmail.com> AuthorDate: Fri Oct 28 12:20:49 2022 +0300 Commit: Maxim Monastirsky <momonas...@gmail.com> CommitDate: Mon Oct 31 11:49:11 2022 +0100 tdf#72238 xmloff,sd: Import of <style:table-cell-properties> Handles fo:border*, fo:padding*, fo:background-color and style:vertical-align attributes. Export is unchanged for now, as older versions still can't read this, and on the other hand we probably want to keep the import of the wrong attributes for the long term, to not break existing documents. Also, we can't fully export fill properties anyway because of tdf#103602. Change-Id: I8687507b98602ffcd05adb2087c894bb45aa3c6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142058 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonas...@gmail.com> diff --git a/sd/qa/unit/data/odg/tablestyles.fodg b/sd/qa/unit/data/odg/tablestyles.fodg new file mode 100644 index 000000000000..7b54e73955f9 --- /dev/null +++ b/sd/qa/unit/data/odg/tablestyles.fodg @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:xlink="http://www.w3.org/1999/xli nk" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:rpt="http://openoffice.org/2005/report" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:field="urn:openoffice:names:experimental:o oo-ms-interop:xmlns:field:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.graphics"> + <office:scripts/> + <office:font-face-decls/> + <office:automatic-styles> + <style:page-layout style:name="PM0"> + <style:page-layout-properties fo:margin-top="1cm" fo:margin-bottom="1cm" fo:margin-left="1cm" fo:margin-right="1cm" fo:page-width="21.59cm" fo:page-height="27.94cm" style:print-orientation="portrait"/> + </style:page-layout> + <style:style style:name="dp1" style:family="drawing-page"> + <style:drawing-page-properties draw:background-size="border" draw:fill="none"/> + </style:style> + <style:style style:name="dp2" style:family="drawing-page"/> + <style:style style:name="ce1" style:family="table-cell"> + <style:table-cell-properties fo:background-color="#ffcc99" fo:border="4.51pt solid #99ccff" fo:padding="0.3cm" style:vertical-align="middle"/> + </style:style> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Default" style:page-layout-name="PM0" draw:style-name="dp1"/> + </office:master-styles> + <office:body> + <office:drawing> + <draw:page draw:name="page1" draw:style-name="dp2" draw:master-page-name="Default"> + <draw:frame svg:width="14.098cm" svg:height="1.998cm" svg:x="3.448cm" svg:y="13.89cm"> + <table:table> + <table:table-column/> + <table:table-row> + <table:table-cell table:style-name="ce1"/> + </table:table-row> + </table:table> + </draw:frame> + </draw:page> + </office:drawing> + </office:body> +</office:document> diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 1a4060731387..f219e936ca9f 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/drawing/BitmapMode.hpp> #include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/drawing/XMasterPagesSupplier.hpp> @@ -95,6 +96,7 @@ public: void testMasterPageBackgroundFullSize(); void testColumnsODG(); void testTdf112126(); + void testCellProperties(); CPPUNIT_TEST_SUITE(SdExportTest); @@ -143,6 +145,7 @@ public: CPPUNIT_TEST(testMasterPageBackgroundFullSize); CPPUNIT_TEST(testColumnsODG); CPPUNIT_TEST(testTdf112126); + CPPUNIT_TEST(testCellProperties); CPPUNIT_TEST_SUITE_END(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override @@ -1994,6 +1997,38 @@ void SdExportTest::testTdf112126() xDocShRef->DoClose(); } +void SdExportTest::testCellProperties() +{ + auto xDocShRef + = loadURL(m_directories.getURLFromSrc(u"sd/qa/unit/data/odg/tablestyles.fodg"), FODG); + utl::TempFileNamed tempFile; + xDocShRef = saveAndReload(xDocShRef.get(), ODG, &tempFile); + + const SdrPage* pPage = GetPage(1, xDocShRef); + auto pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT(pTableObj != nullptr); + uno::Reference<beans::XPropertySet> xCell(pTableObj->getTable()->getCellByPosition(0, 0), + uno::UNO_QUERY_THROW); + + Color nColor; + table::BorderLine2 aBorderLine; + drawing::TextVerticalAdjust aTextAdjust; + sal_Int32 nPadding; + + xCell->getPropertyValue("FillColor") >>= nColor; + CPPUNIT_ASSERT_EQUAL(Color(0xffcc99), nColor); + xCell->getPropertyValue("RightBorder") >>= aBorderLine; + CPPUNIT_ASSERT_EQUAL(Color(0x99ccff), Color(ColorTransparency, aBorderLine.Color)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(159), aBorderLine.LineWidth); + xCell->getPropertyValue("TextRightDistance") >>= nPadding; + CPPUNIT_ASSERT_EQUAL(sal_Int32(300), nPadding); + xCell->getPropertyValue("TextVerticalAdjust") >>= aTextAdjust; + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust::TextVerticalAdjust_CENTER, aTextAdjust); + + xDocShRef->DoClose(); + tempFile.EnableKillingFile(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/source/table/XMLTableExport.cxx b/xmloff/source/table/XMLTableExport.cxx index b3d60c9402eb..366ffaa15d9e 100644 --- a/xmloff/source/table/XMLTableExport.cxx +++ b/xmloff/source/table/XMLTableExport.cxx @@ -92,6 +92,18 @@ const XMLPropertyMapEntry* getCellPropertiesMap() static const XMLPropertyMapEntry aXMLCellProperties[] = { CELLMAP( "RotateAngle", XML_NAMESPACE_STYLE, XML_ROTATION_ANGLE, XML_SD_TYPE_CELL_ROTATION_ANGLE, 0), + CELLMAP( "TextVerticalAdjust", XML_NAMESPACE_STYLE, XML_VERTICAL_ALIGN, XML_SD_TYPE_VERTICAL_ALIGN|MID_FLAG_SPECIAL_ITEM_EXPORT, 0), + CELLMAP( "BackColor", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_SPECIAL_ITEM, 0), + CELLMAP( "LeftBorder", XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_BORDER|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARALLBORDER), + CELLMAP( "LeftBorder", XML_NAMESPACE_FO, XML_BORDER_LEFT, XML_TYPE_BORDER|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARLEFTBORDER), + CELLMAP( "RightBorder", XML_NAMESPACE_FO, XML_BORDER_RIGHT, XML_TYPE_BORDER|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARRIGHTBORDER), + CELLMAP( "TopBorder", XML_NAMESPACE_FO, XML_BORDER_TOP, XML_TYPE_BORDER|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARTOPBORDER), + CELLMAP( "BottomBorder", XML_NAMESPACE_FO, XML_BORDER_BOTTOM, XML_TYPE_BORDER|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARBOTTOMBORDER), + CELLMAP( "TextLeftDistance", XML_NAMESPACE_FO, XML_PADDING, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARALLBORDERDISTANCE), + CELLMAP( "TextLeftDistance", XML_NAMESPACE_FO, XML_PADDING_LEFT, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARLEFTBORDERDISTANCE), + CELLMAP( "TextRightDistance", XML_NAMESPACE_FO, XML_PADDING_RIGHT, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARRIGHTBORDERDISTANCE), + CELLMAP( "TextUpperDistance", XML_NAMESPACE_FO, XML_PADDING_TOP, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARTOPBORDERDISTANCE), + CELLMAP( "TextLowerDistance", XML_NAMESPACE_FO, XML_PADDING_BOTTOM, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_CHARBOTTOMBORDERDISTANCE), MAP_END }; @@ -190,7 +202,7 @@ XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExp { mxCellExportPropertySetMapper = xExportPropertyMapper; mxCellExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(rExp)); - mxCellExportPropertySetMapper->ChainExportMapper(new SvXMLExportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true))); + mxCellExportPropertySetMapper->ChainExportMapper(new XMLCellExportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true))); } mxRowExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef, true ) ); diff --git a/xmloff/source/table/XMLTableImport.cxx b/xmloff/source/table/XMLTableImport.cxx index 9033f5f5b09d..86b19e768e16 100644 --- a/xmloff/source/table/XMLTableImport.cxx +++ b/xmloff/source/table/XMLTableImport.cxx @@ -35,6 +35,8 @@ #include <utility> #include <xmloff/table/XMLTableImport.hxx> +#include <xmloff/xmltypes.hxx> +#include <xmloff/maptype.hxx> #include <xmloff/xmlprmap.hxx> #include <xmloff/txtimp.hxx> #include <xmloff/xmlimp.hxx> @@ -91,6 +93,44 @@ struct MergeInfo : mnStartColumn( nStartColumn ), mnStartRow( nStartRow ), mnEndColumn( nStartColumn + nColumnSpan - 1 ), mnEndRow( nStartRow + nRowSpan - 1 ) {}; }; +class XMLCellImportPropertyMapper : public SvXMLImportPropertyMapper +{ +public: + using SvXMLImportPropertyMapper::SvXMLImportPropertyMapper; + + bool handleSpecialItem( + XMLPropertyState& rProperty, + std::vector< XMLPropertyState >& rProperties, + const OUString& rValue, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& /*rNamespaceMap*/) const override + { + assert(getPropertySetMapper()->GetEntryXMLName(rProperty.mnIndex) == GetXMLToken(XML_BACKGROUND_COLOR)); + (void)rProperty; + + auto nIndex = getPropertySetMapper()->GetEntryIndex(XML_NAMESPACE_DRAW, GetXMLToken(XML_FILL), 0); + XMLPropertyState aFillProperty(nIndex); + + if (IsXMLToken(rValue, XML_TRANSPARENT)) + { + getPropertySetMapper()->importXML(GetXMLToken(XML_NONE), aFillProperty, rUnitConverter); + rProperties.push_back(aFillProperty); + } + else + { + getPropertySetMapper()->importXML(GetXMLToken(XML_SOLID), aFillProperty, rUnitConverter); + rProperties.push_back(aFillProperty); + + nIndex = getPropertySetMapper()->GetEntryIndex(XML_NAMESPACE_DRAW, GetXMLToken(XML_FILL_COLOR), 0); + XMLPropertyState aColorProperty(nIndex); + getPropertySetMapper()->importXML(rValue, aColorProperty, rUnitConverter); + rProperties.push_back(aColorProperty); + } + + return false; + } +}; + } class XMLTableImportContext : public SvXMLImportContext @@ -216,7 +256,7 @@ XMLTableImport::XMLTableImport( SvXMLImport& rImport, const rtl::Reference< XMLP { mxCellImportPropertySetMapper = new SvXMLImportPropertyMapper( xCellPropertySetMapper, rImport ); mxCellImportPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImport)); - mxCellImportPropertySetMapper->ChainImportMapper(new SvXMLImportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true), rImport)); + mxCellImportPropertySetMapper->ChainImportMapper(new XMLCellImportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true), rImport)); } rtl::Reference < XMLPropertySetMapper > xRowMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef, false ) );