sw/qa/extras/odfexport/data/tdf159027.odt |binary
 sw/qa/extras/odfexport/odfexport2.cxx     |   15 +++++++++++++++
 sw/source/core/frmedt/tblsel.cxx          |   15 ++++++++++++---
 3 files changed, 27 insertions(+), 3 deletions(-)

New commits:
commit ffaee0fc5e1c195ff17c9808e98a42e38a89eb70
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Thu Apr 18 16:04:49 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Sep 10 11:49:53 2024 +0200

    tdf#159027: Fix calculation in tables with merged cells
    
    Calculation in tables with merged cells over multiple pages is fixed.
    It's more a workaround than a fix as it skips an empty SwRowFrame
    returned from SwTabFrame::GetFirstNonHeadlineRow()
    
    Includes gerrit#171592 "tdf#159027 test added"
    
    Change-Id: If11838da9769e0f6b0e54da8f422b4884684e30f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166254
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit f60126a6bfae5dad4a11afcc94ddf4a58c5ce8ab)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173085
    Tested-by: allotropia jenkins <jenk...@allotropia.de>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sw/qa/extras/odfexport/data/tdf159027.odt 
b/sw/qa/extras/odfexport/data/tdf159027.odt
new file mode 100644
index 000000000000..38d9b4501d8e
Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf159027.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 01b8e4755486..8149d6cf8cdc 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -36,6 +36,7 @@
 #include <unoprnms.hxx>
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
+#include <IDocumentFieldsAccess.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -1444,6 +1445,20 @@ DECLARE_ODFEXPORT_TEST(testTdf160877, "tdf160877.odt")
     CPPUNIT_ASSERT_EQUAL(OUString("(Sign GB)Test"), 
getParagraph(1)->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf159027)
+{
+    loadAndReload("tdf159027.odt");
+    SwDoc* pDoc = getSwDoc();
+    pDoc->getIDocumentFieldsAccess().UpdateFields(true);
+
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> 
xCellD9(xTextTable->getCellByName(u"D9"_ustr), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"70"_ustr, xCellD9->getString());
+    uno::Reference<text::XTextRange> 
xCellE9(xTextTable->getCellByName(u"E9"_ustr), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"6"_ustr, xCellE9->getString());
+}
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx
index ec56a5285675..26c7a778e487 100644
--- a/sw/source/core/frmedt/tblsel.cxx
+++ b/sw/source/core/frmedt/tblsel.cxx
@@ -1878,9 +1878,18 @@ void MakeSelUnions( SwSelUnions& rUnions, const 
SwLayoutFrame *pStart,
             // erroneous results could occur during split/merge.
             // To prevent these we will determine the first and last row
             // within the union and use their values for a new union
-            const SwLayoutFrame* pRow = pTable->IsFollow() ?
-                                      pTable->GetFirstNonHeadlineRow() :
-                                      static_cast<const 
SwLayoutFrame*>(pTable->Lower());
+            const SwLayoutFrame* pRow = nullptr;
+            if (pTable->IsFollow())
+            {
+                SwRowFrame* pRowFrame = pTable->GetFirstNonHeadlineRow();
+                //tdf#159027: follow returns a frame without height if
+                // merged cells are invoved
+                if (pRowFrame->getFrameArea().IsEmpty())
+                    pRowFrame = static_cast<SwRowFrame*>(pRowFrame->GetNext());
+                pRow = pRowFrame;
+            }
+            else
+                pRow = static_cast<const SwLayoutFrame*>(pTable->Lower());
 
             while ( pRow && !pRow->getFrameArea().Overlaps( aUnion ) )
                 pRow = static_cast<const SwLayoutFrame*>(pRow->GetNext());

Reply via email to