chart2/source/view/main/DataTableView.cxx |    9 +++---
 sw/qa/extras/layout/data/charttable.odt   |binary
 sw/qa/extras/layout/layout3.cxx           |   39 ++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)

New commits:
commit f4ba83e82aafc206d17d2fa66a27573ebc5a3624
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Wed Mar 6 22:52:44 2024 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Mar 8 09:41:15 2024 +0100

    tdf#159422 - chart view: fix symbols position of data table legend
    
    Calculate the correct/optimal row height after calculating and set
    correct width of a table cell. Then we will have the correct row height
    for the symbol positions.
    
    Change-Id: I65bc0f0579ea100906b0b32449c2200a54c2a353
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164512
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/chart2/source/view/main/DataTableView.cxx 
b/chart2/source/view/main/DataTableView.cxx
index c3c807ca099b..eacd91a6a651 100644
--- a/chart2/source/view/main/DataTableView.cxx
+++ b/chart2/source/view/main/DataTableView.cxx
@@ -455,11 +455,9 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
         nRow++;
     }
 
+    // force recalculation of column widths in the table shape
     xBroadcaster->unlockBroadcasts();
-
-    // force recalculation of all cells in the table shape
     pTableObject->DistributeColumns(0, nColumnCount, true, true);
-    pTableObject->DistributeRows(0, nRowCount, true, true);
 
     xBroadcaster->lockBroadcasts();
 
@@ -477,6 +475,10 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
         xPropertySet->setPropertyValue("Width", uno::Any(nColumnWidth));
     }
 
+    // force recalculation of row heights in the table shape
+    xBroadcaster->unlockBroadcasts();
+    pTableObject->DistributeRows(0, nRowCount, true, true);
+
     if (bKeys)
     {
         sal_Int32 nTotalHeight = 0;
@@ -501,7 +503,6 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
             }
         }
     }
-    xBroadcaster->unlockBroadcasts();
 }
 
 void DataTableView::changePosition(sal_Int32 x, sal_Int32 y)
diff --git a/sw/qa/extras/layout/data/charttable.odt 
b/sw/qa/extras/layout/data/charttable.odt
new file mode 100644
index 000000000000..e8dfa37d8006
Binary files /dev/null and b/sw/qa/extras/layout/data/charttable.odt differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index f96b786cc093..7bb1dbced75c 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -2419,6 +2419,45 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159443)
         "4.3");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159422)
+{
+    // Given a document with chart, which have a datatable
+    createSwDoc("charttable.odt");
+    SwDoc* pDoc = getSwDoc();
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    //// Without the fix, this would fail:
+    //// - Expected: 5877
+    //// - Actual  : 5649
+    //// - Delta   : 20
+    sal_Int32 nYSymbol1
+        = getXPath(
+              pXmlDoc,
+              
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[99]/polypolygon/polygon/point[1]"_ostr,
+              "y"_ostr)
+              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(5877, nYSymbol1, 20);
+    sal_Int32 nYSymbol2
+        = getXPath(
+              pXmlDoc,
+              
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[100]/polypolygon/polygon/point[1]"_ostr,
+              "y"_ostr)
+              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(6225, nYSymbol2, 20);
+    sal_Int32 nYSymbol3
+        = getXPath(
+              pXmlDoc,
+              
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[101]/polypolygon/polygon/point[1]"_ostr,
+              "y"_ostr)
+              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(6573, nYSymbol3, 20);
+}
+
 } // end of anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to