sw/qa/extras/txtexport/txtexport.cxx |   39 +++++++++++++++++++++++++++++++++++
 sw/source/filter/ascii/ascatr.cxx    |    6 +++++
 2 files changed, 45 insertions(+)

New commits:
commit 6113440cfe16dadafe36d44796ff0438085d8948
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 23 08:59:16 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Mar 31 08:25:36 2022 +0200

    sw clearing breaks: add plain text export
    
    No need to care about the clearing, but make sure that
    RES_TXTATR_LINEBREAK gets downgraded to a plain CH_TXTATR_NEWLINE.
    
    (cherry picked from commit 59af0be9fbfcef4e157a74099a6aef0c60facb36)
    
    Change-Id: Ia4f6b45f60a414d856db41fd09d06c902dffd908
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132295
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/txtexport/txtexport.cxx 
b/sw/qa/extras/txtexport/txtexport.cxx
index 54f623700fb0..b9b0e95e2875 100644
--- a/sw/qa/extras/txtexport/txtexport.cxx
+++ b/sw/qa/extras/txtexport/txtexport.cxx
@@ -9,7 +9,13 @@
 
 #include <swmodeltestbase.hxx>
 
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+
 #include <osl/thread.hxx>
+#include <comphelper/propertyvalue.hxx>
+
+#include <formatlinebreak.hxx>
 
 class TxtExportTest : public SwModelTestBase
 {
@@ -100,6 +106,39 @@ DECLARE_TXTEXPORT_TEST(testTdf142669_utf16le, 
"UTF16LECRLF.txt")
     CPPUNIT_ASSERT_EQUAL(OUString(u"フー\r\nバー\r\n"), aData);
 }
 
+CPPUNIT_TEST_FIXTURE(TxtExportTest, testClearingBreakExport)
+{
+    // Given a document with a clearing break:
+    mxComponent = loadFromDesktop("private:factory/swriter");
+    uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextContent> xLineBreak(
+        xMSF->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+    auto eClear = static_cast<sal_Int16>(SwLineBreakClear::ALL);
+    xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+    xText->insertString(xCursor, "foo", /*bAbsorb=*/false);
+    xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+    xText->insertString(xCursor, "bar", /*bAbsorb=*/false);
+
+    // When exporting to plain text:
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreProps = {
+        comphelper::makePropertyValue("FilterName", OUString("Text")),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreProps);
+
+    // Then make sure that the newline is not lost:
+    OString aActual = readExportedFile();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: foo\nbar
+    // - Actual  : foobar
+    // i.e. the clearing break was not downgraded to a plain line break.
+    CPPUNIT_ASSERT_EQUAL(OString("foo\nbar" SAL_NEWLINE_STRING), aActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ascii/ascatr.cxx 
b/sw/source/filter/ascii/ascatr.cxx
index 6edccce4298c..805f3ba48bc1 100644
--- a/sw/source/filter/ascii/ascatr.cxx
+++ b/sw/source/filter/ascii/ascatr.cxx
@@ -148,6 +148,12 @@ bool SwASC_AttrIter::OutAttr( sal_Int32 nSwPos )
                                 rFootnote.GetNumber());
                     }
                     break;
+                    case RES_TXTATR_LINEBREAK:
+                    {
+                        // Downgrade the clearing break to a simple linebreak.
+                        sOut = OUStringChar(GetCharOfTextAttr(*pHt));
+                        break;
+                    }
                 }
                 if( !sOut.isEmpty() )
                     m_rWrt.Strm().WriteUnicodeOrByteText(sOut);

Reply via email to