[Libreoffice-commits] core.git: filter/source

Armin Le Grand alg at apache.org
Fri Apr 11 02:20:07 PDT 2014


 filter/source/svg/svgexport.cxx |   72 ++++++++++++++++++++++++++++++++++++----
 filter/source/svg/svgfilter.cxx |    9 ++++-
 filter/source/svg/svgfilter.hxx |    1 
 3 files changed, 75 insertions(+), 7 deletions(-)

New commits:
commit f864c09a9d6bc2c28b30b32c6a0825b5628826b2
Author: Armin Le Grand <alg at apache.org>
Date:   Thu Apr 10 15:02:30 2014 +0000

    Resolves: i124608 when exporting selection...
    
    use selection boundrect as svg canvas
    
    (cherry picked from commit bfc1aa46b9ee9ad37728389eb636fc9fb5b9827f)
    
    Conflicts:
    	filter/source/svg/svgexport.cxx
    	filter/source/svg/svgfilter.cxx
    	filter/source/svg/svgfilter.hxx
    
    Change-Id: Ib10e785ebb611f0e33ea3ae799dfea20b05d250a

diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 5402ad4..0c1db7a 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -23,6 +23,7 @@
 #include "svgscript.hxx"
 #include "impsvgdialog.hxx"
 
+#include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
 #include <com/sun/star/text/textfield/Type.hpp>
 #include <com/sun/star/util/MeasureUnit.hpp>
@@ -46,6 +47,8 @@
 
 #include <boost/preprocessor/repetition/repeat.hpp>
 
+using namespace ::com::sun::star::graphic;
+using namespace ::com::sun::star::geometry;
 using namespace ::com::sun::star;
 
 
@@ -694,6 +697,7 @@ sal_Bool SVGFilter::implLookForFirstVisiblePage()
 sal_Bool SVGFilter::implExportDocument()
 {
     OUString         aAttr;
+    sal_Int32        nDocX = 0, nDocY = 0; // #i124608#
     sal_Int32        nDocWidth = 0, nDocHeight = 0;
     sal_Bool         bRet = sal_False;
     sal_Int32        nLastPage = mSelectedPages.getLength() - 1;
@@ -707,12 +711,60 @@ sal_Bool SVGFilter::implExportDocument()
     const Reference< XPropertySet >             xDefaultPagePropertySet( mxDefaultPage, UNO_QUERY );
     const Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
 
-    if( xDefaultPagePropertySet.is() )
+    // #i124608#
+    mbExportSelection = mbSinglePage && maShapeSelection.is() && maShapeSelection->getCount();
+
+    if(xDefaultPagePropertySet.is())
     {
         xDefaultPagePropertySet->getPropertyValue( "Width" ) >>= nDocWidth;
         xDefaultPagePropertySet->getPropertyValue( "Height" ) >>= nDocHeight;
     }
 
+    if(mbExportSelection)
+    {
+        // #i124608# create BoundRange and set nDocX, nDocY, nDocWidth and nDocHeight
+        basegfx::B2DRange aShapeRange;
+
+        uno::Reference< XPrimitiveFactory2D > xPrimitiveFactory = PrimitiveFactory2D::create( mxContext );
+
+        // 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() )
     {
         xExtDocHandler->unknown( SVG_DTD_STRING );
@@ -738,8 +790,17 @@ sal_Bool SVGFilter::implExportDocument()
     }
     #endif
 
+    // #i124608# set viewBox explicitely to the exported content
+    if (mbExportSelection)
+    {
+        aAttr = OUString::number(nDocX) + " " + OUString::number(nDocY) + " ";
+    }
+    else
+    {
+        aAttr = "0 0 ";
+    }
 
-    aAttr = "0 0 " + OUString::number( nDocWidth ) + " " + OUString::number( nDocHeight );
+    aAttr += OUString::number(nDocWidth) + " " + OUString::number(nDocHeight);
 
     msClipPathId = "presentation_clip_path";
     OUString sClipPathAttrValue = "url(#" + msClipPathId + ")";
@@ -817,9 +878,8 @@ sal_Bool SVGFilter::implExportDocument()
                 implExportTextEmbeddedBitmaps();
             }
 
-            bool bSelection = mbSinglePage && maShapeSelection.is() && maShapeSelection->getCount();
             // #i124608# export a given object selection, so no MasterPage export at all
-            if (!bSelection)
+            if (!mbExportSelection)
                 implExportMasterPages( mMasterPageTargets, 0, mMasterPageTargets.getLength() - 1 );
             implExportDrawPages( mSelectedPages, 0, nLastPage );
 
@@ -1449,7 +1509,7 @@ sal_Bool SVGFilter::implExportDrawPages( const SVGFilter::XDrawPageSequence & rx
     {
         Reference< XShapes > xShapes;
 
-        if (maShapeSelection.is() && maShapeSelection->getCount())
+        if (mbExportSelection)
         {
             // #i124608# export a given object selection
             xShapes = maShapeSelection;
@@ -1794,7 +1854,7 @@ sal_Bool SVGFilter::implExportShape( const Reference< XShape >& rxShape,
 
 sal_Bool SVGFilter::implCreateObjects()
 {
-    if (maShapeSelection.is() && maShapeSelection->getCount())
+    if (mbExportSelection)
     {
         // #i124608# export a given object selection
         if (mSelectedPages.getLength() && mSelectedPages[0].is())
diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx
index c47ce43..994329b 100644
--- a/filter/source/svg/svgfilter.cxx
+++ b/filter/source/svg/svgfilter.cxx
@@ -68,7 +68,14 @@ SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) :
     mbPresentation( sal_False ),
     mbSinglePage( sal_False ),
     mnVisiblePage( -1 ),
-    mpObjects( NULL )
+    mpObjects( NULL ),
+    mxSrcDoc(),
+    mxDstDoc(),
+    mxDefaultPage(),
+    maFilterData(),
+    maShapeSelection(),
+    mbExportSelection(false),
+    maOldFieldHdl()
 {
 }
 
diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx
index c0f6f9d0..e43eeaa 100644
--- a/filter/source/svg/svgfilter.hxx
+++ b/filter/source/svg/svgfilter.hxx
@@ -260,6 +260,7 @@ private:
     Sequence< PropertyValue >           maFilterData;
     // #i124608# explicit ShapeSelection for export when export of the selection is wanted
     Reference< XShapes >                maShapeSelection;
+    bool                                mbExportSelection;
     XDrawPageSequence                   mSelectedPages;
     XDrawPageSequence                   mMasterPageTargets;
 


More information about the Libreoffice-commits mailing list