tdf#144317 sw table minimize: fix signed->unsigned table growth
In the case where the table was already rather oversized,
the minimize and optimize functions would attempt to shrink
the table to the maximum recommended size. But that was done
without checking whether that would result in a negative
position for the column boundary. (At least that is what I
think was happening. This code is a bit too cryptic...)
I tried to make a unit test, but the table size didn't
grow or shrink as I expected it to (and as it seems to
when the command is run by hand...)
An F12 with SW_DEBUG=true ./instdir/program/soffice
shows that the cell gains a huge width, but that didn't
show up either in a parseDump, even after a
Scheduler::ProcessEventsToIdle(). So I gave up (again).
Change-Id: Id4b9defae718694aa76a3db01f6b02ead5f98e6b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123108
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
(cherry picked from commit 7e201916169aca254c0824fb71ed83ca69f4adce)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123156
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx
index 06dc7018..b0fb854 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -1612,15 +1612,18 @@ void SwDoc::AdjustCellWidth( const SwCursor& rCursor,
nDiff -= aTabCols[i] - aTabCols[i-1];
tools::Long nTabRight = aTabCols.GetRight() + nDiff;
const tools::Long nMaxRight = std::max(aTabCols.GetRightMax(), nOldRight);
// If the Table would become too wide, we restrict the
// adjusted amount to the allowed maximum.
if ( !bBalance && nTabRight > aTabCols.GetRightMax() )
// If the Table would become (or is already) too wide,
// restrict the column growth to the allowed maximum.
if (!bBalance && nTabRight > nMaxRight)
{
const tools::Long nTmpD = nTabRight - aTabCols.GetRightMax();
const tools::Long nTmpD = nTabRight - nMaxRight;
nDiff -= nTmpD;
nTabRight -= nTmpD;
}
// all the remaining columns need to be shifted by the same amount
for ( size_t i2 = i; i2 < aTabCols.Count(); ++i2 )
aTabCols[i2] += nDiff;
aTabCols.SetRight( nTabRight );