[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - 2 commits - sc/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Wed Dec 13 13:59:27 UTC 2017
sc/source/ui/inc/printfun.hxx | 106 +++++++++------
sc/source/ui/unoobj/docuno.cxx | 28 +++-
sc/source/ui/view/printfun.cxx | 285 +++++++++++++++++++++--------------------
3 files changed, 239 insertions(+), 180 deletions(-)
New commits:
commit 0321fdb0f73dcf41c502878131e9c580bdd9c6de
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Sat Dec 2 01:17:15 2017 +0900
Calculate print page ranges only when needed, cache in print state
When printing or exporting PDF, we need to calculate the page
print (cell) ranges for the current zoom level (document size).
This is quite a expensive thing to do as you need to inspect
the properties of individual cells.
The calculation ideally needs to be done only once per printing
request, but because of the rendering UNO API, this was done
everytime ScPrintFunc was instantiated, which is for every page
twice (once getRenderer is called and then when render is called).
To fix this performance issue, the print page ranges need to be
carried from one call to ScPrintFunc to the other. There already
is a print state (ScPrintState) which is used for exactly that,
but it didn't do this for print page ranges.
With this, PDF export time in a test case decreased from 17 sec to
around 3 sec.
Reviewed-on: https://gerrit.libreoffice.org/45689
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 5684e53b931eaaac658bc3246ae1c3249e252fdb)
Change-Id: I97ade0e397960c5c98379e4bb28e57c5411ff757
Reviewed-on: https://gerrit.libreoffice.org/46373
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index 9a9f7ef44743..ef8b370adae7 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -65,6 +65,60 @@ struct ScPrintHFParam
const SvxShadowItem* pShadow;
};
+class ScPageRowEntry
+{
+private:
+ SCROW nStartRow;
+ SCROW nEndRow;
+ size_t nPagesX;
+ std::vector<bool> aHidden;
+ //! Cache Number of really visible?
+
+public:
+ ScPageRowEntry() { nStartRow = nEndRow = 0; nPagesX = 0; }
+
+ ScPageRowEntry(const ScPageRowEntry& r);
+ ScPageRowEntry& operator=(const ScPageRowEntry& r);
+
+ SCROW GetStartRow() const { return nStartRow; }
+ SCROW GetEndRow() const { return nEndRow; }
+ size_t GetPagesX() const { return nPagesX; }
+ void SetStartRow(SCROW n) { nStartRow = n; }
+ void SetEndRow(SCROW n) { nEndRow = n; }
+
+ void SetPagesX(size_t nNew);
+ void SetHidden(size_t nX);
+ bool IsHidden(size_t nX) const;
+
+ size_t CountVisible() const;
+};
+
+namespace sc
+{
+
+class PrintPageRanges
+{
+public:
+ PrintPageRanges();
+
+ std::vector<SCCOL> m_aPageEndX;
+ std::vector<SCROW> m_aPageEndY;
+ std::vector<ScPageRowEntry> m_aPageRows;
+
+ size_t m_nPagesX;
+ size_t m_nPagesY;
+ size_t m_nTotalY;
+
+ bool m_bCalculated;
+
+ void calculate(ScDocument* pDoc, ScPageTableParam const & rTableParam,
+ ScPageAreaParam const & rAreaParam,
+ SCROW nStartRow, SCROW nEndRow, SCCOL nStartCol, SCCOL nEndCol,
+ SCTAB nPrintTab);
+};
+
+}
+
struct ScPrintState // Save Variables from ScPrintFunc
{
SCTAB nPrintTab;
@@ -79,6 +133,14 @@ struct ScPrintState // Save Variables from ScPrintFunc
long nTotalPages;
long nPageStart;
long nDocPages;
+
+ // Additional state of page ranges
+ bool bSavedStateRanges;
+ size_t nTotalY;
+ std::vector<SCCOL> aPageEndX;
+ std::vector<SCROW> aPageEndY;
+ std::vector<ScPageRowEntry> aPageRows;
+
ScPrintState()
: nPrintTab(0)
, nStartCol(0)
@@ -92,37 +154,9 @@ struct ScPrintState // Save Variables from ScPrintFunc
, nTotalPages(0)
, nPageStart(0)
, nDocPages(0)
- {
- }
-};
-
-class ScPageRowEntry
-{
-private:
- SCROW nStartRow;
- SCROW nEndRow;
- size_t nPagesX;
- std::vector<bool> aHidden;
- //! Cache Number of really visible?
-
-public:
- ScPageRowEntry() { nStartRow = nEndRow = 0; nPagesX = 0; }
- ~ScPageRowEntry() { }
-
- ScPageRowEntry(const ScPageRowEntry& r);
- ScPageRowEntry& operator=(const ScPageRowEntry& r);
-
- SCROW GetStartRow() const { return nStartRow; }
- SCROW GetEndRow() const { return nEndRow; }
- size_t GetPagesX() const { return nPagesX; }
- void SetStartRow(SCROW n) { nStartRow = n; }
- void SetEndRow(SCROW n) { nEndRow = n; }
-
- void SetPagesX(size_t nNew);
- void SetHidden(size_t nX);
- bool IsHidden(size_t nX) const;
-
- size_t CountVisible() const;
+ , bSavedStateRanges(false)
+ , nTotalY(0)
+ {}
};
class ScPrintFunc
@@ -200,13 +234,7 @@ private:
SCCOL nEndCol;
SCROW nEndRow;
- std::vector< SCCOL > maPageEndX;
- std::vector< SCROW > maPageEndY;
- std::vector< ScPageRowEntry> maPageRows;
-
- size_t nPagesX;
- size_t nPagesY;
- size_t nTotalY;
+ sc::PrintPageRanges m_aRanges;
ScHeaderEditEngine* pEditEngine;
SfxItemSet* pEditDefaults;
@@ -274,7 +302,7 @@ public:
void ResetBreaks( SCTAB nTab );
- void GetPrintState( ScPrintState& rState );
+ void GetPrintState(ScPrintState& rState, bool bSavePageRanges = false);
bool GetLastSourceRange( ScRange& rRange ) const;
sal_uInt16 GetLeftMargin() const{return nLeftMargin;}
sal_uInt16 GetRightMargin() const{return nRightMargin;}
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index c4c28780d9ae..286f9a407b54 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1089,6 +1089,7 @@ void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
}
DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
+ m_pPrintState.reset();
}
else if ( nId == SFX_HINT_DATACHANGED )
{
@@ -1096,7 +1097,7 @@ void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
// (if a broadcast is added to SetDrawModified, is has to be tested here, too)
DELETEZ( pPrintFuncCache );
-
+ m_pPrintState.reset();
// handle "OnCalculate" sheet events (search also for VBA event handlers)
if ( pDocShell )
{
@@ -1467,6 +1468,8 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
}
sal_Int32 nPages = pPrintFuncCache->GetPageCount();
+ m_pPrintState.reset();
+
sal_Int32 nSelectCount = nPages;
if ( !aPagesStr.isEmpty() )
{
@@ -1583,7 +1586,7 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
if (!m_pPrintState)
{
m_pPrintState.reset(new ScPrintState());
- pPrintFunc->GetPrintState(*m_pPrintState);
+ pPrintFunc->GetPrintState(*m_pPrintState, true);
}
long nPropCount = bWasCellRange ? 3 : 2;
@@ -1669,11 +1672,16 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
// to increase performance, ScPrintState might be used here for subsequent
// pages of the same sheet
- ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
- aFunc.SetDrawView( pDrawView );
- aFunc.SetRenderFlag( true );
+ std::unique_ptr<ScPrintFunc> pPrintFunc;
+ if (m_pPrintState)
+ pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, &aStatus.GetOptions()));
+ else
+ pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions()));
+
+ pPrintFunc->SetDrawView(pDrawView);
+ pPrintFunc->SetRenderFlag( true );
if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
- aFunc.SetExclusivelyDrawOleAndDrawObjects();
+ pPrintFunc->SetExclusivelyDrawOleAndDrawObjects();
Range aPageRange( nRenderer+1, nRenderer+1 );
MultiSelection aPage( aPageRange );
@@ -1709,7 +1717,13 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
}
}
- (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, true, nullptr );
+ (void)pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, true, nullptr );
+
+ if (!m_pPrintState)
+ {
+ m_pPrintState.reset(new ScPrintState());
+ pPrintFunc->GetPrintState(*m_pPrintState, true);
+ }
// resolve the hyperlinks for PDF export
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 5b109edefbd9..2398f41ee45a 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -221,9 +221,6 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTa
mbHasPrintRange(true),
nTabPages ( 0 ),
nTotalPages ( 0 ),
- nPagesX(0),
- nPagesY(0),
- nTotalY(0),
pPageData ( pData )
{
pDev = pPrinter.get();
@@ -241,9 +238,6 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
bPrintCurrentTable ( false ),
bMultiArea ( false ),
mbHasPrintRange(true),
- nPagesX(0),
- nPagesY(0),
- nTotalY(0),
pPageData ( nullptr )
{
pDev = pPrinter.get();
@@ -254,14 +248,22 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
nEndCol = rState.nEndCol;
nEndRow = rState.nEndRow;
nZoom = rState.nZoom;
- nPagesX = rState.nPagesX;
- nPagesY = rState.nPagesY;
+ m_aRanges.m_nPagesX = rState.nPagesX;
+ m_aRanges.m_nPagesY = rState.nPagesY;
nTabPages = rState.nTabPages;
nTotalPages = rState.nTotalPages;
nPageStart = rState.nPageStart;
nDocPages = rState.nDocPages;
bState = true;
+ if (rState.bSavedStateRanges)
+ {
+ m_aRanges.m_nTotalY = rState.nTotalY;
+ m_aRanges.m_aPageEndX = rState.aPageEndX;
+ m_aRanges.m_aPageEndY = rState.aPageEndY;
+ m_aRanges.m_aPageRows = rState.aPageRows;
+ m_aRanges.m_bCalculated = true;
+ }
aSrcOffset = pPrinter->PixelToLogic(pPrinter->GetPageOffsetPixel(), MAP_100TH_MM);
Construct( pOptions );
}
@@ -283,9 +285,6 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
mbHasPrintRange(true),
nTabPages ( 0 ),
nTotalPages ( 0 ),
- nPagesX(0),
- nPagesY(0),
- nTotalY(0),
pPageData ( nullptr )
{
pDev = pOutDev;
@@ -302,9 +301,6 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
bPrintCurrentTable ( false ),
bMultiArea ( false ),
mbHasPrintRange(true),
- nPagesX(0),
- nPagesY(0),
- nTotalY(0),
pPageData ( nullptr )
{
pDev = pOutDev;
@@ -315,18 +311,27 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
nEndCol = rState.nEndCol;
nEndRow = rState.nEndRow;
nZoom = rState.nZoom;
- nPagesX = rState.nPagesX;
- nPagesY = rState.nPagesY;
+ m_aRanges.m_nPagesX = rState.nPagesX;
+ m_aRanges.m_nPagesY = rState.nPagesY;
nTabPages = rState.nTabPages;
nTotalPages = rState.nTotalPages;
nPageStart = rState.nPageStart;
nDocPages = rState.nDocPages;
bState = true;
+ if (rState.bSavedStateRanges)
+ {
+ m_aRanges.m_nTotalY = rState.nTotalY;
+ m_aRanges.m_aPageEndX = rState.aPageEndX;
+ m_aRanges.m_aPageEndY = rState.aPageEndY;
+ m_aRanges.m_aPageRows = rState.aPageRows;
+ m_aRanges.m_bCalculated = true;
+ }
+
Construct( pOptions );
}
-void ScPrintFunc::GetPrintState( ScPrintState& rState )
+void ScPrintFunc::GetPrintState(ScPrintState& rState, bool bSavePageRanges)
{
rState.nPrintTab = nPrintTab;
rState.nStartCol = nStartCol;
@@ -334,12 +339,20 @@ void ScPrintFunc::GetPrintState( ScPrintState& rState )
rState.nEndCol = nEndCol;
rState.nEndRow = nEndRow;
rState.nZoom = nZoom;
- rState.nPagesX = nPagesX;
- rState.nPagesY = nPagesY;
+ rState.nPagesX = m_aRanges.m_nPagesX;
+ rState.nPagesY = m_aRanges.m_nPagesY;
rState.nTabPages = nTabPages;
rState.nTotalPages = nTotalPages;
rState.nPageStart = nPageStart;
rState.nDocPages = nDocPages;
+ if (bSavePageRanges)
+ {
+ rState.bSavedStateRanges = true;
+ rState.nTotalY = m_aRanges.m_nTotalY;
+ rState.aPageEndX = m_aRanges.m_aPageEndX;
+ rState.aPageEndY = m_aRanges.m_aPageEndY;
+ rState.aPageRows = m_aRanges.m_aPageRows;
+ }
}
bool ScPrintFunc::GetLastSourceRange( ScRange& rRange ) const
@@ -358,23 +371,23 @@ void ScPrintFunc::FillPageData()
rData.SetPrintRange( ScRange( nStartCol, nStartRow, nPrintTab,
nEndCol, nEndRow, nPrintTab ) );
// #i123672#
- if(maPageEndX.empty())
+ if(m_aRanges.m_aPageEndX.empty())
{
OSL_ENSURE(false, "vector access error for maPageEndX (!)");
}
else
{
- rData.SetPagesX( nPagesX, &maPageEndX[0]);
+ rData.SetPagesX( m_aRanges.m_nPagesX, &m_aRanges.m_aPageEndX[0]);
}
// #i123672#
- if(maPageEndY.empty())
+ if(m_aRanges.m_aPageEndY.empty())
{
OSL_ENSURE(false, "vector access error for maPageEndY (!)");
}
else
{
- rData.SetPagesY( nTotalY, &maPageEndY[0]);
+ rData.SetPagesY( m_aRanges.m_nTotalY, &m_aRanges.m_aPageEndY[0]);
}
// Settings
@@ -2466,13 +2479,13 @@ long ScPrintFunc::CountPages() // sets also nPagesX, nP
{
CalcZoom(i);
if ( aTableParam.bSkipEmpty )
- for (nY=0; nY<nPagesY; nY++)
+ for (nY=0; nY< m_aRanges.m_nPagesY; nY++)
{
- OSL_ENSURE(nY < maPageRows.size(), "vector access error for maPageRows (!)");
- nPages += maPageRows[nY].CountVisible();
+ OSL_ENSURE(nY < m_aRanges.m_aPageRows.size(), "vector access error for aPageRows");
+ nPages += m_aRanges.m_aPageRows[nY].CountVisible();
}
else
- nPages += ((long) nPagesX) * nPagesY;
+ nPages += ((long) m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
if ( pPageData )
FillPageData();
}
@@ -2481,13 +2494,13 @@ long ScPrintFunc::CountPages() // sets also nPagesX, nP
{
CalcZoom(RANGENO_NORANGE); // calculate Zoom
if ( aTableParam.bSkipEmpty )
- for (nY=0; nY<nPagesY; nY++)
+ for (nY=0; nY<m_aRanges.m_nPagesY; nY++)
{
- OSL_ENSURE(nY < maPageRows.size(), "vector access error for maPageRows (!)");
- nPages += maPageRows[nY].CountVisible();
+ OSL_ENSURE(nY < m_aRanges.m_aPageRows.size(), "vector access error for aPageRows");
+ nPages += m_aRanges.m_aPageRows[nY].CountVisible();
}
else
- nPages += ((long) nPagesX) * nPagesY;
+ nPages += ((long) m_aRanges.m_nPagesX) * m_aRanges.m_nPagesY;
if ( pPageData )
FillPageData();
}
@@ -2495,7 +2508,7 @@ long ScPrintFunc::CountPages() // sets also nPagesX, nP
}
else
{
- nPagesX = nPagesY = nTotalY = 0;
+ m_aRanges.m_nPagesX = m_aRanges.m_nPagesY = m_aRanges.m_nTotalY = 0;
return 0;
}
}
@@ -2674,16 +2687,16 @@ long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,
if (aTableParam.bTopDown) // top-bottom
{
nX1 = nStartCol;
- for (nCountX=0; nCountX<nPagesX; nCountX++)
+ for (nCountX=0; nCountX<m_aRanges.m_nPagesX; nCountX++)
{
- OSL_ENSURE(nCountX < maPageEndX.size(), "vector access error for maPageEndX (!)");
- nX2 = maPageEndX[nCountX];
- for (nCountY=0; nCountY<nPagesY; nCountY++)
+ OSL_ENSURE(nCountX < m_aRanges.m_aPageEndX.size(), "vector access error for aPageEndX (!)");
+ nX2 = m_aRanges.m_aPageEndX[nCountX];
+ for (nCountY=0; nCountY<m_aRanges.m_nPagesY; nCountY++)
{
- OSL_ENSURE(nCountY < maPageRows.size(), "vector access error for maPageRows (!)");
- nY1 = maPageRows[nCountY].GetStartRow();
- nY2 = maPageRows[nCountY].GetEndRow();
- if ( !aTableParam.bSkipEmpty || !maPageRows[nCountY].IsHidden(nCountX) )
+ OSL_ENSURE(nCountY < m_aRanges.m_aPageRows.size(), "vector access error for aPageRows (!)");
+ nY1 = m_aRanges.m_aPageRows[nCountY].GetStartRow();
+ nY2 = m_aRanges.m_aPageRows[nCountY].GetEndRow();
+ if ( !aTableParam.bSkipEmpty || !m_aRanges.m_aPageRows[nCountY].IsHidden(nCountX) )
{
if ( rPageRanges.IsSelected( nPageNo+nStartPage+1 ) )
{
@@ -2699,17 +2712,17 @@ long ScPrintFunc::DoPrint( const MultiSelection& rPageRanges,
}
else // left to right
{
- for (nCountY=0; nCountY<nPagesY; nCountY++)
+ for (nCountY=0; nCountY<m_aRanges.m_nPagesY; nCountY++)
{
- OSL_ENSURE(nCountY < maPageRows.size(), "vector access error for maPageRows (!)");
- nY1 = maPageRows[nCountY].GetStartRow();
- nY2 = maPageRows[nCountY].GetEndRow();
+ OSL_ENSURE(nCountY < m_aRanges.m_aPageRows.size(), "vector access error for aPageRows");
+ nY1 = m_aRanges.m_aPageRows[nCountY].GetStartRow();
+ nY2 = m_aRanges.m_aPageRows[nCountY].GetEndRow();
nX1 = nStartCol;
- for (nCountX=0; nCountX<nPagesX; nCountX++)
+ for (nCountX=0; nCountX<m_aRanges.m_nPagesX; nCountX++)
{
- OSL_ENSURE(nCountX < maPageEndX.size(), "vector access error for maPageEndX (!)");
- nX2 = maPageEndX[nCountX];
- if ( !aTableParam.bSkipEmpty || !maPageRows[nCountY].IsHidden(nCountX) )
+ OSL_ENSURE(nCountX < m_aRanges.m_aPageEndX.size(), "vector access error for aPageEndX");
+ nX2 = m_aRanges.m_aPageEndX[nCountX];
+ if ( !aTableParam.bSkipEmpty || !m_aRanges.m_aPageRows[nCountY].IsHidden(nCountX) )
{
if ( rPageRanges.IsSelected( nPageNo+nStartPage+1 ) )
{
@@ -2775,7 +2788,7 @@ void ScPrintFunc::CalcZoom( sal_uInt16 nRangeNo ) // calcu
if (!AdjustPrintArea(false)) // empty
{
nZoom = 100;
- nPagesX = nPagesY = nTotalY = 0;
+ m_aRanges.m_nPagesX = m_aRanges.m_nPagesY = m_aRanges.m_nTotalY = 0;
return;
}
@@ -2808,7 +2821,7 @@ void ScPrintFunc::CalcZoom( sal_uInt16 nRangeNo ) // calcu
break;
CalcPages();
- bool bFitsPage = (nPagesX * nPagesY <= nPagesToFit);
+ bool bFitsPage = (m_aRanges.m_nPagesX * m_aRanges.m_nPagesY <= nPagesToFit);
if (bFitsPage)
{
@@ -2867,7 +2880,7 @@ void ScPrintFunc::CalcZoom( sal_uInt16 nRangeNo ) // calcu
break;
CalcPages();
- bool bFitsPage = ((!nW || (nPagesX <= nW)) && (!nH || (nPagesY <= nH)));
+ bool bFitsPage = ((!nW || (m_aRanges.m_nPagesX <= nW)) && (!nH || (m_aRanges.m_nPagesY <= nH)));
if (bFitsPage)
{
@@ -2975,7 +2988,7 @@ static void lcl_SetHidden( ScDocument* pDoc, SCTAB nPrintTab, ScPageRowEntry& rP
for (size_t i=0; i<nPagesX; i++)
{
- OSL_ENSURE(i < rPageEndX.size(), "vector access error for maPageEndX (!)");
+ OSL_ENSURE(i < rPageEndX.size(), "vector access error for aPageEndX");
SCCOL nEndCol = rPageEndX[i];
if ( pDoc->IsPrintEmpty( nPrintTab, nStartCol, nStartRow, nEndCol, nEndRow,
bLeftIsEmpty, &aTempRange, &aTempRect ) )
@@ -2992,64 +3005,88 @@ static void lcl_SetHidden( ScDocument* pDoc, SCTAB nPrintTab, ScPageRowEntry& rP
void ScPrintFunc::CalcPages() // calculates aPageRect and pages from nZoom
{
+ pDoc->SetPageSize(nPrintTab, GetDocPageSize());
+
+ m_aRanges.calculate(pDoc, aTableParam, aAreaParam, nStartRow, nEndRow, nStartCol, nEndCol, nPrintTab);
+}
+
+namespace sc
+{
+
+PrintPageRanges::PrintPageRanges()
+ : m_nPagesX(0)
+ , m_nPagesY(0)
+ , m_nTotalY(0)
+ , m_bCalculated(false)
+{}
+
+void PrintPageRanges::calculate(ScDocument* pDoc, ScPageTableParam const & rTableParam,
+ ScPageAreaParam const & rAreaParam,
+ SCROW nStartRow, SCROW nEndRow,
+ SCCOL nStartCol, SCCOL nEndCol,
+ SCTAB nPrintTab)
+{
+ // Already calculated?
+ if (m_bCalculated)
+ return;
+
// #i123672# use dynamic mem to react on size changes
- if (maPageEndX.size() < MAXCOL+1)
+ if (m_aPageEndX.size() < MAXCOL+1)
{
- maPageEndX.resize(MAXCOL+1, SCCOL());
+ m_aPageEndX.resize(MAXCOL+1, SCCOL());
}
- pDoc->SetPageSize( nPrintTab, GetDocPageSize() );
- if (aAreaParam.bPrintArea)
+ if (rAreaParam.bPrintArea)
{
- ScRange aRange( nStartCol, nStartRow, nPrintTab, nEndCol, nEndRow, nPrintTab );
- pDoc->UpdatePageBreaks( nPrintTab, &aRange );
+ ScRange aRange(nStartCol, nStartRow, nPrintTab, nEndCol, nEndRow, nPrintTab);
+ pDoc->UpdatePageBreaks(nPrintTab, &aRange);
}
else
{
- pDoc->UpdatePageBreaks( nPrintTab ); // else, end is marked
+ pDoc->UpdatePageBreaks(nPrintTab); // else, end is marked
}
- const size_t nRealCnt = nEndRow-nStartRow+1;
+ const size_t nRealCnt = nEndRow - nStartRow + 1;
// #i123672# use dynamic mem to react on size changes
- if (maPageEndY.size() < nRealCnt+1)
+ if (m_aPageEndY.size() < nRealCnt+1)
{
- maPageEndY.resize(nRealCnt+1, SCROW());
+ m_aPageEndY.resize(nRealCnt + 1, SCROW());
}
// #i123672# use dynamic mem to react on size changes
- if (maPageRows.size() < nRealCnt+1)
+ if (m_aPageRows.size() < nRealCnt+1)
{
- maPageRows.resize(nRealCnt+1, ScPageRowEntry());
+ m_aPageRows.resize(nRealCnt+1, ScPageRowEntry());
}
// Page alignment/splitting after breaks in Col/RowFlags
// Of several breaks in a hidden area, only one counts.
- nPagesX = 0;
- nPagesY = 0;
- nTotalY = 0;
+ m_nPagesX = 0;
+ m_nPagesY = 0;
+ m_nTotalY = 0;
bool bVisCol = false;
- for (SCCOL i=nStartCol; i<=nEndCol; i++)
+ for (SCCOL i = nStartCol; i <= nEndCol; i++)
{
bool bHidden = pDoc->ColHidden(i, nPrintTab);
- bool bPageBreak = (pDoc->HasColBreak(i, nPrintTab) & BREAK_PAGE);
- if ( i>nStartCol && bVisCol && bPageBreak )
+ bool bPageBreak(pDoc->HasColBreak(i, nPrintTab) & BREAK_PAGE);
+ if (i > nStartCol && bVisCol && bPageBreak)
{
- OSL_ENSURE(nPagesX < maPageEndX.size(), "vector access error for maPageEndX (!)");
- maPageEndX[nPagesX] = i-1;
- ++nPagesX;
+ OSL_ENSURE(m_nPagesX < m_aPageEndX.size(), "vector access error for aPageEndX");
+ m_aPageEndX[m_nPagesX] = i-1;
+ ++m_nPagesX;
bVisCol = false;
}
if (!bHidden)
bVisCol = true;
}
- if (bVisCol) // also at the end, no empty pages
+ if (bVisCol) // also at the end, no empty pages
{
- OSL_ENSURE(nPagesX < maPageEndX.size(), "vector access error for maPageEndX (!)");
- maPageEndX[nPagesX] = nEndCol;
- ++nPagesX;
+ OSL_ENSURE(m_nPagesX < m_aPageEndX.size(), "vector access error for aPageEndX");
+ m_aPageEndX[m_nPagesX] = nEndCol;
+ ++m_nPagesX;
}
bool bVisRow = false;
@@ -3068,22 +3105,21 @@ void ScPrintFunc::CalcPages() // calculates aPageRect and pages fr
if (bPageBreak)
nNextPageBreak = pRowBreakIter->next();
- if (nRow > nStartRow && bVisRow && bPageBreak )
+ if (nRow > nStartRow && bVisRow && bPageBreak)
{
- OSL_ENSURE(nTotalY < maPageEndY.size(), "vector access error for maPageEndY (!)");
- maPageEndY[nTotalY] = nRow-1;
- ++nTotalY;
+ OSL_ENSURE(m_nTotalY < m_aPageEndY.size(), "vector access error for rPageEndY");
+ m_aPageEndY[m_nTotalY] = nRow - 1;
+ ++m_nTotalY;
- if ( !aTableParam.bSkipEmpty ||
- !pDoc->IsPrintEmpty( nPrintTab, nStartCol, nPageStartRow, nEndCol, nRow-1 ) )
+ if (!rTableParam.bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nRow-1))
{
- OSL_ENSURE(nPagesY < maPageRows.size(), "vector access error for maPageRows (!)");
- maPageRows[nPagesY].SetStartRow( nPageStartRow );
- maPageRows[nPagesY].SetEndRow( nRow-1 );
- maPageRows[nPagesY].SetPagesX( nPagesX );
- if (aTableParam.bSkipEmpty)
- lcl_SetHidden( pDoc, nPrintTab, maPageRows[nPagesY], nStartCol, maPageEndX );
- ++nPagesY;
+ OSL_ENSURE(m_nPagesY < m_aPageRows.size(), "vector access error for rPageRows");
+ m_aPageRows[m_nPagesY].SetStartRow(nPageStartRow);
+ m_aPageRows[m_nPagesY].SetEndRow(nRow - 1);
+ m_aPageRows[m_nPagesY].SetPagesX(m_nPagesX);
+ if (rTableParam.bSkipEmpty)
+ lcl_SetHidden(pDoc, nPrintTab, m_aPageRows[m_nPagesY], nStartCol, m_aPageEndX);
+ ++m_nPagesY;
}
nPageStartRow = nRow;
@@ -3111,22 +3147,24 @@ void ScPrintFunc::CalcPages() // calculates aPageRect and pages fr
if (bVisRow)
{
- OSL_ENSURE(nTotalY < maPageEndY.size(), "vector access error for maPageEndY (!)");
- maPageEndY[nTotalY] = nEndRow;
- ++nTotalY;
+ OSL_ENSURE(m_nTotalY < m_aPageEndY.size(), "vector access error for maPageEndY");
+ m_aPageEndY[m_nTotalY] = nEndRow;
+ ++m_nTotalY;
- if ( !aTableParam.bSkipEmpty ||
- !pDoc->IsPrintEmpty( nPrintTab, nStartCol, nPageStartRow, nEndCol, nEndRow ) )
+ if (!rTableParam.bSkipEmpty || !pDoc->IsPrintEmpty(nPrintTab, nStartCol, nPageStartRow, nEndCol, nEndRow))
{
- OSL_ENSURE(nPagesY < maPageRows.size(), "vector access error for maPageRows (!)");
- maPageRows[nPagesY].SetStartRow( nPageStartRow );
- maPageRows[nPagesY].SetEndRow( nEndRow );
- maPageRows[nPagesY].SetPagesX( nPagesX );
- if (aTableParam.bSkipEmpty)
- lcl_SetHidden( pDoc, nPrintTab, maPageRows[nPagesY], nStartCol, maPageEndX );
- ++nPagesY;
+ OSL_ENSURE(m_nPagesY < m_aPageRows.size(), "vector access error for maPageRows");
+ m_aPageRows[m_nPagesY].SetStartRow(nPageStartRow);
+ m_aPageRows[m_nPagesY].SetEndRow(nEndRow);
+ m_aPageRows[m_nPagesY].SetPagesX(m_nPagesX);
+ if (rTableParam.bSkipEmpty)
+ lcl_SetHidden(pDoc, nPrintTab, m_aPageRows[m_nPagesY], nStartCol, m_aPageEndX);
+ ++m_nPagesY;
}
}
+
+ m_bCalculated = true;
}
+} // end namespace sc
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1af3c82471815cc612276c74a1fa767103f618f2
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Sat Dec 2 01:12:23 2017 +0900
Convert from unique_ptr<bool[]> to vector<bool>
Reviewed-on: https://gerrit.libreoffice.org/45688
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 75702b13961e545809ce1f2b5a45787f42ffcbc6)
Change-Id: Ie8b6a7bb3c3a624ece42bf57c93fe76f1f4ad3db
Reviewed-on: https://gerrit.libreoffice.org/46372
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index 38e697c44b45..9a9f7ef44743 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -102,12 +102,12 @@ private:
SCROW nStartRow;
SCROW nEndRow;
size_t nPagesX;
- bool* pHidden;
+ std::vector<bool> aHidden;
//! Cache Number of really visible?
public:
- ScPageRowEntry() { nStartRow = nEndRow = 0; nPagesX = 0; pHidden = nullptr; }
- ~ScPageRowEntry() { delete[] pHidden; }
+ ScPageRowEntry() { nStartRow = nEndRow = 0; nPagesX = 0; }
+ ~ScPageRowEntry() { }
ScPageRowEntry(const ScPageRowEntry& r);
ScPageRowEntry& operator=(const ScPageRowEntry& r);
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 6a1dd38be3ca..5b109edefbd9 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -100,42 +100,25 @@ ScPageRowEntry::ScPageRowEntry(const ScPageRowEntry& r)
nStartRow = r.nStartRow;
nEndRow = r.nEndRow;
nPagesX = r.nPagesX;
- if (r.pHidden && nPagesX)
- {
- pHidden = new bool[nPagesX];
- memcpy( pHidden, r.pHidden, nPagesX * sizeof(bool) );
- }
- else
- pHidden = nullptr;
+
+ aHidden = r.aHidden;
+ aHidden.resize(nPagesX, false);
}
ScPageRowEntry& ScPageRowEntry::operator=(const ScPageRowEntry& r)
{
- delete[] pHidden;
-
nStartRow = r.nStartRow;
nEndRow = r.nEndRow;
nPagesX = r.nPagesX;
- if (r.pHidden && nPagesX)
- {
- pHidden = new bool[nPagesX];
- memcpy( pHidden, r.pHidden, nPagesX * sizeof(bool) );
- }
- else
- pHidden = nullptr;
-
+ aHidden = r.aHidden;
+ aHidden.resize(nPagesX, false);
return *this;
}
void ScPageRowEntry::SetPagesX(size_t nNew)
{
- if (pHidden)
- {
- OSL_FAIL("SetPagesX nicht nach SetHidden");
- delete[] pHidden;
- pHidden = nullptr;
- }
nPagesX = nNew;
+ aHidden.resize(nPagesX, false);
}
void ScPageRowEntry::SetHidden(size_t nX)
@@ -146,28 +129,24 @@ void ScPageRowEntry::SetHidden(size_t nX)
--nPagesX;
else
{
- if (!pHidden)
- {
- pHidden = new bool[nPagesX];
- memset( pHidden, false, nPagesX * sizeof(bool) );
- }
- pHidden[nX] = true;
+ aHidden.resize(nPagesX, false);
+ aHidden[nX] = true;
}
}
}
bool ScPageRowEntry::IsHidden(size_t nX) const
{
- return nX>=nPagesX || ( pHidden && pHidden[nX] ); //! inline?
+ return nX >= nPagesX || aHidden[nX]; //! inline?
}
size_t ScPageRowEntry::CountVisible() const
{
- if ( pHidden )
+ if (!aHidden.empty())
{
size_t nVis = 0;
for (size_t i=0; i<nPagesX; i++)
- if (!pHidden[i])
+ if (!aHidden[i])
++nVis;
return nVis;
}
More information about the Libreoffice-commits
mailing list