writerfilter/qa/cppunittests/rtftok/data/old-para-num-left-margin.rtf |   14 
+++++
 writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx               |   25 
++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx                        |    4 -
 3 files changed, 41 insertions(+), 2 deletions(-)

New commits:
commit a974bccd06ac6c7081256d32d2372ea05b253fbb
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Sep 26 08:14:21 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Sep 26 09:05:50 2022 +0200

    tdf#150762 RTF import: fix missing left margin on numbered paragraph
    
    The bugdoc has a numbered paragraph with a custom left margin, but this
    left margin is missing in Writer.
    
    This went wrong in commit 61b7034824dead1635f9e9c6ec996297e10f6910
    (tdf#104016 RTF import: deduplicate before text indent from numbering,
    2017-12-05), and now it's broken because the numbering properties are
    applied before paragraph properties in the DOCX case, but the RTF
    tokenizer didn't do this ordering.
    
    This behavior of sw core somewhat makes sense, users expect the margins
    from direct formatting to go away if you apply a new numbering. So fix
    the problem by tweaking the RTF tokenizer to emit the numbering tokens
    first and only then the paragraph tokens, which is an order that's
    closer to the working DOCX tokenizer.
    
    This only affects the old (WW6-style) paragraph numbering markup, not
    the newer (WW8-style) numbering markup.
    
    Change-Id: I39698f57684d47c03ea4848fc8eb6b2e855c4fbc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140584
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git 
a/writerfilter/qa/cppunittests/rtftok/data/old-para-num-left-margin.rtf 
b/writerfilter/qa/cppunittests/rtftok/data/old-para-num-left-margin.rtf
new file mode 100644
index 000000000000..99825370e3b4
--- /dev/null
+++ b/writerfilter/qa/cppunittests/rtftok/data/old-para-num-left-margin.rtf
@@ -0,0 +1,14 @@
+{\rtf1\ansi
+\margt1497\margb590\margl590\margr590\pgwsxn11906\pghsxn16838
+\pard\plain First\par
+\pard\plain
+{\*\pn \pnlvlbody
+{\pntxtb \'78}
+}
+{\b\f7\fs22 Second\par}
+\pard\plain\li1191
+{\*\pn \pnlvlbody
+{\pntxtb \'78}
+}
+{\f7\fs22 Third, with left indent\par}
+}
diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
index 6020453ba783..f33f0f0e58be 100644
--- a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
 
 #include <vcl/graph.hxx>
 
@@ -119,6 +120,30 @@ CPPUNIT_TEST_FIXTURE(Test, testDuplicatedImage)
     // i.e. there was a 3rd, duplicated image.
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xDrawPage->getCount());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testOldParaNumLeftMargin)
+{
+    // Given a document with 3 paragraphs, the third one with a left indent:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"old-para-num-left-margin.rtf";
+
+    // When importing that document:
+    getComponent() = loadFromDesktop(aURL);
+
+    // Then make sure that the third paragraph has a left indent:
+    uno::Reference<text::XTextDocument> xTextDocument(getComponent(), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xText(xTextDocument->getText(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphs = 
xText->createEnumeration();
+    xParagraphs->nextElement();
+    xParagraphs->nextElement();
+    uno::Reference<beans::XPropertySet> xParagraph(xParagraphs->nextElement(), 
uno::UNO_QUERY);
+    sal_Int32 nParaLeftMargin{};
+    xParagraph->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 2101
+    // - Actual  : 0
+    // i.e. the left indent was 0, not 1191 twips (from the file) in mm100.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2101), nParaLeftMargin);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index ad96a449befb..3df44f0124c9 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -3383,9 +3383,9 @@ void RTFDocumentImpl::afterPopState(RTFParserState& 
rState)
 
                 // Use it
                 putNestedSprm(m_aStates.top().getParagraphSprms(), 
NS_ooxml::LN_CT_PPrBase_numPr,
-                              NS_ooxml::LN_CT_NumPr_ilvl, pIlvlValue);
+                              NS_ooxml::LN_CT_NumPr_ilvl, pIlvlValue, 
RTFOverwrite::YES_PREPEND);
                 putNestedSprm(m_aStates.top().getParagraphSprms(), 
NS_ooxml::LN_CT_PPrBase_numPr,
-                              NS_ooxml::LN_CT_NumPr_numId, pIdValue);
+                              NS_ooxml::LN_CT_NumPr_numId, pIdValue, 
RTFOverwrite::YES_PREPEND);
             }
         }
         break;

Reply via email to