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

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 14 11:02:51 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf118701.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx        |   18 ++++++++++++++++--
 writerfilter/source/dmapper/DomainMapper.cxx      |    5 +++--
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   22 +++++-----------------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    5 ++++-
 5 files changed, 28 insertions(+), 22 deletions(-)

New commits:
commit 616a47c9570f9ce67b18a124f08f4a342bff3468
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Fri Jul 10 18:52:42 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Tue Jul 14 13:02:13 2020 +0200

    tdf#134793 DOCX import: fix numbering with inline images
    
    before page break. Previous fix for tdf#118701
    didn't keep numbering of the paragraph marked
    for deletion.
    
    This reverts commit b216fc5b583050cfb1cdf9bd82ec3c1bd2e09d70
    (tdf#118701 DOCX import: fix image position on page break).
    
    Change-Id: I5bde927f15b4b1f682d81482734fadff7690f6d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98541
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf118701.docx b/sw/qa/extras/ooxmlexport/data/tdf118701.docx
index 654a22709919..8fb26669d1fa 100644
Binary files a/sw/qa/extras/ooxmlexport/data/tdf118701.docx 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 776fe5df0010..6168211ce34e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -34,9 +34,23 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133334_followPgStyle, "tdf133334_followPgStyle.o
     CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
-DECLARE_OOXMLIMPORT_TEST(testTdf118701, "tdf118701.docx")
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf118701, "tdf118701.docx")
 {
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("At least one paragraph is missing from the file!", 3, getParagraphs());
+    // This was 6, related to moving inline images after the page breaks
+    CPPUNIT_ASSERT_EQUAL(4, getPages());
+
+    xmlDocUniquePtr pXmlDoc = parseExport();
+
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr[1]/w:numPr", 0);
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr[1]/w:numPr", 0);
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:pPr[1]/w:numPr", 0);
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[4]/w:pPr[1]/w:numPr", 1);
+
+    // Keep numbering of the paragraph of the inline image
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[8]/w:pPr[1]/w:numPr", 0);
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr[1]/w:numPr", 1);
+    // This was 0
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[10]/w:pPr[1]/w:numPr", 1);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf133370_columnBreak, "tdf133370_columnBreak.odt")
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 5df7bb33b1ae..65b0b4a86a83 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3500,7 +3500,8 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
                             && !bSingleParagraphAfterRedline
                             && !m_pImpl->GetIsDummyParaAddedForTableInSection()
                             && !( pSectionContext && pSectionContext->GetBreakType() != -1 && pContext && pContext->isSet(PROP_BREAK_TYPE) )
-                            && !m_pImpl->GetIsPreviousParagraphFramed());
+                            && !m_pImpl->GetIsPreviousParagraphFramed()
+                            && !m_pImpl->IsParaWithInlineObject());
 
             const bool bNoNumbering = bRemove || (!m_pImpl->GetParaChanged() && m_pImpl->GetParaSectpr() && bSingleParagraph);
             PropertyMapPtr xContext = bNoNumbering ? m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) : PropertyMapPtr();
@@ -3516,7 +3517,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
             }
             m_pImpl->SetParaSectpr(false);
             finishParagraph(bRemove);
-            if (bRemove && m_pImpl->IsLastParaEmpty())
+            if (bRemove)
                 m_pImpl->RemoveLastParagraph();
         }
         else
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 777006bb58de..25820d086c12 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -309,7 +309,8 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_bParaHadField(false),
         m_bParaAutoBefore(false),
         m_bFirstParagraphInCell(true),
-        m_bSaveFirstParagraphInCell(false)
+        m_bSaveFirstParagraphInCell(false),
+        m_bParaWithInlineObject(false)
 
 {
     m_aBaseUrl = rMediaDesc.getUnpackedValueOrDefault(
@@ -474,22 +475,6 @@ 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)
@@ -2056,6 +2041,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
         m_bFirstParagraphInCell = false;
 
     m_bParaAutoBefore = false;
+    m_bParaWithInlineObject = false;
 
 #ifdef DBG_UTIL
     TagLogger::getInstance().endElement();
@@ -6600,6 +6586,8 @@ void  DomainMapper_Impl::ImportGraphic(const writerfilter::Reference< Properties
             }
             m_aTextAppendStack.top().m_aAnchoredObjects.push_back(aInfo);
         }
+        else if (eGraphicImportType == IMPORT_AS_DETECTED_INLINE)
+            m_bParaWithInlineObject = true;
     }
 
     // Clear the reference, so in case the embedded object is inside a
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index e145547f3ddd..9886f7665c6b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -626,7 +626,6 @@ public:
 
     void RemoveDummyParaForTableInSection();
     void AddDummyParaForTableInSection();
-    bool IsLastParaEmpty();
     void RemoveLastParagraph( );
     void SetIsLastParagraphInSection( bool bIsLast );
     bool GetIsLastParagraphInSection() const { return m_bIsLastParaInSection;}
@@ -1063,6 +1062,8 @@ public:
     bool m_bIsActualParagraphFramed;
     std::vector<css::uno::Any> aFramedRedlines;
 
+    bool IsParaWithInlineObject() const { return m_bParaWithInlineObject; }
+
 private:
     void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType);
     // Start a new index section; if needed, finish current paragraph
@@ -1076,6 +1077,8 @@ private:
     /// Current paragraph in a table is first paragraph of a cell
     bool m_bFirstParagraphInCell;
     bool m_bSaveFirstParagraphInCell;
+    /// Current paragraph had at least one inline object in it.
+    bool m_bParaWithInlineObject;
 };
 
 } //namespace dmapper


More information about the Libreoffice-commits mailing list