sw/qa/core/layout/data/floattable-2cols.docx      |binary
 sw/qa/core/layout/flycnt.cxx                      |   30 ++++++++++++++++++++++
 sw/qa/extras/layout/layout.cxx                    |   16 +++++++++++
 sw/source/core/layout/fly.cxx                     |    6 ++++
 sw/source/core/text/itrform2.cxx                  |   10 ++-----
 sw/source/core/text/widorp.cxx                    |   24 +++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    9 ------
 xmloff/source/text/txtparae.cxx                   |    2 -
 8 files changed, 81 insertions(+), 16 deletions(-)

New commits:
commit 4cec874df4958a8f21021e40b3f06c58734560fc
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed Mar 8 08:02:55 2023 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Mar 9 09:17:53 2023 +0100

    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.
    
    (cherry picked from commit 65dd1525e826006f78f86688032459dbd7ab4bb4)
    
    Change-Id: I8378d356e116774275dff337d17b19bd79c84c1c

diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 587fa4d4294e..3d3ec308e2ab 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
@@ -4720,6 +4721,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 7550cc6ff0f7..8246e5eade06 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2639,15 +2639,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;
commit 256ccc1d4cb63838d264e04b5bd2e18a3fd4f4ba
Author:     Miklos Vajna <[email protected]>
AuthorDate: Tue Mar 7 08:25:56 2023 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Mar 9 09:12:54 2023 +0100

    sw floattable: grow the print area as well in SwFlyFrame::Grow_()
    
    The bugdoc should be of 3 pages, but the last for of the floating table
    went to the 3rd page.
    
    The reason for this was that SwTabFrame::MakeAll() calculated
    nDistanceToUpperPrtBottom, then determined that the upper has to grow,
    and called GetUpper()->Grow(LONG_MAX, /*bTest=*/true).
    
    Now this growth was less than what would be possible, because a previous
    invocation of SwFlyFrame::Grow_() increased the frame area (with
    margins) but not the print area (with margins). This meant that the
    frame can't grow too much because its frame height is already 7044 twips
    but its print height is only 548. This combination of "not enough inner
    space" and "can't grow too much, either" resulted in moving the last row
    to an unwanted 3rd page.
    
    Fix the problem by not only increasing the frame height but also the
    print height in SwFlyFrame::Grow_(), this keeps the last row on the 2nd
    page, like Word does.
    
    (cherry picked from commit 5d5dca66e17c90e20197d0d76113254b13ff0bb7)
    
    Change-Id: I7850b54b030c42034e0a117d52d2148fa6ba2f83

diff --git a/sw/qa/core/layout/data/floattable-2cols.docx 
b/sw/qa/core/layout/data/floattable-2cols.docx
new file mode 100644
index 000000000000..c43779f2aac9
Binary files /dev/null and b/sw/qa/core/layout/data/floattable-2cols.docx differ
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index d400fd85de0a..254a316886c7 100644
--- a/sw/qa/core/layout/flycnt.cxx
+++ b/sw/qa/core/layout/flycnt.cxx
@@ -390,6 +390,36 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFooter2Rows)
     // 2nd half of the split row and the last row went to a 3rd page.
     CPPUNIT_ASSERT(!pPage2->GetNext());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFly2Cols)
+{
+    // Given a document with a 2nd page that contains the second half of a 
split row and 2 columns:
+    std::shared_ptr<comphelper::ConfigurationChanges> pChanges(
+        comphelper::ConfigurationChanges::create());
+    
officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set(true,
+                                                                               
         pChanges);
+    pChanges->commit();
+    comphelper::ScopeGuard g([pChanges] {
+        
officecfg::Office::Writer::Filter::Import::DOCX::ImportFloatingTableAsSplitFly::set(
+            false, pChanges);
+        pChanges->commit();
+    });
+    createSwDoc("floattable-2cols.docx");
+
+    // When laying out that document:
+    calcLayout();
+
+    // Then make sure that the table is split to 2 pages:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage1);
+    auto pPage2 = dynamic_cast<SwPageFrame*>(pPage1->GetNext());
+    CPPUNIT_ASSERT(pPage2);
+    // Without the accompanying fix in place, this test would have failed. The 
2nd page only had the
+    // 2nd half of the split row and the very last row went to a 3rd page.
+    CPPUNIT_ASSERT(!pPage2->GetNext());
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 89637ff6f5cf..88c58c7f27f3 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -2083,6 +2083,12 @@ SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst )
                         aRectFnSet.AddBottom(aFrm, nRemaining);
                     }
                     InvalidateObjRectWithSpaces();
+                    {
+                        // Margins are unchanged, so increase the print height 
similar to the frame
+                        // height.
+                        SwFrameAreaDefinition::FramePrintAreaWriteAccess 
aPrt(*this);
+                        aRectFnSet.AddBottom(aPrt, nRemaining );
+                    }
                     aNew = GetObjRectWithSpaces();
                 }
             }
commit 60eb36063a7ecfaccfe5d12a7528267bc14ad6e8
Author:     Miklos Vajna <[email protected]>
AuthorDate: Mon Mar 6 08:22:40 2023 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Mar 9 09:09:03 2023 +0100

    sw floattable: clean up not needed scope in SwTextFormatter::FormatLine()
    
    Leftover from commit 25a16e7543965565a4227506003adc916deea500 (sw
    floattable: fix cid#1520804, 2023-02-09).
    
    (cherry picked from commit aac624d1e3cd6fc023e25fedbfe48ed330a308ec)
    
    Change-Id: Iecf4d8708c6acc3a49a0a987370911f32e6ac3e8

diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 6c1f0c06a5a5..045be23a15dc 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1933,13 +1933,11 @@ TextFrameIndex 
SwTextFormatter::FormatLine(TextFrameIndex const nStartPos)
             m_pCurr->Height( GetFrameRstHeight() + 1, false );
             m_pCurr->SetRealHeight( GetFrameRstHeight() + 1 );
 
+            // Don't oversize the line in case of split flys, so we don't try 
to move the anchor
+            // of a precede fly forward, next to its follow.
+            if (m_pFrame->HasNonLastSplitFlyDrawObj())
             {
-                // Don't oversize the line in case of split flys, so we don't 
try to move the anchor
-                // of a precede fly forward, next to its follow.
-                if (m_pFrame->HasNonLastSplitFlyDrawObj())
-                {
-                    m_pCurr->SetRealHeight(GetFrameRstHeight());
-                }
+                m_pCurr->SetRealHeight(GetFrameRstHeight());
             }
 
             m_pCurr->Width(0);
commit dd53c628de427379fc60dec3d122d448a25e5ed1
Author:     Miklos Vajna <[email protected]>
AuthorDate: Mon Mar 6 08:18:41 2023 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Mar 9 09:01:48 2023 +0100

    xmloff: fix -Wmaybe-uninitialized
    
    In case operator >>=() of uno::Any fails, it leaves nTabIndex
    uninitialized and it seems gcc notices this sometimes:
    
    In file included from include/com/sun/star/uno/Any.h:30,
                     from include/com/sun/star/uno/Any.hxx:35,
                     from include/o3tl/any.hxx:21,
                     from xmloff/source/text/txtparae.cxx:22:
    include/rtl/ustring.hxx: In member function ‘void 
XMLTextParagraphExport::ExportContentControl(const 
com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>&, bool, 
bool, bool&)’:
    include/rtl/ustring.hxx:3044:22: warning: ‘nTabIndex’ may be used 
uninitialized in this function [-Wmaybe-uninitialized]
     3044 |         return number( static_cast< unsigned long long >( i ), 
radix );
          |                
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xmloff/source/text/txtparae.cxx:3999:20: note: ‘nTabIndex’ was declared here
     3999 |         sal_uInt32 nTabIndex;
          |                    ^~~~~~~~~
    
    (cherry picked from commit 26e945d22e597d84666225c8d0e9590412e404d7)
    
    Change-Id: Ia39e85575bde4011247583265497ddf4d0d4c52b

diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index aa81727678c6..38602b0788d7 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -4085,7 +4085,7 @@ void XMLTextParagraphExport::ExportContentControl(
             GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_ID, 
OUString::number(nId));
         }
 
-        sal_uInt32 nTabIndex;
+        sal_uInt32 nTabIndex = 0;
         xPropertySet->getPropertyValue("TabIndex") >>= nTabIndex;
         if (nTabIndex)
         {

Reply via email to