xref: /aoo42x/main/filter/source/svg/svgfilter.cxx (revision 235a45cd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 
27 #include <cstdio>
28 #include "svgfilter.hxx"
29 #include <vos/mutex.hxx>
30 
31 #include <com/sun/star/drawing/XDrawPage.hpp>
32 #include <com/sun/star/drawing/XDrawView.hpp>
33 #include <com/sun/star/frame/XDesktop.hdl>
34 #include <com/sun/star/frame/XController.hdl>
35 #include <com/sun/star/view/XSelectionSupplier.hpp>
36 
37 #define SVG_FILTER_SERVICE_NAME         "com.sun.star.comp.Draw.SVGFilter"
38 #define SVG_FILTER_IMPLEMENTATION_NAME  SVG_FILTER_SERVICE_NAME
39 
40 using ::rtl::OUString;
41 using namespace ::com::sun::star;
42 
43 // -------------
44 // - SVGFilter -
45 // -------------
46 
SVGFilter(const Reference<XMultiServiceFactory> & rxMSF)47 SVGFilter::SVGFilter( const Reference< XMultiServiceFactory > &rxMSF ) :
48     mxMSF( rxMSF ),
49     mpSVGDoc( NULL ),
50     mpSVGExport( NULL ),
51 	mpSVGFontExport( NULL ),
52 	mpSVGWriter( NULL ),
53 	mpDefaultSdrPage( NULL ),
54 	mpSdrModel( NULL ),
55     mbPresentation( sal_False ),
56     mpObjects( NULL ),
57     mxSrcDoc(),
58 #ifdef SOLAR_JAVA
59     mxDstDoc(),
60 #endif
61     mxDefaultPage(),
62     maFilterData(),
63     maShapeSelection(),
64     mbExportSelection(false),
65     maUniqueIdVector(),
66     mnMasterSlideId(0),
67     mnSlideId(0),
68     mnDrawingGroupId(0),
69     mnDrawingId(0),
70     maOldFieldHdl()
71 {
72 }
73 
74 // -----------------------------------------------------------------------------
75 
~SVGFilter()76 SVGFilter::~SVGFilter()
77 {
78     DBG_ASSERT( mpSVGDoc == NULL, "mpSVGDoc not destroyed" );
79     DBG_ASSERT( mpSVGExport == NULL, "mpSVGExport not destroyed" );
80 	DBG_ASSERT( mpSVGFontExport == NULL, "mpSVGFontExport not destroyed" );
81     DBG_ASSERT( mpSVGWriter == NULL, "mpSVGWriter not destroyed" );
82 	DBG_ASSERT( mpObjects == NULL, "mpObjects not destroyed" );
83 }
84 
85 // -----------------------------------------------------------------------------
86 
filter(const Sequence<PropertyValue> & rDescriptor)87 sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescriptor )
88 	throw (RuntimeException)
89 {
90 	vos::OGuard aGuard( Application::GetSolarMutex() );
91     Window*     pFocusWindow = Application::GetFocusWindow();
92 	sal_Int16 	nCurrentPageNumber = -1;
93     sal_Bool    bRet;
94 
95     if( pFocusWindow )
96     	pFocusWindow->EnterWait();
97 
98 #ifdef SOLAR_JAVA
99     if( mxDstDoc.is() )
100         bRet = sal_False;//implImport( rDescriptor );
101     else
102 #endif
103     if( mxSrcDoc.is() )
104 	{
105         // #124608# detext selection
106         sal_Bool bSelectionOnly = sal_False;
107         bool bGotSelection(false);
108         Reference< drawing::XShapes > xShapes;
109 
110         // #124608# extract Single selection wanted from dialog return values
111         for ( sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++ )
112         {
113             if ( rDescriptor[nInd].Name.equalsAscii( "SelectionOnly" ) )
114             {
115                 rDescriptor[nInd].Value >>= bSelectionOnly;
116             }
117         }
118 
119         uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
120 													uno::UNO_QUERY);
121 		if( xDesktop.is() )
122 		{
123 			uno::Reference< frame::XFrame > xFrame( xDesktop->getCurrentFrame() );
124 
125 			if( xFrame.is() )
126 			{
127 				uno::Reference< frame::XController > xController( xFrame->getController() );
128 
129 				if( xController.is() )
130 				{
131 					uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
132 
133 					if( xDrawView.is() )
134 					{
135 						uno::Reference< drawing::XDrawPage > xDrawPage( xDrawView->getCurrentPage() );
136 
137 						if( xDrawPage.is() )
138 						{
139 							uno::Reference< beans::XPropertySet >( xDrawPage, uno::UNO_QUERY )->
140 								getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Number" ) ) ) >>= nCurrentPageNumber;
141 						}
142 					}
143 
144                     if(bSelectionOnly)
145                     {
146                         // #124608# when selection only is wanted, get the current object selection
147                         // from the DrawView
148                         Reference< view::XSelectionSupplier > xSelection (xController, UNO_QUERY);
149 
150                         if (xSelection.is())
151                         {
152                             uno::Any aSelection;
153 
154                             if(xSelection->getSelection() >>= aSelection)
155                             {
156                                 bGotSelection = (sal_True == ( aSelection >>= xShapes ));
157                             }
158                         }
159                     }
160                 }
161 			}
162 		}
163 
164         if(bSelectionOnly && bGotSelection && 0 == xShapes->getCount())
165         {
166             // #124608# export selection, got xShapes but no shape selected -> nothing
167             // to export, we are done (maybe return true, but a hint that nothing was done
168             // may be useful; it may have happened by error)
169             bRet = sal_False;
170         }
171         else
172         {
173             Sequence< PropertyValue > aNewDescriptor(rDescriptor);
174             const bool bSinglePage(nCurrentPageNumber > 0);
175 
176             if(bSinglePage || bGotSelection)
177             {
178                 const sal_uInt32 nOldLength = rDescriptor.getLength();
179                 sal_uInt32 nInsert(nOldLength);
180 
181                 aNewDescriptor.realloc(nOldLength + (bSinglePage ? 1 : 0) + (bGotSelection ? 1 : 0));
182 
183                 if(bSinglePage)
184                 {
185                     aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PagePos"));
186                     aNewDescriptor[nInsert].Value <<= static_cast<sal_Int16>(nCurrentPageNumber - 1);
187                     nInsert++;
188                 }
189 
190                 if(bGotSelection)
191                 {
192                     // #124608# add retrieved ShapeSelection if export of only selected shapes is wanted
193                     // so that the filter implementation can use it
194                     aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShapeSelection"));
195                     aNewDescriptor[nInsert].Value <<= xShapes;
196                     // reactivate this when you add other properties to aNewDescriptor
197                     // nInsert++;
198                 }
199             }
200 
201             bRet = implExport(aNewDescriptor);
202         }
203     }
204     else
205         bRet = sal_False;
206 
207     if( pFocusWindow )
208     	pFocusWindow->LeaveWait();
209 
210 	return bRet;
211 }
212 
213 // -----------------------------------------------------------------------------
214 
cancel()215 void SAL_CALL SVGFilter::cancel( ) throw (RuntimeException)
216 {
217 }
218 
219 // -----------------------------------------------------------------------------
220 
setSourceDocument(const Reference<XComponent> & xDoc)221 void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc )
222 	throw (IllegalArgumentException, RuntimeException)
223 {
224 	mxSrcDoc = xDoc;
225 }
226 
227 // -----------------------------------------------------------------------------
228 
229 #ifdef SOLAR_JAVA
setTargetDocument(const Reference<XComponent> & xDoc)230 void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc )
231 	throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
232 {
233 	mxDstDoc = xDoc;
234 }
235 #endif
236 
237 // -----------------------------------------------------------------------------
238 
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> &)239 void SAL_CALL SVGFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& /* aArguments */ )
240 	throw (Exception, RuntimeException)
241 {
242 }
243 
244 // -----------------------------------------------------------------------------
245 
SVGFilter_getImplementationName()246 OUString SVGFilter_getImplementationName ()
247 	throw (RuntimeException)
248 {
249     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_IMPLEMENTATION_NAME ) );
250 }
251 
252 // -----------------------------------------------------------------------------
253 
SVGFilter_supportsService(const OUString & rServiceName)254 sal_Bool SAL_CALL SVGFilter_supportsService( const OUString& rServiceName )
255 	throw (RuntimeException)
256 {
257     return( rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SVG_FILTER_SERVICE_NAME ) ) );
258 }
259 
260 // -----------------------------------------------------------------------------
261 
SVGFilter_getSupportedServiceNames()262 Sequence< OUString > SAL_CALL SVGFilter_getSupportedServiceNames(  ) throw (RuntimeException)
263 {
264 	Sequence < OUString > aRet(1);
265     OUString* pArray = aRet.getArray();
266     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_SERVICE_NAME ) );
267     return aRet;
268 }
269 
270 // -----------------------------------------------------------------------------
271 
SVGFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)272 Reference< XInterface > SAL_CALL SVGFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
273 {
274 	return (cppu::OWeakObject*) new SVGFilter( rSMgr );
275 }
276 
277 // -----------------------------------------------------------------------------
278 
getImplementationName()279 OUString SAL_CALL SVGFilter::getImplementationName(  )
280 	throw (RuntimeException)
281 {
282 	return SVGFilter_getImplementationName();
283 }
284 
285 // -----------------------------------------------------------------------------
286 
supportsService(const OUString & rServiceName)287 sal_Bool SAL_CALL SVGFilter::supportsService( const OUString& rServiceName )
288 	throw (RuntimeException)
289 {
290     return SVGFilter_supportsService( rServiceName );
291 }
292 
293 // -----------------------------------------------------------------------------
294 
getSupportedServiceNames()295 ::com::sun::star::uno::Sequence< OUString > SAL_CALL SVGFilter::getSupportedServiceNames(  ) throw (RuntimeException)
296 {
297     return SVGFilter_getSupportedServiceNames();
298 }
299