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