diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-01-24 17:01:29 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-01-24 18:18:28 +0100 |
commit | ff139ea42279cc9861abb13e22878c9d435acb21 (patch) | |
tree | 68d2bd4e87cc7a76fc384ba825de6833e67b57e1 | |
parent | e064188f7ddc68040fa89c7d81ab974517c45f44 (diff) |
DOCX export: fix line spacing when spacing is 0
When the input was:
<w:pPr>
<w:spacing w:line="0" w:lineRule="atLeast"/>
</w:pPr>
Then we used to write:
<w:pPr>
<w:spacing w:lineRule="auto"/>
</w:pPr>
which is clarly wrong.
The comment at the end of AttributeOutputBase::ParaLineSpacing()
documents the intention reasonably clearly (and is in sync with what's
in the DOC and DOCX spec), adapt
DocxAttributeOutput::ParaLineSpacing_Impl() accordingly.
Change-Id: I60cbc3392a6460ba2760b2c02ae0755726478ec1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87351
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 29 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 6 |
2 files changed, 31 insertions, 4 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index d582e777de06..1b4bf79fdc2d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -20,6 +20,8 @@ #include <com/sun/star/text/TableColumnSeparator.hpp> #include <com/sun/star/text/XDocumentIndex.hpp> #include <com/sun/star/text/RelOrientation.hpp> +#include <com/sun/star/style/LineSpacing.hpp> +#include <com/sun/star/style/LineSpacingMode.hpp> class Test : public SwModelTestBase { @@ -219,6 +221,33 @@ DECLARE_OOXMLEXPORT_TEST(testTdf121658, "tdf121658.docx") assertXPath(pXmlSettings, "/w:settings/w:doNotHyphenateCaps"); } +CPPUNIT_TEST_FIXTURE(SwModelTestBase, testZeroLineSpacing) +{ + // Create the doc model. + loadURL("private:factory/swriter", nullptr); + uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), uno::UNO_QUERY); + style::LineSpacing aSpacing; + aSpacing.Mode = style::LineSpacingMode::MINIMUM; + aSpacing.Height = 0; + xParagraph->setPropertyValue("ParaLineSpacing", uno::makeAny(aSpacing)); + + // Export to docx. + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text"); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + mbExported = true; + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: atLeast + // - Actual : auto + // i.e. the minimal linespacing was lost on export. + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "lineRule", "atLeast"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "line", "0"); +} + CPPUNIT_TEST_FIXTURE(SwModelTestBase, testSemiTransparentText) { // Create an in-memory empty document. diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index d30d19eaad66..cef9035c15e9 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -7724,20 +7724,18 @@ void DocxAttributeOutput::ParaLineSpacing_Impl( short nSpace, short nMulti ) FSNS( XML_w, XML_lineRule ), "exact", FSNS( XML_w, XML_line ), OString::number( -nSpace ).getStr() ); } - else if( nMulti ) + else if( nSpace > 0 && nMulti ) { AddToAttrList( m_pParagraphSpacingAttrList, 2, FSNS( XML_w, XML_lineRule ), "auto", FSNS( XML_w, XML_line ), OString::number( nSpace ).getStr() ); } - else if ( nSpace > 0 ) + else { AddToAttrList( m_pParagraphSpacingAttrList, 2, FSNS( XML_w, XML_lineRule ), "atLeast", FSNS( XML_w, XML_line ), OString::number( nSpace ).getStr() ); } - else - AddToAttrList( m_pParagraphSpacingAttrList, FSNS( XML_w, XML_lineRule ), "auto" ); } void DocxAttributeOutput::ParaAdjust( const SvxAdjustItem& rAdjust ) |