Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <cstdio>
31 : :
32 : : #include <comphelper/servicedecl.hxx>
33 : : #include <uno/environment.h>
34 : : #include <com/sun/star/drawing/XDrawPage.hpp>
35 : : #include <com/sun/star/drawing/XDrawView.hpp>
36 : : #include <com/sun/star/frame/XDesktop.hpp>
37 : : #include <com/sun/star/frame/XController.hpp>
38 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
39 : : #include <com/sun/star/drawing/XDrawSubController.hpp>
40 : : #include <com/sun/star/container/XNamed.hpp>
41 : : #include <com/sun/star/uno/XComponentContext.hpp>
42 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
43 : : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
44 : : #include <com/sun/star/drawing/framework/XResource.hpp>
45 : : #include <com/sun/star/drawing/framework/XView.hpp>
46 : : #include <com/sun/star/drawing/framework/ResourceId.hpp>
47 : : #include <comphelper/processfactory.hxx>
48 : :
49 : : #include <osl/mutex.hxx>
50 : :
51 : : #include "svgfilter.hxx"
52 : :
53 : : using ::rtl::OUString;
54 : : using namespace ::com::sun::star;
55 : :
56 : : // -------------
57 : : // - SVGFilter -
58 : : // -------------
59 : :
60 : 10 : SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) :
61 [ + - ]: 10 : mxMSF( rxCtx->getServiceManager(),
62 : : uno::UNO_QUERY_THROW ),
63 : : mpSVGDoc( NULL ),
64 : : mpSVGExport( NULL ),
65 : : mpSVGFontExport( NULL ),
66 : : mpSVGWriter( NULL ),
67 : : mpDefaultSdrPage( NULL ),
68 : : mpSdrModel( NULL ),
69 : : mbPresentation( sal_False ),
70 : : mbExportAll( sal_False ),
71 [ + - ][ + - ]: 20 : mpObjects( NULL )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
72 : :
73 : : {
74 : 10 : }
75 : :
76 : : // -----------------------------------------------------------------------------
77 : :
78 [ + - ][ + - ]: 10 : SVGFilter::~SVGFilter()
[ + - ][ + - ]
79 : : {
80 : : DBG_ASSERT( mpSVGDoc == NULL, "mpSVGDoc not destroyed" );
81 : : DBG_ASSERT( mpSVGExport == NULL, "mpSVGExport not destroyed" );
82 : : DBG_ASSERT( mpSVGFontExport == NULL, "mpSVGFontExport not destroyed" );
83 : : DBG_ASSERT( mpSVGWriter == NULL, "mpSVGWriter not destroyed" );
84 : : DBG_ASSERT( mpObjects == NULL, "mpObjects not destroyed" );
85 [ - + ]: 10 : }
86 : :
87 : : // -----------------------------------------------------------------------------
88 : :
89 : :
90 : 0 : sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescriptor )
91 : : throw (RuntimeException)
92 : : {
93 [ # # ]: 0 : SolarMutexGuard aGuard;
94 [ # # ]: 0 : Window* pFocusWindow = Application::GetFocusWindow();
95 : : sal_Bool bRet;
96 : :
97 [ # # ]: 0 : if( pFocusWindow )
98 [ # # ]: 0 : pFocusWindow->EnterWait();
99 : :
100 [ # # ]: 0 : if( mxDstDoc.is() )
101 [ # # ]: 0 : bRet = implImport( rDescriptor );
102 [ # # ]: 0 : else if( mxSrcDoc.is() )
103 : : {
104 [ # # ]: 0 : if( !mbExportAll )
105 : : {
106 [ # # ]: 0 : uno::Reference< frame::XDesktop > xDesktop( mxMSF->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ),
107 [ # # ][ # # ]: 0 : uno::UNO_QUERY);
[ # # ]
108 [ # # ]: 0 : if( xDesktop.is() )
109 : : {
110 [ # # ][ # # ]: 0 : uno::Reference< frame::XFrame > xFrame( xDesktop->getCurrentFrame() );
111 : :
112 [ # # ]: 0 : if( xFrame.is() )
113 : : {
114 [ # # ][ # # ]: 0 : uno::Reference< frame::XController > xController( xFrame->getController() );
115 : :
116 [ # # ]: 0 : if( xController.is() )
117 : : {
118 : : /*
119 : : * Get the selection from the Slide Sorter Center Pane
120 : : */
121 [ # # ]: 0 : if( !mSelectedPages.hasElements() )
122 : : {
123 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xControllerPropertySet( xController, uno::UNO_QUERY );
124 : 0 : uno::Reference< drawing::XDrawSubController > xSubController;
125 [ # # ]: 0 : xControllerPropertySet->getPropertyValue(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubController" ) ) )
126 [ # # ][ # # ]: 0 : >>= xSubController;
[ # # ]
127 : :
128 [ # # ]: 0 : if( xSubController.is() )
129 : : {
130 [ # # ][ # # ]: 0 : uno::Any aSelection = xSubController->getSelection();
131 [ # # ]: 0 : if( aSelection.hasValue() )
132 : : {
133 [ # # ]: 0 : ObjectSequence aSelectedPageSequence;
134 [ # # ]: 0 : aSelection >>= aSelectedPageSequence;
135 [ # # ]: 0 : mSelectedPages.realloc( aSelectedPageSequence.getLength() );
136 [ # # ]: 0 : for( sal_Int32 i = 0; i < mSelectedPages.getLength(); ++i )
137 : : {
138 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xDrawPage( aSelectedPageSequence[i], uno::UNO_QUERY );
139 [ # # ][ # # ]: 0 : mSelectedPages[i] = xDrawPage;
140 [ # # ]: 0 : }
141 : 0 : }
142 : 0 : }
143 : : }
144 : 0 : }
145 : 0 : }
146 : 0 : }
147 : : }
148 : :
149 : : /*
150 : : * Export all slides, or requested "PagePos"
151 : : */
152 [ # # ]: 0 : if( !mSelectedPages.hasElements() )
153 : : {
154 : 0 : sal_Int32 nLength = rDescriptor.getLength();
155 : 0 : const PropertyValue* pValue = rDescriptor.getConstArray();
156 : 0 : sal_Int32 nPageToExport = -1;
157 : :
158 [ # # ]: 0 : for ( sal_Int32 i = 0 ; i < nLength; ++i)
159 : : {
160 [ # # ]: 0 : if ( pValue[ i ].Name == "PagePos" )
161 : : {
162 : 0 : pValue[ i ].Value >>= nPageToExport;
163 : : }
164 : : }
165 : :
166 [ # # ]: 0 : uno::Reference< drawing::XMasterPagesSupplier > xMasterPagesSupplier( mxSrcDoc, uno::UNO_QUERY );
167 [ # # ]: 0 : uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( mxSrcDoc, uno::UNO_QUERY );
168 : :
169 [ # # ][ # # ]: 0 : if( xMasterPagesSupplier.is() && xDrawPagesSupplier.is() )
[ # # ]
170 : : {
171 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), uno::UNO_QUERY );
[ # # ]
172 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY );
[ # # ]
173 [ # # ][ # # ]: 0 : if( xMasterPages.is() && xMasterPages->getCount() &&
[ # # # # ]
[ # # ][ # # ]
[ # # ]
174 [ # # ][ # # ]: 0 : xDrawPages.is() && xDrawPages->getCount() )
175 : : {
176 [ # # ][ # # ]: 0 : sal_Int32 nDPCount = xDrawPages->getCount();
177 : :
178 [ # # ][ # # ]: 0 : mSelectedPages.realloc( nPageToExport != -1 ? 1 : nDPCount );
179 : : sal_Int32 i;
180 [ # # ]: 0 : for( i = 0; i < nDPCount; ++i )
181 : : {
182 [ # # ][ # # ]: 0 : if( nPageToExport != -1 && nPageToExport == i )
183 : : {
184 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), uno::UNO_QUERY );
[ # # ]
185 [ # # ][ # # ]: 0 : mSelectedPages[0] = xDrawPage;
186 : : }
187 : : else
188 : : {
189 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), uno::UNO_QUERY );
[ # # ]
190 [ # # ][ # # ]: 0 : mSelectedPages[i] = xDrawPage;
191 : : }
192 : : }
193 : 0 : }
194 : 0 : }
195 : : }
196 : :
197 : : /*
198 : : * We get all master page that are targeted by at least one draw page.
199 : : * The master page are put in an unordered set.
200 : : */
201 [ # # ]: 0 : ObjectSet aMasterPageTargetSet;
202 [ # # ]: 0 : for( sal_Int32 i = 0; i < mSelectedPages.getLength(); ++i )
203 : : {
204 [ # # ][ # # ]: 0 : uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( mSelectedPages[i], uno::UNO_QUERY );
205 [ # # ]: 0 : if( xMasterPageTarget.is() )
206 : : {
207 [ # # ][ # # ]: 0 : aMasterPageTargetSet.insert( xMasterPageTarget->getMasterPage() );
[ # # ]
208 : : }
209 : 0 : }
210 : : // Later we move them to a uno::Sequence so we can get them by index
211 [ # # ]: 0 : mMasterPageTargets.realloc( aMasterPageTargetSet.size() );
212 [ # # ]: 0 : ObjectSet::const_iterator aElem = aMasterPageTargetSet.begin();
213 [ # # ][ # # ]: 0 : for( sal_Int32 i = 0; aElem != aMasterPageTargetSet.end(); ++aElem, ++i)
214 : : {
215 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPage > xMasterPage( *aElem, uno::UNO_QUERY );
216 [ # # ][ # # ]: 0 : mMasterPageTargets[i] = xMasterPage;
217 : 0 : }
218 : :
219 [ # # ][ # # ]: 0 : bRet = implExport( rDescriptor );
220 : : }
221 : : else
222 : 0 : bRet = sal_False;
223 : :
224 [ # # ]: 0 : if( pFocusWindow )
225 [ # # ]: 0 : pFocusWindow->LeaveWait();
226 : :
227 [ # # ]: 0 : return bRet;
228 : : }
229 : :
230 : : // -----------------------------------------------------------------------------
231 : :
232 : 0 : void SAL_CALL SVGFilter::cancel( ) throw (RuntimeException)
233 : : {
234 : 0 : }
235 : :
236 : : // -----------------------------------------------------------------------------
237 : :
238 : 0 : void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc )
239 : : throw (IllegalArgumentException, RuntimeException)
240 : : {
241 : 0 : mxSrcDoc = xDoc;
242 : 0 : }
243 : :
244 : : // -----------------------------------------------------------------------------
245 : :
246 : 0 : void SAL_CALL SVGFilter::setTargetDocument( const Reference< XComponent >& xDoc )
247 : : throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
248 : : {
249 : 0 : mxDstDoc = xDoc;
250 : 0 : }
251 : :
252 : : // -----------------------------------------------------------------------------
253 : :
254 : 10 : rtl::OUString SAL_CALL SVGFilter::detect( Sequence< PropertyValue >& io_rDescriptor ) throw (RuntimeException)
255 : : {
256 : 10 : uno::Reference< io::XInputStream > xInput;
257 : :
258 : 10 : const beans::PropertyValue* pAttribs = io_rDescriptor.getConstArray();
259 : 10 : const sal_Int32 nAttribs = io_rDescriptor.getLength();
260 [ + + ]: 80 : for( sal_Int32 i = 0; i < nAttribs; i++ )
261 : : {
262 [ + + ]: 70 : if ( pAttribs[i].Name == "InputStream" )
263 [ + - ]: 10 : pAttribs[i].Value >>= xInput;
264 : : }
265 : :
266 [ - + ]: 10 : if( !xInput.is() )
267 : 0 : return rtl::OUString();
268 : :
269 [ + - ]: 10 : uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
270 [ + - ]: 10 : if( xSeek.is() )
271 [ + - ][ + - ]: 10 : xSeek->seek( 0 );
272 : :
273 : : // read the first 1024 bytes & check a few magic string
274 : : // constants (heuristically)
275 : 10 : const sal_Int32 nLookAhead = 1024;
276 [ + - ]: 10 : uno::Sequence< sal_Int8 > aBuf( nLookAhead );
277 [ + - ][ + - ]: 10 : const sal_uInt64 nBytes=xInput->readBytes(aBuf, nLookAhead);
278 : 10 : const sal_Int8* const pBuf=aBuf.getConstArray();
279 : :
280 : 10 : sal_Int8 aMagic1[] = {'<', 's', 'v', 'g'};
281 [ - + ]: 10 : if( std::search(pBuf, pBuf+nBytes,
282 [ + - ]: 10 : aMagic1, aMagic1+sizeof(aMagic1)/sizeof(*aMagic1)) != pBuf+nBytes )
283 [ # # ]: 0 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("svg_Scalable_Vector_Graphics") );
284 : :
285 : 10 : sal_Int8 aMagic2[] = {'D', 'O', 'C', 'T', 'Y', 'P', 'E', ' ', 's', 'v', 'g'};
286 [ - + ]: 10 : if( std::search(pBuf, pBuf+nBytes,
287 [ + - ]: 10 : aMagic2, aMagic2+sizeof(aMagic2)/sizeof(*aMagic2)) != pBuf+nBytes )
288 [ # # ]: 0 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("svg_Scalable_Vector_Graphics") );
289 : :
290 [ + - ]: 10 : return rtl::OUString();
291 : : }
292 : :
293 : : // -----------------------------------------------------------------------------
294 : :
295 : : namespace sdecl = comphelper::service_decl;
296 : 6 : sdecl::class_<SVGFilter> serviceImpl;
297 : 6 : const sdecl::ServiceDecl svgFilter(
298 : : serviceImpl,
299 : : "com.sun.star.comp.Draw.SVGFilter",
300 : : "com.sun.star.document.ImportFilter;"
301 : : "com.sun.star.document.ExportFilter;"
302 : : "com.sun.star.document.ExtendedTypeDetection" );
303 : :
304 : : // The C shared lib entry points
305 : 6 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
306 : : sal_Char const* pImplName,
307 : : ::com::sun::star::lang::XMultiServiceFactory* pServiceManager,
308 : : ::com::sun::star::registry::XRegistryKey* pRegistryKey )
309 : : {
310 : : return component_getFactoryHelper( pImplName, pServiceManager,
311 : 6 : pRegistryKey, svgFilter );
312 [ + - ][ + - ]: 18 : }
313 : :
314 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|