sw/qa/extras/layout/layout.cxx                    |   16 ++++++++++++++
 sw/source/core/text/widorp.cxx                    |   24 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    9 --------
 3 files changed, 40 insertions(+), 9 deletions(-)

New commits:
commit 65dd1525e826006f78f86688032459dbd7ab4bb4
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 8 08:02:55 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 8 08:18:01 2023 +0000

    sw floattable: partially re-enable widow / orphan control in tables
    
    Widow / orphan control in DOCX tables were disabled in commit
    8b13da71aedd094de0d351a4bd5ad43fdb4bddde (tdf#128959 DOCX import: fix
    missing text lines in tables, 2020-01-28).
    
    That workaround helped with the particular bugdoc, but it also disabled
    widow / orphan handling in general, and breaks e.g. orig-nocompat.docx
    from tdf#61594, because the second page's last row is meant to contain 6
    lines with widow control enabled, but the model has widow control
    disabled, so the layout can't work properly.
    
    Fix the problem by improving the layout's WidowsAndOrphans::FindWidows()
    to handle conflicting widow / orphan control requirements in a fixed table
    row height context, so the writerfilter/ change from the above commit
    can be reverted without re-introducing tdf#128959.
    
    An alternative would be to keep the layout unchanged and limit the
    writerfilter/ change to fixed height rows, but that still feels like a
    (more specific) workaround.
    
    Change-Id: I8378d356e116774275dff337d17b19bd79c84c1c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148456
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 8e1fe15c32ea..001440cd5890 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -42,6 +42,7 @@
 #include <svx/svdpage.hxx>
 #include <svx/svdotext.hxx>
 #include <dcontact.hxx>
+#include <frameformats.hxx>
 
 /// Test to assert layout / rendering result of Writer.
 class SwLayoutWriter : public SwModelTestBase
@@ -4644,6 +4645,21 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf128959)
     assertXPath(pXmlDoc,
                 
"/root/page[2]/body/tab[1]/row[1]/cell[1]/txt[1]/SwParaPortion/SwLineLayout[1]",
                 "portion", "amet commodo magna eros quis urna.");
+
+    // Also check that the widow control for the paragraph is not turned off:
+    SwFrameFormats& rTableFormats = *pDocument->GetTableFrameFormats();
+    SwFrameFormat* pTableFormat = rTableFormats[0];
+    SwTable* pTable = SwTable::FindTable(pTableFormat);
+    const SwTableBox* pCell = pTable->GetTableBox("A1");
+    const SwStartNode* pStartNode = pCell->GetSttNd();
+    SwNodeIndex aNodeIndex(*pStartNode);
+    ++aNodeIndex;
+    const SwTextNode* pTextNode = aNodeIndex.GetNode().GetTextNode();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 2
+    // - Actual  : 0
+    // i.e. the original fix only worked as the entire widow / orphan control 
was switched off.
+    CPPUNIT_ASSERT_EQUAL(2, 
static_cast<int>(pTextNode->GetSwAttrSet().GetWidows().GetValue()));
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf121658)
diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx
index ceae9ee8d70c..a89751f736da 100644
--- a/sw/source/core/text/widorp.cxx
+++ b/sw/source/core/text/widorp.cxx
@@ -519,6 +519,30 @@ bool WidowsAndOrphans::FindWidows( SwTextFrame *pFrame, 
SwTextMargin &rLine )
         }
         if( nLines <= nNeed )
             return false;
+
+        if (pFrame->IsInTab())
+        {
+            const SwFrame* pRow = pFrame;
+            while (pRow && !pRow->IsRowFrame())
+            {
+                pRow = pRow->GetUpper();
+            }
+
+            if (pRow->HasFixSize())
+            {
+                // This is a follow frame and our side is fixed.
+                const SwAttrSet& rSet = 
pFrame->GetTextNodeForParaProps()->GetSwAttrSet();
+                const SvxOrphansItem& rOrph = rSet.GetOrphans();
+                if (nLines <= rOrph.GetValue())
+                {
+                    // If the master gives us a line as part of widow control, 
then its orphan
+                    // control will move everything to the follow, which is 
worse than having no
+                    // widow / orphan control at all.  Don't send a Widows 
prepare hint, in this
+                    // case.
+                    return true;
+                }
+            }
+        }
     }
 
     pMaster->Prepare( PrepareHint::Widows, static_cast<void*>(&nNeed) );
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index bc5b44ac4863..7e8dd6bd57c7 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2642,15 +2642,6 @@ void DomainMapper_Impl::finishParagraph( const 
PropertyMapPtr& pPropertyMap, con
                         }
                     }
                 }
-
-                // fix table paragraph properties
-                if (xTextRange.is() && xParaProps && m_nTableDepth > 0 && 
!m_bIsInComments)
-                {
-                    // tdf#128959 table paragraphs haven't got window and 
orphan controls
-                    uno::Any aAny(static_cast<sal_Int8>(0));
-                    xParaProps->setPropertyValue("ParaOrphans", aAny);
-                    xParaProps->setPropertyValue("ParaWidows", aAny);
-                }
             }
             if( !bKeepLastParagraphProperties )
                 rAppendContext.pLastParagraphProperties = pToBeSavedProperties;

Reply via email to