sc/inc/column.hxx               |    3 +
 sc/source/core/data/column2.cxx |   31 ++++++++++++++++++++
 sc/source/core/data/table1.cxx  |   61 +++++++++++++++++++++++++++++++++++++++-
 sc/source/core/data/table2.cxx  |    4 ++
 sc/source/ui/view/printfun.cxx  |    2 +
 5 files changed, 100 insertions(+), 1 deletion(-)

New commits:
commit c07d2ea9589cf794bd300697e8a40bf9f94a8346
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Mar 28 14:31:21 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Apr 5 03:45:59 2022 +0200

    sc: make printing of Sparklines work
    
    Sparkline cells don't contain any data, so they would be ignored
    if we don't include them in the function that determine if there
    is any data in a cell or not.
    This is the main reason why the cells weren't drawn when printing
    as they had no data so they were ignored.
    
    Change-Id: I7849f1a00c9421616b8af90bdac368fd63ae1087
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132514
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index f60ea22cbc30..0a2b16c809d9 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -677,6 +677,9 @@ public:
     void CopyCellSparklinesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& 
rDestCol, SCROW nRowOffsetDest = 0) const;
     void DuplicateSparklines(SCROW nStartRow, size_t nDataSize, ScColumn& 
rDestCol,
                              sc::ColumnBlockPosition& rDestBlockPos, SCROW 
nRowOffsetDest = 0) const;
+    bool HasSparklines() const;
+    SCROW GetSparklinesMaxRow() const;
+    SCROW GetSparklinesMinRow() const;
 
     // cell notes
     ScPostIt* GetCellNote( SCROW nRow );
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 787059376f44..d8e1003beaff 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2088,6 +2088,37 @@ void ScColumn::DuplicateSparklines(SCROW nStartRow, 
size_t nDataSize, ScColumn&
     rDestBlockPos.miSparklinePos = rDestCol.maSparklines.begin();
 }
 
+bool ScColumn::HasSparklines() const
+{
+    if (maSparklines.block_size() == 1 && maSparklines.begin()->type == 
sc::element_type_empty)
+        return false; // all elements are empty
+    return true; // otherwise some must be sparklines
+}
+
+SCROW ScColumn::GetSparklinesMaxRow() const
+{
+    SCROW maxRow = 0;
+    for (const auto& rSparkline : maSparklines)
+    {
+        if (rSparkline.type == sc::element_type_sparkline)
+            maxRow = rSparkline.position + rSparkline.size - 1;
+    }
+    return maxRow;
+}
+
+SCROW ScColumn::GetSparklinesMinRow() const
+{
+    SCROW minRow = 0;
+    sc::SparklineStoreType::const_iterator it = 
std::find_if(maSparklines.begin(), maSparklines.end(),
+        [](const auto& rSparkline)
+        {
+            return rSparkline.type == sc::element_type_sparkline;
+        });
+    if (it != maSparklines.end())
+        minRow = it->position;
+    return minRow;
+}
+
 // Notes
 
 ScPostIt* ScColumn::GetCellNote(SCROW nRow)
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 51f6d35710a7..5c35eba2fb9c 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -539,6 +539,20 @@ bool ScTable::GetCellArea( SCCOL& rEndCol, SCROW& rEndRow 
) const
                     nMaxX = i;
                 }
             }
+            if (aCol[i].HasSparklines())
+            {
+                SCROW maxSparklineRow = aCol[i].GetSparklinesMaxRow();
+                if (maxSparklineRow >= nMaxY)
+                {
+                    bFound = true;
+                    nMaxY = maxSparklineRow;
+                }
+                if (i > nMaxX)
+                {
+                    bFound = true;
+                    nMaxX = i;
+                }
+            }
     }
 
     rEndCol = nMaxX;
@@ -608,6 +622,20 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& 
rEndRow, bool bNotes, bool bC
                     nMaxX = i;
                 }
             }
+            if (aCol[i].HasSparklines())
+            {
+                SCROW maxSparklineRow = aCol[i].GetSparklinesMaxRow();
+                if (maxSparklineRow >= nMaxY)
+                {
+                    bFound = true;
+                    nMaxY = maxSparklineRow;
+                }
+                if (i > nMaxX)
+                {
+                    bFound = true;
+                    nMaxX = i;
+                }
+            }
         }
     }
 
@@ -695,8 +723,16 @@ bool ScTable::GetPrintAreaHor( SCROW nStartRow, SCROW 
nEndRow,
         if (!aCol[i].IsEmptyBlock( nStartRow, nEndRow ))        //TODO: bNotes 
??????
         {
             bFound = true;
-            if (i>nMaxX)
+            if (i > nMaxX)
+                nMaxX = i;
+        }
+        else if (aCol[i].HasSparklines())
+        {
+            if (i > nMaxX)
+            {
+                bFound = true;
                 nMaxX = i;
+            }
         }
     }
 
@@ -742,6 +778,15 @@ bool ScTable::GetPrintAreaVer( SCCOL nStartCol, SCCOL 
nEndCol,
                 nMaxY = maxNoteRow;
             }
         }
+        if (aCol[i].HasSparklines())
+        {
+            SCROW maxNoteRow = aCol[i].GetSparklinesMaxRow();
+            if (maxNoteRow > nMaxY)
+            {
+                bFound = true;
+                nMaxY = maxNoteRow;
+            }
+        }
     }
 
     rEndRow = nMaxY;
@@ -804,6 +849,20 @@ bool ScTable::GetDataStart( SCCOL& rStartCol, SCROW& 
rStartRow ) const
                 nMinX = i;
             }
         }
+        if (aCol[i].HasSparklines())
+        {
+            SCROW minSparkline = aCol[i].GetSparklinesMinRow();
+            if (minSparkline <= nMinY)
+            {
+                bFound = true;
+                nMinY = minSparkline;
+            }
+            if (i < nMinX)
+            {
+                bFound = true;
+                nMinX = i;
+            }
+        }
     }
     rStartCol = nMinX;
     rStartRow = nMinY;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 010f324d2c74..d0d9598fa952 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2352,6 +2352,10 @@ bool ScTable::IsBlockEmpty( SCCOL nCol1, SCROW nRow1, 
SCCOL nCol2, SCROW nRow2,
     for (SCCOL i=nCol1; i<=nCol2 && bEmpty; i++)
     {
         bEmpty = aCol[i].IsEmptyBlock( nRow1, nRow2 );
+        if (bEmpty)
+        {
+            bEmpty = aCol[i].IsSparklinesEmptyBlock(nRow1, nRow2);
+        }
         if (!bIgnoreNotes && bEmpty)
         {
             bEmpty = aCol[i].IsNotesEmptyBlock(nRow1, nRow2);
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index d0fdb87edc12..fc75fb3bbc80 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -615,6 +615,7 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* 
pDev, double /* nPri
 
     aOutputData.DrawShadow();
     aOutputData.DrawFrame(*pDev);
+    aOutputData.DrawSparklines(*pDev);
     aOutputData.DrawStrings();
 
     if (!bMetaFile && pViewData)
@@ -1672,6 +1673,7 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL 
nX2, SCROW nY2,
     {
         aOutputData.DrawExtraShadow( bShLeft, bShTop, bShRight, bShBottom );
         aOutputData.DrawFrame(*pDev);
+        aOutputData.DrawSparklines(*pDev);
         aOutputData.DrawStrings();
         aOutputData.DrawEdit(false);
     }

Reply via email to