sw/qa/extras/ooxmlexport/data/tdf148834_lineNumbering.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 4 + sw/qa/extras/ooxmlexport/ooxmlexport18.cxx | 13 +++++ sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 7 ++ sw/source/filter/ww8/attributeoutputbase.hxx | 1 sw/source/filter/ww8/docxattributeoutput.cxx | 2 sw/source/filter/ww8/ww8atr.cxx | 36 +++++++++++++- 7 files changed, 62 insertions(+), 1 deletion(-)
New commits: commit 91358f11ee7e87c8c8290b9507f64d8f90aac3ea Author: Justin Luth <jl...@mail.com> AuthorDate: Fri Aug 18 21:55:12 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Sun Aug 20 03:34:41 2023 +0200 tdf#148834 docxexport: also write suppressLineNumbers = false This code also affects DOC export, but shouldn't be detrimental. It just means that some unnecessary sprms will not be added to DOC files. RTF - similar to old DOCX - only outputs if !IsCount, but I didn't find a corresponding "enable" to offset \noline. make CppunitTest_sw_ooxmlexport18 \ CPPUNIT_TEST_NAME=testTdf148834_lineNumbering Change-Id: Ib5369c2f2c24f75dab7d02e3591a4ddefa335ebf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155858 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf148834_lineNumbering.odt b/sw/qa/extras/ooxmlexport/data/tdf148834_lineNumbering.odt new file mode 100644 index 000000000000..4006cfe66239 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf148834_lineNumbering.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 67fba9e9b114..eb26ce7763b8 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -1145,6 +1145,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf128290) xmlDocUniquePtr pXml = parseExport("word/document.xml"); CPPUNIT_ASSERT(pXml); assertXPath(pXml, "/w:document/w:body/w:tbl/w:tblPr/w:tblLayout", "type", "fixed"); + + // ensure unnecessary suppressLineNumbers entry is not created. + xmlDocUniquePtr pStylesXml = parseExport("word/styles.xml"); + assertXPath(pStylesXml, "//w:style[@w:styleId='Normal']/w:pPr/w:suppressLineNumbers", 0); } DECLARE_OOXMLEXPORT_TEST(testTdf120394, "tdf120394.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index 4d1136f24c42..6835a06d5ff4 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -516,6 +516,19 @@ DECLARE_OOXMLEXPORT_TEST(testTdf153964_firstIndentAfterBreak14, "tdf153964_first CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaFirstLineIndent")); } +CPPUNIT_TEST_FIXTURE(Test, testTdf148834_lineNumbering) +{ + loadAndSave("tdf148834_lineNumbering.odt"); + + xmlDocUniquePtr pStylesXml = parseExport("word/styles.xml"); + // user specified: do not include in line numbering + assertXPath(pStylesXml, "//w:style[@w:styleId='Normal']/w:pPr/w:suppressLineNumbers", 1); + // even though it matches the parent style, these should always avoid showing line numberings + assertXPath(pStylesXml, "//w:style[@w:styleId='Footer']/w:pPr/w:suppressLineNumbers", 1); + assertXPath(pStylesXml, + "//w:style[@w:styleId='0NUMBERED']/w:pPr/w:suppressLineNumbers", "val", "0"); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf76022_textboxWrap) { // Granted, this is an ODT with a bit of an anomaly - tables ignore fly wrapping. diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx index 607feea76ac7..05559dc49e18 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx @@ -882,6 +882,13 @@ DECLARE_OOXMLEXPORT_TEST(testFdo66543, "fdo66543.docx") uno::Reference< text::XTextRange > paragraph1 = getParagraph( 1 ); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(paragraph1, "ParaLineNumberStartValue")); + + if (!isExported()) + return; + + // ensure unnecessary suppressLineNumbers entry is not created. + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, "//w:p[1]/w:pPr/w:suppressLineNumbers", 0); } CPPUNIT_TEST_FIXTURE(Test, testN822175) diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx index d5d92924ba9c..bad43d37843a 100644 --- a/sw/source/filter/ww8/attributeoutputbase.hxx +++ b/sw/source/filter/ww8/attributeoutputbase.hxx @@ -618,6 +618,7 @@ protected: virtual void FormatTextGrid( const SwTextGridItem& ) = 0; /// Sfx item RES_LINENUMBER + void FormatLineNumberingBase(const SwFormatLineNumber&); virtual void FormatLineNumbering( const SwFormatLineNumber& ) = 0; /// Sfx item RES_FRAMEDIR diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index d6c9c14544b1..df29dd801e08 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -9869,6 +9869,8 @@ void DocxAttributeOutput::FormatLineNumbering( const SwFormatLineNumber& rNumber { if ( !rNumbering.IsCount( ) ) m_pSerializer->singleElementNS(XML_w, XML_suppressLineNumbers); + else + m_pSerializer->singleElementNS(XML_w, XML_suppressLineNumbers, FSNS(XML_w, XML_val), "0"); } void DocxAttributeOutput::FormatFrameDirection( const SvxFrameDirectionItem& rDirection ) diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index e3d39a56d4a7..4751047e0f74 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3774,6 +3774,40 @@ void WW8AttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines ) m_rWW8Export.m_pO->insert( m_rWW8Export.m_pO->end(), aZeroArr, aZeroArr+3); } +void AttributeOutputBase::FormatLineNumberingBase(const SwFormatLineNumber& rNumbering) +{ + // always write out suppressLineNumberings - even if it matches the parent, + // so that even if the parent is modified, special styles/situations won't lose that suppression + if (!rNumbering.IsCount()) + { + FormatLineNumbering(rNumbering); + return; + } + + // Don't spam suppressLineNumberings = false - that is the default when not specified at all + if (auto pNd = dynamic_cast<const SwContentNode*>(GetExport().m_pOutFormatNode)) //paragraph + { + // useless IsCount can be added to paragraph when specifying MID_LINENUMBER_STARTVALUE + const auto& rSet = static_cast<SwTextFormatColl&>(pNd->GetAnyFormatColl()).GetAttrSet(); + const SwFormatLineNumber& rInherited = rSet.GetLineNumber(); + if (rInherited.IsCount() && rInherited.GetStartValue() != rNumbering.GetStartValue()) + return; // same IsCount as parent style + } + else if (GetExport().m_bStyDef) //style + { + if (GetExport().m_pCurrentStyle && GetExport().m_pCurrentStyle->DerivedFrom()) + { + const auto& rSet = GetExport().m_pCurrentStyle->DerivedFrom()->GetAttrSet(); + if (rSet.GetLineNumber().IsCount()) + return; // same as parent style + } + else + return; // same as default value + } + + FormatLineNumbering(rNumbering); +} + void AttributeOutputBase::ParaOutlineLevelBase( const SfxUInt16Item& rItem ) { sal_uInt16 nOutLvl = rItem.GetValue(); @@ -5749,7 +5783,7 @@ void AttributeOutputBase::OutputItem( const SfxPoolItem& rHt ) FormatTextGrid( static_cast< const SwTextGridItem& >( rHt ) ); break; case RES_LINENUMBER: - FormatLineNumbering( static_cast< const SwFormatLineNumber& >( rHt ) ); + FormatLineNumberingBase(static_cast<const SwFormatLineNumber&>(rHt)); break; case RES_FRAMEDIR: FormatFrameDirection( static_cast< const SvxFrameDirectionItem& >( rHt ) );