[Libreoffice-commits] core.git: 3 commits - sc/inc sc/source svtools/source
Eike Rathke
erack at redhat.com
Tue Aug 29 10:48:16 UTC 2017
sc/inc/docuno.hxx | 3
sc/source/ui/unoobj/docuno.cxx | 154 ++++++++++++++-----
svtools/source/filter/DocumentToGraphicRenderer.cxx | 8
svtools/source/filter/GraphicExportOptionsDialog.cxx | 7
4 files changed, 130 insertions(+), 42 deletions(-)
New commits:
commit 8c0c897c8cb92285e6461cc99ab0f2bbe15be65f
Author: Eike Rathke <erack at redhat.com>
Date: Tue Aug 29 11:15:57 2017 +0200
Export to PNG: init DPI with screen resolution, tdf#108317
This whole concept of "use a JPG dialog for PNG export" is nonsense anyway,
but.. as long as there isn't anything better at least have sensible defaults.
Change-Id: I0c074f7bb2989122aed039c739fd1813f371cbca
diff --git a/svtools/source/filter/GraphicExportOptionsDialog.cxx b/svtools/source/filter/GraphicExportOptionsDialog.cxx
index cb7928ad104e..cb7cb64c919e 100644
--- a/svtools/source/filter/GraphicExportOptionsDialog.cxx
+++ b/svtools/source/filter/GraphicExportOptionsDialog.cxx
@@ -18,6 +18,7 @@
*/
#include <svtools/GraphicExportOptionsDialog.hxx>
+#include <vcl/svapp.hxx>
using namespace css::beans;
using namespace css::lang;
@@ -61,6 +62,12 @@ void GraphicExportOptionsDialog::initialize()
{
mCurrentPage = mRenderer.getCurrentPageWriter();
mSize100mm = mRenderer.getDocumentSizeIn100mm(mCurrentPage);
+ // Init DPI with screen resolution, taking width. This may lead to unusual
+ // DPI values but ensures a size in pixels that matches the actual screen
+ // content, which is vital for example for Calc with drawing layer and
+ // pixel images.
+ Size aSizePixels = Application::GetDefaultDevice()->LogicToPixel( mSize100mm, MapUnit::Map100thMM );
+ mResolution = aSizePixels.Width() / getViewWidthInch();
}
IMPL_LINK_NOARG( GraphicExportOptionsDialog, widthModifiedHandle, Edit&, void )
commit d34fa1fc643cc49253e7340b3de1c87a49875e8a
Author: Eike Rathke <erack at redhat.com>
Date: Tue Aug 29 11:09:34 2017 +0200
Export to PNG: export selected cell range only, not as page, tdf#108317
Change-Id: If662f4ed360c702e572fc5d7b473eb53b9cb14d2
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 00ff88999bd0..67ee07440884 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -106,7 +106,8 @@ private:
bool FillRenderMarkData( const css::uno::Any& aSelection,
const css::uno::Sequence< css::beans::PropertyValue >& rOptions,
- ScMarkData& rMark, ScPrintSelectionStatus& rStatus, OUString& rPagesStr ) const;
+ ScMarkData& rMark, ScPrintSelectionStatus& rStatus, OUString& rPagesStr,
+ bool& rbRenderToGraphic ) const;
css::uno::Reference<css::uno::XAggregation> const & GetFormatter();
void HandleCalculateEvents();
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 67659f7076e4..b7b55293edd9 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1432,7 +1432,8 @@ static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, too
bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
const uno::Sequence< beans::PropertyValue >& rOptions,
ScMarkData& rMark,
- ScPrintSelectionStatus& rStatus, OUString& rPagesStr ) const
+ ScPrintSelectionStatus& rStatus, OUString& rPagesStr,
+ bool& rbRenderToGraphic ) const
{
OSL_ENSURE( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
OSL_ENSURE( pDocShell, "FillRenderMarkData: DocShell must be set" );
@@ -1477,6 +1478,10 @@ bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
{
rOptions[i].Value >>= xView;
}
+ else if ( rOptions[i].Name == "RenderToGraphic" )
+ {
+ rOptions[i].Value >>= rbRenderToGraphic;
+ }
}
// "Print Content" selection wins over "Selected Sheets" option
@@ -1613,7 +1618,8 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
ScMarkData aMark;
ScPrintSelectionStatus aStatus;
OUString aPagesStr;
- if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
+ bool bRenderToGraphic = false;
+ if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
return 0;
// The same ScPrintFuncCache object in pPrintFuncCache is used as long as
@@ -1650,6 +1656,11 @@ static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const OUString& rPa
return *aIter; // returns -1 if reached the end
}
+static bool lcl_renderSelectionToGraphic( bool bRenderToGraphic, const ScPrintSelectionStatus& rStatus )
+{
+ return bRenderToGraphic && rStatus.GetMode() == SC_PRINTSEL_RANGE;
+}
+
uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nSelRenderer,
const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& rOptions )
{
@@ -1665,7 +1676,8 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
OUString aPagesStr;
// #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
long nTotalPages = 0;
- if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
+ bool bRenderToGraphic = false;
+ if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
{
if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
{
@@ -1681,10 +1693,26 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
{
// getRenderer(0) is used to query the settings, so it must always return something
- SCTAB const nCurTab = 0; //! use current sheet from view?
- ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
- Size aTwips = aDefaultFunc.GetPageSize();
- awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
+ awt::Size aPageSize;
+ if (lcl_renderSelectionToGraphic( bRenderToGraphic, aStatus))
+ {
+ assert( aMark.IsMarked());
+ ScRange aRange;
+ aMark.GetMarkArea( aRange );
+ 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();
+ }
+ else
+ {
+ SCTAB const nCurTab = 0; //! use current sheet from view?
+ ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
+ Size aTwips = aDefaultFunc.GetPageSize();
+ aPageSize.Width = TwipsToHMM( aTwips.Width());
+ aPageSize.Height = TwipsToHMM( aTwips.Height());
+ }
uno::Sequence<beans::PropertyValue> aSequence( comphelper::InitPropertySequence({
{ SC_UNONAME_PAGESIZE, uno::Any(aPageSize) }
@@ -1712,24 +1740,41 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
aMark.GetMarkArea( aRange );
pSelRange = &aRange;
}
- ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
- pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
- aFunc.SetRenderFlag( true );
- Range aPageRange( nRenderer+1, nRenderer+1 );
- MultiSelection aPage( aPageRange );
- aPage.SetTotalRange( Range(0,RANGE_MAX) );
- aPage.Select( aPageRange );
+ awt::Size aPageSize;
+ bool bWasCellRange = false;
+ ScRange aCellRange;
+ if (lcl_renderSelectionToGraphic( bRenderToGraphic, aStatus))
+ {
+ bWasCellRange = true;
+ aCellRange = aRange;
+ 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();
+ }
+ else
+ {
+ ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
+ pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
+ aFunc.SetRenderFlag( true );
- long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
- long nTabStart = pPrintFuncCache->GetTabStart( nTab );
+ Range aPageRange( nRenderer+1, nRenderer+1 );
+ MultiSelection aPage( aPageRange );
+ aPage.SetTotalRange( Range(0,RANGE_MAX) );
+ aPage.Select( aPageRange );
- (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, nullptr );
+ long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
+ long nTabStart = pPrintFuncCache->GetTabStart( nTab );
- ScRange aCellRange;
- bool bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
- Size aTwips = aFunc.GetPageSize();
- awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
+ (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, nullptr );
+
+ bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
+ Size aTwips = aFunc.GetPageSize();
+ aPageSize.Width = TwipsToHMM( aTwips.Width());
+ aPageSize.Height = TwipsToHMM( aTwips.Height());
+ }
long nPropCount = bWasCellRange ? 3 : 2;
uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
@@ -1769,7 +1814,8 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
ScMarkData aMark;
ScPrintSelectionStatus aStatus;
OUString aPagesStr;
- if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
+ bool bRenderToGraphic = false;
+ if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
throw lang::IllegalArgumentException();
if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
@@ -1786,9 +1832,38 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
if ( !pDev )
throw lang::IllegalArgumentException();
- SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
ScDocument& rDoc = pDocShell->GetDocument();
+ ScRange aRange;
+ const ScRange* pSelRange = nullptr;
+ if ( aMark.IsMarked() )
+ {
+ aMark.GetMarkArea( aRange );
+ pSelRange = &aRange;
+ }
+
+ if (lcl_renderSelectionToGraphic( bRenderToGraphic, aStatus))
+ {
+ // Similar to as in and when calling ScTransferObj::PaintToDev()
+
+ Point aPoint;
+ tools::Rectangle aBound( aPoint, pDev->GetOutputSize());
+
+ ScViewData aViewData(nullptr,nullptr);
+ aViewData.InitData( &rDoc );
+
+ aViewData.SetTabNo( aRange.aStart.Tab() );
+ aViewData.SetScreen( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row() );
+
+ const double nPrintFactor = 1.0; /* XXX: currently (2017-08-28) is not evaluated */
+ // The bMetaFile argument maybe could be
+ // pDev->GetConnectMetaFile() != nullptr
+ // but for some yet unknow reason does not draw cell content if true.
+ ScPrintFunc::DrawToDev( &rDoc, pDev, nPrintFactor, aBound, &aViewData, false /*bMetaFile*/ );
+
+ return;
+ }
+
struct DrawViewKeeper
{
FmFormView* mpDrawView;
@@ -1803,6 +1878,7 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
}
} aDrawViewKeeper;
+ SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
ScDrawLayer* pModel = rDoc.GetDrawLayer();
if( pModel )
@@ -1812,14 +1888,6 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
aDrawViewKeeper.mpDrawView->SetPrintPreview();
}
- ScRange aRange;
- const ScRange* pSelRange = nullptr;
- if ( aMark.IsMarked() )
- {
- aMark.GetMarkArea( aRange );
- pSelRange = &aRange;
- }
-
// to increase performance, ScPrintState might be used here for subsequent
// pages of the same sheet
diff --git a/svtools/source/filter/DocumentToGraphicRenderer.cxx b/svtools/source/filter/DocumentToGraphicRenderer.cxx
index 9c23168b209a..6c95747ef09d 100644
--- a/svtools/source/filter/DocumentToGraphicRenderer.cxx
+++ b/svtools/source/filter/DocumentToGraphicRenderer.cxx
@@ -89,13 +89,15 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 aCurrentPage)
PropertyValues renderProperties;
- renderProperties.realloc( 3 );
+ renderProperties.realloc( 4 );
renderProperties[0].Name = "IsPrinter";
renderProperties[0].Value <<= true;
renderProperties[1].Name = "RenderDevice";
renderProperties[1].Value <<= xDevice;
renderProperties[2].Name = "View";
renderProperties[2].Value <<= mxController;
+ renderProperties[3].Name = "RenderToGraphic";
+ renderProperties[3].Value <<= true;
awt::Size aSize;
@@ -133,13 +135,15 @@ Graphic DocumentToGraphicRenderer::renderToGraphic(
double fScaleY = aTargetSizePixel.Height() / (double) aDocumentSizePixel.Height();
PropertyValues renderProps;
- renderProps.realloc( 3 );
+ renderProps.realloc( 4 );
renderProps[0].Name = "IsPrinter";
renderProps[0].Value <<= true;
renderProps[1].Name = "RenderDevice";
renderProps[1].Value <<= xDevice;
renderProps[2].Name = "View";
renderProps[2].Value <<= mxController;
+ renderProps[3].Name = "RenderToGraphic";
+ renderProps[3].Value <<= true;
GDIMetaFile aMtf;
commit 408b260c4f2873439473d8520352c1b3acaa157a
Author: Eike Rathke <erack at redhat.com>
Date: Mon Aug 28 15:54:41 2017 +0200
Add keeper for FmFormView* pDrawView
So later we can bail out at any point without having to manually keep track of it.
Change-Id: I4414456b870d4a82b4baf8209bdabcc5a8b63c35
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index c532ed6b3fda..67659f7076e4 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1789,15 +1789,27 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
ScDocument& rDoc = pDocShell->GetDocument();
- FmFormView* pDrawView = nullptr;
+ struct DrawViewKeeper
+ {
+ FmFormView* mpDrawView;
+ DrawViewKeeper() : mpDrawView(nullptr) {}
+ ~DrawViewKeeper()
+ {
+ if (mpDrawView)
+ {
+ mpDrawView->HideSdrPage();
+ delete mpDrawView;
+ }
+ }
+ } aDrawViewKeeper;
ScDrawLayer* pModel = rDoc.GetDrawLayer();
if( pModel )
{
- pDrawView = new FmFormView( pModel, pDev );
- pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
- pDrawView->SetPrintPreview();
+ aDrawViewKeeper.mpDrawView = new FmFormView( pModel, pDev );
+ aDrawViewKeeper.mpDrawView->ShowSdrPage(aDrawViewKeeper.mpDrawView->GetModel()->GetPage(nTab));
+ aDrawViewKeeper.mpDrawView->SetPrintPreview();
}
ScRange aRange;
@@ -1812,7 +1824,7 @@ 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( pDrawView );
+ aFunc.SetDrawView( aDrawViewKeeper.mpDrawView );
aFunc.SetRenderFlag( true );
if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
aFunc.SetExclusivelyDrawOleAndDrawObjects();
@@ -1945,10 +1957,6 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
}
rBookmarks.clear();
}
-
- if ( pDrawView )
- pDrawView->HideSdrPage();
- delete pDrawView;
}
// XLinkTargetSupplier
More information about the Libreoffice-commits
mailing list