sw/qa/core/layout/data/floattable-deleted-anchor.docx    |binary
 sw/qa/core/layout/flycnt.cxx                             |   25 +++++++++++++++
 sw/source/core/text/frmform.cxx                          |   13 +++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    3 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx        |    3 -
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |    3 -
 6 files changed, 37 insertions(+), 10 deletions(-)

New commits:
commit 5304dce75a127debfbf45ff2c66aa33a6de81360
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Apr 26 16:17:10 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Apr 27 13:28:42 2023 +0200

    sw floattable: DOCX import: m_bConvertedTable is now unused
    
    This was added in commit 659c0227a50d298780d72902314e03df8824bc06
    (tdf#107889 DOCX import: consider page breaks for multi-page
    floattables, 2017-05-16), but is no longer used since commit
    c50bf5a5daaae3d40f89ea0784a75a8a571c208d (sw floattable: remove no
    longer needed DOCX import heuristics, 2023-04-12).
    
    (cherry picked from commit 400d970f27078a93eab97ead8a6934a32272f549)
    
    Change-Id: Ieba43e1175ab59c29c0555299facb8fc0e865acf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151085
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index d9d5a0aa6f90..905c197c6e44 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1586,9 +1586,6 @@ void DomainMapperTableHandler::endTable(unsigned int 
nestedTableLevel, bool bTab
                 AfterConvertToTextFrame(m_rDMapper_Impl, aFramedRedlines, 
redPos, redLen, redCell, redTable);
             }
         }
-
-        // We're right after a table conversion.
-        m_rDMapper_Impl.m_bConvertedTable = true;
     }
 
     m_aTableProperties.clear();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 25694e4835bc..9e6ce49ec750 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2473,9 +2473,6 @@ void DomainMapper_Impl::finishParagraph( const 
PropertyMapPtr& pPropertyMap, con
                         rAppendContext.m_aAnchoredObjects.clear();
                     }
 
-                    // We're no longer right after a table conversion.
-                    m_bConvertedTable = false;
-
                     if (xCursor.is())
                     {
                         xCursor->goLeft(1, true);
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index cc5488aa5518..d91a2b5c1a6f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -1010,9 +1010,6 @@ public:
 
     DeletableTabStop                m_aCurrentTabStop;
 
-    /// If we're right after the end of a table.
-    bool m_bConvertedTable = false;
-
     bool IsOOXMLImport() const { return m_eDocumentType == 
SourceDocumentType::OOXML; }
 
     bool IsRTFImport() const { return m_eDocumentType == 
SourceDocumentType::RTF; }
commit 2059554160f496e83dff126627e029ad67a77e8a
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Apr 26 11:44:43 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Apr 27 13:28:36 2023 +0200

    sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 3
    
    Converting the bugdoc to PDF crashed Writer layout since commit
    ce3308a926f036b87515b8cd97d2b197063dc77a (tdf#61594 sw floattable:
    import floating tables as split flys by default, 2023-04-12).
    
    Part 1 already fixed the crash, but a layout loop remains. The current
    problem is that we could have a document of 3 pages where the last page
    had no anchor for the fly frame, so it took the anchor from the previous
    page, but this lead to negative frame heights and at the end an empty
    3rd page.
    
    To fix the problem:
    
    1) Make sure SwTextFrame::FormatAdjust() doesn't break the invariant
       that only the last frame of a floattable anchor has text content.
    
    2) Make sure SwTextFrame::AdjustFollow_() doesn't join a frame that
       still hosts non-last split flys.
    
    With this, we have exactly 3 anchor frames (in a flow frame chain) for
    the 3 pages and the 3rd page looks correct. The original document still
    needs more work to fix the layout loop, though.
    
    (cherry picked from commit 73bada774ef37efd5a4498ccc083b1358314557d)
    
    Change-Id: I2fc9c4728fdf191ac5b5b435a10d553a699bae75
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151084
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/core/layout/data/floattable-deleted-anchor.docx 
b/sw/qa/core/layout/data/floattable-deleted-anchor.docx
new file mode 100644
index 000000000000..cab5b68ff94d
Binary files /dev/null and 
b/sw/qa/core/layout/data/floattable-deleted-anchor.docx differ
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index ca68365700b4..f7e6992bf014 100644
--- a/sw/qa/core/layout/flycnt.cxx
+++ b/sw/qa/core/layout/flycnt.cxx
@@ -737,6 +737,31 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyTableRowKeep)
     auto pCell3 = dynamic_cast<SwCellFrame*>(pRow3->GetLower());
     CPPUNIT_ASSERT(pCell3->GetFollowCell());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFlyDeletedAnchor)
+{
+    // Given a document with a floating table that spans over 3 pages:
+    createSwDoc("floattable-deleted-anchor.docx");
+
+    // When laying out that document:
+    calcLayout();
+
+    // Then make sure that there are 3 anchors for the 3 pages:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage1);
+    SwFrame* pBody1 = pPage1->GetLower();
+    CPPUNIT_ASSERT(pBody1);
+    auto pAnchor1 = dynamic_cast<SwTextFrame*>(pBody1->GetLower()->GetNext());
+    CPPUNIT_ASSERT(pAnchor1);
+    SwTextFrame* pAnchor2 = pAnchor1->GetFollow();
+    CPPUNIT_ASSERT(pAnchor2);
+    SwTextFrame* pAnchor3 = pAnchor2->GetFollow();
+    // Without the accompanying fix in place, this test would have failed, the 
fly frame on the 3rd
+    // page was anchored to a text frame on the 2nd page, leading to a 
negative frame height.
+    CPPUNIT_ASSERT(pAnchor3);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index f756b186c464..7d1e686db748 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -633,6 +633,13 @@ void SwTextFrame::AdjustFollow_( SwTextFormatter &rLine,
         while( GetFollow() && GetFollow()->GetFollow() &&
                nNewOfst >= GetFollow()->GetFollow()->GetOffset() )
         {
+            if (HasNonLastSplitFlyDrawObj())
+            {
+                // A non-last split fly is anchored to us, don't move content 
from the last frame to
+                // this one and don't join.
+                return;
+            }
+
             JoinFrame();
         }
     }
@@ -1109,7 +1116,11 @@ void SwTextFrame::FormatAdjust( SwTextFormatter &rLine,
         // AdjustFollow might execute JoinFrame() because of this.
         // Else, nEnd is the end of the last line in the Master.
         TextFrameIndex nOld = nEnd;
-        nEnd = rLine.GetEnd();
+        // Make sure content from the last floating table anchor is not 
shifted to previous anchors.
+        if (!HasNonLastSplitFlyDrawObj())
+        {
+            nEnd = rLine.GetEnd();
+        }
         if( GetFollow() )
         {
             if( nNew && nOld < nEnd )

Reply via email to