You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by al...@apache.org on 2014/07/21 16:57:51 UTC

svn commit: r1612298 - in /openoffice/branches/AOO410/main/filter: ./ source/svg/svgexport.cxx source/svg/svgfilter.cxx source/svg/svgfilter.hxx

Author: alg
Date: Mon Jul 21 14:57:51 2014
New Revision: 1612298

URL: http://svn.apache.org/r1612298
Log:
i124608 Added functionality to export only selected objects in SVG export

Modified:
    openoffice/branches/AOO410/main/filter/   (props changed)
    openoffice/branches/AOO410/main/filter/source/svg/svgexport.cxx
    openoffice/branches/AOO410/main/filter/source/svg/svgfilter.cxx
    openoffice/branches/AOO410/main/filter/source/svg/svgfilter.hxx

Propchange: openoffice/branches/AOO410/main/filter/
------------------------------------------------------------------------------
  Merged /openoffice/trunk/main/filter:r1585498,1586325

Modified: openoffice/branches/AOO410/main/filter/source/svg/svgexport.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/AOO410/main/filter/source/svg/svgexport.cxx?rev=1612298&r1=1612297&r2=1612298&view=diff
==============================================================================
--- openoffice/branches/AOO410/main/filter/source/svg/svgexport.cxx (original)
+++ openoffice/branches/AOO410/main/filter/source/svg/svgexport.cxx Mon Jul 21 14:57:51 2014
@@ -31,6 +31,8 @@
 #include "svgfilter.hxx"
 #include "impsvgdialog.hxx"
 
+#include <com/sun/star/graphic/XPrimitiveFactory2D.hpp>
+
 #include <svx/unopage.hxx>
 #include <svx/unoshape.hxx>
 #include <svx/svdpage.hxx>
@@ -39,6 +41,8 @@
 #include <editeng/flditem.hxx>
 #include <editeng/numitem.hxx>
 
+using namespace ::com::sun::star::graphic;
+using namespace ::com::sun::star::geometry;
 using ::rtl::OUString;
 
 // -------------
@@ -213,6 +217,11 @@ sal_Bool SVGFilter::implExport( const Se
         {
             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
@@ -393,6 +402,7 @@ sal_Bool SVGFilter::implExportDocument( 
 				"SVGFilter::implExportDocument: invalid parameter" );
 
 	OUString		aAttr;
+	sal_Int32		nDocX = 0, nDocY = 0; // #124608#
 	sal_Int32		nDocWidth = 0, nDocHeight = 0;
 	sal_Int32		nVisible = -1, nVisibleMaster = -1;
 	sal_Bool 		bRet = sal_False;
@@ -402,12 +412,63 @@ sal_Bool SVGFilter::implExportDocument( 
 
 	const Reference< XPropertySet >             xDefaultPagePropertySet( mxDefaultPage, UNO_QUERY );
     const Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
- 	
-    if( xDefaultPagePropertySet.is() )
-	{
-		xDefaultPagePropertySet->getPropertyValue( B2UCONST( "Width" ) ) >>= nDocWidth;
-		xDefaultPagePropertySet->getPropertyValue( B2UCONST( "Height" ) ) >>= nDocHeight;
-	}
+
+    // #124608#
+    mbExportSelection = maShapeSelection.is() && maShapeSelection->getCount();
+
+    if(xDefaultPagePropertySet.is())
+    {
+        xDefaultPagePropertySet->getPropertyValue(B2UCONST("Width")) >>= nDocWidth;
+        xDefaultPagePropertySet->getPropertyValue(B2UCONST("Height")) >>= nDocHeight;
+    }
+
+    if(mbExportSelection)
+    {
+        // #124608# create BoundRange and set nDocX, nDocY, nDocWidth and nDocHeight
+        basegfx::B2DRange aShapeRange;
+
+        Reference< XPrimitiveFactory2D > xPrimitiveFactory(
+            mxMSF->createInstance(
+                String(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.graphic.PrimitiveFactory2D"))),
+                UNO_QUERY);
+
+        // use XPrimitiveFactory2D and go the way over getting the primitives; this
+        // will give better precision (doubles) and be based on the true object
+        // geometry. If needed aViewInformation may be expanded to carry a view
+        // resolution for which to prepare the geometry.
+        if(xPrimitiveFactory.is())
+        {
+            Reference< XShape > xShapeCandidate; 
+            const Sequence< PropertyValue > aViewInformation;
+            const Sequence< PropertyValue > aParams;
+
+            for(sal_Int32 a(0); a < maShapeSelection->getCount(); a++)
+            {
+                if((maShapeSelection->getByIndex(a) >>= xShapeCandidate) && xShapeCandidate.is())
+                {
+                    const Sequence< Reference< XPrimitive2D > > aPrimitiveSequence(
+                        xPrimitiveFactory->createPrimitivesFromXShape( xShapeCandidate, aParams ));
+                    const sal_Int32 nCount(aPrimitiveSequence.getLength());
+
+                    for(sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
+                    {
+                        const RealRectangle2D aRect(aPrimitiveSequence[nIndex]->getRange(aViewInformation));
+
+                        aShapeRange.expand(basegfx::B2DTuple(aRect.X1, aRect.Y1));
+                        aShapeRange.expand(basegfx::B2DTuple(aRect.X2, aRect.Y2));
+                    }
+                }
+            }
+        }
+
+        if(!aShapeRange.isEmpty())
+        {
+            nDocX = basegfx::fround(aShapeRange.getMinX());
+            nDocY = basegfx::fround(aShapeRange.getMinY());
+            nDocWidth  = basegfx::fround(aShapeRange.getWidth());
+            nDocHeight = basegfx::fround(aShapeRange.getHeight());
+        }
+    }
       
     if( xExtDocHandler.is() && !mpSVGExport->IsUseTinyProfile() )
     {
@@ -429,11 +490,23 @@ sal_Bool SVGFilter::implExportDocument( 
 	mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "height", aAttr );
 #endif
 
-    aAttr = B2UCONST( "0 0 " );
+    // #124608# set viewBox explicitely to the exported content
+    if(mbExportSelection)
+    {
+        aAttr = OUString::valueOf( nDocX );
+        aAttr += B2UCONST( " " );
+        aAttr += OUString::valueOf( nDocY );
+        aAttr += B2UCONST( " " );
+    }
+    else
+    {
+        aAttr = B2UCONST( "0 0 " );
+    }
+
     aAttr += OUString::valueOf( nDocWidth );
     aAttr += B2UCONST( " " );
     aAttr += OUString::valueOf( nDocHeight );
-	mpSVGExport->SetViewBox( Rectangle( Point(), Size( nDocWidth, nDocHeight ) ) );
+	mpSVGExport->SetViewBox( Rectangle( Point(nDocX, nDocY), Size( nDocWidth, nDocHeight ) ) );
     mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "viewBox", aAttr );
 	mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "preserveAspectRatio", B2UCONST( "xMidYMid" ) );
 	mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "fill-rule", B2UCONST( "evenodd" ) );
@@ -507,10 +580,19 @@ sal_Bool SVGFilter::implExportDocument( 
 
 	if( -1 != nVisible )
 	{
-		if( bSinglePage )
-			implExportPages( rxMasterPages, nVisibleMaster, nVisibleMaster, nVisibleMaster, sal_True );
-		else
-		{
+        if(bSinglePage)
+        {
+            if(mbExportSelection)
+            {
+                // #124608# export a given object selection, so no MasterPage export at all
+            }
+            else
+            {
+                implExportPages(rxMasterPages,nVisibleMaster,nVisibleMaster,nVisibleMaster,sal_True);
+            }
+        }
+        else
+        {
 			implGenerateMetaData( rxMasterPages, rxDrawPages );
 			implGenerateScript( rxMasterPages, rxDrawPages );
 			implExportPages( rxMasterPages, 0, rxMasterPages->getCount() - 1, nVisibleMaster, sal_True );
@@ -623,7 +705,17 @@ sal_Bool SVGFilter::implExportPages( con
 
 		if( xDrawPage.is() )
 		{
-			Reference< XShapes > xShapes( xDrawPage, UNO_QUERY );
+            Reference< XShapes > xShapes;
+
+            if(mbExportSelection)
+            {
+                // #124608# export a given object selection
+                xShapes = maShapeSelection;
+            }
+            else
+            {
+                xShapes = Reference< XShapes >( xDrawPage, UNO_QUERY );
+            }
 
 			if( xShapes.is() ) 
 			{
@@ -860,6 +952,7 @@ sal_Bool SVGFilter::implCreateObjects( c
 {
     if( SVG_EXPORT_ALLPAGES == nPageToExport )
     {
+        // export the whole document
 	    sal_Int32 i, nCount;
 
         for( i = 0, nCount = rxMasterPages->getCount(); i < nCount; ++i )
@@ -899,34 +992,43 @@ sal_Bool SVGFilter::implCreateObjects( c
         DBG_ASSERT( nPageToExport >= 0 && nPageToExport < rxDrawPages->getCount(),
                     "SVGFilter::implCreateObjects: invalid page number to export" );
 
-        Reference< XDrawPage > xDrawPage;
-
-  		rxDrawPages->getByIndex( nPageToExport ) >>= xDrawPage;
+        if(mbExportSelection)
+        {
+            // #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() )
-    		{
-    			Reference< XDrawPage > xMasterPage( xMasterTarget->getMasterPage() );
+            if(xDrawPage.is())
+            {
+                Reference< XMasterPageTarget > xMasterTarget(xDrawPage,UNO_QUERY);
 
-                if( xMasterPage.is() )
+                if(xMasterTarget.is())
                 {
-        			Reference< XShapes > xShapes( xMasterPage, UNO_QUERY );
+                    Reference< XDrawPage > xMasterPage(xMasterTarget->getMasterPage());
 
-        			implCreateObjectsFromBackground( xMasterPage );
+                    if(xMasterPage.is())
+                    {
+                        Reference< XShapes > xShapes(xMasterPage,UNO_QUERY);
+
+                        implCreateObjectsFromBackground(xMasterPage);
 
-        			if( xShapes.is() )
-        				implCreateObjectsFromShapes( xShapes );
+                        if(xShapes.is())
+                            implCreateObjectsFromShapes(xShapes);
+                    }
                 }
-            }
-       
-    	    Reference< XShapes > xShapes( xDrawPage, UNO_QUERY );
 
-  			if( xShapes.is() )
-  				implCreateObjectsFromShapes( xShapes );
-  		}
+                Reference< XShapes > xShapes(xDrawPage,UNO_QUERY);
+
+                if(xShapes.is())
+                    implCreateObjectsFromShapes(xShapes);
+            }
+        }
     }
 
 	return sal_True;

Modified: openoffice/branches/AOO410/main/filter/source/svg/svgfilter.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/AOO410/main/filter/source/svg/svgfilter.cxx?rev=1612298&r1=1612297&r2=1612298&view=diff
==============================================================================
--- openoffice/branches/AOO410/main/filter/source/svg/svgfilter.cxx (original)
+++ openoffice/branches/AOO410/main/filter/source/svg/svgfilter.cxx Mon Jul 21 14:57:51 2014
@@ -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
@@ -51,7 +52,22 @@ SVGFilter::SVGFilter( const Reference< X
 	mpSVGWriter( NULL ),
 	mpDefaultSdrPage( NULL ),
 	mpSdrModel( NULL ),
-    mbPresentation( sal_False )
+    mbPresentation( sal_False ),
+    mpObjects( NULL ),
+    mxSrcDoc(),
+#ifdef SOLAR_JAVA
+    mxDstDoc(),
+#endif
+    mxDefaultPage(),
+    maFilterData(),
+    maShapeSelection(),
+    mbExportSelection(false),
+    maUniqueIdVector(),
+    mnMasterSlideId(0),
+    mnSlideId(0),
+    mnDrawingGroupId(0),
+    mnDrawingId(0),
+    maOldFieldHdl()
 {
 }
 
@@ -86,7 +102,21 @@ sal_Bool SAL_CALL SVGFilter::filter( con
 #endif
     if( mxSrcDoc.is() )
 	{
-		uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), 
+        // #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,23 +140,67 @@ sal_Bool SAL_CALL SVGFilter::filter( con
 								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 )
-		{
-			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 );
-		}
-		
-		bRet = implExport( aNewDescriptor );
-	}
+
+        if(bSelectionOnly && bGotSelection && 0 == xShapes->getCount())
+        {
+            // #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);
+
+                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;
 

Modified: openoffice/branches/AOO410/main/filter/source/svg/svgfilter.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/AOO410/main/filter/source/svg/svgfilter.hxx?rev=1612298&r1=1612297&r2=1612298&view=diff
==============================================================================
--- openoffice/branches/AOO410/main/filter/source/svg/svgfilter.hxx (original)
+++ openoffice/branches/AOO410/main/filter/source/svg/svgfilter.hxx Mon Jul 21 14:57:51 2014
@@ -246,6 +246,11 @@ private:
 #endif
 	Reference< XDrawPage > 				mxDefaultPage;
     Sequence< PropertyValue >           maFilterData;
+
+    // #124608# explicit ShapeSelection for export when export of the selection is wanted
+    Reference< XShapes >                maShapeSelection;
+    bool                                mbExportSelection;
+
     UniqueIdVector                      maUniqueIdVector;
     sal_Int32                           mnMasterSlideId;
     sal_Int32                           mnSlideId;