sw/qa/extras/odfimport/data/paste-first-para-direct-format.odt |binary
 sw/qa/extras/odfimport/odfimport.cxx                           |   28 
++++++++++
 sw/source/filter/xml/xmlimp.cxx                                |    8 ++
 3 files changed, 36 insertions(+)

New commits:
commit ae9fe9d7107b2e25c9316033651e49c08537c0e9
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Oct 2 16:45:35 2020 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Oct 2 21:38:07 2020 +0200

    ODT import: copy direct para formatting for first para in insert mode
    
    It was inconsistent that we copied the paragraph style, but not the
    direct paragraph formatting from the to-be-deleted first inserted node
    to the last-before-insertion node.
    
    Change-Id: Ie5161c6314d7c1a71599bfe4eeafd3398450bd77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103864
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/odfimport/data/paste-first-para-direct-format.odt 
b/sw/qa/extras/odfimport/data/paste-first-para-direct-format.odt
new file mode 100644
index 000000000000..866d29c5ffbb
Binary files /dev/null and 
b/sw/qa/extras/odfimport/data/paste-first-para-direct-format.odt differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index e14e23dba0d1..73ce92082e60 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -40,6 +40,8 @@
 #include <com/sun/star/container/XIndexContainer.hpp>
 #include <com/sun/star/drawing/XDrawPage.hpp>
 #include <com/sun/star/text/XTextFramesSupplier.hpp>
+#include <com/sun/star/document/XDocumentInsertable.hpp>
+#include <com/sun/star/style/ParagraphAdjust.hpp>
 
 #include <comphelper/propertysequence.hxx>
 
@@ -1111,5 +1113,31 @@ DECLARE_ODFIMPORT_TEST(testTdf134971, "tdf134971a.odt")
     CPPUNIT_ASSERT_EQUAL(OUString("Arial"), sString);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testPasteFirstParaDirectFormat)
+{
+    // Create a new document.
+    mxComponent = loadFromDesktop("private:factory/swriter", 
"com.sun.star.text.TextDocument");
+    {
+        // Set some direct formatting on the first paragraph, but leave 
paragraph adjust at its
+        // default (left).
+        uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), 
uno::UNO_QUERY);
+        xParagraph->setPropertyValue("PageNumberOffset", 
uno::makeAny(static_cast<sal_Int16>(0)));
+    }
+
+    // Paste from ODT.
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<document::XDocumentInsertable> 
xCursor(xText->createTextCursorByRange(xText->getStart()), uno::UNO_QUERY);
+    
xCursor->insertDocumentFromURL(m_directories.getURLFromSrc(mpTestDocumentPath) 
+ "paste-first-para-direct-format.odt", {});
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 3 (center)
+    // - Actual  : 0 (left)
+    // i.e. the inserted document's first paragraph's paragraph formatting was 
lost.
+    uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(style::ParagraphAdjust_CENTER),
+                         getProperty<sal_Int16>(xParagraph, "ParaAdjust"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 00c141332a15..2d591f122e57 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -786,7 +786,15 @@ void SwXMLImport::endDocument()
                 if (!pTextNode->GetText().isEmpty())
                     pDelNd->FormatToTextAttr( pTextNode );
                 else
+                {
                     pTextNode->ChgFormatColl( pDelNd->GetTextColl() );
+                    if (!pDelNd->GetNoCondAttr(RES_PARATR_LIST_ID, 
/*bInParents=*/false))
+                    {
+                        // MergeListsAtDocumentInsertPosition() will deal with 
lists below, copy
+                        // paragraph direct formatting otherwise.
+                        pDelNd->CopyCollFormat(*pTextNode);
+                    }
+                }
                 pTextNode->JoinNext();
             }
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to