tdf#166953 writerfilter: add column width when adding extra cell

It's not so obvious how the cell widths are set...

1. The table gets USHRT_MAX as initial width
2. All the cells in the table get USHRT_MAX/nCells as initial width
   (this is SwFrameSizeItem in box item set)
3. Table property "Width" is set -> this scales all the box widths
4. Row property "TableColumnSeparators" is set; this is *relative* widths
   to a hard-coded value of TableColumnRelativeSum=10000

Evidently the result is bad if the number of separators is too low.

(regression from commit 038473595e)

Change-Id: Ie71889a074bff43d8f0c34ccefb4d30ed0a9f0c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188153
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 23e308d5e02ee45ef589d3fddf53dabaa12aadfe)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188207
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
This commit is contained in:
Michael Stahl
2025-07-23 17:19:16 +02:00
parent 64c13de974
commit b2dcf38fdb
3 changed files with 384 additions and 0 deletions
File diff suppressed because one or more lines are too long
+39
View File
@@ -176,6 +176,45 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf158586_lostFrame)
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testTdf166953)
{
auto verify = [this]() {
xmlDocUniquePtr pLayout = parseLayoutDump();
assertXPath(pLayout, "/root/page[1]/body/tab/row[1]/infos/bounds", "width", u"14149");
// the problem was that this width was 544
assertXPath(pLayout, "/root/page[1]/body/tab/row[1]/cell[1]/infos/bounds", "width",
u"14146");
// there is another cell in this row that was added by writerfilter
assertXPath(pLayout, "/root/page[1]/body/tab/row[2]/infos/bounds", "width", u"14149");
// the problem was that this width was 544
assertXPath(pLayout, "/root/page[1]/body/tab/row[2]/cell[1]/infos/bounds", "width",
u"2408");
assertXPath(pLayout, "/root/page[1]/body/tab/row[2]/cell[2]/infos/bounds", "width",
u"11738");
// there is another cell in this row that was added by writerfilter
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/infos/bounds", "width", u"14149");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[1]/infos/bounds", "width",
u"3309");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[2]/infos/bounds", "width",
u"1759");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[3]/infos/bounds", "width",
u"1729");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[4]/infos/bounds", "width",
u"1831");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[5]/infos/bounds", "width",
u"1863");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[6]/infos/bounds", "width",
u"1865");
assertXPath(pLayout, "/root/page[1]/body/tab/row[3]/cell[7]/infos/bounds", "width",
u"1791");
// there is another cell in this row that was already in the RTF
};
createSwDoc("Tpl-2min3_s1.rtf");
verify();
saveAndReload(mpFilter);
verify();
}
CPPUNIT_TEST_FIXTURE(Test, testEndnotesAtSectEndRTF)
{
// Given a document, endnotes at collected at section end:
@@ -25,6 +25,7 @@
#include "util.hxx"
#include <comphelper/sequence.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <com/sun/star/text/TableColumnSeparator.hpp>
using namespace com::sun::star;
@@ -428,6 +429,29 @@ void TableManager::HandleSmallerRows()
pRowData->addCell(xNewCellTextCursor, pCellPropMap);
pRowData->endCell(xNewCellTextCursor);
pRowData->getProperties()->setValue(TablePropertyMap::TABLE_WIDTH, nMaxRowWidth);
// tdf#166953 the TableColumnSeparators property needs another
// separator for the extra cell added to it
auto const oSep{ pRowData->getProperties()->getProperty(
PROP_TABLE_COLUMN_SEPARATORS) };
if (oSep)
{
auto const oldSeps{
oSep->second.get<uno::Sequence<text::TableColumnSeparator>>()
};
::std::remove_const_t<decltype(oldSeps)> newSeps{ oldSeps.getLength() + 1 };
auto const it{ ::std::transform(
oldSeps.begin(), oldSeps.end(), newSeps.getArray(), [&](auto const sep) {
double const pos{ sep.Position * double(nRowWidth) / nMaxRowWidth };
return text::TableColumnSeparator{
static_cast<sal_Int16>(::rtl::math::round(pos)), sep.IsVisible
};
}) };
// TODO replace magic number
it->Position = ::rtl::math::round(10000 * double(nRowWidth) / nMaxRowWidth);
it->IsVisible = true;
pRowData->getProperties()->Insert(PROP_TABLE_COLUMN_SEPARATORS,
uno::Any(newSeps));
}
}
}
}