[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-0' - sw/qa writerfilter/source

Bakos Attila (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 5 18:11:18 UTC 2021


 sw/qa/extras/ooxmlexport/data/tdf118701.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx        |    5 +++++
 writerfilter/source/dmapper/DomainMapper.cxx      |    2 +-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   16 ++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    1 +
 5 files changed, 23 insertions(+), 1 deletion(-)

New commits:
commit 7214899e06143966564b036b49c18ab5c6fb9d73
Author:     Bakos Attila <bakos.attilakaroly at nisz.hu>
AuthorDate: Tue Jun 30 15:03:31 2020 +0200
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Tue Jan 5 19:10:43 2021 +0100

    tdf#118701 DOCX import: fix image position on page break
    
    If an image anchored to an empty paragraph only with
    section properties, don't remove that paragraph to keep
    the image on the page before the page break.
    
    IsLastParaEmpty() tries to move a text cursor over the
    empty paragraph marked for deletion. If it contains an
    image anchored as a character, the cursor won't reach
    the end of the previous paragraph by goLeft(2).
    
    Co-authored-by: Attila Bánhegyi (NISZ)
    
    Change-Id: Ic22c7553948eb06739232d7e35fc49ad14f96518
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97518
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit b216fc5b583050cfb1cdf9bd82ec3c1bd2e09d70)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108724
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf118701.docx b/sw/qa/extras/ooxmlexport/data/tdf118701.docx
new file mode 100644
index 000000000000..654a22709919
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf118701.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 1fd8ad4a7d84..7bc5d9c49d12 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -46,6 +46,11 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133334_followPgStyle, "tdf133334_followPgStyle.o
     CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testTdf118701, "tdf118701.docx")
+{
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("At least one paragraph is missing from the file!", 3, getParagraphs());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf133370_columnBreak, "tdf133370_columnBreak.odt")
 {
     // Since non-DOCX formats ignores column breaks in non-column situtations, don't export to docx.
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 76fc96b9f56c..2cc14b6b11ea 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3525,7 +3525,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
             }
             m_pImpl->SetParaSectpr(false);
             finishParagraph(bRemove);
-            if (bRemove)
+            if (bRemove && m_pImpl->IsLastParaEmpty())
                 m_pImpl->RemoveLastParagraph();
         }
         else
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 12aa623de2b2..a1e33965a278 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -479,6 +479,22 @@ void DomainMapper_Impl::AddDummyParaForTableInSection()
     }
 }
 
+bool DomainMapper_Impl::IsLastParaEmpty()
+{
+    bool bRet = true;
+    if (!m_aTextAppendStack.empty() && m_aTextAppendStack.top().xTextAppend)
+    {
+        //creating cursor for finding text content
+        uno::Reference<text::XTextCursor> xCursor = m_aTextAppendStack.top().xTextAppend->createTextCursor();
+        xCursor->gotoEnd(false);
+        //selecting the last 2 characters in the document
+        xCursor->goLeft(2, true);
+        //the last paragraph is empty, if they are newlines
+        bRet = xCursor->getString().match(OUString(SAL_NEWLINE_STRING).concat(SAL_NEWLINE_STRING));
+    }
+    return bRet;
+}
+
 void DomainMapper_Impl::RemoveLastParagraph( )
 {
     if (m_bDiscardHeaderFooter)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index dc0693ecae6e..5c4cc16f3549 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -626,6 +626,7 @@ public:
 
     void RemoveDummyParaForTableInSection();
     void AddDummyParaForTableInSection();
+    bool IsLastParaEmpty();
     void RemoveLastParagraph( );
     void SetIsLastParagraphInSection( bool bIsLast );
     bool GetIsLastParagraphInSection() const { return m_bIsLastParaInSection;}


More information about the Libreoffice-commits mailing list