filter/source/svg/svgexport.cxx | 76 ++++++++++++++++++++++++++++----------- filter/source/svg/svgfilter.cxx | 77 +++++++++++++++++++++++++++++++++++----- filter/source/svg/svgfilter.hxx | 4 ++ 3 files changed, 127 insertions(+), 30 deletions(-)
New commits: commit 42c2b0cecfae5845439e0392a399497062238b15 Author: Armin Le Grand <a...@apache.org> Date: Mon Apr 7 14:58:01 2014 +0000 i124608 Added functionality to export only selected objects in SVG export diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx index fe8ff08..0a05141 100644 --- a/filter/source/svg/svgexport.cxx +++ b/filter/source/svg/svgexport.cxx @@ -213,6 +213,11 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor ) { pValue[ i ].Value >>= maFilterData; } + else if( pValue[ i ].Name.equalsAscii( "ShapeSelection" ) ) + { + // #124608# read selection if given + pValue[ i ].Value >>= maShapeSelection; + } } // if no filter data is given use stored/prepared ones @@ -507,8 +512,17 @@ sal_Bool SVGFilter::implExportDocument( const Reference< XDrawPages >& rxMasterP if( -1 != nVisible ) { - if( bSinglePage ) - implExportPages( rxMasterPages, nVisibleMaster, nVisibleMaster, nVisibleMaster, sal_True ); + if(bSinglePage) + { + if(maShapeSelection.is() && maShapeSelection->getCount()) + { + // #124608# export a given object selection, so no MasterPage export at all + } + else + { + implExportPages(rxMasterPages,nVisibleMaster,nVisibleMaster,nVisibleMaster,sal_True); + } + } else { implGenerateMetaData( rxMasterPages, rxDrawPages ); @@ -623,7 +637,17 @@ sal_Bool SVGFilter::implExportPages( const Reference< XDrawPages >& rxPages, if( xDrawPage.is() ) { - Reference< XShapes > xShapes( xDrawPage, UNO_QUERY ); + Reference< XShapes > xShapes; + + if(maShapeSelection.is() && maShapeSelection->getCount()) + { + // #124608# export a given object selection + xShapes = maShapeSelection; + } + else + { + xShapes = Reference< XShapes >( xDrawPage, UNO_QUERY ); + } if( xShapes.is() ) { @@ -860,6 +884,7 @@ sal_Bool SVGFilter::implCreateObjects( const Reference< XDrawPages >& rxMasterPa { if( SVG_EXPORT_ALLPAGES == nPageToExport ) { + // export the whole document sal_Int32 i, nCount; for( i = 0, nCount = rxMasterPages->getCount(); i < nCount; ++i ) @@ -899,34 +924,43 @@ sal_Bool SVGFilter::implCreateObjects( const Reference< XDrawPages >& rxMasterPa DBG_ASSERT( nPageToExport >= 0 && nPageToExport < rxDrawPages->getCount(), "SVGFilter::implCreateObjects: invalid page number to export" ); - Reference< XDrawPage > xDrawPage; - - rxDrawPages->getByIndex( nPageToExport ) >>= xDrawPage; + if(maShapeSelection.is() && maShapeSelection->getCount()) + { + // #124608# export a given object selection + implCreateObjectsFromShapes(maShapeSelection); + } + else + { + // export a given xDrawPage + Reference< XDrawPage > xDrawPage; - if( xDrawPage.is() ) - { - Reference< XMasterPageTarget > xMasterTarget( xDrawPage, UNO_QUERY ); + rxDrawPages->getByIndex(nPageToExport) >>= xDrawPage; - if( xMasterTarget.is() ) + if(xDrawPage.is()) { - Reference< XDrawPage > xMasterPage( xMasterTarget->getMasterPage() ); + Reference< XMasterPageTarget > xMasterTarget(xDrawPage,UNO_QUERY); - if( xMasterPage.is() ) + if(xMasterTarget.is()) { - Reference< XShapes > xShapes( xMasterPage, UNO_QUERY ); + Reference< XDrawPage > xMasterPage(xMasterTarget->getMasterPage()); + + if(xMasterPage.is()) + { + Reference< XShapes > xShapes(xMasterPage,UNO_QUERY); - implCreateObjectsFromBackground( xMasterPage ); + implCreateObjectsFromBackground(xMasterPage); - if( xShapes.is() ) - implCreateObjectsFromShapes( xShapes ); + if(xShapes.is()) + implCreateObjectsFromShapes(xShapes); + } } - } - Reference< XShapes > xShapes( xDrawPage, UNO_QUERY ); + Reference< XShapes > xShapes(xDrawPage,UNO_QUERY); - if( xShapes.is() ) - implCreateObjectsFromShapes( xShapes ); - } + if(xShapes.is()) + implCreateObjectsFromShapes(xShapes); + } + } } return sal_True; diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx index e7f3a3f..4b7bedd 100644 --- a/filter/source/svg/svgfilter.cxx +++ b/filter/source/svg/svgfilter.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/drawing/XDrawView.hpp> #include <com/sun/star/frame/XDesktop.hdl> #include <com/sun/star/frame/XController.hdl> +#include <com/sun/star/view/XSelectionSupplier.hpp> #define SVG_FILTER_SERVICE_NAME "com.sun.star.comp.Draw.SVGFilter" #define SVG_FILTER_IMPLEMENTATION_NAME SVG_FILTER_SERVICE_NAME @@ -86,6 +87,20 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto #endif if( mxSrcDoc.is() ) { + // #124608# detext selection + sal_Bool bSelectionOnly = sal_False; + bool bGotSelection(false); + Reference< drawing::XShapes > xShapes; + + // #124608# extract Single selection wanted from dialog return values + for ( sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++ ) + { + if ( rDescriptor[nInd].Name.equalsAscii( "SelectionOnly" ) ) + { + rDescriptor[nInd].Value >>= bSelectionOnly; + } + } + uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), uno::UNO_QUERY); if( xDesktop.is() ) @@ -110,22 +125,66 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Number" ) ) ) >>= nCurrentPageNumber; } } + + if(bSelectionOnly) + { + // #124608# when selection only is wanted, get the current object selection + // from the DrawView + Reference< view::XSelectionSupplier > xSelection (xController, UNO_QUERY); + + if (xSelection.is()) + { + uno::Any aSelection; + + if(xSelection->getSelection() >>= aSelection) + { + bGotSelection = (sal_True == ( aSelection >>= xShapes )); + } + } + } } } } - Sequence< PropertyValue > aNewDescriptor( rDescriptor ); - - if( nCurrentPageNumber > 0 ) + if(bSelectionOnly && bGotSelection && 0 == xShapes->getCount()) { - const sal_uInt32 nOldLength = rDescriptor.getLength(); - - aNewDescriptor.realloc( nOldLength + 1 ); - aNewDescriptor[ nOldLength ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PagePos" ) ); - aNewDescriptor[ nOldLength ].Value <<= static_cast< sal_Int16 >( nCurrentPageNumber - 1 ); + // #124608# export selection, got xShapes but no shape selected -> nothing + // to export, we are done (maybe return true, but a hint that nothing was done + // may be useful; it may have happened by error) + bRet = sal_False; } + else + { + Sequence< PropertyValue > aNewDescriptor(rDescriptor); + const bool bSinglePage(nCurrentPageNumber > 0); + + if(bSinglePage || bGotSelection) + { + const sal_uInt32 nOldLength = rDescriptor.getLength(); + sal_uInt32 nInsert(nOldLength); - bRet = implExport( aNewDescriptor ); + aNewDescriptor.realloc(nOldLength + (bSinglePage ? 1 : 0) + (bGotSelection ? 1 : 0)); + + if(bSinglePage) + { + aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PagePos")); + aNewDescriptor[nInsert].Value <<= static_cast<sal_Int16>(nCurrentPageNumber - 1); + nInsert++; + } + + if(bGotSelection) + { + // #124608# add retrieved ShapeSelection if export of only selected shapes is wanted + // so that the filter implementation can use it + aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShapeSelection")); + aNewDescriptor[nInsert].Value <<= xShapes; + // reactivate this when you add other properties to aNewDescriptor + // nInsert++; + } + } + + bRet = implExport(aNewDescriptor); + } } else bRet = sal_False; diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx index 97a660e..e11e28f 100644 --- a/filter/source/svg/svgfilter.hxx +++ b/filter/source/svg/svgfilter.hxx @@ -246,6 +246,10 @@ private: #endif Reference< XDrawPage > mxDefaultPage; Sequence< PropertyValue > maFilterData; + + // #124608# explicit ShapeSelection for export when export of the selection is wanted + Reference< XShapes > maShapeSelection; + UniqueIdVector maUniqueIdVector; sal_Int32 mnMasterSlideId; sal_Int32 mnSlideId; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits