From fa5c01e67775c01b302fc08033a0eb78d3b87489 Mon Sep 17 00:00:00 2001 From: Sarper Akdemir Date: Fri, 3 Mar 2023 18:04:46 +0300 Subject: [PATCH] related tdf#102261: xmloff: ODF import/export for ParaTabStopDefaultDistance Introduces ODF import/export for ParaTabStopDefaultDistance (loext:tab-stop-distance). Also adds a unit test that covers import & export of the property. Change-Id: I8a69a9e2b73e8f1172f92dc35fada901f4b887f4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148540 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- .../OpenDocument-v1.3+libreoffice-schema.rng | 6 +++ xmloff/inc/xmlprop.hxx | 1 + .../data/paragraph-tab-stop-distance.fodp | 19 +++++++++ xmloff/qa/unit/text.cxx | 41 +++++++++++++++++++ xmloff/source/text/txtprmap.cxx | 2 + 5 files changed, 69 insertions(+) create mode 100644 xmloff/qa/unit/data/paragraph-tab-stop-distance.fodp diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index f0f84bd3fd40..fa38694f9cff 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -2615,6 +2615,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. + + + + + + diff --git a/xmloff/inc/xmlprop.hxx b/xmloff/inc/xmlprop.hxx index ab7c53de01cf..3b2cd86816bc 100644 --- a/xmloff/inc/xmlprop.hxx +++ b/xmloff/inc/xmlprop.hxx @@ -513,6 +513,7 @@ inline constexpr OUStringLiteral PROP_ParaRightMarginRelative = u"ParaRightMargi inline constexpr OUStringLiteral PROP_ParaShadowFormat = u"ParaShadowFormat"; inline constexpr OUStringLiteral PROP_ParaSplit = u"ParaSplit"; inline constexpr OUStringLiteral PROP_ParaTabStops = u"ParaTabStops"; +inline constexpr OUStringLiteral PROP_ParaTabStopDefaultDistance = u"ParaTabStopDefaultDistance"; inline constexpr OUStringLiteral PROP_ParaTopMargin = u"ParaTopMargin"; inline constexpr OUStringLiteral PROP_ParaTopMarginRelative = u"ParaTopMarginRelative"; inline constexpr OUStringLiteral PROP_ParaUserDefinedAttributes = u"ParaUserDefinedAttributes"; diff --git a/xmloff/qa/unit/data/paragraph-tab-stop-distance.fodp b/xmloff/qa/unit/data/paragraph-tab-stop-distance.fodp new file mode 100644 index 000000000000..f51e75b79699 --- /dev/null +++ b/xmloff/qa/unit/data/paragraph-tab-stop-distance.fodp @@ -0,0 +1,19 @@ + + + + + + + + + + + + + starttab1tab2tab4 + + + + + + diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 7fe762580ac1..5d3a9cf4ac99 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -1047,6 +1048,46 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFloatingTableImport) CPPUNIT_ASSERT(bIsSplitAllowed); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testParagraphScopedTabDistance) +{ + // Given a document with paragraph scoped default tab stop distance (loext:tab-stop-distance="0.5cm") + loadFromURL(u"paragraph-tab-stop-distance.fodp"); + + uno::Reference xDoc(mxComponent, uno::UNO_QUERY); + uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + + uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText + = uno::Reference(xShape, uno::UNO_QUERY_THROW)->getText(); + + uno::Reference paraEnumAccess(xText, uno::UNO_QUERY); + uno::Reference paraEnum(paraEnumAccess->createEnumeration()); + uno::Reference xParagraph(paraEnum->nextElement(), uno::UNO_QUERY_THROW); + + uno::Reference runEnumAccess(xParagraph, uno::UNO_QUERY); + uno::Reference runEnum = runEnumAccess->createEnumeration(); + uno::Reference xRun(runEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xPropSet(xRun, uno::UNO_QUERY_THROW); + + // Make sure the tab stop default distance is imported correctly + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 10000 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(static_cast(10000), + xPropSet->getPropertyValue("ParaTabStopDefaultDistance").get()); + + // Save the imported file to test the export too + save("impress8"); + + // Then make sure we write the tab-stop-distance + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + assertXPath(pXmlDoc, "//style:style[@style:name='P1']/style:paragraph-properties", + "tab-stop-distance", "10cm"); + + assertXPath(pXmlDoc, "//text:p[@text:style-name='P1']"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index c57c8c243540..c3b7403de1d7 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -446,6 +446,8 @@ XMLPropertyMapEntry const aXMLParaPropMap[] = MP_ED( PROP_ParaIsHangingPunctuation, STYLE, PUNCTUATION_WRAP, XML_TYPE_TEXT_PUNCTUATION_WRAP, 0 ), MP_ED( PROP_ParaIsForbiddenRules, STYLE, LINE_BREAK, XML_TYPE_TEXT_LINE_BREAK, 0 ), MP_E( PROP_TabStopDistance, STYLE, TAB_STOP_DISTANCE, XML_TYPE_MEASURE, 0 ), + MAP_EXT_I( PROP_ParaTabStopDefaultDistance, XML_NAMESPACE_STYLE, XML_TAB_STOP_DISTANCE, XML_TYPE_MEASURE|XML_TYPE_PROP_PARAGRAPH, 0 ), + MAP_EXT( PROP_ParaTabStopDefaultDistance, XML_NAMESPACE_LO_EXT, XML_TAB_STOP_DISTANCE, XML_TYPE_MEASURE|XML_TYPE_PROP_PARAGRAPH, 0 ), // RES_PARATR_VERTALIGN MP_E( PROP_ParaVertAlignment, STYLE, VERTICAL_ALIGN, XML_TYPE_TEXT_VERTICAL_ALIGN, 0 ),