summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-04-22 10:03:47 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-04-22 11:11:50 +0200
commit50774644bbede54784bf710e8f4c527110513361 (patch)
treeed4b507695d356f85b669185ee6ece2a69459c6f /sc
parentde1a94a6f3d10138897befd82ba14b2a897eaed9 (diff)
fix an off-by-one error in GetEmptyLinesInBlock()
The function has been there since the initial commit and is not documented, but I think it counts the shortest amount of empty cells in the given area starting from the direction given. And AFAICT the off-by-one error was there since the initial commit, when it returned one less if the entire area was empty and the direction was vertical (horizontal was fine). And ScHTMLExport::FillGraphList() even was adjusted for this until my recent commit changing that code). But then ad2bc869bfe2d34bde added a shortcut for unallocated columns that didn't have the error. And the error even got corrected during the rewrite in c008dc483f8c6840803983e7e351cec6fdd32070, but then 01de94471c20a8b9c36d6080638d70e57eac55bf reverted that. Anyway, so fix this, I think all the relevant code should(?) now work properly. Change-Id: I194691f7276a1cea75945de05cb0dda2cdca859a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133319 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/source/core/data/column2.cxx6
2 files changed, 4 insertions, 3 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 5e5af3a31fa6..e28992d21cfe 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1534,6 +1534,7 @@ public:
SCCOL& rEndCol, SCROW nEndRow ) const;
SC_DLLPUBLIC bool IsEmptyBlock(SCCOL nStartCol, SCROW nStartRow,
SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const;
+ // I think this returns the number of empty cells starting from the given direction.
SC_DLLPUBLIC SCSIZE GetEmptyLinesInBlock( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab,
ScDirection eDir );
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index c29b49e9d0de..f933497b4a75 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1329,13 +1329,13 @@ bool ScColumn::IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const
SCSIZE ScColumn::GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const
{
- // Given a range of rows, find a top or bottom empty segment. Skip the start row.
+ // Given a range of rows, find a top or bottom empty segment.
switch (eDir)
{
case DIR_TOP:
{
// Determine the length of empty head segment.
- size_t nLength = nEndRow - nStartRow;
+ size_t nLength = nEndRow - nStartRow + 1;
std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nStartRow);
sc::CellStoreType::const_iterator it = aPos.first;
if (it->type != sc::element_type_empty)
@@ -1350,7 +1350,7 @@ SCSIZE ScColumn::GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirecti
case DIR_BOTTOM:
{
// Determine the length of empty tail segment.
- size_t nLength = nEndRow - nStartRow;
+ size_t nLength = nEndRow - nStartRow + 1;
std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nEndRow);
sc::CellStoreType::const_iterator it = aPos.first;
if (it->type != sc::element_type_empty)