summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-09-30 20:39:39 +0300
committerMuhammet Kara <muhammet.kara@collabora.com>2019-10-11 10:13:22 +0200
commitc11d96f0b521ee7df77576963b60178d2c40431b (patch)
tree7141da3e6e1f440cc16f74ea19a3bd25883fffcf /sc/source
parente6c4674418cd7423943599f3bd3cdf1643284690 (diff)
Handle SinglePageSheets option for pdf export
When the single page sheets option is selected on the pdf export dialog of Calc, a pdf for general preview of the document is created, which is not meant for printing. Each sheet is exported as a single page, thus causing the resulting pdf to have pages with different sizes. This is a follow-up to commit 079cd016408d54d91 Change-Id: I038761f06bbf4b0425df89bcda4ee111a61be1d5 Reviewed-on: https://gerrit.libreoffice.org/79895 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/80635 Tested-by: Jenkins
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/unoobj/docuno.cxx131
1 files changed, 127 insertions, 4 deletions
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 58fdad8890f2..e312f9e59ea5 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1594,13 +1594,22 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
maValidPages.clear();
sal_Int32 nContent = 0;
+ bool bSinglePageSheets = false;
for ( const auto& rValue : rOptions)
{
if ( rValue.Name == "PrintRange" )
{
rValue.Value >>= nContent;
- break;
}
+ else if ( rValue.Name == "SinglePageSheets" )
+ {
+ rValue.Value >>= bSinglePageSheets;
+ }
+ }
+
+ if (bSinglePageSheets)
+ {
+ return pDocShell->GetDocument().GetTableCount();
}
bool bIsPrintEvenPages = nContent != 3;
@@ -1660,6 +1669,7 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
// #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
long nTotalPages = 0;
bool bRenderToGraphic = false;
+ bool bSinglePageSheets = false;
if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
{
if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
@@ -1668,7 +1678,21 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
}
nTotalPages = pPrintFuncCache->GetPageCount();
}
+
+ for ( const auto& rValue : rOptions)
+ {
+ if ( rValue.Name == "SinglePageSheets" )
+ {
+ rValue.Value >>= bSinglePageSheets;
+ break;
+ }
+ }
+
+ if (bSinglePageSheets)
+ nTotalPages = pDocShell->GetDocument().GetTableCount();
+
sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
+
if ( nRenderer < 0 )
{
if ( nSelRenderer != 0 )
@@ -1713,7 +1737,9 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
// printer is used as device (just for page layout), draw view is not needed
SCTAB nTab;
- if ( !maValidPages.empty() )
+ if (bSinglePageSheets)
+ nTab = nSelRenderer;
+ else if ( !maValidPages.empty() )
nTab = pPrintFuncCache->GetTabForPage( maValidPages.at( nRenderer )-1 );
else
nTab = pPrintFuncCache->GetTabForPage( nRenderer );
@@ -1721,7 +1747,56 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
ScRange aRange;
const ScRange* pSelRange = nullptr;
- if ( aMark.IsMarked() )
+ if ( bSinglePageSheets )
+ {
+ awt::Size aPageSize;
+ SCCOL nStartCol;
+ SCROW nStartRow;
+ const ScDocument* pDocument = &pDocShell->GetDocument();
+ pDocument->GetDataStart( nTab, nStartCol, nStartRow );
+ SCCOL nEndCol;
+ SCROW nEndRow;
+ pDocument->GetPrintArea( nTab, nEndCol, nEndRow );
+
+ aRange.aStart = ScAddress(nStartCol, nStartRow, nTab);
+ aRange.aEnd = ScAddress(nEndCol, nEndRow, nTab);
+ pSelRange = &aRange;
+
+ table::CellRangeAddress aRangeAddress( nTab,
+ aRange.aStart.Col(), aRange.aStart.Row(),
+ aRange.aEnd.Col(), aRange.aEnd.Row() );
+ tools::Rectangle aMMRect( pDocShell->GetDocument().GetMMRect(
+ aRange.aStart.Col(), aRange.aStart.Row(),
+ aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab()));
+
+ aPageSize.Width = aMMRect.GetWidth();
+ aPageSize.Height = aMMRect.GetHeight();
+
+ awt::Size aCalcPageSize ( aMMRect.GetSize().Width(), aMMRect.GetSize().Height() );
+ awt::Point aCalcPagePos( aMMRect.getX(), aMMRect.getY() );
+
+ uno::Sequence<beans::PropertyValue> aSequence(5);
+ beans::PropertyValue* pArray = aSequence.getArray();
+ pArray[0].Name = SC_UNONAME_PAGESIZE;
+ pArray[0].Value <<= aPageSize;
+ // #i111158# all positions are relative to the whole page, including non-printable area
+ pArray[1].Name = SC_UNONAME_INC_NP_AREA;
+ pArray[1].Value <<= true;
+ pArray[2].Name = SC_UNONAME_SOURCERANGE;
+ pArray[2].Value <<= aRangeAddress;
+ pArray[3].Name = SC_UNONAME_CALCPAGESIZE;
+ pArray[3].Value <<= aCalcPageSize;
+ pArray[4].Name = SC_UNONAME_CALCPAGEPOS;
+ pArray[4].Value <<= aCalcPagePos;
+
+ if( ! pPrinterOptions )
+ pPrinterOptions.reset(new ScPrintUIOptions);
+ else
+ pPrinterOptions->SetDefaults();
+ pPrinterOptions->appendPrintUIOptions( aSequence );
+ return aSequence;
+ }
+ else if ( aMark.IsMarked() )
{
aMark.GetMarkArea( aRange );
pSelRange = &aRange;
@@ -1840,6 +1915,7 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
ScPrintSelectionStatus aStatus;
OUString aPagesStr;
bool bRenderToGraphic = false;
+ bool bSinglePageSheets = false;
if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
throw lang::IllegalArgumentException();
@@ -1848,6 +1924,19 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus ));
}
long nTotalPages = pPrintFuncCache->GetPageCount();
+
+ for ( const auto& rValue : rOptions)
+ {
+ if ( rValue.Name == "SinglePageSheets" )
+ {
+ rValue.Value >>= bSinglePageSheets;
+ break;
+ }
+ }
+
+ if (bSinglePageSheets)
+ nTotalPages = pDocShell->GetDocument().GetTableCount();
+
sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
if ( nRenderer < 0 )
throw lang::IllegalArgumentException();
@@ -1860,7 +1949,39 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
ScRange aRange;
const ScRange* pSelRange = nullptr;
- if ( aMark.IsMarked() )
+ if ( bSinglePageSheets )
+ {
+ awt::Size aPageSize;
+ SCCOL nStartCol;
+ SCROW nStartRow;
+ rDoc.GetDataStart( nSelRenderer, nStartCol, nStartRow );
+ SCCOL nEndCol;
+ SCROW nEndRow;
+ rDoc.GetPrintArea( nSelRenderer, nEndCol, nEndRow );
+
+ aRange.aStart = ScAddress(nStartCol, nStartRow, nSelRenderer);
+ aRange.aEnd = ScAddress(nEndCol, nEndRow, nSelRenderer);
+
+ tools::Rectangle aMMRect( pDocShell->GetDocument().GetMMRect(
+ aRange.aStart.Col(), aRange.aStart.Row(),
+ aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab()));
+
+ aPageSize.Width = aMMRect.GetWidth();
+ aPageSize.Height = aMMRect.GetHeight();
+
+ //Set visible tab
+ SCTAB nVisTab = rDoc.GetVisibleTab();
+ if (nVisTab != nSelRenderer)
+ {
+ nVisTab = nSelRenderer;
+ rDoc.SetVisibleTab(nVisTab);
+ }
+
+ pDocShell->DoDraw(pDev, Point(0,0), Size(aPageSize.Width, aPageSize.Height), JobSetup());
+
+ return;
+ }
+ else if ( aMark.IsMarked() )
{
aMark.GetMarkArea( aRange );
pSelRange = &aRange;
@@ -1902,6 +2023,8 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
} aDrawViewKeeper;
SCTAB nTab;
+ if (bSinglePageSheets)
+ nTab = nSelRenderer;
if ( !maValidPages.empty() )
nTab = pPrintFuncCache->GetTabForPage( maValidPages.at( nRenderer )-1 );
else