[Libreoffice-commits] core.git: 2 commits - sw/inc sw/qa sw/source

Jan Holesovsky kendy at collabora.com
Wed Sep 13 06:43:00 UTC 2017


 sw/inc/shellio.hxx                   |    4 +-
 sw/qa/extras/txtexport/txtexport.cxx |   63 +++++++++++++++++++++++++++++++++++
 sw/source/filter/ascii/ascatr.cxx    |    4 +-
 sw/source/filter/writer/writer.cxx   |    2 -
 4 files changed, 69 insertions(+), 4 deletions(-)

New commits:
commit 3563220f048da5e0e893b8ac7faf5e8f14889fa5
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 12 13:29:46 2017 +0200

    tdf#112191: Unit test.
    
    This was the hard part of the fix :-)
    
    Change-Id: Iae335c9d41d9b3420472b5d02113e2b42ab825da
    Reviewed-on: https://gerrit.libreoffice.org/42203
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/sw/qa/extras/txtexport/txtexport.cxx b/sw/qa/extras/txtexport/txtexport.cxx
index b9cd02bdf0b5..59e64d215872 100644
--- a/sw/qa/extras/txtexport/txtexport.cxx
+++ b/sw/qa/extras/txtexport/txtexport.cxx
@@ -11,8 +11,41 @@
 
 #include <swmodule.hxx>
 #include <swdll.hxx>
+
+#include <shellio.hxx>
+#include <unotextrange.hxx>
 #include <usrpref.hxx>
 
+class TxtImportTest : public SwModelTestBase
+{
+public:
+    TxtImportTest() :
+        SwModelTestBase("/sw/qa/extras/txtexport/data/", "Text")
+    {}
+
+    // Export & assert part of the document (defined by SwPaM).
+    void assertExportedRange(const OString& aExpected, SwPaM& rPaM)
+    {
+        WriterRef rAsciiWriter;
+        GetASCWriter(aEmptyOUStr, OUString(), rAsciiWriter);
+        CPPUNIT_ASSERT(rAsciiWriter.is());
+
+        // no start char
+        rAsciiWriter->bUCS2_WithStartChar = false;
+
+        SvMemoryStream aMemoryStream;
+
+        SwWriter aWriter(aMemoryStream, rPaM);
+        ErrCode nError = aWriter.Write(rAsciiWriter);
+        CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, nError);
+
+        const char* pData = static_cast<const char*>(aMemoryStream.GetData());
+        OString aResult(pData, aMemoryStream.GetSize());
+
+        CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
+    }
+};
+
 class TxtExportTest : public SwModelTestBase
 {
 public:
@@ -36,6 +69,7 @@ protected:
     }
 };
 
+#define DECLARE_TXTIMPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, TxtImportTest)
 #define DECLARE_TXTEXPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, TxtExportTest)
 
 DECLARE_TXTEXPORT_TEST(testBullets, "bullets.odt")
@@ -71,6 +105,35 @@ DECLARE_TXTEXPORT_TEST(testBullets, "bullets.odt")
     CPPUNIT_ASSERT_EQUAL(aExpected, aData);
 }
 
+DECLARE_TXTIMPORT_TEST(testTdf112191, "bullets.odt")
+{
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    // just the 5th paragraph - no bullet
+    uno::Reference<text::XTextRange> xPara(getParagraph(5));
+    SwUnoInternalPaM aPaM(*pDoc);
+    bool bSuccess = sw::XTextRangeToSwPaM(aPaM, xPara);
+    CPPUNIT_ASSERT(bSuccess);
+
+    assertExportedRange(OString("First bullet"), aPaM);
+
+    // but when we extend to the next paragraph - now there are bullets
+    xPara = getParagraph(6);
+    SwUnoInternalPaM aPaM2(*pDoc);
+    bSuccess = sw::XTextRangeToSwPaM(aPaM2, xPara);
+    CPPUNIT_ASSERT(bSuccess);
+
+    OUString aString = OStringToOUString(
+        "    \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+        "    \xe2\x80\xa2 Second bullet", RTL_TEXTENCODING_UTF8);
+
+    SwPaM aPaM3(*aPaM2.GetMark(), *aPaM.GetPoint());
+    assertExportedRange(OUStringToOString(aString, osl_getThreadTextEncoding()), aPaM3);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 9ead87264328beddddead1c7e878c2aee03e03af
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 12 13:28:32 2017 +0200

    tdf#112191: Don't export bullets when only one paragraph is selected.
    
    Change-Id: Ibea54f857e78a850ea05643743884ae2157dae57
    Reviewed-on: https://gerrit.libreoffice.org/42202
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/sw/inc/shellio.hxx b/sw/inc/shellio.hxx
index 1ebc33e4e0a8..92544413bdfa 100644
--- a/sw/inc/shellio.hxx
+++ b/sw/inc/shellio.hxx
@@ -370,7 +370,6 @@ class SW_DLLPUBLIC Writer
 
 protected:
 
-    SwPaM* pOrigPam;            // Last Pam that has to be processed.
     const OUString* pOrigFileName;
 
     void ResetWriter();
@@ -390,6 +389,7 @@ protected:
 
 public:
     SwDoc* pDoc;
+    SwPaM* pOrigPam;            // Last Pam that has to be processed.
     SwPaM* pCurPam;
     bool bWriteAll : 1;
     bool bShowProgress : 1;
@@ -544,7 +544,7 @@ namespace SwReaderWriter
 }
 
 void GetRTFWriter( const OUString&, const OUString&, WriterRef& );
-void GetASCWriter( const OUString&, const OUString&, WriterRef& );
+SW_DLLPUBLIC void GetASCWriter(const OUString&, const OUString&, WriterRef&);
 void GetHTMLWriter( const OUString&, const OUString&, WriterRef& );
 void GetXMLWriter( const OUString&, const OUString&, WriterRef& );
 
diff --git a/sw/source/filter/ascii/ascatr.cxx b/sw/source/filter/ascii/ascatr.cxx
index 1a3f416ea91f..77b57e4f01dd 100644
--- a/sw/source/filter/ascii/ascatr.cxx
+++ b/sw/source/filter/ascii/ascatr.cxx
@@ -178,10 +178,12 @@ static Writer& OutASC_SwTextNode( Writer& rWrt, SwContentNode& rNode )
     if( bLastNd )
         nEnd = rWrt.pCurPam->GetMark()->nContent.GetIndex();
 
+    bool bIsOneParagraph = rWrt.pOrigPam->Start()->nNode == rWrt.pOrigPam->End()->nNode;
+
     SwASC_AttrIter aAttrIter( static_cast<SwASCWriter&>(rWrt), rNd, nStrPos );
 
     const SwNumRule* pNumRule = rNd.GetNumRule();
-    if (pNumRule && !nStrPos && rWrt.bExportPargraphNumbering)
+    if (pNumRule && !nStrPos && rWrt.bExportPargraphNumbering && !bIsOneParagraph)
     {
         bool bIsOutlineNumRule = pNumRule == rNd.GetDoc()->GetOutlineNumRule();
 
diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx
index 863a016a10bc..50cd3a3812c4 100644
--- a/sw/source/filter/writer/writer.cxx
+++ b/sw/source/filter/writer/writer.cxx
@@ -116,7 +116,7 @@ void Writer_Impl::InsertBkmk(const ::sw::mark::IMark& rBkmk)
 
 Writer::Writer()
     : m_pImpl(o3tl::make_unique<Writer_Impl>())
-    , pOrigPam(nullptr), pOrigFileName(nullptr), pDoc(nullptr), pCurPam(nullptr)
+    , pOrigFileName(nullptr), pDoc(nullptr), pOrigPam(nullptr), pCurPam(nullptr)
 {
     bWriteAll = bShowProgress = bUCS2_WithStartChar = true;
     bASCII_NoLastLineEnd = bASCII_ParaAsBlanc = bASCII_ParaAsCR =


More information about the Libreoffice-commits mailing list