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_XMLOFF_SHAPEIMPORT_HXX
21 : #define INCLUDED_XMLOFF_SHAPEIMPORT_HXX
22 :
23 : #include <sal/config.h>
24 : #include <xmloff/dllapi.h>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/frame/XModel.hpp>
27 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 : #include <com/sun/star/drawing/XShapes.hpp>
29 : #include <com/sun/star/drawing/HomogenMatrix.hpp>
30 : #include <com/sun/star/drawing/ProjectionMode.hpp>
31 : #include <com/sun/star/drawing/ShadeMode.hpp>
32 : #include <salhelper/simplereferenceobject.hxx>
33 : #include <xmloff/xmlictxt.hxx>
34 :
35 : #include <xmloff/table/XMLTableImport.hxx>
36 : #include <basegfx/vector/b3dvector.hxx>
37 : #include <vector>
38 :
39 : class SvXMLImport;
40 : class SvXMLImportContext;
41 : class SvXMLTokenMap;
42 : class SvXMLStylesContext;
43 : class XMLSdPropHdlFactory;
44 : class XMLPropertySetMapper;
45 : class SvXMLImportPropertyMapper;
46 :
47 :
48 :
49 : enum SdXMLGroupShapeElemTokenMap
50 : {
51 : XML_TOK_GROUP_GROUP,
52 : XML_TOK_GROUP_RECT,
53 : XML_TOK_GROUP_LINE,
54 : XML_TOK_GROUP_CIRCLE,
55 : XML_TOK_GROUP_ELLIPSE,
56 : XML_TOK_GROUP_POLYGON,
57 : XML_TOK_GROUP_POLYLINE,
58 : XML_TOK_GROUP_PATH,
59 :
60 : XML_TOK_GROUP_CONTROL,
61 : XML_TOK_GROUP_CONNECTOR,
62 : XML_TOK_GROUP_MEASURE,
63 : XML_TOK_GROUP_PAGE,
64 : XML_TOK_GROUP_CAPTION,
65 :
66 : XML_TOK_GROUP_CHART,
67 : XML_TOK_GROUP_3DSCENE,
68 :
69 : XML_TOK_GROUP_FRAME,
70 :
71 : XML_TOK_GROUP_CUSTOM_SHAPE,
72 :
73 : XML_TOK_GROUP_ANNOTATION,
74 :
75 : XML_TOK_GROUP_A,
76 :
77 : XML_TOK_GROUP_LAST
78 : };
79 :
80 : enum SdXMLFrameShapeElemTokenMap
81 : {
82 : XML_TOK_FRAME_TEXT_BOX,
83 : XML_TOK_FRAME_IMAGE,
84 : XML_TOK_FRAME_OBJECT,
85 : XML_TOK_FRAME_OBJECT_OLE,
86 : XML_TOK_FRAME_PLUGIN,
87 : XML_TOK_FRAME_FRAME,
88 : XML_TOK_FRAME_FLOATING_FRAME,
89 : XML_TOK_FRAME_APPLET,
90 : XML_TOK_FRAME_TABLE,
91 :
92 : XML_TOK_FRAME_LAST
93 : };
94 :
95 : enum SdXML3DSceneShapeElemTokenMap
96 : {
97 : XML_TOK_3DSCENE_3DSCENE,
98 : XML_TOK_3DSCENE_3DCUBE,
99 : XML_TOK_3DSCENE_3DSPHERE,
100 : XML_TOK_3DSCENE_3DLATHE,
101 : XML_TOK_3DSCENE_3DEXTRUDE,
102 :
103 : XML_TOK_3DSCENE_LAST
104 : };
105 :
106 : enum SdXMLShapeAttrTokenMap
107 : {
108 : XML_TOK_SHAPE_NAME,
109 : XML_TOK_SHAPE_DRAWSTYLE_NAME_GRAPHICS,
110 : XML_TOK_SHAPE_PRESENTATION_CLASS,
111 : XML_TOK_SHAPE_DRAWSTYLE_NAME_PRESENTATION,
112 : XML_TOK_SHAPE_TRANSFORM,
113 : XML_TOK_SHAPE_IS_PLACEHOLDER,
114 : XML_TOK_SHAPE_IS_USER_TRANSFORMED
115 : };
116 :
117 : enum SdXML3DObjectAttrTokenMap
118 : {
119 : XML_TOK_3DOBJECT_DRAWSTYLE_NAME,
120 : XML_TOK_3DOBJECT_TRANSFORM
121 : };
122 :
123 : enum SdXML3DPolygonBasedAttrTokenMap
124 : {
125 : XML_TOK_3DPOLYGONBASED_VIEWBOX,
126 : XML_TOK_3DPOLYGONBASED_D
127 : };
128 :
129 : enum SdXML3DCubeObjectAttrTokenMap
130 : {
131 : XML_TOK_3DCUBEOBJ_MINEDGE,
132 : XML_TOK_3DCUBEOBJ_MAXEDGE
133 : };
134 :
135 : enum SdXML3DSphereObjectAttrTokenMap
136 : {
137 : XML_TOK_3DSPHEREOBJ_CENTER,
138 : XML_TOK_3DSPHEREOBJ_SIZE
139 : };
140 :
141 : enum SdXMLPolygonShapeAttrTokenMap
142 : {
143 : XML_TOK_POLYGONSHAPE_VIEWBOX,
144 : XML_TOK_POLYGONSHAPE_POINTS
145 : };
146 :
147 : enum SdXMLPathShapeAttrTokenMap
148 : {
149 : XML_TOK_PATHSHAPE_VIEWBOX,
150 : XML_TOK_PATHSHAPE_D
151 : };
152 :
153 : enum SdXML3DSceneShapeAttrTokenMap
154 : {
155 : XML_TOK_3DSCENESHAPE_TRANSFORM,
156 : XML_TOK_3DSCENESHAPE_VRP,
157 : XML_TOK_3DSCENESHAPE_VPN,
158 : XML_TOK_3DSCENESHAPE_VUP,
159 : XML_TOK_3DSCENESHAPE_PROJECTION,
160 : XML_TOK_3DSCENESHAPE_DISTANCE,
161 : XML_TOK_3DSCENESHAPE_FOCAL_LENGTH,
162 : XML_TOK_3DSCENESHAPE_SHADOW_SLANT,
163 : XML_TOK_3DSCENESHAPE_SHADE_MODE,
164 : XML_TOK_3DSCENESHAPE_AMBIENT_COLOR,
165 : XML_TOK_3DSCENESHAPE_LIGHTING_MODE
166 : };
167 :
168 : enum SdXML3DLightAttrTokenMap
169 : {
170 : XML_TOK_3DLIGHT_DIFFUSE_COLOR,
171 : XML_TOK_3DLIGHT_DIRECTION,
172 : XML_TOK_3DLIGHT_ENABLED,
173 : XML_TOK_3DLIGHT_SPECULAR
174 : };
175 :
176 :
177 : // dr3d:3dlight context
178 :
179 : class SdXML3DLightContext: public SvXMLImportContext
180 : {
181 : // local parameters which need to be read
182 : sal_Int32 maDiffuseColor;
183 : ::basegfx::B3DVector maDirection;
184 : bool mbEnabled;
185 : bool mbSpecular;
186 :
187 : public:
188 : SdXML3DLightContext(
189 : SvXMLImport& rImport,
190 : sal_uInt16 nPrfx,
191 : const OUString& rLName,
192 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
193 : virtual ~SdXML3DLightContext();
194 :
195 112 : sal_Int32 GetDiffuseColor() { return maDiffuseColor; }
196 336 : const ::basegfx::B3DVector& GetDirection() { return maDirection; }
197 112 : bool GetEnabled() { return mbEnabled; }
198 : bool GetSpecular() { return mbSpecular; }
199 : };
200 :
201 :
202 :
203 : typedef ::std::vector< SdXML3DLightContext* > Imp3DLightList;
204 :
205 : class SdXML3DSceneAttributesHelper
206 : {
207 : protected:
208 : SvXMLImport& mrImport;
209 :
210 : // list for local light contexts
211 : Imp3DLightList maList;
212 :
213 : // local parameters which need to be read
214 : com::sun::star::drawing::HomogenMatrix mxHomMat;
215 : bool mbSetTransform;
216 :
217 : com::sun::star::drawing::ProjectionMode mxPrjMode;
218 : sal_Int32 mnDistance;
219 : sal_Int32 mnFocalLength;
220 : sal_Int32 mnShadowSlant;
221 : com::sun::star::drawing::ShadeMode mxShadeMode;
222 : sal_Int32 maAmbientColor;
223 : bool mbLightingMode;
224 :
225 : ::basegfx::B3DVector maVRP;
226 : ::basegfx::B3DVector maVPN;
227 : ::basegfx::B3DVector maVUP;
228 : bool mbVRPUsed;
229 : bool mbVPNUsed;
230 : bool mbVUPUsed;
231 :
232 : public:
233 : SdXML3DSceneAttributesHelper( SvXMLImport& rImporter );
234 : ~SdXML3DSceneAttributesHelper();
235 :
236 : /** creates a 3d ligth context and adds it to the internal list for later processing */
237 : SvXMLImportContext * create3DLightContext( sal_uInt16 nPrfx, const OUString& rLName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
238 :
239 : /** this should be called for each scene attribute */
240 : void processSceneAttribute( sal_uInt16 nPrefix, const OUString& rLocalName, const OUString& rValue );
241 :
242 : /** this sets the scene attributes at this propertyset */
243 : void setSceneAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet );
244 : };
245 :
246 :
247 :
248 4426 : class SvXMLShapeContext : public SvXMLImportContext
249 : {
250 : protected:
251 : com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxShape;
252 : bool mbTemporaryShape;
253 : OUString msHyperlink;
254 :
255 : public:
256 4409 : SvXMLShapeContext( SvXMLImport& rImp, sal_uInt16 nPrfx,
257 4409 : const OUString& rLName, bool bTemporaryShape ) : SvXMLImportContext( rImp, nPrfx, rLName ), mbTemporaryShape(bTemporaryShape) {}
258 :
259 : TYPEINFO_OVERRIDE();
260 :
261 144 : const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& getShape() const { return mxShape; }
262 :
263 : void setHyperlink( const OUString& rHyperlink );
264 : };
265 :
266 :
267 :
268 : class ShapeSortContext;
269 : struct XMLShapeImportHelperImpl;
270 : struct XMLShapeImportPageContextImpl;
271 :
272 : class XMLOFF_DLLPUBLIC XMLShapeImportHelper : public salhelper::SimpleReferenceObject
273 : {
274 : XMLShapeImportHelperImpl* mpImpl;
275 :
276 : XMLShapeImportPageContextImpl* mpPageContext;
277 :
278 : com::sun::star::uno::Reference< com::sun::star::frame::XModel > mxModel;
279 :
280 : // PropertySetMappers and factory
281 : XMLSdPropHdlFactory* mpSdPropHdlFactory;
282 : SvXMLImportPropertyMapper* mpPropertySetMapper;
283 : SvXMLImportPropertyMapper* mpPresPagePropsMapper;
284 :
285 : // contexts for Style and AutoStyle import
286 : SvXMLStylesContext* mpStylesContext;
287 : SvXMLStylesContext* mpAutoStylesContext;
288 :
289 : // contexts for xShape contents TokenMaps
290 : SvXMLTokenMap* mpGroupShapeElemTokenMap;
291 : SvXMLTokenMap* mpFrameShapeElemTokenMap;
292 : SvXMLTokenMap* mp3DSceneShapeElemTokenMap;
293 : SvXMLTokenMap* mp3DObjectAttrTokenMap;
294 : SvXMLTokenMap* mp3DPolygonBasedAttrTokenMap;
295 : SvXMLTokenMap* mp3DCubeObjectAttrTokenMap;
296 : SvXMLTokenMap* mp3DSphereObjectAttrTokenMap;
297 : SvXMLTokenMap* mp3DSceneShapeAttrTokenMap;
298 : SvXMLTokenMap* mp3DLightAttrTokenMap;
299 : SvXMLTokenMap* mpPathShapeAttrTokenMap;
300 : SvXMLTokenMap* mpPolygonShapeAttrTokenMap;
301 :
302 : const OUString msStartShape;
303 : const OUString msEndShape;
304 : const OUString msStartGluePointIndex;
305 : const OUString msEndGluePointIndex;
306 :
307 : rtl::Reference< XMLTableImport > mxShapeTableImport;
308 :
309 : protected:
310 : SvXMLImport& mrImporter;
311 :
312 : public:
313 : XMLShapeImportHelper( SvXMLImport& rImporter,
314 : const com::sun::star::uno::Reference< com::sun::star::frame::XModel>& rModel,
315 : SvXMLImportPropertyMapper *pExtMapper=0 );
316 :
317 : virtual ~XMLShapeImportHelper();
318 :
319 : SvXMLShapeContext* CreateGroupChildContext(
320 : SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
321 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
322 : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
323 : bool bTemporaryShape = false);
324 :
325 : SvXMLShapeContext* CreateFrameChildContext(
326 : SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
327 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
328 : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
329 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xFrameAttrList);
330 : static SvXMLImportContext* CreateFrameChildContext(
331 : SvXMLImportContext *pThisContext, sal_uInt16 nPrefix, const OUString& rLocalName,
332 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
333 :
334 : SvXMLShapeContext* Create3DSceneChildContext(
335 : SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
336 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
337 : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
338 :
339 : const SvXMLTokenMap& GetGroupShapeElemTokenMap();
340 : const SvXMLTokenMap& GetFrameShapeElemTokenMap();
341 : const SvXMLTokenMap& Get3DSceneShapeElemTokenMap();
342 : const SvXMLTokenMap& Get3DObjectAttrTokenMap();
343 : const SvXMLTokenMap& Get3DPolygonBasedAttrTokenMap();
344 : const SvXMLTokenMap& Get3DCubeObjectAttrTokenMap();
345 : const SvXMLTokenMap& Get3DSphereObjectAttrTokenMap();
346 : const SvXMLTokenMap& Get3DLightAttrTokenMap();
347 :
348 : // Styles and AutoStyles contexts
349 1821 : SvXMLStylesContext* GetStylesContext() const { return mpStylesContext; }
350 : void SetStylesContext(SvXMLStylesContext* pNew);
351 7720 : SvXMLStylesContext* GetAutoStylesContext() const { return mpAutoStylesContext; }
352 : void SetAutoStylesContext(SvXMLStylesContext* pNew);
353 :
354 : // get factories and mappers
355 810 : SvXMLImportPropertyMapper* GetPropertySetMapper() const { return mpPropertySetMapper; }
356 130 : SvXMLImportPropertyMapper* GetPresPagePropsMapper() const { return mpPresPagePropsMapper; }
357 :
358 : // this function is called whenever the implementation classes like to add this new
359 : // shape to the given XShapes.
360 : virtual void addShape(
361 : com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
362 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
363 : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
364 :
365 : // this function is called whenever the implementation classes have finished importing
366 : // a shape to the given XShapes. The shape is already inserted into its XShapes and
367 : // all properties and styles are set.
368 : virtual void finishShape(
369 : com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
370 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
371 : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
372 :
373 : // helper functions for z-order sorting
374 : void pushGroupForSorting( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
375 : void popGroupAndSort();
376 :
377 : void shapeWithZIndexAdded( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
378 : sal_Int32 nZIndex );
379 :
380 : void addShapeConnection( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rConnectorShape,
381 : bool bStart,
382 : const OUString& rDestShapeId,
383 : sal_Int32 nDestGlueId );
384 :
385 : /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
386 : the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
387 : void addGluePointMapping( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
388 : sal_Int32 nSourceId, sal_Int32 nDestinnationId );
389 :
390 : /** find mapping for given DestinationID. This allows to extract the original draw:id imported with a draw:glue-point */
391 : sal_Int32 findGluePointMapping(
392 : const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
393 : sal_Int32 nDestinnationId ) const;
394 :
395 : /** moves all current DestinationId's for rXShape by n */
396 : void moveGluePointMapping( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, const sal_Int32 n );
397 :
398 : /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
399 : inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
400 : sal_Int32 getGluePointId( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, sal_Int32 nSourceId );
401 :
402 : /** this method must be calling before the first shape is imported for the given page.
403 : Calls to this method can be nested */
404 : void startPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
405 :
406 : /** this method must be calling after the last shape is imported for the given page
407 : Calls to this method can be nested */
408 : void endPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
409 :
410 : void restoreConnections();
411 :
412 : /** creates a property mapper for external chaining */
413 : static SvXMLImportPropertyMapper* CreateShapePropMapper(
414 : const com::sun::star::uno::Reference< com::sun::star::frame::XModel>& rModel, SvXMLImport& rImport );
415 :
416 : // #88546#
417 : /** defines if the import should increment the progress bar or not */
418 : void enableHandleProgressBar( bool bEnable = true );
419 : bool IsHandleProgressBarEnabled() const;
420 :
421 : /** queries the capability of the current model to create presentation shapes */
422 : bool IsPresentationShapesSupported();
423 :
424 1 : XMLSdPropHdlFactory* GetSdPropHdlFactory() const { return mpSdPropHdlFactory; }
425 :
426 : const rtl::Reference< XMLTableImport >& GetShapeTableImport();
427 : };
428 :
429 : #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
430 :
431 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|