From 3d74ddd190a5087e0a54ef7b14d0a43006745ec3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 5 Apr 2019 19:30:45 +0200 Subject: writerfilter: implement RTF derived styles defaulting It turns out that the situation fixed in commit 1be0a3fa9ebb22b607c54b47739d4467acfed259 also applies to the definition of the styles themselves. To implement the same style import as Word, the style definitions need to be stored twice: once as read from the file, and another time with attributes defaulted and deduplicated vs. the parent style; the second representation is then sent to the domain mapper. To make this easier, add a bool parameter to cloneAndDeduplicate() to disable the implicit pPr dereferencing that happens when creating the hard formatted paragraph properties (this could potentially be cleaned up further if those paragraph properties would use pPr wrapper themselves). Also implement defaulting of line spacing in getDefaultSPRM(). Change-Id: I4810e917697b3af244e5dbdd7f5a45b4767c93fc Reviewed-on: https://gerrit.libreoffice.org/70320 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- .../rtfexport/data/para-style-bottom-margin-2.rtf | 12 +++++++++ sw/qa/extras/rtfexport/rtfexport5.cxx | 27 +++++++++++++++++++ .../rtfimport/data/para-style-bottom-margin.rtf | 14 ++++++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 31 ++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 sw/qa/extras/rtfexport/data/para-style-bottom-margin-2.rtf create mode 100644 sw/qa/extras/rtfimport/data/para-style-bottom-margin.rtf (limited to 'sw') diff --git a/sw/qa/extras/rtfexport/data/para-style-bottom-margin-2.rtf b/sw/qa/extras/rtfexport/data/para-style-bottom-margin-2.rtf new file mode 100644 index 000000000000..b4261e717070 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/para-style-bottom-margin-2.rtf @@ -0,0 +1,12 @@ +{\rtf1 +\ansi\ansicpg1252\deff0 +{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2 Times New Roman;}} +{\stylesheet +{\ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \snext0 Normal;} +{\s15\ql \li720\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin720\itap0\contextualspace \sbasedon0 \snext15 List Paragraph;} +} +\pard\plain \ltrpar\s15\ql \li720\ri0\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin720\itap0\contextualspace +\par +\pard\plain +\par +} diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx b/sw/qa/extras/rtfexport/rtfexport5.cxx index a60eb485ccdf..b2b898738d1d 100644 --- a/sw/qa/extras/rtfexport/rtfexport5.cxx +++ b/sw/qa/extras/rtfexport/rtfexport5.cxx @@ -194,6 +194,33 @@ DECLARE_RTFEXPORT_TEST(testParaBottomMargin, "para-bottom-margin.rtf") CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty(getParagraph(1), "ParaTopMargin")); } +DECLARE_RTFIMPORT_TEST(testParaStyleBottomMargin2, "para-style-bottom-margin-2.rtf") +{ + uno::Reference xPropertySet( + getStyles("ParagraphStyles")->getByName("Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty(xPropertySet, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, + getProperty(xPropertySet, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(115), + getProperty(xPropertySet, "ParaLineSpacing").Height); + + // the derived style contains \sa200, as does its parent + uno::Reference xPropertySet1( + getStyles("ParagraphStyles")->getByName("List Paragraph"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty(xPropertySet1, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, + getProperty(xPropertySet1, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(115), + getProperty(xPropertySet1, "ParaLineSpacing").Height); + // for the paragraph there is no \saN, so it should default to 0 + auto const xPara(getParagraph(1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xPara, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, + getProperty(xPara, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(115), + getProperty(xPara, "ParaLineSpacing").Height); +} + DECLARE_RTFEXPORT_TEST(testFdo66040, "fdo66040.rtf") { uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); diff --git a/sw/qa/extras/rtfimport/data/para-style-bottom-margin.rtf b/sw/qa/extras/rtfimport/data/para-style-bottom-margin.rtf new file mode 100644 index 000000000000..d7ebc215f3fc --- /dev/null +++ b/sw/qa/extras/rtfimport/data/para-style-bottom-margin.rtf @@ -0,0 +1,14 @@ +{\rtf1 +\ansi\ansicpg1252\deff0 +{\fonttbl +{\f0 Times New Roman;} +} +{\stylesheet +{\sa200\sl276\slmult1 \snext0 Normal;} +{\s19 \sbasedon0 \snext0 toc 1;} +} +\pard\plain \s19 +foo +\par +\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index fd87b50331cc..8e126203238f 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -1562,6 +1564,35 @@ DECLARE_RTFIMPORT_TEST(testDefaultValues, "default-values.rtf") CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_AUTO), getProperty(run, "CharColor")); } +DECLARE_RTFIMPORT_TEST(testParaStyleBottomMargin, "para-style-bottom-margin.rtf") +{ + uno::Reference xPropertySet( + getStyles("ParagraphStyles")->getByName("Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty(xPropertySet, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, + getProperty(xPropertySet, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(115), + getProperty(xPropertySet, "ParaLineSpacing").Height); + + // The reason why this is 0 despite the default style containing \sa200 + // is that Word will actually interpret \basedonN + // as "set style N and for every attribute of that style, + // set an attribute with default value on the style" + uno::Reference xPropertySet1( + getStyles("ParagraphStyles")->getByName("Contents 1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xPropertySet1, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, + getProperty(xPropertySet1, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(100), + getProperty(xPropertySet1, "ParaLineSpacing").Height); + auto const xPara(getParagraph(1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xPara, "ParaBottomMargin")); + CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP, // 0 or 3 ??? + getProperty(xPara, "ParaLineSpacing").Mode); + CPPUNIT_ASSERT_EQUAL(sal_Int16(100), + getProperty(xPara, "ParaLineSpacing").Height); +} + // tests should only be added to rtfIMPORT *if* they fail round-tripping in rtfEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit