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 {
89 vos::OGuard aGuard( Application::GetSolarMutex() );
90 Window* pFocusWindow = Application::GetFocusWindow();
91 sal_Int16 nCurrentPageNumber = -1;
92 sal_Bool bRet;
93
94 if( pFocusWindow )
95 pFocusWindow->EnterWait();
96
97 #ifdef SOLAR_JAVA
98 if( mxDstDoc.is() )
99 bRet = sal_False;//implImport( rDescriptor );
100 else
101 #endif
102 if( mxSrcDoc.is() )
103 {
104 // #124608# detext selection
105 sal_Bool bSelectionOnly = sal_False;
106 bool bGotSelection(false);
107 Reference< drawing::XShapes > xShapes;
108
109 // #124608# extract Single selection wanted from dialog return values
110 for ( sal_Int32 nInd = 0; nInd < rDescriptor.getLength(); nInd++ )
111 {
112 if ( rDescriptor[nInd].Name.equalsAscii( "SelectionOnly" ) )
113 {
114 rDescriptor[nInd].Value >>= bSelectionOnly;
115 }
116 }
117
118 uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
119 uno::UNO_QUERY);
120 if( xDesktop.is() )
121 {
122 uno::Reference< frame::XFrame > xFrame( xDesktop->getCurrentFrame() );
123
124 if( xFrame.is() )
125 {
126 uno::Reference< frame::XController > xController( xFrame->getController() );
127
128 if( xController.is() )
129 {
130 uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
131
132 if( xDrawView.is() )
133 {
134 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawView->getCurrentPage() );
135
136 if( xDrawPage.is() )
137 {
138 uno::Reference< beans::XPropertySet >( xDrawPage, uno::UNO_QUERY )->
139 getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Number" ) ) ) >>= nCurrentPageNumber;
140 }
141 }
142
143 if(bSelectionOnly)
144 {
145 // #124608# when selection only is wanted, get the current object selection
146 // from the DrawView
147 Reference< view::XSelectionSupplier > xSelection (xController, UNO_QUERY);
148
149 if (xSelection.is())
150 {
151 uno::Any aSelection;
152
153 if(xSelection->getSelection() >>= aSelection)
154 {
155 bGotSelection = (sal_True == ( aSelection >>= xShapes ));
156 }
157 }
158 }
159 }
160 }
161 }
162
163 if(bSelectionOnly && bGotSelection && 0 == xShapes->getCount())
164 {
165 // #124608# export selection, got xShapes but no shape selected -> nothing
166 // to export, we are done (maybe return true, but a hint that nothing was done
167 // may be useful; it may have happened by error)
168 bRet = sal_False;
169 }
170 else
171 {
172 Sequence< PropertyValue > aNewDescriptor(rDescriptor);
173 const bool bSinglePage(nCurrentPageNumber > 0);
174
175 if(bSinglePage || bGotSelection)
176 {
177 const sal_uInt32 nOldLength = rDescriptor.getLength();
178 sal_uInt32 nInsert(nOldLength);
179
180 aNewDescriptor.realloc(nOldLength + (bSinglePage ? 1 : 0) + (bGotSelection ? 1 : 0));
181
182 if(bSinglePage)
183 {
184 aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PagePos"));
185 aNewDescriptor[nInsert].Value <<= static_cast<sal_Int16>(nCurrentPageNumber - 1);
186 nInsert++;
187 }
188
189 if(bGotSelection)
190 {
191 // #124608# add retrieved ShapeSelection if export of only selected shapes is wanted
192 // so that the filter implementation can use it
193 aNewDescriptor[nInsert].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShapeSelection"));
194 aNewDescriptor[nInsert].Value <<= xShapes;
195 // reactivate this when you add other properties to aNewDescriptor
196 // nInsert++;
197 }
198 }
199
200 bRet = implExport(aNewDescriptor);
201 }
202 }
203 else
204 bRet = sal_False;
205
206 if( pFocusWindow )
207 pFocusWindow->LeaveWait();
208
209 return bRet;
210 }
211
212 // -----------------------------------------------------------------------------
213
cancel()214 void SAL_CALL SVGFilter::cancel( )
215 {
216 }
217
218 // -----------------------------------------------------------------------------
219
setSourceDocument(const Reference<XComponent> & xDoc)220 void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc )
221 {
222 mxSrcDoc = xDoc;
223 }
224
225 // -----------------------------------------------------------------------------
226
227 #ifdef SOLAR_JAVA
setTargetDocument(const Reference<XComponent> & xDoc)228 void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc )
229 {
230 mxDstDoc = xDoc;
231 }
232 #endif
233
234 // -----------------------------------------------------------------------------
235
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> &)236 void SAL_CALL SVGFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& /* aArguments */ )
237 {
238 }
239
240 // -----------------------------------------------------------------------------
241
SVGFilter_getImplementationName()242 OUString SVGFilter_getImplementationName ()
243 {
244 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_IMPLEMENTATION_NAME ) );
245 }
246
247 // -----------------------------------------------------------------------------
248
SVGFilter_supportsService(const OUString & rServiceName)249 sal_Bool SAL_CALL SVGFilter_supportsService( const OUString& rServiceName )
250 {
251 return( rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SVG_FILTER_SERVICE_NAME ) ) );
252 }
253
254 // -----------------------------------------------------------------------------
255
SVGFilter_getSupportedServiceNames()256 Sequence< OUString > SAL_CALL SVGFilter_getSupportedServiceNames( )
257 {
258 Sequence < OUString > aRet(1);
259 OUString* pArray = aRet.getArray();
260 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SVG_FILTER_SERVICE_NAME ) );
261 return aRet;
262 }
263
264 // -----------------------------------------------------------------------------
265
SVGFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)266 Reference< XInterface > SAL_CALL SVGFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
267 {
268 return (cppu::OWeakObject*) new SVGFilter( rSMgr );
269 }
270
271 // -----------------------------------------------------------------------------
272
getImplementationName()273 OUString SAL_CALL SVGFilter::getImplementationName( )
274 {
275 return SVGFilter_getImplementationName();
276 }
277
278 // -----------------------------------------------------------------------------
279
supportsService(const OUString & rServiceName)280 sal_Bool SAL_CALL SVGFilter::supportsService( const OUString& rServiceName )
281 {
282 return SVGFilter_supportsService( rServiceName );
283 }
284
285 // -----------------------------------------------------------------------------
286
getSupportedServiceNames()287 ::com::sun::star::uno::Sequence< OUString > SAL_CALL SVGFilter::getSupportedServiceNames( )
288 {
289 return SVGFilter_getSupportedServiceNames();
290 }
291