Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef SVGFILTER_HXX
21 : #define SVGFILTER_HXX
22 :
23 : #include <com/sun/star/uno/Type.hxx>
24 : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
25 : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
26 : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
27 : #include <com/sun/star/container/XNamed.hpp>
28 :
29 : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
30 : #include <com/sun/star/presentation/XPresentationSupplier.hpp>
31 : #include <com/sun/star/document/XFilter.hpp>
32 : #include <com/sun/star/document/XImporter.hpp>
33 : #include <com/sun/star/document/XExporter.hpp>
34 : #include <com/sun/star/document/XExtendedFilterDetection.hpp>
35 : #include <com/sun/star/lang/XInitialization.hpp>
36 : #include <com/sun/star/lang/XServiceInfo.hpp>
37 : #include <com/sun/star/beans/XPropertySet.hpp>
38 : #include <com/sun/star/lang/XComponent.hpp>
39 : #include <cppuhelper/implbase4.hxx>
40 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : #include <com/sun/star/io/XActiveDataSource.hpp>
42 : #include <com/sun/star/presentation/AnimationEffect.hpp>
43 : #include <com/sun/star/presentation/AnimationSpeed.hpp>
44 : #include <com/sun/star/presentation/ClickAction.hpp>
45 : #include <com/sun/star/presentation/FadeEffect.hpp>
46 : #include <com/sun/star/text/XText.hpp>
47 : #include <com/sun/star/frame/XDesktop.hpp>
48 : #include <com/sun/star/java/XJavaVM.hpp>
49 : #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
50 : #include <com/sun/star/style/ParagraphAdjust.hpp>
51 : #include <com/sun/star/drawing/FillStyle.hpp>
52 : #include <com/sun/star/graphic/XGraphicProvider.hpp>
53 : #include <com/sun/star/xml/sax/XWriter.hpp>
54 :
55 : #include <boost/unordered_set.hpp>
56 : #include <boost/unordered_map.hpp>
57 : #include <osl/diagnose.h>
58 : #include <sal/log.hxx>
59 : #include <rtl/process.h>
60 : #include <basegfx/polygon/b2dpolypolygon.hxx>
61 : #include <basegfx/polygon/b2dpolygonclipper.hxx>
62 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
63 : #include <comphelper/processfactory.hxx>
64 : #include <unotools/tempfile.hxx>
65 : #include <unotools/localfilehelper.hxx>
66 : #include <unotools/ucbstreamhelper.hxx>
67 : #include <unotools/streamwrap.hxx>
68 : #include <vcl/cvtgrf.hxx>
69 : #include <vcl/svapp.hxx>
70 : #include <vcl/outdev.hxx>
71 : #include <vcl/metaact.hxx>
72 : #include <svtools/grfmgr.hxx>
73 : #include <svx/unomodel.hxx>
74 : #include <svx/unoapi.hxx>
75 : #include <svx/svdxcgv.hxx>
76 : #include <svx/svdobj.hxx>
77 : #include <xmloff/xmlexp.hxx>
78 :
79 : #include <cstdio>
80 :
81 :
82 : using namespace ::com::sun::star::animations;
83 : using namespace ::com::sun::star::beans;
84 : using namespace ::com::sun::star::container;
85 : using namespace ::com::sun::star::document;
86 : using namespace ::com::sun::star::drawing;
87 : using namespace ::com::sun::star::io;
88 : using namespace ::com::sun::star::java;
89 : using namespace ::com::sun::star::lang;
90 : using namespace ::com::sun::star::presentation;
91 : using namespace ::com::sun::star::style;
92 : using namespace ::com::sun::star::text;
93 : using namespace ::com::sun::star::uno;
94 : using namespace ::com::sun::star::xml::sax;
95 :
96 : using namespace ::std;
97 :
98 : // -----------
99 : // - Defines -
100 : // -----------
101 :
102 : #define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
103 :
104 :
105 : // -----------
106 : // - statics -
107 : // -----------
108 :
109 : // Placeholder tag used into the ImplWriteActions method to filter text placeholder fields
110 0 : static const ::rtl::OUString sPlaceholderTag = ::rtl::OUString::createFromAscii( "<[:isPlaceholder:]>" );
111 :
112 :
113 : // -------------
114 : // - SVGExport -
115 : // -------------
116 :
117 : // #110680#
118 : class SVGExport : public SvXMLExport
119 : {
120 : typedef ::std::list< ::basegfx::B2DPolyPolygon > B2DPolyPolygonList;
121 :
122 : public:
123 :
124 : SVGExport( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
125 : const Reference< XDocumentHandler >& rxHandler,
126 : const Sequence< PropertyValue >& rFilterData );
127 :
128 : virtual ~SVGExport();
129 :
130 : sal_Bool IsUseTinyProfile() const;
131 : sal_Bool IsEmbedFonts() const;
132 : sal_Bool IsUsePositionedCharacters() const;
133 : sal_Bool IsUseNativeTextDecoration() const;
134 : sal_Bool IsUseOpacity() const;
135 :
136 : protected:
137 :
138 0 : virtual void _ExportStyles( sal_Bool /* bUsed */ ) {}
139 0 : virtual void _ExportAutoStyles() {}
140 0 : virtual void _ExportContent() {}
141 0 : virtual void _ExportMasterStyles() {}
142 0 : virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum /* eClass */ ) { return 0; }
143 :
144 : private:
145 :
146 : const Sequence< PropertyValue >& mrFilterData;
147 :
148 : SVGExport();
149 : };
150 :
151 : // ------------------------
152 : // - ObjectRepresentation -
153 : // ------------------------
154 :
155 : class ObjectRepresentation
156 : {
157 : private:
158 :
159 : Reference< XInterface > mxObject;
160 : GDIMetaFile* mpMtf;
161 :
162 : public:
163 :
164 : ObjectRepresentation();
165 : ObjectRepresentation( const Reference< XInterface >& rxIf,
166 : const GDIMetaFile& rMtf );
167 : ObjectRepresentation( const ObjectRepresentation& rPresentation );
168 : ~ObjectRepresentation();
169 :
170 : ObjectRepresentation& operator=( const ObjectRepresentation& rPresentation );
171 : sal_Bool operator==( const ObjectRepresentation& rPresentation ) const;
172 :
173 0 : const Reference< XInterface >& GetObject() const { return mxObject; }
174 0 : sal_Bool HasRepresentation() const { return mpMtf != NULL; }
175 0 : const GDIMetaFile& GetRepresentation() const { return *mpMtf; }
176 : };
177 :
178 : // -------------------
179 : // - PagePropertySet -
180 : // -------------------
181 :
182 0 : struct PagePropertySet
183 : {
184 : sal_Bool bIsBackgroundVisible;
185 : sal_Bool bAreBackgroundObjectsVisible;
186 : sal_Bool bIsPageNumberFieldVisible;
187 : sal_Bool bIsDateTimeFieldVisible;
188 : sal_Bool bIsFooterFieldVisible;
189 : sal_Bool bIsHeaderFieldVisible;
190 : sal_Int32 nPageNumberingType;
191 : sal_Bool bIsDateTimeFieldFixed;
192 : sal_Int16 nPageNumber;
193 : sal_Int32 nDateTimeFormat;
194 : ::rtl::OUString sDateTimeText;
195 : ::rtl::OUString sFooterText;
196 : ::rtl::OUString sHeaderText;
197 : };
198 :
199 :
200 :
201 : // ---------------------------
202 : // - HashReferenceXInterface -
203 : // ---------------------------
204 :
205 : struct HashReferenceXInterface
206 : {
207 0 : size_t operator()( const Reference< XInterface >& rxIf ) const
208 : {
209 0 : return reinterpret_cast< size_t >( rxIf.get() );
210 : }
211 : };
212 :
213 : // ---------------------------
214 : // - HashOUString -
215 : // ---------------------------
216 :
217 : struct HashOUString
218 : {
219 0 : size_t operator()( const ::rtl::OUString& oustr ) const { return static_cast< size_t >( oustr.hashCode() ); }
220 : };
221 :
222 : // ---------------------------
223 : // - HashUChar -
224 : // ---------------------------
225 :
226 : struct HashUChar
227 : {
228 0 : size_t operator()( const sal_Unicode uchar ) const { return static_cast< size_t >( uchar ); }
229 : };
230 :
231 : // ---------------------------
232 : // - HashBitmap -
233 : // ---------------------------
234 :
235 : struct HashBitmap
236 : {
237 : size_t operator()( const ObjectRepresentation& rObjRep ) const;
238 : };
239 :
240 : // ---------------------------
241 : // - EqualityBitmap -
242 : // ---------------------------
243 :
244 : struct EqualityBitmap
245 : {
246 : bool operator()( const ObjectRepresentation& rObjRep1,
247 : const ObjectRepresentation& rObjRep2 ) const;
248 : };
249 :
250 :
251 : // -------------
252 : // - SVGFilter -
253 : // -------------
254 :
255 : class SVGFontExport;
256 : class SVGActionWriter;
257 : class EditFieldInfo;
258 :
259 : class SVGFilter : public cppu::WeakImplHelper4 < XFilter,
260 : XImporter,
261 : XExporter,
262 : XExtendedFilterDetection >
263 : {
264 : public:
265 : typedef ::boost::unordered_map< Reference< XInterface >, ObjectRepresentation, HashReferenceXInterface > ObjectMap;
266 : typedef ::boost::unordered_set< Reference< XInterface >, HashReferenceXInterface > ObjectSet;
267 : typedef Sequence< Reference< XInterface > > ObjectSequence;
268 : typedef Sequence< Reference< XDrawPage > > XDrawPageSequence;
269 :
270 : typedef ::boost::unordered_set< sal_Unicode, HashUChar > UCharSet;
271 : typedef ::boost::unordered_map< ::rtl::OUString, UCharSet, HashOUString > UCharSetMap;
272 : typedef ::boost::unordered_map< Reference< XInterface >, UCharSetMap, HashReferenceXInterface > UCharSetMapMap;
273 :
274 : typedef ::boost::unordered_map< Reference< XInterface >, ::rtl::OUString, HashReferenceXInterface > UOStringMap;
275 :
276 : typedef ::boost::unordered_set< ObjectRepresentation, HashBitmap, EqualityBitmap > MetaBitmapActionSet;
277 :
278 : private:
279 :
280 : Reference< XComponentContext > mxContext;
281 : SvXMLElementExport* mpSVGDoc;
282 : SVGExport* mpSVGExport;
283 : SVGFontExport* mpSVGFontExport;
284 : SVGActionWriter* mpSVGWriter;
285 : SdrPage* mpDefaultSdrPage;
286 : SdrModel* mpSdrModel;
287 : sal_Bool mbPresentation;
288 : sal_Bool mbExportAll;
289 : sal_Bool mbSinglePage;
290 : sal_Int32 mnVisiblePage;
291 : PagePropertySet mVisiblePagePropSet;
292 : ::rtl::OUString msClipPathId;
293 : UCharSetMapMap mTextFieldCharSets;
294 : Reference< XInterface > mCreateOjectsCurrentMasterPage;
295 : UOStringMap mTextShapeIdListMap;
296 : #ifndef DISABLE_EXPORT
297 : MetaBitmapActionSet mEmbeddedBitmapActionSet;
298 : ObjectMap mEmbeddedBitmapActionMap;
299 : #endif
300 : ObjectMap* mpObjects;
301 : Reference< XComponent > mxSrcDoc;
302 : Reference< XComponent > mxDstDoc;
303 : Reference< XDrawPage > mxDefaultPage;
304 : Sequence< PropertyValue > maFilterData;
305 : XDrawPageSequence mSelectedPages;
306 : XDrawPageSequence mMasterPageTargets;
307 :
308 : Link maOldFieldHdl;
309 :
310 : sal_Bool implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
311 :
312 : sal_Bool implExport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
313 : Reference< XWriter > implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm );
314 :
315 : sal_Bool implGetPagePropSet( const Reference< XDrawPage > & rxPage );
316 : sal_Bool implGenerateMetaData();
317 : void implExportTextShapeIndex();
318 : void implEmbedBulletGlyphs();
319 : void implEmbedBulletGlyph( sal_Unicode cBullet, const ::rtl::OUString & sPathData );
320 : sal_Bool implExportTextEmbeddedBitmaps();
321 : sal_Bool implGenerateScript();
322 :
323 : sal_Bool implExportDocument();
324 : sal_Bool implExportAnimations();
325 :
326 : sal_Bool implExportMasterPages( const XDrawPageSequence& rxPages,
327 : sal_Int32 nFirstPage, sal_Int32 nLastPage );
328 : sal_Bool implExportDrawPages( const XDrawPageSequence& rxPages,
329 : sal_Int32 nFirstPage, sal_Int32 nLastPage );
330 : sal_Bool implExportPage( const ::rtl::OUString & sPageId,
331 : const Reference< XDrawPage > & rxPage,
332 : const Reference< XShapes > & xShapes,
333 : sal_Bool bMaster );
334 :
335 : sal_Bool implExportShapes( const Reference< XShapes >& rxShapes );
336 : sal_Bool implExportShape( const Reference< XShape >& rxShape );
337 :
338 : sal_Bool implCreateObjects();
339 : sal_Bool implCreateObjectsFromShapes( const Reference< XDrawPage > & rxPage, const Reference< XShapes >& rxShapes );
340 : sal_Bool implCreateObjectsFromShape( const Reference< XDrawPage > & rxPage, const Reference< XShape >& rxShape );
341 : sal_Bool implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage );
342 :
343 : ::rtl::OUString implGetClassFromShape( const Reference< XShape >& rxShape );
344 : void implRegisterInterface( const Reference< XInterface >& rxIf );
345 : const ::rtl::OUString & implGetValidIDFromInterface( const Reference< XInterface >& rxIf );
346 : ::rtl::OUString implGetInterfaceName( const Reference< XInterface >& rxIf );
347 : sal_Bool implLookForFirstVisiblePage();
348 : Any implSafeGetPagePropSet( const ::rtl::OUString & sPropertyName,
349 : const Reference< XPropertySet > & rxPropSet,
350 : const Reference< XPropertySetInfo > & rxPropSetInfo );
351 : DECL_LINK( CalcFieldHdl, EditFieldInfo* );
352 :
353 : protected:
354 :
355 : // XFilter
356 : virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException);
357 : virtual void SAL_CALL cancel( ) throw (RuntimeException);
358 :
359 : // XImporter
360 : virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
361 :
362 : // XExporter
363 : virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
364 :
365 : // XExtendedFilterDetection
366 : virtual rtl::OUString SAL_CALL detect( Sequence< PropertyValue >& io_rDescriptor ) throw (RuntimeException);
367 :
368 : public:
369 :
370 : explicit SVGFilter( const Reference< XComponentContext >& rxCtx );
371 : virtual ~SVGFilter();
372 : };
373 :
374 : #endif // SVGFILTER_HXX
375 :
376 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|