sw/source/core/layout/tabfrm.cxx |   37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

New commits:
commit 8044fbab5fd3382843369e7c692e27ba615e1518
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Sep 17 16:32:59 2024 +0500
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Mon Sep 23 15:39:44 2024 +0200

    tdf#163006: fix keep-together rows height calculation
    
    In commit dcb682563b24bf487a40a9fe7710b4d500850a52 (INTEGRATION: CWS
    swnewtable (1.92.14); FILE MERGED, 2007-02-28), a code was introduced
    in sw/source/core/layout/tabfrm.cxx, that considers the rows having
    m_bIsRowSpanLine set. In SwTabFrame::CalcHeightOfFirstContentLine,
    when getting pFirstRow, such a RowSpanLine was skipped when counting
    the keep-together rows.
    
    However, it was implemented incorrectly: the resulting number of rows,
    excluding the RowSpanLine, then used in a call to lcl_GetHeightOfRows,
    which didn't skip the said row, and thus calculated its (zero) height
    instead of an actual keep-together line.
    
    This fixes the said calculation, and also another place in the same
    file, where the same calculation is done, where RowSpanLine's weren't
    checked at all.
    
    Change-Id: I125a8f6de389d6b7600f3e13343594ac82249d29
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173559
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 2f6504dd84fc37bbf8d7798d4a60fc592aa7a67e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173501
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index fad21eebcce9..b1e1783bc015 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -2935,6 +2935,13 @@ void SwTabFrame::MakeAll(vcl::RenderContext* 
pRenderContext)
                 if ( bTableRowKeep )
                 {
                     const SwRowFrame* pTmpRow = GetFirstNonHeadlineRow();
+                    // Copying the "NEW TABLES" comment, apparently related to 
commit dcb682563b24bf487a40a9fe7710b4d500850a52
+                    if (pTmpRow && pTmpRow->IsRowSpanLine())
+                    {
+                        ++nMinNumOfLines;
+                        pTmpRow = static_cast<const 
SwRowFrame*>(pTmpRow->GetNext());
+                    }
+
                     while ( pTmpRow && pTmpRow->ShouldRowKeepWithNext() )
                     {
                         ++nMinNumOfLines;
@@ -6674,47 +6681,41 @@ SwTwips SwTabFrame::CalcHeightOfFirstContentLine() const
         return aRectFnSet.GetHeight(getFrameArea());
     }
 
-    SwTwips nTmpHeight = 0;
-
     const SwRowFrame* pFirstRow = GetFirstNonHeadlineRow();
     OSL_ENSURE( !IsFollow() || pFirstRow, "FollowTable without Lower" );
 
     // NEW TABLES
-    if ( pFirstRow && pFirstRow->IsRowSpanLine() && pFirstRow->GetNext() )
+    bool bHasRowSpanLine = pFirstRow && pFirstRow->IsRowSpanLine() && 
pFirstRow->GetNext();
+    if (bHasRowSpanLine)
         pFirstRow = static_cast<const SwRowFrame*>(pFirstRow->GetNext());
+    const SwRowFrame* pFirstKeepTogetherRow = pFirstRow;
 
-    // Calculate the height of the headlines:
-    const sal_uInt16 nRepeat = GetTable()->GetRowsToRepeat();
-    SwTwips nRepeatHeight = nRepeat ? lcl_GetHeightOfRows( GetLower(), nRepeat 
) : 0;
-
-    // Calculate the height of the keeping lines
-    // (headlines + following keeping lines):
-    SwTwips nKeepHeight = nRepeatHeight;
+    // Check how many rows want to keep together
+    sal_uInt16 nKeepRows = 0;
     if ( 
GetFormat()->GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::TABLE_ROW_KEEP)
 )
     {
-        sal_uInt16 nKeepRows = nRepeat;
-
-        // Check how many rows want to keep together
         while ( pFirstRow && pFirstRow->ShouldRowKeepWithNext() )
         {
             ++nKeepRows;
             pFirstRow = static_cast<const SwRowFrame*>(pFirstRow->GetNext());
         }
-
-        if ( nKeepRows > nRepeat )
-            nKeepHeight = lcl_GetHeightOfRows( GetLower(), nKeepRows );
     }
 
+    SwTwips nTmpHeight;
+
     // For master tables, the height of the headlines + the height of the
     // keeping lines (if any) has to be considered. For follow tables, we
     // only consider the height of the keeping rows without the repeated lines:
     if ( !IsFollow() )
     {
-        nTmpHeight = nKeepHeight;
+        nKeepRows += GetTable()->GetRowsToRepeat();
+        if (bHasRowSpanLine)
+            ++nKeepRows;
+        nTmpHeight = lcl_GetHeightOfRows(GetLower(), nKeepRows);
     }
     else
     {
-        nTmpHeight = nKeepHeight - nRepeatHeight;
+        nTmpHeight = lcl_GetHeightOfRows(pFirstKeepTogetherRow, nKeepRows);
     }
 
     // pFirstRow row is the first non-heading row.

Reply via email to