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 INCLUDED_FILTER_SOURCE_SVG_SVGFILTER_HXX
21 : #define INCLUDED_FILTER_SOURCE_SVG_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/text/XText.hpp>
42 : #include <com/sun/star/style/ParagraphAdjust.hpp>
43 : #include <com/sun/star/drawing/FillStyle.hpp>
44 : #include <com/sun/star/xml/sax/XWriter.hpp>
45 :
46 : #include <boost/unordered_set.hpp>
47 : #include <boost/unordered_map.hpp>
48 : #include <osl/diagnose.h>
49 : #include <sal/log.hxx>
50 : #include <rtl/process.h>
51 : #include <basegfx/polygon/b2dpolypolygon.hxx>
52 : #include <basegfx/polygon/b2dpolygonclipper.hxx>
53 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
54 : #include <comphelper/processfactory.hxx>
55 : #include <unotools/tempfile.hxx>
56 : #include <unotools/ucbstreamhelper.hxx>
57 : #include <unotools/streamwrap.hxx>
58 : #include <vcl/cvtgrf.hxx>
59 : #include <vcl/svapp.hxx>
60 : #include <vcl/outdev.hxx>
61 : #include <svtools/grfmgr.hxx>
62 : #include <svx/unoapi.hxx>
63 : #include <svx/svdxcgv.hxx>
64 : #include <svx/svdobj.hxx>
65 : #include <xmloff/xmlexp.hxx>
66 :
67 : #include <cstdio>
68 :
69 :
70 : using namespace ::com::sun::star::animations;
71 : using namespace ::com::sun::star::beans;
72 : using namespace ::com::sun::star::container;
73 : using namespace ::com::sun::star::document;
74 : using namespace ::com::sun::star::drawing;
75 : using namespace ::com::sun::star::io;
76 : using namespace ::com::sun::star::lang;
77 : using namespace ::com::sun::star::presentation;
78 : using namespace ::com::sun::star::style;
79 : using namespace ::com::sun::star::text;
80 : using namespace ::com::sun::star::uno;
81 : using namespace ::com::sun::star::xml::sax;
82 :
83 : using namespace ::std;
84 :
85 : #define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
86 :
87 :
88 : // Placeholder tag used into the ImplWriteActions method to filter text placeholder fields
89 0 : static const OUString sPlaceholderTag( "<[:isPlaceholder:]>" );
90 :
91 : class SVGExport : public SvXMLExport
92 : {
93 : typedef ::std::list< ::basegfx::B2DPolyPolygon > B2DPolyPolygonList;
94 :
95 : bool mbIsUseTinyProfile;
96 : bool mbIsEmbedFonts;
97 : bool mbIsUseOpacity;
98 : bool mbIsUseNativeTextDecoration;
99 : bool mbIsUsePositionedCharacters;
100 :
101 : public:
102 :
103 : SVGExport( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
104 : const Reference< XDocumentHandler >& rxHandler,
105 : const Sequence< PropertyValue >& rFilterData );
106 :
107 : virtual ~SVGExport();
108 :
109 0 : bool IsUseTinyProfile() const { return mbIsUseTinyProfile; };
110 0 : bool IsEmbedFonts() const { return mbIsEmbedFonts; };
111 0 : bool IsUseOpacity() const { return mbIsUseOpacity; };
112 0 : bool IsUseNativeTextDecoration() const { return mbIsUseNativeTextDecoration; };
113 0 : bool IsUsePositionedCharacters() const { return mbIsUsePositionedCharacters; };
114 :
115 : void writeMtf( const GDIMetaFile& rMtf );
116 :
117 : protected:
118 :
119 0 : virtual void _ExportStyles( bool /* bUsed */ ) SAL_OVERRIDE {}
120 0 : virtual void _ExportAutoStyles() SAL_OVERRIDE {}
121 0 : virtual void _ExportContent() SAL_OVERRIDE {}
122 0 : virtual void _ExportMasterStyles() SAL_OVERRIDE {}
123 0 : virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum /* eClass */ ) SAL_OVERRIDE { return 0; }
124 :
125 : private:
126 :
127 : SVGExport();
128 : };
129 :
130 : class ObjectRepresentation
131 : {
132 : private:
133 :
134 : Reference< XInterface > mxObject;
135 : GDIMetaFile* mpMtf;
136 :
137 : public:
138 :
139 : ObjectRepresentation();
140 : ObjectRepresentation( const Reference< XInterface >& rxIf,
141 : const GDIMetaFile& rMtf );
142 : ObjectRepresentation( const ObjectRepresentation& rPresentation );
143 : ~ObjectRepresentation();
144 :
145 : ObjectRepresentation& operator=( const ObjectRepresentation& rPresentation );
146 : bool operator==( const ObjectRepresentation& rPresentation ) const;
147 :
148 0 : const Reference< XInterface >& GetObject() const { return mxObject; }
149 0 : bool HasRepresentation() const { return mpMtf != NULL; }
150 0 : const GDIMetaFile& GetRepresentation() const { return *mpMtf; }
151 : };
152 :
153 0 : struct PagePropertySet
154 : {
155 : bool bIsBackgroundVisible;
156 : bool bAreBackgroundObjectsVisible;
157 : bool bIsPageNumberFieldVisible;
158 : bool bIsDateTimeFieldVisible;
159 : bool bIsFooterFieldVisible;
160 : bool bIsHeaderFieldVisible;
161 : sal_Int32 nPageNumberingType;
162 : bool bIsDateTimeFieldFixed;
163 : sal_Int16 nPageNumber;
164 : sal_Int32 nDateTimeFormat;
165 : OUString sDateTimeText;
166 : OUString sFooterText;
167 : OUString sHeaderText;
168 : };
169 :
170 : struct HashReferenceXInterface
171 : {
172 0 : size_t operator()( const Reference< XInterface >& rxIf ) const
173 : {
174 0 : return reinterpret_cast< size_t >( rxIf.get() );
175 : }
176 : };
177 :
178 : struct HashUChar
179 : {
180 0 : size_t operator()( const sal_Unicode uchar ) const { return static_cast< size_t >( uchar ); }
181 : };
182 :
183 : struct HashBitmap
184 : {
185 : size_t operator()( const ObjectRepresentation& rObjRep ) const;
186 : };
187 :
188 : struct EqualityBitmap
189 : {
190 : bool operator()( const ObjectRepresentation& rObjRep1,
191 : const ObjectRepresentation& rObjRep2 ) const;
192 : };
193 :
194 : class SVGFontExport;
195 : class SVGActionWriter;
196 : class EditFieldInfo;
197 :
198 : class SVGFilter : public cppu::WeakImplHelper4 < XFilter,
199 : XImporter,
200 : XExporter,
201 : XExtendedFilterDetection >
202 : {
203 : public:
204 : typedef ::boost::unordered_map< Reference< XInterface >, ObjectRepresentation, HashReferenceXInterface > ObjectMap;
205 : typedef ::boost::unordered_set< Reference< XInterface >, HashReferenceXInterface > ObjectSet;
206 : typedef Sequence< Reference< XInterface > > ObjectSequence;
207 : typedef Sequence< Reference< XDrawPage > > XDrawPageSequence;
208 :
209 : typedef ::boost::unordered_set< sal_Unicode, HashUChar > UCharSet;
210 : typedef ::boost::unordered_map< OUString, UCharSet, OUStringHash > UCharSetMap;
211 : typedef ::boost::unordered_map< Reference< XInterface >, UCharSetMap, HashReferenceXInterface > UCharSetMapMap;
212 :
213 : typedef ::boost::unordered_map< Reference< XInterface >, OUString, HashReferenceXInterface > UOStringMap;
214 :
215 : typedef ::boost::unordered_set< ObjectRepresentation, HashBitmap, EqualityBitmap > MetaBitmapActionSet;
216 :
217 : private:
218 :
219 : Reference< XComponentContext > mxContext;
220 : SvXMLElementExport* mpSVGDoc;
221 : SVGExport* mpSVGExport;
222 : SVGFontExport* mpSVGFontExport;
223 : SVGActionWriter* mpSVGWriter;
224 : SdrPage* mpDefaultSdrPage;
225 : SdrModel* mpSdrModel;
226 : bool mbPresentation;
227 : bool mbSinglePage;
228 : sal_Int32 mnVisiblePage;
229 : PagePropertySet mVisiblePagePropSet;
230 : OUString msClipPathId;
231 : UCharSetMapMap mTextFieldCharSets;
232 : Reference< XInterface > mCreateOjectsCurrentMasterPage;
233 : UOStringMap mTextShapeIdListMap;
234 : #ifndef DISABLE_EXPORT
235 : MetaBitmapActionSet mEmbeddedBitmapActionSet;
236 : ObjectMap mEmbeddedBitmapActionMap;
237 : #endif
238 : ObjectMap* mpObjects;
239 : Reference< XComponent > mxSrcDoc;
240 : Reference< XComponent > mxDstDoc;
241 : Reference< XDrawPage > mxDefaultPage;
242 : Sequence< PropertyValue > maFilterData;
243 : // #i124608# explicit ShapeSelection for export when export of the selection is wanted
244 : Reference< XShapes > maShapeSelection;
245 : bool mbExportSelection;
246 : XDrawPageSequence mSelectedPages;
247 : XDrawPageSequence mMasterPageTargets;
248 :
249 : Link maOldFieldHdl;
250 : Link maNewFieldHdl;
251 :
252 : bool implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException, std::exception);
253 :
254 : bool implExport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException);
255 : Reference< XWriter > implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm );
256 :
257 : bool implGetPagePropSet( const Reference< XDrawPage > & rxPage );
258 : bool implGenerateMetaData();
259 : void implExportTextShapeIndex();
260 : void implEmbedBulletGlyphs();
261 : void implEmbedBulletGlyph( sal_Unicode cBullet, const OUString & sPathData );
262 : bool implExportTextEmbeddedBitmaps();
263 : bool implGenerateScript();
264 :
265 : bool implExportDocument();
266 : bool implExportAnimations();
267 :
268 : bool implExportMasterPages( const XDrawPageSequence& rxPages,
269 : sal_Int32 nFirstPage, sal_Int32 nLastPage );
270 : bool implExportDrawPages( const XDrawPageSequence& rxPages,
271 : sal_Int32 nFirstPage, sal_Int32 nLastPage );
272 : bool implExportPage( const OUString & sPageId,
273 : const Reference< XDrawPage > & rxPage,
274 : const Reference< XShapes > & xShapes,
275 : bool bMaster );
276 :
277 : bool implExportShapes( const Reference< XShapes >& rxShapes,
278 : bool bMaster );
279 : bool implExportShape( const Reference< XShape >& rxShape,
280 : bool bMaster );
281 :
282 : bool implCreateObjects();
283 : bool implCreateObjectsFromShapes( const Reference< XDrawPage > & rxPage, const Reference< XShapes >& rxShapes );
284 : bool implCreateObjectsFromShape( const Reference< XDrawPage > & rxPage, const Reference< XShape >& rxShape );
285 : bool implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage );
286 :
287 : OUString implGetClassFromShape( const Reference< XShape >& rxShape );
288 : void implRegisterInterface( const Reference< XInterface >& rxIf );
289 : const OUString & implGetValidIDFromInterface( const Reference< XInterface >& rxIf );
290 : OUString implGetInterfaceName( const Reference< XInterface >& rxIf );
291 : bool implLookForFirstVisiblePage();
292 : Any implSafeGetPagePropSet( const OUString & sPropertyName,
293 : const Reference< XPropertySet > & rxPropSet,
294 : const Reference< XPropertySetInfo > & rxPropSetInfo );
295 : DECL_LINK( CalcFieldHdl, EditFieldInfo* );
296 :
297 : bool isStreamGZip(css::uno::Reference<css::io::XInputStream> xInput);
298 : bool isStreamSvg(css::uno::Reference<css::io::XInputStream> xInput);
299 :
300 : protected:
301 :
302 : // XFilter
303 : virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
304 : virtual void SAL_CALL cancel( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
305 :
306 : // XImporter
307 : virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException, std::exception) SAL_OVERRIDE;
308 :
309 : // XExporter
310 : virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException, std::exception) SAL_OVERRIDE;
311 :
312 : // XExtendedFilterDetection
313 : virtual OUString SAL_CALL detect( Sequence< PropertyValue >& io_rDescriptor ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
314 :
315 : public:
316 :
317 : explicit SVGFilter( const Reference< XComponentContext >& rxCtx );
318 : virtual ~SVGFilter();
319 : };
320 :
321 : #endif // INCLUDED_FILTER_SOURCE_SVG_SVGFILTER_HXX
322 :
323 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|