Kaydet (Commit) 5684e53b authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

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.

Change-Id: I97ade0e397960c5c98379e4bb28e57c5411ff757
Reviewed-on: https://gerrit.libreoffice.org/45689Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 75702b13
......@@ -66,6 +66,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;
......@@ -80,6 +134,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)
......@@ -93,36 +155,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(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 +235,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 +303,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;}
......
......@@ -1296,6 +1296,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 == SfxHintId::DataChanged )
{
......@@ -1303,6 +1304,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 )
......@@ -1660,6 +1662,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() )
{
......@@ -1806,7 +1810,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);
}
aPageSize.Width = TwipsToHMM( aTwips.Width());
......@@ -1929,11 +1933,16 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
// pages of the same sheet
ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
aFunc.SetDrawView( aDrawViewKeeper.mpDrawView );
aFunc.SetRenderFlag( true );
std::unique_ptr<ScPrintFunc, o3tl::default_delete<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( aDrawViewKeeper.mpDrawView );
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 );
......@@ -1969,7 +1978,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
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment