sw/qa/extras/ooxmlexport/ooxmlexport10.cxx |    2 +-
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx  |    2 +-
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx  |    4 ++--
 sw/source/core/docnode/ndtbl.cxx           |   10 ++++++----
 4 files changed, 10 insertions(+), 8 deletions(-)

New commits:
commit 65987cb2f8ed6b6cf67032cbce4c5e58f2577803
Author:     Michael Stahl <michael.st...@collabora.com>
AuthorDate: Mon Jul 21 19:20:51 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jul 23 10:43:24 2025 +0200

    sw: fix rounding problem in lcl_SetTableBoxWidths2()
    
    Prevents bunch of warnings like:
    
        swnewtable.cxx:2525: Line width differs from table width: 14148 current 
[0]: 14144
    
    Change-Id: Ic24096d91ad6646635038a06b74251e3bcbad134
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188152
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index e7e39549cb0b..f55c4e1fe627 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -468,7 +468,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf59274)
     // This was 1224: too narrow first cell in first row
     assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcW", "w", u"4291");
     // This was 3674: too wide last cell in first row
-    assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[4]/w:tcPr/w:tcW", "w", u"1695");
+    assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[4]/w:tcPr/w:tcW", "w", u"1696");
 }
 
 DECLARE_OOXMLEXPORT_TEST(testDMLGroupshapeSdt, "dml-groupshape-sdt.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 60c65bd222f1..5f8dacd51b80 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -259,7 +259,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSegFaultWhileSave)
     loadAndSave("test_segfault_while_save.docx");
     // fdo#74499
     xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6137), getXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").toInt32());
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6138), getXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").toInt32());
 }
 
 CPPUNIT_TEST_FIXTURE(Test, fdo69656)
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 475e8be96fd7..be904cd07f47 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -191,7 +191,7 @@ CPPUNIT_TEST_FIXTURE(Test, testFDO76586)
 
     // there is only one table in the test file
     assertXPath(pXmlDoc, "//w:tblGrid/w:gridCol[1]", "w", u"1601");
-    assertXPath(pXmlDoc, "//w:tblGrid/w:gridCol[2]", "w", u"7843");
+    assertXPath(pXmlDoc, "//w:tblGrid/w:gridCol[2]", "w", u"7844");
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testFDO76587 )
@@ -235,7 +235,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf131819)
     xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
     // These were 4030 and 4249.
     assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tbl/w:tblGrid/w:gridCol[1]", "w", 
u"3841");
-    assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tbl/w:tblGrid/w:gridCol[2]", "w", 
u"4049");
+    assertXPath(pXmlDoc, 
"/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tbl/w:tblGrid/w:gridCol[2]", "w", 
u"4050");
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf131959)
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 7f824ec88feb..0ee003d24c91 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -1379,22 +1379,24 @@ lcl_SetTableBoxWidths2(SwTable & rTable, size_t const 
nMaxBoxes,
 {
     // rhbz#820283, fdo#55462: set default box widths so table width is covered
     SwTableLines & rLines = rTable.GetTabLines();
+    assert(nMaxBoxes != 0); // no valid table without boxes
+    auto const nTableWidth{USHRT_MAX}; // default
+    auto const nWidth{nTableWidth / nMaxBoxes};
+    auto const nRest{nTableWidth % nMaxBoxes};
     for (size_t nTmpLine = 0; nTmpLine < rLines.size(); ++nTmpLine)
     {
         SwTableBoxes & rBoxes = rLines[nTmpLine]->GetTabBoxes();
         assert(!rBoxes.empty()); // ensured by convertToTable
         size_t const nMissing = nMaxBoxes - rBoxes.size();
-        if (nMissing)
+        if (nMissing || nRest != 0)
         {
             // default width for box at the end of an incomplete line
             SwTableBoxFormat *const pNewFormat = rDoc.MakeTableBoxFormat();
-            size_t nWidth = nMaxBoxes ? USHRT_MAX / nMaxBoxes : USHRT_MAX;
             pNewFormat->SetFormatAttr( SwFormatFrameSize(SwFrameSize::Variable,
-                        nWidth * (nMissing + 1)) );
+                        nWidth * (nMissing + 1) + nRest) );
             pNewFormat->Add(*rBoxes.back());
         }
     }
-    size_t nWidth = nMaxBoxes ? USHRT_MAX / nMaxBoxes : USHRT_MAX;
     // default width for all boxes not at the end of an incomplete line
     rBoxFormat.SetFormatAttr(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
 }

Reply via email to