diff options
author | Eike Rathke <erack@redhat.com> | 2017-09-22 16:29:10 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-09-22 21:56:02 +0200 |
commit | 2d0d777fe8830a39a316b01e08864e4694a51964 (patch) | |
tree | e961caff734538fd05c1949edab0e9f9589d8419 | |
parent | 5f5458ee5959e563bb5c1fbe78a94429017d83f0 (diff) |
Export to PNG: selected shapes via drawing::GraphicExportFilter, tdf#108317
Change-Id: Id09d9b21b2e6c018dd199a1911a9125c118abec2
Reviewed-on: https://gerrit.libreoffice.org/42658
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | filter/source/graphic/GraphicExportFilter.cxx | 52 | ||||
-rw-r--r-- | filter/source/graphic/GraphicExportFilter.hxx | 11 |
2 files changed, 63 insertions, 0 deletions
diff --git a/filter/source/graphic/GraphicExportFilter.cxx b/filter/source/graphic/GraphicExportFilter.cxx index ba99893c6e7f..882e53f0cabd 100644 --- a/filter/source/graphic/GraphicExportFilter.cxx +++ b/filter/source/graphic/GraphicExportFilter.cxx @@ -19,6 +19,8 @@ #include "GraphicExportFilter.hxx" +#include <com/sun/star/drawing/GraphicExportFilter.hpp> + #include <vcl/graphicfilter.hxx> #include <svl/outstrm.hxx> #include <svtools/DocumentToGraphicRenderer.hxx> @@ -115,6 +117,22 @@ sal_Bool SAL_CALL GraphicExportFilter::filter( const Sequence<PropertyValue>& rD { gatherProperties(rDescriptor); + if (mbSelectionOnly && mxDocument.is()) + { + uno::Reference< frame::XModel > xModel( mxDocument, uno::UNO_QUERY); + if (xModel.is()) + { + uno::Reference< frame::XController > xController( xModel->getCurrentController()); + if (xController.is()) + { + uno::Reference< drawing::XShapes > xShapes; + uno::Reference< drawing::XShape > xShape; + if (DocumentToGraphicRenderer::isShapeSelected( xShapes, xShape, xController)) + return filterExportShape( rDescriptor, xShapes, xShape); + } + } + } + return filterRenderDocument(); } @@ -193,6 +211,40 @@ bool GraphicExportFilter::filterRenderDocument() const return false; } +bool GraphicExportFilter::filterExportShape( + const css::uno::Sequence< css::beans::PropertyValue > & rDescriptor, + const css::uno::Reference< css::drawing::XShapes > & rxShapes, + const css::uno::Reference< css::drawing::XShape > & rxShape ) const +{ + uno::Reference< lang::XComponent > xSourceDoc; + if (rxShapes.is()) + xSourceDoc.set( rxShapes, uno::UNO_QUERY_THROW ); + else if (rxShape.is()) + xSourceDoc.set( rxShape, uno::UNO_QUERY_THROW ); + if (!xSourceDoc.is()) + return false; + + uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = + drawing::GraphicExportFilter::create( mxContext ); + if (!xGraphicExporter.is()) + return false; + + // Need to replace the internal filter name with the short name + // (extension). + uno::Sequence< beans::PropertyValue > aDescriptor( rDescriptor); + for (sal_Int32 i = 0; i < aDescriptor.getLength(); ++i) + { + if (aDescriptor[i].Name == "FilterName") + { + aDescriptor[i].Value <<= mFilterExtension; + break; + } + } + + xGraphicExporter->setSourceDocument( xSourceDoc ); + return xGraphicExporter->filter( aDescriptor ); +} + void SAL_CALL GraphicExportFilter::cancel( ) { } diff --git a/filter/source/graphic/GraphicExportFilter.hxx b/filter/source/graphic/GraphicExportFilter.hxx index 9d213352c770..697592b82286 100644 --- a/filter/source/graphic/GraphicExportFilter.hxx +++ b/filter/source/graphic/GraphicExportFilter.hxx @@ -28,6 +28,13 @@ #include <cppuhelper/implbase.hxx> #include <comphelper/processfactory.hxx> +namespace com { namespace sun { namespace star { + namespace drawing { + class XShapes; + class XShape; + } +}}} + using namespace css; using namespace css::uno; using namespace css::lang; @@ -57,6 +64,10 @@ class GraphicExportFilter : css::uno::Any maQuality; bool filterRenderDocument() const; + bool filterExportShape( + const css::uno::Sequence< css::beans::PropertyValue > & rDescriptor, + const css::uno::Reference< css::drawing::XShapes > & rxShapes, + const css::uno::Reference< css::drawing::XShape > & rxShape ) const; public: explicit GraphicExportFilter( const Reference<XComponentContext>& rxContext ); |