diff options
author | Eike Rathke <erack@redhat.com> | 2017-07-24 22:31:34 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-07-24 23:32:49 +0200 |
commit | a7a99a574660fc62a9514b2ed3f8ddfe8ad8540c (patch) | |
tree | d88f51f469c5623e96c0bb93dfa1868a7f619a48 | |
parent | d30ae9c17ba51a55dd491f4c91712860b495f424 (diff) |
Export to PNG: use selection if Selection is selected
The SelectionOnly property from the export file dialog was not passed down from
GraphicExportFilter::filter() to DocumentToGraphicRenderer so that always
passed a component model instead of a selection object to the implementation of
XRenderable (getRendererCount(), getRenderer(), render())
Also have GraphicExportDialog consider the selection so the
DocumentToGraphicRenderer at its GraphicExportOptionsDialog calls XRenderable
the same.
Change-Id: I976bf16cf87cf5ca2678bdba7adfaf61c2063168
Reviewed-on: https://gerrit.libreoffice.org/40380
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | filter/source/graphic/GraphicExportDialog.cxx | 12 | ||||
-rw-r--r-- | filter/source/graphic/GraphicExportDialog.hxx | 1 | ||||
-rw-r--r-- | filter/source/graphic/GraphicExportFilter.cxx | 7 | ||||
-rw-r--r-- | filter/source/graphic/GraphicExportFilter.hxx | 1 | ||||
-rw-r--r-- | include/svtools/DocumentToGraphicRenderer.hxx | 5 | ||||
-rw-r--r-- | include/svtools/GraphicExportOptionsDialog.hxx | 3 | ||||
-rw-r--r-- | svtools/source/filter/DocumentToGraphicRenderer.cxx | 35 | ||||
-rw-r--r-- | svtools/source/filter/GraphicExportOptionsDialog.cxx | 5 |
8 files changed, 55 insertions, 14 deletions
diff --git a/filter/source/graphic/GraphicExportDialog.cxx b/filter/source/graphic/GraphicExportDialog.cxx index 4cd6346ae3c7..4f1d47acaf68 100644 --- a/filter/source/graphic/GraphicExportDialog.cxx +++ b/filter/source/graphic/GraphicExportDialog.cxx @@ -35,8 +35,9 @@ using namespace css::uno; using namespace css::beans; using namespace css::lang; -GraphicExportDialog::GraphicExportDialog( const Reference< XComponentContext >& ) - : meFieldUnit(FUNIT_NONE) +GraphicExportDialog::GraphicExportDialog( const Reference< XComponentContext >& ) : + meFieldUnit(FUNIT_NONE), + mbSelectionOnly(false) { } @@ -84,6 +85,10 @@ void GraphicExportDialog::setPropertyValues( const Sequence<PropertyValue>& aPro { maMediaDescriptor[ i ].Value >>= maFilterDataSequence; } + else if ( maMediaDescriptor[ i ].Name == "SelectionOnly" ) + { + maMediaDescriptor[ i ].Value >>= mbSelectionOnly; + } } } @@ -96,7 +101,8 @@ void GraphicExportDialog::setTitle( const OUString& aTitle ) sal_Int16 GraphicExportDialog::execute() { sal_Int16 nReturn = ui::dialogs::ExecutableDialogResults::CANCEL; - ScopedVclPtrInstance< GraphicExportOptionsDialog > graphicExportOptionsDialog( Application::GetDefDialogParent(), mxSourceDocument ); + ScopedVclPtrInstance< GraphicExportOptionsDialog > graphicExportOptionsDialog( Application::GetDefDialogParent(), + mxSourceDocument, mbSelectionOnly ); if (graphicExportOptionsDialog->Execute() == RET_OK ) { maFilterDataSequence = graphicExportOptionsDialog->getFilterData(); diff --git a/filter/source/graphic/GraphicExportDialog.hxx b/filter/source/graphic/GraphicExportDialog.hxx index bad51f9ae1ee..dcbb8e5bcd9d 100644 --- a/filter/source/graphic/GraphicExportDialog.hxx +++ b/filter/source/graphic/GraphicExportDialog.hxx @@ -48,6 +48,7 @@ class GraphicExportDialog : public cppu::WeakImplHelper OUString maDialogTitle; FieldUnit meFieldUnit; + bool mbSelectionOnly; public: diff --git a/filter/source/graphic/GraphicExportFilter.cxx b/filter/source/graphic/GraphicExportFilter.cxx index 15dea5400298..e4279513416e 100644 --- a/filter/source/graphic/GraphicExportFilter.cxx +++ b/filter/source/graphic/GraphicExportFilter.cxx @@ -26,6 +26,7 @@ GraphicExportFilter::GraphicExportFilter( const Reference<XComponentContext>& ) : mTargetWidth(0) , mTargetHeight(0) + , mbSelectionOnly(false) {} GraphicExportFilter::~GraphicExportFilter() @@ -56,6 +57,10 @@ void GraphicExportFilter::gatherProperties( const Sequence<PropertyValue>& rProp { aProperty.Value >>= mxOutputStream; } + else if ( aProperty.Name == "SelectionOnly" ) + { + aProperty.Value >>= mbSelectionOnly; + } } for ( sal_Int32 i = 0; i < mFilterDataSequence.getLength(); i++ ) @@ -93,7 +98,7 @@ sal_Bool SAL_CALL GraphicExportFilter::filter( const Sequence<PropertyValue>& rD { gatherProperties(rDescriptor); - DocumentToGraphicRenderer aRenderer( mxDocument ); + DocumentToGraphicRenderer aRenderer( mxDocument, mbSelectionOnly ); sal_Int32 aCurrentPage = aRenderer.getCurrentPageWriter(); Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(aCurrentPage); diff --git a/filter/source/graphic/GraphicExportFilter.hxx b/filter/source/graphic/GraphicExportFilter.hxx index 1f639ca9d775..1514bdefa774 100644 --- a/filter/source/graphic/GraphicExportFilter.hxx +++ b/filter/source/graphic/GraphicExportFilter.hxx @@ -48,6 +48,7 @@ class GraphicExportFilter : sal_Int32 mTargetWidth; sal_Int32 mTargetHeight; + bool mbSelectionOnly; public: explicit GraphicExportFilter( const Reference<XComponentContext>& rxContext ); diff --git a/include/svtools/DocumentToGraphicRenderer.hxx b/include/svtools/DocumentToGraphicRenderer.hxx index e43e47208198..2e6ee141773a 100644 --- a/include/svtools/DocumentToGraphicRenderer.hxx +++ b/include/svtools/DocumentToGraphicRenderer.hxx @@ -38,9 +38,12 @@ class SVT_DLLPUBLIC DocumentToGraphicRenderer css::uno::Reference<css::frame::XController> mxController; css::uno::Reference<css::view::XRenderable> mxRenderable; css::uno::Reference<css::awt::XToolkit> mxToolkit; + bool mbSelectionOnly; + + css::uno::Any getSelection() const; public: - DocumentToGraphicRenderer(const css::uno::Reference<css::lang::XComponent>& xDocument); + DocumentToGraphicRenderer(const css::uno::Reference<css::lang::XComponent>& xDocument, bool bSelectionOnly); ~DocumentToGraphicRenderer(); sal_Int32 getCurrentPageWriter( ); diff --git a/include/svtools/GraphicExportOptionsDialog.hxx b/include/svtools/GraphicExportOptionsDialog.hxx index 5524b96d4db3..2ed5dfdd7749 100644 --- a/include/svtools/GraphicExportOptionsDialog.hxx +++ b/include/svtools/GraphicExportOptionsDialog.hxx @@ -61,7 +61,8 @@ private: DECL_LINK( resolutionModifiedHandle, Edit&, void ); public: - GraphicExportOptionsDialog( vcl::Window* pWindow, const css::uno::Reference<css::lang::XComponent>& rxSourceDocument ); + GraphicExportOptionsDialog( vcl::Window* pWindow, + const css::uno::Reference<css::lang::XComponent>& rxSourceDocument, bool bSelectionOnly ); virtual ~GraphicExportOptionsDialog() override; virtual void dispose() override; css::uno::Sequence<css::beans::PropertyValue> getFilterData(); diff --git a/svtools/source/filter/DocumentToGraphicRenderer.cxx b/svtools/source/filter/DocumentToGraphicRenderer.cxx index a94b8febf3dd..9c23168b209a 100644 --- a/svtools/source/filter/DocumentToGraphicRenderer.cxx +++ b/svtools/source/filter/DocumentToGraphicRenderer.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/awt/XDevice.hpp> #include <com/sun/star/text/XPageCursor.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/beans/PropertyValues.hpp> #include <toolkit/helper/vclunohelper.hxx> @@ -37,12 +38,13 @@ using namespace css::uno; using namespace css::lang; using namespace css::beans; -DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent>& rxDocument ) : +DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent>& rxDocument, bool bSelectionOnly ) : mxDocument(rxDocument), mxModel( mxDocument, uno::UNO_QUERY ), mxController( mxModel->getCurrentController() ), mxRenderable (mxDocument, uno::UNO_QUERY ), - mxToolkit( VCLUnoHelper::CreateToolkit() ) + mxToolkit( VCLUnoHelper::CreateToolkit() ), + mbSelectionOnly( bSelectionOnly ) { } @@ -56,12 +58,34 @@ Size DocumentToGraphicRenderer::getDocumentSizeInPixels(sal_Int32 aCurrentPage) return Application::GetDefaultDevice()->LogicToPixel( aSize100mm, MapUnit::Map100thMM ); } +uno::Any DocumentToGraphicRenderer::getSelection() const +{ + uno::Any aSelection; + aSelection <<= mxDocument; // default: render whole document + if (mbSelectionOnly && mxController.is()) + { + try + { + uno::Reference< view::XSelectionSupplier > xSelSup( mxController, uno::UNO_QUERY); + if (xSelSup.is()) + { + uno::Any aViewSelection( xSelSup->getSelection()); + if (aViewSelection.hasValue()) + aSelection = aViewSelection; + } + } + catch (const uno::Exception&) + { + } + } + return aSelection; +} + Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 aCurrentPage) { Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) ); - uno::Any selection; - selection <<= mxDocument; + uno::Any selection( getSelection()); PropertyValues renderProperties; @@ -134,8 +158,7 @@ Graphic DocumentToGraphicRenderer::renderToGraphic( pOutputDev->Erase(); } - uno::Any aSelection; - aSelection <<= mxDocument; + uno::Any aSelection( getSelection()); mxRenderable->render(aCurrentPage - 1, aSelection, renderProps ); aMtf.Stop(); diff --git a/svtools/source/filter/GraphicExportOptionsDialog.cxx b/svtools/source/filter/GraphicExportOptionsDialog.cxx index e7591cc2b98d..cb7928ad104e 100644 --- a/svtools/source/filter/GraphicExportOptionsDialog.cxx +++ b/svtools/source/filter/GraphicExportOptionsDialog.cxx @@ -23,10 +23,11 @@ using namespace css::beans; using namespace css::lang; using namespace css::uno; -GraphicExportOptionsDialog::GraphicExportOptionsDialog(vcl::Window* pWindow, const Reference<XComponent>& rxSourceDocument) : +GraphicExportOptionsDialog::GraphicExportOptionsDialog(vcl::Window* pWindow, + const Reference<XComponent>& rxSourceDocument, bool bSelectionOnly) : ModalDialog(pWindow, "GraphicExporter", "svt/ui/GraphicExportOptionsDialog.ui"), mResolution(96.0), - mRenderer(rxSourceDocument) + mRenderer(rxSourceDocument, bSelectionOnly) { get(mpWidth, "spin-width"); get(mpHeight, "spin-height"); |