fix typo
[LibreOffice.git] / filter / source / svg / svgfilter.hxx
blob0a2ee253f3f366f8895a54215410a9d104ee9805
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef SVGFILTER_HXX
30 #define SVGFILTER_HXX
32 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
33 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
34 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
35 #include <com/sun/star/container/XNamed.hpp>
37 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
38 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
39 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
40 #include <com/sun/star/document/XFilter.hpp>
41 #include <com/sun/star/document/XImporter.hpp>
42 #include <com/sun/star/document/XExporter.hpp>
43 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
44 #include <com/sun/star/lang/XInitialization.hpp>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/lang/XComponent.hpp>
48 #include <cppuhelper/implbase4.hxx>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/io/XActiveDataSource.hpp>
51 #include <com/sun/star/presentation/AnimationEffect.hpp>
52 #include <com/sun/star/presentation/AnimationSpeed.hpp>
53 #include <com/sun/star/presentation/ClickAction.hpp>
54 #include <com/sun/star/presentation/FadeEffect.hpp>
55 #include <com/sun/star/text/XText.hpp>
56 #include <com/sun/star/frame/XDesktop.hpp>
57 #include <com/sun/star/java/XJavaVM.hpp>
58 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
59 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60 #include <com/sun/star/style/ParagraphAdjust.hdl>
61 #include <com/sun/star/style/ParagraphAdjust.hpp>
62 #include <com/sun/star/drawing/FillStyle.hpp>
63 #include <com/sun/star/graphic/XGraphicProvider.hpp>
64 #include <com/sun/star/graphic/XGraphicProvider.hdl>
67 #include <boost/unordered_set.hpp>
68 #include <boost/unordered_map.hpp>
69 #include <osl/diagnose.h>
70 #include <rtl/process.h>
71 #include <basegfx/polygon/b2dpolypolygon.hxx>
72 #include <basegfx/polygon/b2dpolygonclipper.hxx>
73 #include <basegfx/polygon/b2dpolypolygontools.hxx>
74 #include <tools/debug.hxx>
75 #include <comphelper/processfactory.hxx>
76 #include <unotools/tempfile.hxx>
77 #include <unotools/localfilehelper.hxx>
78 #include <unotools/ucbstreamhelper.hxx>
79 #include <unotools/streamwrap.hxx>
80 #include <vcl/cvtgrf.hxx>
81 #include <vcl/svapp.hxx>
82 #include <vcl/outdev.hxx>
83 #include <vcl/metaact.hxx>
84 #include <svtools/grfmgr.hxx>
85 #include <svx/unomodel.hxx>
86 #include <svx/unoapi.hxx>
87 #include <svx/svdxcgv.hxx>
88 #include <svx/svdobj.hxx>
89 #include <xmloff/xmlexp.hxx>
91 #include <cstdio>
94 using namespace ::com::sun::star::animations;
95 using namespace ::com::sun::star::beans;
96 using namespace ::com::sun::star::container;
97 using namespace ::com::sun::star::document;
98 using namespace ::com::sun::star::drawing;
99 using namespace ::com::sun::star::io;
100 using namespace ::com::sun::star::java;
101 using namespace ::com::sun::star::lang;
102 using namespace ::com::sun::star::presentation;
103 using namespace ::com::sun::star::style;
104 using namespace ::com::sun::star::text;
105 using namespace ::com::sun::star::uno;
106 using namespace ::com::sun::star::xml::sax;
108 using namespace ::std;
110 // -----------
111 // - Defines -
112 // -----------
114 #define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
117 // -----------
118 // - statics -
119 // -----------
121 // Placeholder tag used into the ImplWriteActions method to filter text placeholder fields
122 static const ::rtl::OUString sPlaceholderTag = ::rtl::OUString::createFromAscii( "<[:isPlaceholder:]>" );
125 // -------------
126 // - SVGExport -
127 // -------------
129 // #110680#
130 class SVGExport : public SvXMLExport
132 typedef ::std::list< ::basegfx::B2DPolyPolygon > B2DPolyPolygonList;
134 public:
136 SVGExport( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
137 const Reference< XDocumentHandler >& rxHandler,
138 const Sequence< PropertyValue >& rFilterData );
140 virtual ~SVGExport();
142 sal_Bool IsUseTinyProfile() const;
143 sal_Bool IsEmbedFonts() const;
144 sal_Bool IsUseNativeTextDecoration() const;
145 ::rtl::OUString GetGlyphPlacement() const;
146 sal_Bool IsUseOpacity() const;
147 sal_Bool IsUseGradient() const;
149 void pushClip( const ::basegfx::B2DPolyPolygon& rPolyPoly );
150 void popClip();
151 sal_Bool hasClip() const;
152 const ::basegfx::B2DPolyPolygon* getCurClip() const;
154 protected:
156 virtual void _ExportStyles( sal_Bool /* bUsed */ ) {}
157 virtual void _ExportAutoStyles() {}
158 virtual void _ExportContent() {}
159 virtual void _ExportMasterStyles() {}
160 virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum /* eClass */ ) { return 0; }
162 private:
164 const Sequence< PropertyValue >& mrFilterData;
165 B2DPolyPolygonList maClipList;
167 SVGExport();
170 // ------------------------
171 // - ObjectRepresentation -
172 // ------------------------
174 class ObjectRepresentation
176 private:
178 Reference< XInterface > mxObject;
179 GDIMetaFile* mpMtf;
181 public:
183 ObjectRepresentation();
184 ObjectRepresentation( const Reference< XInterface >& rxIf,
185 const GDIMetaFile& rMtf );
186 ObjectRepresentation( const ObjectRepresentation& rPresentation );
187 ~ObjectRepresentation();
189 ObjectRepresentation& operator=( const ObjectRepresentation& rPresentation );
190 sal_Bool operator==( const ObjectRepresentation& rPresentation ) const;
192 const Reference< XInterface >& GetObject() const { return mxObject; }
193 sal_Bool HasRepresentation() const { return mpMtf != NULL; }
194 const GDIMetaFile& GetRepresentation() const { return *mpMtf; }
197 // -------------------
198 // - PagePropertySet -
199 // -------------------
201 struct PagePropertySet
203 sal_Bool bIsBackgroundVisible;
204 sal_Bool bAreBackgroundObjectsVisible;
205 sal_Bool bIsPageNumberFieldVisible;
206 sal_Bool bIsDateTimeFieldVisible;
207 sal_Bool bIsFooterFieldVisible;
208 sal_Bool bIsHeaderFieldVisible;
209 sal_Int32 nPageNumberingType;
210 sal_Bool bIsDateTimeFieldFixed;
211 sal_Int16 nPageNumber;
212 sal_Int32 nDateTimeFormat;
213 ::rtl::OUString sDateTimeText;
214 ::rtl::OUString sFooterText;
215 ::rtl::OUString sHeaderText;
220 // ---------------------------
221 // - HashReferenceXInterface -
222 // ---------------------------
224 struct HashReferenceXInterface
226 size_t operator()( const Reference< XInterface >& rxIf ) const
228 return reinterpret_cast< size_t >( rxIf.get() );
232 // ---------------------------
233 // - HashOUString -
234 // ---------------------------
236 struct HashOUString
238 size_t operator()( const ::rtl::OUString& oustr ) const { return static_cast< size_t >( oustr.hashCode() ); }
241 // ---------------------------
242 // - HashUChar -
243 // ---------------------------
245 struct HashUChar
247 size_t operator()( const sal_Unicode uchar ) const { return static_cast< size_t >( uchar ); }
251 // -------------
252 // - SVGFilter -
253 // -------------
255 class SVGFontExport;
256 class SVGActionWriter;
257 class EditFieldInfo;
259 class SVGFilter : public cppu::WeakImplHelper4 < XFilter,
260 XImporter,
261 XExporter,
262 XExtendedFilterDetection >
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;
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;
274 private:
276 Reference< XMultiServiceFactory > mxMSF;
277 SvXMLElementExport* mpSVGDoc;
278 SVGExport* mpSVGExport;
279 SVGFontExport* mpSVGFontExport;
280 SVGActionWriter* mpSVGWriter;
281 SdrPage* mpDefaultSdrPage;
282 SdrModel* mpSdrModel;
283 sal_Bool mbPresentation;
284 sal_Bool mbExportAll;
285 sal_Bool mbSinglePage;
286 sal_Int32 mnVisiblePage;
287 sal_Int32 mnVisibleMasterPage;
288 sal_Bool mbIsPageVisible;
289 PagePropertySet mVisiblePagePropSet;
290 ::rtl::OUString msClipPathId;
291 UCharSetMapMap mTextFieldCharSets;
292 Reference< XInterface > mCreateOjectsCurrentMasterPage;
294 ObjectMap* mpObjects;
295 Reference< XComponent > mxSrcDoc;
296 Reference< XComponent > mxDstDoc;
297 Reference< XDrawPage > mxDefaultPage;
298 Sequence< PropertyValue > maFilterData;
299 XDrawPageSequence mSelectedPages;
300 XDrawPageSequence mMasterPageTargets;
302 Link maOldFieldHdl;
304 sal_Bool implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
306 sal_Bool implExport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
307 Reference< XDocumentHandler > implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm );
309 sal_Bool implGetPagePropSet( const Reference< XDrawPage > & rxPage );
310 sal_Bool implGenerateMetaData();
311 sal_Bool implGenerateScript();
313 sal_Bool implExportDocument();
314 sal_Bool implExportAnimations();
316 sal_Bool implExportPages( const XDrawPageSequence& rxPages,
317 sal_Int32 nFirstPage, sal_Int32 nLastPage,
318 sal_Int32 nVisiblePage, sal_Bool bMaster );
320 sal_Bool implExportShapes( const Reference< XShapes >& rxShapes );
321 sal_Bool implExportShape( const Reference< XShape >& rxShape );
323 sal_Bool implCreateObjects();
324 sal_Bool implCreateObjectsFromShapes( const Reference< XShapes >& rxShapes );
325 sal_Bool implCreateObjectsFromShape( const Reference< XShape >& rxShape );
326 sal_Bool implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage );
328 ::rtl::OUString implGetClassFromShape( const Reference< XShape >& rxShape );
329 void implRegisterInterface( const Reference< XInterface >& rxIf );
330 const ::rtl::OUString & implGetValidIDFromInterface( const Reference< XInterface >& rxIf );
331 ::rtl::OUString implGetInterfaceName( const Reference< XInterface >& rxIf );
332 sal_Bool implLookForFirstVisiblePage();
333 Any implSafeGetPagePropSet( const ::rtl::OUString & sPropertyName,
334 const Reference< XPropertySet > & rxPropSet,
335 const Reference< XPropertySetInfo > & rxPropSetInfo );
336 DECL_LINK( CalcFieldHdl, EditFieldInfo* );
338 protected:
340 // XFilter
341 virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException);
342 virtual void SAL_CALL cancel( ) throw (RuntimeException);
344 // XImporter
345 virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
347 // XExporter
348 virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
350 // XExtendedFilterDetection
351 virtual rtl::OUString SAL_CALL detect( Sequence< PropertyValue >& io_rDescriptor ) throw (RuntimeException);
353 public:
355 explicit SVGFilter( const Reference< XComponentContext >& rxCtx );
356 virtual ~SVGFilter();
359 // -----------------------------------------------------------------------------
363 class SvStream;
364 class Graphic;
366 bool importSvg(SvStream & rStream, Graphic & rGraphic );
368 #endif // SVGFILTER_HXX
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */