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

Armin Le Grand alg at apache.org
Tue Apr 8 07:46:50 PDT 2014


 filter/source/flash/swfexporter.cxx |   73 ++++++++++++++++++++++++----
 filter/source/flash/swfexporter.hxx |   22 +++++++-
 filter/source/flash/swffilter.cxx   |   92 +++++++++++++++++++++++++++++++-----
 3 files changed, 161 insertions(+), 26 deletions(-)

New commits:
commit 70ba557865d1d528fba0899732fc3e67e71d8f55
Author: Armin Le Grand <alg at apache.org>
Date:   Tue Apr 8 12:24:24 2014 +0000

    Resolves: #i56084# added support for export selection in swf export
    
    (cherry picked from commit 9cfa6464411e39e1cbaef8f0c7c64bddbed4033b)
    
    Conflicts:
    	filter/source/flash/swfexporter.cxx
    	filter/source/flash/swfexporter.hxx
    	filter/source/flash/swffilter.cxx
    
    Change-Id: I987c43af54982daea532c8f4f915eb2bd91ea267

diff --git a/filter/source/flash/swfexporter.cxx b/filter/source/flash/swfexporter.cxx
index 50ddc3b..26c8197 100644
--- a/filter/source/flash/swfexporter.cxx
+++ b/filter/source/flash/swfexporter.cxx
@@ -94,10 +94,21 @@ void PageInfo::addShape( ShapeInfo* pShapeInfo )
 }
 #endif
 
+FlashExporter::FlashExporter(
+    const Reference< XComponentContext > &rxContext,
 
+    // #i56084# variables for selection export
+    const Reference< XShapes >& rxSelectedShapes,
+    const Reference< XDrawPage >& rxSelectedDrawPage,
 
-FlashExporter::FlashExporter(const Reference< XComponentContext > &rxContext, sal_Int32 nJPEGCompressMode, sal_Bool bExportOLEAsJPEG)
+    sal_Int32 nJPEGCompressMode,
+    sal_Bool bExportOLEAsJPEG)
     : mxContext(rxContext)
+    // #i56084# variables for selection export
+    , mxSelectedShapes(rxSelectedShapes)
+    , mxSelectedDrawPage(rxSelectedDrawPage)
+    , mbExportSelection(false)
+
     , mpWriter(NULL)
     , mnDocWidth(0)
     , mnDocHeight(0)
@@ -106,6 +117,11 @@ FlashExporter::FlashExporter(const Reference< XComponentContext > &rxContext, sa
     , mbPresentation(true)
     , mnPageNumber(-1)
 {
+    if(mxSelectedDrawPage.is() && mxSelectedShapes.is() && mxSelectedShapes->getCount())
+    {
+        // #i56084# determine export selection
+        mbExportSelection = true;
+    }
 }
 
 
@@ -145,7 +161,16 @@ sal_Bool FlashExporter::exportAll( Reference< XComponent > xDoc, Reference< XOut
         return sal_False;
 
     Reference< XDrawPage > xDrawPage;
-    xDrawPages->getByIndex(0) >>= xDrawPage;
+
+    // #i56084# set xDrawPage directly when exporting selection
+    if(mbExportSelection)
+    {
+        xDrawPage = mxSelectedDrawPage;
+    }
+    else
+    {
+        xDrawPages->getByIndex(0) >>= xDrawPage;
+    }
 
     Reference< XPropertySet > xProp( xDrawPage, UNO_QUERY );
     try
@@ -164,17 +189,29 @@ sal_Bool FlashExporter::exportAll( Reference< XComponent > xDoc, Reference< XOut
         return false; // no writer, no cookies
     }
 
-    const sal_Int32 nPageCount = xDrawPages->getCount();
+    // #i56084# nPageCount is 1 when exporting selection
+    const sal_Int32 nPageCount = mbExportSelection ? 1 : xDrawPages->getCount();
     sal_uInt16 nPage;
+
     if ( xStatusIndicator.is() )
-        xStatusIndicator->start( "Macromedia Flash (SWF)", nPageCount);
+    {
+        xStatusIndicator->start("Macromedia Flash (SWF)", nPageCount);
+    }
+
     for( nPage = 0; nPage < nPageCount; nPage++)
     {
+        // #i56084# keep PageNumber? We could determine the PageNumber of the single to-be-eported page
+        // when exporting the selection, but this is only used for swf internal, so no need to do so (AFAIK)
         mnPageNumber = nPage + 1;
 
         if ( xStatusIndicator.is() )
             xStatusIndicator->setValue( nPage );
-        xDrawPages->getByIndex(nPage) >>= xDrawPage;
+
+        // #i56084# get current xDrawPage when not exporting selection; else alraedy set above
+        if(!mbExportSelection)
+        {
+            xDrawPages->getByIndex(nPage) >>= xDrawPage;
+        }
 
         if( !xDrawPage.is())
             continue;
@@ -188,11 +225,25 @@ sal_Bool FlashExporter::exportAll( Reference< XComponent > xDoc, Reference< XOut
                 continue;
         }
 
-        exportBackgrounds( xDrawPage, nPage, false );
-        exportBackgrounds( xDrawPage, nPage, true );
+        // #i56084# no background when exporting selection
+        if(!mbExportSelection)
+        {
+            exportBackgrounds( xDrawPage, nPage, false );
+            exportBackgrounds( xDrawPage, nPage, true );
+        }
 
         maPagesMap[nPage].mnForegroundID = mpWriter->startSprite();
-        exportDrawPageContents( xDrawPage, false, false );
+
+        // #i56084# directly export selection in export selection mode
+        if(mbExportSelection)
+        {
+            exportShapes( mxSelectedShapes, false, false );
+        }
+        else
+        {
+            exportDrawPageContents( xDrawPage, false, false );
+        }
+
         mpWriter->endSprite();
 
         // AS: If the background is different than the previous slide,
@@ -467,7 +518,7 @@ sal_uInt16 FlashExporter::exportMasterPageObjects(sal_uInt16 nPage, Reference< X
 
 /** export's the definition of the shapes inside this drawing page and adds the
     shape infos to the current PageInfo */
-void FlashExporter::exportDrawPageContents( Reference< XDrawPage >& xPage, bool bStream, bool bMaster )
+void FlashExporter::exportDrawPageContents( const Reference< XDrawPage >& xPage, bool bStream, bool bMaster )
 {
     Reference< XShapes > xShapes( xPage, UNO_QUERY );
     exportShapes(xShapes, bStream, bMaster);
@@ -477,7 +528,7 @@ void FlashExporter::exportDrawPageContents( Reference< XDrawPage >& xPage, bool
 
 /** export's the definition of the shapes inside this XShapes container and adds the
     shape infos to the current PageInfo */
-void FlashExporter::exportShapes( Reference< XShapes >& xShapes, bool bStream, bool bMaster )
+void FlashExporter::exportShapes( const Reference< XShapes >& xShapes, bool bStream, bool bMaster )
 {
     OSL_ENSURE( (xShapes->getCount() <= 0xffff), "overflow in FlashExporter::exportDrawPageContents()" );
 
@@ -509,7 +560,7 @@ void FlashExporter::exportShapes( Reference< XShapes >& xShapes, bool bStream, b
 
 
 /** export this shape definition and adds it's info to the current PageInfo */
-void FlashExporter::exportShape( Reference< XShape >& xShape, bool bMaster )
+void FlashExporter::exportShape( const Reference< XShape >& xShape, bool bMaster )
 {
     Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
     if( !xPropSet.is() )
diff --git a/filter/source/flash/swfexporter.hxx b/filter/source/flash/swfexporter.hxx
index f3ec8c8..ac8159a 100644
--- a/filter/source/flash/swfexporter.hxx
+++ b/filter/source/flash/swfexporter.hxx
@@ -150,7 +150,15 @@ typedef ::std::map<sal_uInt32, PageInfo> PageInfoMap;
 class FlashExporter
 {
 public:
-    FlashExporter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, sal_Int32 nJPEGCompressMode = -1, sal_Bool bExportOLEAsJPEG = false);
+    FlashExporter(
+        const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
+
+        // #i56084# variables for selection export
+        const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxSelectedShapes,
+        const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxSelectedDrawPage,
+
+        sal_Int32 nJPEGCompressMode = -1,
+        sal_Bool bExportOLEAsJPEG = false);
     ~FlashExporter();
 
     void Flush();
@@ -167,6 +175,12 @@ public:
 
 private:
     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
+
+    // #i56084# variables for selection export
+    const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > mxSelectedShapes;
+    const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > mxSelectedDrawPage;
+    bool mbExportSelection;
+
     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XGraphicExportFilter > mxGraphicExporter;
 
     PageInfoMap maPagesMap;
@@ -174,9 +188,9 @@ private:
     sal_uInt16 exportDrawPageBackground(sal_uInt16 nPage, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage);
     sal_uInt16 exportMasterPageObjects(sal_uInt16 nPage, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xMasterPage);
 
-    void exportDrawPageContents( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage, bool bStream, bool bMaster  );
-    void exportShapes( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xShapes, bool bStream, bool bMaster );
-    void exportShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape, bool bMaster);
+    void exportDrawPageContents( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage, bool bStream, bool bMaster  );
+    void exportShapes( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xShapes, bool bStream, bool bMaster );
+    void exportShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape, bool bMaster);
 
     sal_uInt32 ActionSummer(::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape);
     sal_uInt32 ActionSummer(::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xShapes);
diff --git a/filter/source/flash/swffilter.cxx b/filter/source/flash/swffilter.cxx
index 7af99f1..1aeac4f 100644
--- a/filter/source/flash/swffilter.cxx
+++ b/filter/source/flash/swffilter.cxx
@@ -29,6 +29,13 @@
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
 #include <com/sun/star/io/XOutputStream.hpp>
+
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XShapes.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XController.hdl>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+
 #include <cppuhelper/implbase1.hxx>
 #include <cppuhelper/implbase4.hxx>
 #include <cppuhelper/supportsservice.hxx>
@@ -45,6 +52,7 @@ using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::drawing;
 using namespace ::com::sun::star::presentation;
 using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::view;
 
 using ::com::sun::star::lang::XComponent;
 using ::com::sun::star::beans::PropertyValue;
@@ -144,6 +152,11 @@ class FlashExportFilter : public cppu::WeakImplHelper4
     Reference< XComponentContext > mxContext;
     Reference< XStatusIndicator> mxStatusIndicator;
 
+    // #i56084# variables for selection export
+    Reference< XShapes > mxSelectedShapes;
+    Reference< XDrawPage > mxSelectedDrawPage;
+    bool mbExportSelection;
+
 public:
     FlashExportFilter( const Reference< XComponentContext > &rxContext);
 
@@ -167,16 +180,16 @@ public:
     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()  throw(RuntimeException, std::exception) SAL_OVERRIDE;
 };
 
-
-
 FlashExportFilter::FlashExportFilter(const Reference< XComponentContext > &rxContext)
-:   mxContext( rxContext )
+    : mxDoc()
+    , mxContext(rxContext)
+    , mxStatusIndicator()
+    , mxSelectedShapes()
+    , mxSelectedDrawPage()
+    , mbExportSelection(false)
 {
 }
 
-
-
-
 OUString exportBackground(FlashExporter &aFlashExporter, Reference< XDrawPage > xDrawPage, const OUString& sPath, sal_uInt32 nPage, const char* suffix)
 {
     OUString filename = STR("slide") + VAL(nPage+1) + STR(suffix) + STR(".swf");
@@ -228,7 +241,56 @@ sal_Bool SAL_CALL FlashExportFilter::filter( const ::com::sun::star::uno::Sequen
     Sequence< PropertyValue > aFilterData;
     aFilterData = findPropertyValue<Sequence< PropertyValue > >(aDescriptor, "FilterData", aFilterData);
 
-    if (findPropertyValue<sal_Bool>(aFilterData, "ExportMultipleFiles", false ))
+    // #i56084# check if selection shall be exported only; if yes, get the selected page and the selection itself
+    if(findPropertyValue<sal_Bool>(aDescriptor, "SelectionOnly", sal_False))
+    {
+        Reference< XDesktop2 > xDesktop(Desktop::create(mxContext));
+
+        if(xDesktop.is())
+        {
+            Reference< XFrame > xFrame(xDesktop->getCurrentFrame());
+
+            if(xFrame.is())
+            {
+                Reference< XController > xController(xFrame->getController());
+
+                if(xController.is())
+                {
+                    Reference< XDrawView > xDrawView(xController, UNO_QUERY);
+
+                    if(xDrawView.is())
+                    {
+                        mxSelectedDrawPage = xDrawView->getCurrentPage();
+                    }
+
+                    if(mxSelectedDrawPage.is())
+                    {
+                        Reference< XSelectionSupplier > xSelection(xController, UNO_QUERY);
+
+                        if(xSelection.is())
+                        {
+                            Any aSelection;
+
+                            if(xSelection->getSelection() >>= aSelection)
+                            {
+                                aSelection >>= mxSelectedShapes;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    if(mxSelectedDrawPage.is() && mxSelectedShapes.is() && mxSelectedShapes->getCount())
+    {
+        // #i56084# to export selection we need the selected page and the selected shapes.
+        // There must be shapes selected, else fallback to regular export (export all)
+        mbExportSelection = true;
+    }
+
+    // #i56084# no multiple files (suppress) when selection since selection can only export a single page
+    if (!mbExportSelection && findPropertyValue<sal_Bool>(aFilterData, "ExportMultipleFiles", false ))
     {
         ExportAsMultipleFiles(aDescriptor);
     }
@@ -327,8 +389,12 @@ sal_Bool FlashExportFilter::ExportAsMultipleFiles(const Sequence< PropertyValue
     // TODO: check for errors
     (void) err;
 
-    FlashExporter aFlashExporter( mxContext, findPropertyValue<sal_Int32>(aFilterData, "CompressMode", 75),
-                                         findPropertyValue<sal_Bool>(aFilterData, "ExportOLEAsJPEG", false));
+    FlashExporter aFlashExporter(
+        mxContext,
+        mxSelectedShapes,
+        mxSelectedDrawPage,
+        findPropertyValue<sal_Int32>(aFilterData, "CompressMode", 75),
+        findPropertyValue<sal_Bool>(aFilterData, "ExportOLEAsJPEG", false));
 
     const sal_Int32 nPageCount = xDrawPages->getCount();
     if ( mxStatusIndicator.is() )
@@ -400,8 +466,12 @@ sal_Bool FlashExportFilter::ExportAsSingleFile(const Sequence< PropertyValue >&
         return sal_False;
     }
 
-    FlashExporter aFlashExporter( mxContext, findPropertyValue<sal_Int32>(aFilterData, "CompressMode", 75),
-                                         findPropertyValue<sal_Bool>(aFilterData, "ExportOLEAsJPEG", false));
+    FlashExporter aFlashExporter(
+        mxContext,
+        mxSelectedShapes,
+        mxSelectedDrawPage,
+        findPropertyValue<sal_Int32>(aFilterData, "CompressMode", 75),
+        findPropertyValue<sal_Bool>(aFilterData, "ExportOLEAsJPEG", false));
 
     return aFlashExporter.exportAll( mxDoc, xOutputStream, mxStatusIndicator );
 }


More information about the Libreoffice-commits mailing list