1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
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>
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
;
96 using namespace ::std
;
98 #define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
101 // Placeholder tag used into the ImplWriteActions method to filter text placeholder fields
102 static const OUString sPlaceholderTag
= OUString::createFromAscii( "<[:isPlaceholder:]>" );
104 class SVGExport
: public SvXMLExport
106 typedef ::std::list
< ::basegfx::B2DPolyPolygon
> B2DPolyPolygonList
;
110 SVGExport( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
,
111 const Reference
< XDocumentHandler
>& rxHandler
,
112 const Sequence
< PropertyValue
>& rFilterData
);
114 virtual ~SVGExport();
116 sal_Bool
IsUseTinyProfile() const;
117 sal_Bool
IsEmbedFonts() const;
118 sal_Bool
IsUsePositionedCharacters() const;
119 sal_Bool
IsUseNativeTextDecoration() const;
120 sal_Bool
IsUseOpacity() const;
122 void writeMtf( const GDIMetaFile
& rMtf
);
126 virtual void _ExportStyles( sal_Bool
/* bUsed */ ) {}
127 virtual void _ExportAutoStyles() {}
128 virtual void _ExportContent() {}
129 virtual void _ExportMasterStyles() {}
130 virtual sal_uInt32
exportDoc( enum ::xmloff::token::XMLTokenEnum
/* eClass */ ) { return 0; }
134 const Sequence
< PropertyValue
>& mrFilterData
;
139 class ObjectRepresentation
143 Reference
< XInterface
> mxObject
;
148 ObjectRepresentation();
149 ObjectRepresentation( const Reference
< XInterface
>& rxIf
,
150 const GDIMetaFile
& rMtf
);
151 ObjectRepresentation( const ObjectRepresentation
& rPresentation
);
152 ~ObjectRepresentation();
154 ObjectRepresentation
& operator=( const ObjectRepresentation
& rPresentation
);
155 sal_Bool
operator==( const ObjectRepresentation
& rPresentation
) const;
157 const Reference
< XInterface
>& GetObject() const { return mxObject
; }
158 sal_Bool
HasRepresentation() const { return mpMtf
!= NULL
; }
159 const GDIMetaFile
& GetRepresentation() const { return *mpMtf
; }
162 struct PagePropertySet
164 sal_Bool bIsBackgroundVisible
;
165 sal_Bool bAreBackgroundObjectsVisible
;
166 sal_Bool bIsPageNumberFieldVisible
;
167 sal_Bool bIsDateTimeFieldVisible
;
168 sal_Bool bIsFooterFieldVisible
;
169 sal_Bool bIsHeaderFieldVisible
;
170 sal_Int32 nPageNumberingType
;
171 sal_Bool bIsDateTimeFieldFixed
;
172 sal_Int16 nPageNumber
;
173 sal_Int32 nDateTimeFormat
;
174 OUString sDateTimeText
;
175 OUString sFooterText
;
176 OUString sHeaderText
;
179 struct HashReferenceXInterface
181 size_t operator()( const Reference
< XInterface
>& rxIf
) const
183 return reinterpret_cast< size_t >( rxIf
.get() );
189 size_t operator()( const OUString
& oustr
) const { return static_cast< size_t >( oustr
.hashCode() ); }
194 size_t operator()( const sal_Unicode uchar
) const { return static_cast< size_t >( uchar
); }
199 size_t operator()( const ObjectRepresentation
& rObjRep
) const;
202 struct EqualityBitmap
204 bool operator()( const ObjectRepresentation
& rObjRep1
,
205 const ObjectRepresentation
& rObjRep2
) const;
209 class SVGActionWriter
;
212 class SVGFilter
: public cppu::WeakImplHelper4
< XFilter
,
215 XExtendedFilterDetection
>
218 typedef ::boost::unordered_map
< Reference
< XInterface
>, ObjectRepresentation
, HashReferenceXInterface
> ObjectMap
;
219 typedef ::boost::unordered_set
< Reference
< XInterface
>, HashReferenceXInterface
> ObjectSet
;
220 typedef Sequence
< Reference
< XInterface
> > ObjectSequence
;
221 typedef Sequence
< Reference
< XDrawPage
> > XDrawPageSequence
;
223 typedef ::boost::unordered_set
< sal_Unicode
, HashUChar
> UCharSet
;
224 typedef ::boost::unordered_map
< OUString
, UCharSet
, HashOUString
> UCharSetMap
;
225 typedef ::boost::unordered_map
< Reference
< XInterface
>, UCharSetMap
, HashReferenceXInterface
> UCharSetMapMap
;
227 typedef ::boost::unordered_map
< Reference
< XInterface
>, OUString
, HashReferenceXInterface
> UOStringMap
;
229 typedef ::boost::unordered_set
< ObjectRepresentation
, HashBitmap
, EqualityBitmap
> MetaBitmapActionSet
;
233 Reference
< XComponentContext
> mxContext
;
234 SvXMLElementExport
* mpSVGDoc
;
235 SVGExport
* mpSVGExport
;
236 SVGFontExport
* mpSVGFontExport
;
237 SVGActionWriter
* mpSVGWriter
;
238 SdrPage
* mpDefaultSdrPage
;
239 SdrModel
* mpSdrModel
;
240 sal_Bool mbPresentation
;
241 sal_Bool mbExportAll
;
242 sal_Bool mbSinglePage
;
243 sal_Int32 mnVisiblePage
;
244 PagePropertySet mVisiblePagePropSet
;
245 OUString msClipPathId
;
246 UCharSetMapMap mTextFieldCharSets
;
247 Reference
< XInterface
> mCreateOjectsCurrentMasterPage
;
248 UOStringMap mTextShapeIdListMap
;
249 #ifndef DISABLE_EXPORT
250 MetaBitmapActionSet mEmbeddedBitmapActionSet
;
251 ObjectMap mEmbeddedBitmapActionMap
;
253 ObjectMap
* mpObjects
;
254 Reference
< XComponent
> mxSrcDoc
;
255 Reference
< XComponent
> mxDstDoc
;
256 Reference
< XDrawPage
> mxDefaultPage
;
257 Sequence
< PropertyValue
> maFilterData
;
258 XDrawPageSequence mSelectedPages
;
259 XDrawPageSequence mMasterPageTargets
;
263 sal_Bool
implImport( const Sequence
< PropertyValue
>& rDescriptor
) throw (RuntimeException
);
265 sal_Bool
implExport( const Sequence
< PropertyValue
>& rDescriptor
) throw (RuntimeException
);
266 Reference
< XWriter
> implCreateExportDocumentHandler( const Reference
< XOutputStream
>& rxOStm
);
268 sal_Bool
implGetPagePropSet( const Reference
< XDrawPage
> & rxPage
);
269 sal_Bool
implGenerateMetaData();
270 void implExportTextShapeIndex();
271 void implEmbedBulletGlyphs();
272 void implEmbedBulletGlyph( sal_Unicode cBullet
, const OUString
& sPathData
);
273 sal_Bool
implExportTextEmbeddedBitmaps();
274 sal_Bool
implGenerateScript();
276 sal_Bool
implExportDocument();
277 sal_Bool
implExportAnimations();
279 sal_Bool
implExportMasterPages( const XDrawPageSequence
& rxPages
,
280 sal_Int32 nFirstPage
, sal_Int32 nLastPage
);
281 sal_Bool
implExportDrawPages( const XDrawPageSequence
& rxPages
,
282 sal_Int32 nFirstPage
, sal_Int32 nLastPage
);
283 sal_Bool
implExportPage( const OUString
& sPageId
,
284 const Reference
< XDrawPage
> & rxPage
,
285 const Reference
< XShapes
> & xShapes
,
288 sal_Bool
implExportShapes( const Reference
< XShapes
>& rxShapes
);
289 sal_Bool
implExportShape( const Reference
< XShape
>& rxShape
);
291 sal_Bool
implCreateObjects();
292 sal_Bool
implCreateObjectsFromShapes( const Reference
< XDrawPage
> & rxPage
, const Reference
< XShapes
>& rxShapes
);
293 sal_Bool
implCreateObjectsFromShape( const Reference
< XDrawPage
> & rxPage
, const Reference
< XShape
>& rxShape
);
294 sal_Bool
implCreateObjectsFromBackground( const Reference
< XDrawPage
>& rxMasterPage
);
296 OUString
implGetClassFromShape( const Reference
< XShape
>& rxShape
);
297 void implRegisterInterface( const Reference
< XInterface
>& rxIf
);
298 const OUString
& implGetValidIDFromInterface( const Reference
< XInterface
>& rxIf
);
299 OUString
implGetInterfaceName( const Reference
< XInterface
>& rxIf
);
300 sal_Bool
implLookForFirstVisiblePage();
301 Any
implSafeGetPagePropSet( const OUString
& sPropertyName
,
302 const Reference
< XPropertySet
> & rxPropSet
,
303 const Reference
< XPropertySetInfo
> & rxPropSetInfo
);
304 DECL_LINK( CalcFieldHdl
, EditFieldInfo
* );
309 virtual sal_Bool SAL_CALL
filter( const Sequence
< PropertyValue
>& rDescriptor
) throw(RuntimeException
);
310 virtual void SAL_CALL
cancel( ) throw (RuntimeException
);
313 virtual void SAL_CALL
setTargetDocument( const Reference
< XComponent
>& xDoc
) throw(IllegalArgumentException
, RuntimeException
);
316 virtual void SAL_CALL
setSourceDocument( const Reference
< XComponent
>& xDoc
) throw(IllegalArgumentException
, RuntimeException
);
318 // XExtendedFilterDetection
319 virtual OUString SAL_CALL
detect( Sequence
< PropertyValue
>& io_rDescriptor
) throw (RuntimeException
);
323 explicit SVGFilter( const Reference
< XComponentContext
>& rxCtx
);
324 virtual ~SVGFilter();
327 #endif // SVGFILTER_HXX
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */