xref: /AOO41X/main/filter/source/svg/svgfilter.hxx (revision 33f678dd487b6ffa444f902e3effe534b60ad3e9)
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 #ifndef SVGFILTER_HXX
25 #define SVGFILTER_HXX
26 
27 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
28 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
29 #include <com/sun/star/container/XNamed.hpp>
30 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
31 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
32 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
33 #include <com/sun/star/document/XFilter.hpp>
34 #ifdef SOLAR_JAVA
35 #include <com/sun/star/document/XImporter.hpp>
36 #endif // SOLAR_JAVA
37 #include <com/sun/star/document/XExporter.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
42 #include <cppuhelper/implbase1.hxx>
43 #ifdef SOLAR_JAVA
44 #include <cppuhelper/implbase5.hxx>
45 #else // !SOLAR_JAVA
46 #include <cppuhelper/implbase4.hxx>
47 #endif
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <com/sun/star/io/XActiveDataSource.hpp>
50 #include <com/sun/star/presentation/AnimationEffect.hpp>
51 #include <com/sun/star/presentation/AnimationSpeed.hpp>
52 #include <com/sun/star/presentation/ClickAction.hpp>
53 #include <com/sun/star/presentation/FadeEffect.hpp>
54 #include <com/sun/star/text/XText.hpp>
55 #include <com/sun/star/frame/XDesktop.hpp>
56 #include <com/sun/star/java/XJavaVM.hpp>
57 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 
60 #include <hash_map>
61 #include <osl/diagnose.h>
62 #include <rtl/process.h>
63 #include <basegfx/polygon/b2dpolypolygon.hxx>
64 #include <basegfx/polygon/b2dpolygonclipper.hxx>
65 #include <basegfx/polygon/b2dpolypolygontools.hxx>
66 #include <tools/debug.hxx>
67 #include <comphelper/processfactory.hxx>
68 #include <unotools/tempfile.hxx>
69 #include <unotools/localfilehelper.hxx>
70 #include <unotools/ucbstreamhelper.hxx>
71 #include <unotools/streamwrap.hxx>
72 #include <vcl/cvtgrf.hxx>
73 #include <vcl/svapp.hxx>
74 #include <vcl/outdev.hxx>
75 #include <vcl/metaact.hxx>
76 #include <svtools/grfmgr.hxx>
77 #include <svx/unomodel.hxx>
78 #include <svx/unoapi.hxx>
79 #include <svx/svdxcgv.hxx>
80 #include <svx/svdobj.hxx>
81 #include <xmloff/xmlexp.hxx>
82 #include "svgfilter.hxx"
83 #include "svgscript.hxx"
84 
85 #include <cstdio>
86 
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::container;
89 using namespace ::com::sun::star::lang;
90 using namespace ::com::sun::star::beans;
91 using namespace ::com::sun::star::java;
92 using namespace ::com::sun::star::drawing;
93 using namespace ::com::sun::star::presentation;
94 using namespace ::com::sun::star::document;
95 using namespace ::com::sun::star::text;
96 using namespace ::com::sun::star::io;
97 using namespace ::com::sun::star::xml::sax;
98 using namespace ::std;
99 
100 // -----------
101 // - Defines -
102 // -----------
103 
104 #define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
105 
106 // -------------
107 // - SVGExport -
108 // -------------
109 
110 // #110680#
111 class SVGExport : public SvXMLExport
112 {
113     typedef ::std::list< ::basegfx::B2DPolyPolygon > B2DPolyPolygonList;
114 
115     rtl::OUString   maGlyphPlacement;
116 
117     sal_Bool    mbTinyProfile;
118     sal_Bool    mbTSpans;
119     sal_Bool    mbEmbedFonts;
120     sal_Bool    mbNativeTextDecoration;
121     sal_Bool    mbOpacity;
122     sal_Bool    mbGradient;
123 
124     Rectangle   maViewBox;
125 
126 public:
127 
128     SVGExport( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
129                 const Reference< XDocumentHandler >& rxHandler,
130                 const Sequence< PropertyValue >& rFilterData );
131 
132     virtual ~SVGExport();
133 
IsUseTinyProfile() const134     sal_Bool IsUseTinyProfile() const { return mbTinyProfile; };
IsUseTSpans() const135     sal_Bool IsUseTSpans() const { return mbTSpans; };
IsEmbedFonts() const136     sal_Bool IsEmbedFonts() const { return mbEmbedFonts; };
IsUseNativeTextDecoration() const137     sal_Bool IsUseNativeTextDecoration() const { return mbNativeTextDecoration; };
GetGlyphPlacement() const138     ::rtl::OUString GetGlyphPlacement() const { return maGlyphPlacement; };
IsUseOpacity() const139     sal_Bool IsUseOpacity() const { return mbOpacity; };
IsUseGradient() const140     sal_Bool IsUseGradient() const { return mbGradient; };
141 
GetViewBox() const142     const Rectangle& GetViewBox() const { return maViewBox; };
SetViewBox(const Rectangle & rViewBox)143     void SetViewBox( const Rectangle& rViewBox ) { maViewBox = rViewBox; };
IsVisible(const Rectangle & rRect) const144     sal_Bool IsVisible( const Rectangle& rRect ) const { return GetViewBox().IsOver( rRect ); };
145 
146     void  pushClip( const ::basegfx::B2DPolyPolygon& rPolyPoly );
147     void  popClip();
148     sal_Bool  hasClip() const;
149     const ::basegfx::B2DPolyPolygon* getCurClip() const;
150 
151     void writeMtf( const GDIMetaFile& rMtf );
152 
153 protected:
154 
_ExportStyles(sal_Bool)155 virtual void            _ExportStyles( sal_Bool /* bUsed */ ) {}
_ExportAutoStyles()156 virtual void            _ExportAutoStyles() {}
_ExportContent()157 virtual void            _ExportContent() {}
_ExportMasterStyles()158 virtual void            _ExportMasterStyles() {}
exportDoc(enum::xmloff::token::XMLTokenEnum)159 virtual sal_uInt32      exportDoc( enum ::xmloff::token::XMLTokenEnum /* eClass */ ) { return 0; }
160 
161 private:
162 
163     B2DPolyPolygonList      maClipList;
164 
165     SVGExport();
166 };
167 
168 // ------------------------
169 // - ObjectRepresentation -
170 // ------------------------
171 
172 class ObjectRepresentation
173 {
174 private:
175 
176     Reference< XInterface >         mxObject;
177     GDIMetaFile*                    mpMtf;
178 
179 public:
180 
181                                     ObjectRepresentation();
182                                     ObjectRepresentation( const Reference< XInterface >& rxIf,
183                                                           const GDIMetaFile& rMtf );
184                                     ObjectRepresentation( const ObjectRepresentation& rPresentation );
185                                     ~ObjectRepresentation();
186 
187     ObjectRepresentation&           operator=( const ObjectRepresentation& rPresentation );
188     sal_Bool                            operator==( const ObjectRepresentation& rPresentation ) const;
189 
GetObject() const190     const Reference< XInterface >&  GetObject() const { return mxObject; }
HasRepresentation() const191     sal_Bool                        HasRepresentation() const { return mpMtf != NULL; }
GetRepresentation() const192     const GDIMetaFile&              GetRepresentation() const { return *mpMtf; }
193 };
194 
195 // ---------------------------
196 // - HashReferenceXInterface -
197 // ---------------------------
198 
199 struct HashReferenceXInterface
200 {
operator ()HashReferenceXInterface201     size_t operator()( const Reference< XInterface >& rxIf ) const
202     {
203         return reinterpret_cast< size_t >( rxIf.get() );
204     }
205 };
206 
207 // -------------
208 // - SVGFilter -
209 // -------------
210 
211 class SVGFontExport;
212 class SVGActionWriter;
213 class EditFieldInfo;
214 
215 #ifdef SOLAR_JAVA
216 class SVGFilter : public cppu::WeakImplHelper5 < XFilter,
217                                                  XImporter,
218                                                  XExporter,
219                                                  XInitialization,
220                                                  XServiceInfo >
221 #else // !SOLAR_JAVA
222 class SVGFilter : public cppu::WeakImplHelper4 < XFilter,
223                                                  XExporter,
224                                                  XInitialization,
225                                                  XServiceInfo >
226 #endif
227 {
228     typedef ::std::hash_map< Reference< XInterface >, ObjectRepresentation, HashReferenceXInterface > ObjectMap;
229     typedef ::std::vector< ::rtl::OUString > UniqueIdVector;
230 
231 private:
232 
233     Reference< XMultiServiceFactory >   mxMSF;
234     SvXMLElementExport*                 mpSVGDoc;
235     SVGExport*                          mpSVGExport;
236     SVGFontExport*                      mpSVGFontExport;
237     SVGActionWriter*                    mpSVGWriter;
238     SdrPage*                            mpDefaultSdrPage;
239     SdrModel*                           mpSdrModel;
240     sal_Bool                            mbPresentation;
241 
242     ObjectMap*                          mpObjects;
243     Reference< XComponent >             mxSrcDoc;
244 #ifdef SOLAR_JAVA
245     Reference< XComponent >             mxDstDoc;
246 #endif
247     Reference< XDrawPage >              mxDefaultPage;
248     Sequence< PropertyValue >           maFilterData;
249 
250     // #124608# explicit ShapeSelection for export when export of the selection is wanted
251     Reference< XShapes >                maShapeSelection;
252     bool                                mbExportSelection;
253 
254     UniqueIdVector                      maUniqueIdVector;
255     sal_Int32                           mnMasterSlideId;
256     sal_Int32                           mnSlideId;
257     sal_Int32                           mnDrawingGroupId;
258     sal_Int32                           mnDrawingId;
259     Link                                maOldFieldHdl;
260 
261 #ifdef SOLAR_JAVA
262     sal_Bool                            implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
263 #endif
264 
265     sal_Bool                            implExport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
266     Reference< XDocumentHandler >       implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm );
267 
268     sal_Bool                            implGenerateMetaData( const Reference< XDrawPages >& rxMasterPages,
269                                                               const Reference< XDrawPages >& rxDrawPages );
270     sal_Bool                            implGenerateScript( const Reference< XDrawPages >& rxMasterPages,
271                                                             const Reference< XDrawPages >& rxDrawPages );
272 
273     sal_Bool                            implExportDocument( const Reference< XDrawPages >& rxMasterPages,
274                                                             const Reference< XDrawPages >& rxDrawPages,
275                                                             sal_Int32 nPageToExport );
276 
277     sal_Bool                            implExportPages( const Reference< XDrawPages >& rxPages,
278                                                          sal_Int32 nFirstPage, sal_Int32 nLastPage,
279                                                          sal_Int32 nVisiblePage, sal_Bool bMaster );
280 
281     sal_Bool                            implExportShapes( const Reference< XShapes >& rxShapes );
282     sal_Bool                            implExportShape( const Reference< XShape >& rxShape );
283 
284     sal_Bool                            implCreateObjects( const Reference< XDrawPages >& rxMasterPages,
285                                                            const Reference< XDrawPages >& rxDrawPages,
286                                                            sal_Int32 nPageToExport );
287     sal_Bool                            implCreateObjectsFromShapes( const Reference< XShapes >& rxShapes );
288     sal_Bool                            implCreateObjectsFromShape( const Reference< XShape >& rxShape );
289     sal_Bool                            implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage );
290 
291     ::rtl::OUString                     implGetDescriptionFromShape( const Reference< XShape >& rxShape );
292     ::rtl::OUString                     implGetValidIDFromInterface( const Reference< XInterface >& rxIf, sal_Bool bUnique = sal_False );
293 
294     sal_Bool                                implHasText( const GDIMetaFile& rMtf ) const;
295 
296                                         DECL_LINK( CalcFieldHdl, EditFieldInfo* );
297 
298 protected:
299 
300     // XFilter
301     virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException);
302     virtual void SAL_CALL cancel( ) throw (RuntimeException);
303 
304 #ifdef SOLAR_JAVA
305     // XImporter
306     virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
307 #endif
308 
309     // XExporter
310     virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException);
311 
312     // XInitialization
313     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
314 
315     // XServiceInfo
316     virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
317     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException);
318     virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()  throw(RuntimeException);
319 
320 public:
321 
322                 SVGFilter( const Reference< XMultiServiceFactory > &rxMSF );
323     virtual     ~SVGFilter();
324 };
325 
326 // -----------------------------------------------------------------------------
327 
328 ::rtl::OUString SVGFilter_getImplementationName ()
329     throw ( ::com::sun::star::uno::RuntimeException );
330 
331 // -----------------------------------------------------------------------------
332 
333 sal_Bool SAL_CALL SVGFilter_supportsService( const ::rtl::OUString& ServiceName )
334     throw ( ::com::sun::star::uno::RuntimeException );
335 
336 // -----------------------------------------------------------------------------
337 
338 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SVGFilter_getSupportedServiceNames(  )
339     throw ( ::com::sun::star::uno::RuntimeException );
340 
341 // -----------------------------------------------------------------------------
342 
343 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
344 SAL_CALL SVGFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
345     throw ( ::com::sun::star::uno::Exception );
346 
347 #endif // SVGFILTER_HXX
348