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 : #ifndef INCLUDED_XMLOFF_SHAPEEXPORT_HXX
20 : #define INCLUDED_XMLOFF_SHAPEEXPORT_HXX
21 :
22 : #include <sal/config.h>
23 : #include <xmloff/dllapi.h>
24 : #include <sal/types.h>
25 :
26 : #include <rtl/ref.hxx>
27 : #include <rtl/ustring.hxx>
28 : #include <rtl/ustrbuf.hxx>
29 : #include <xmloff/uniref.hxx>
30 :
31 : #include <com/sun/star/drawing/XShape.hpp>
32 : #include <com/sun/star/drawing/XShapes.hpp>
33 : #include <com/sun/star/awt/Point.hpp>
34 : #include <com/sun/star/beans/PropertyValue.hpp>
35 :
36 : #include <map>
37 : #include <xmloff/xmlprmap.hxx>
38 : #include <xmloff/xmlexppr.hxx>
39 : #include <xmloff/animexp.hxx>
40 : #include <xmloff/families.hxx>
41 :
42 : #include <xmloff/table/XMLTableExport.hxx>
43 :
44 : // shape export features are bits used for the nFeature
45 : // parameter of XMLShapeExport::exportShape
46 :
47 : #define SEF_EXPORT_X 0x0001
48 : #define SEF_EXPORT_Y 0x0002
49 : #define SEF_EXPORT_POSITION 0x0003
50 :
51 : #define SEF_EXPORT_WIDTH 0x0004
52 : #define SEF_EXPORT_HEIGHT 0x0008
53 : #define SEF_EXPORT_SIZE 0x000c
54 :
55 : // when you set this flag a chart does NOT export its own data as table element
56 : #define SEF_EXPORT_NO_CHART_DATA 0x0010
57 :
58 : // When setting the flag below no ignorableWhiteSpace will be called around
59 : // the drawing object elements
60 : #define SEF_EXPORT_NO_WS 0x0020
61 :
62 : // When setting the flag below a callout shape is exported as office:annotation
63 : #define SEF_EXPORT_ANNOTATION 0x0040
64 :
65 : #define SEF_DEFAULT SEF_EXPORT_POSITION|SEF_EXPORT_SIZE
66 :
67 : enum XmlShapeType
68 : {
69 : XmlShapeTypeUnknown, // not known
70 :
71 : XmlShapeTypeDrawRectangleShape, // "com.sun.star.drawing.RectangleShape"
72 : XmlShapeTypeDrawEllipseShape, // "com.sun.star.drawing.EllipseShape"
73 : XmlShapeTypeDrawControlShape, // "com.sun.star.drawing.ControlShape"
74 : XmlShapeTypeDrawConnectorShape, // "com.sun.star.drawing.ConnectorShape"
75 : XmlShapeTypeDrawMeasureShape, // "com.sun.star.drawing.MeasureShape"
76 : XmlShapeTypeDrawLineShape, // "com.sun.star.drawing.LineShape"
77 : XmlShapeTypeDrawPolyPolygonShape, // "com.sun.star.drawing.PolyPolygonShape"
78 : XmlShapeTypeDrawPolyLineShape, // "com.sun.star.drawing.PolyLineShape"
79 : XmlShapeTypeDrawOpenBezierShape, // "com.sun.star.drawing.OpenBezierShape"
80 : XmlShapeTypeDrawClosedBezierShape, // "com.sun.star.drawing.ClosedBezierShape"
81 : XmlShapeTypeDrawGraphicObjectShape, // "com.sun.star.drawing.GraphicObjectShape"
82 : XmlShapeTypeDrawGroupShape, // "com.sun.star.drawing.GroupShape"
83 : XmlShapeTypeDrawTextShape, // "com.sun.star.drawing.TextShape"
84 : XmlShapeTypeDrawOLE2Shape, // "com.sun.star.drawing.OLE2Shape"
85 : XmlShapeTypeDrawChartShape, // embedded com.sun.star.chart
86 : XmlShapeTypeDrawSheetShape, // embedded com.sun.star.sheet
87 : XmlShapeTypeDrawPageShape, // "com.sun.star.drawing.PageShape"
88 : XmlShapeTypeDrawFrameShape, // "com.sun.star.drawing.FrameShape"
89 : XmlShapeTypeDrawCaptionShape, // "com.sun.star.drawing.CaptionShape"
90 : XmlShapeTypeDrawAppletShape, // "com.sun.star.drawing.AppletShape"
91 : XmlShapeTypeDrawPluginShape, // "com.sun.star.drawing.PlugginShape"
92 :
93 : XmlShapeTypeDraw3DSceneObject, // "com.sun.star.drawing.Shape3DSceneObject"
94 : XmlShapeTypeDraw3DCubeObject, // "com.sun.star.drawing.Shape3DCubeObject"
95 : XmlShapeTypeDraw3DSphereObject, // "com.sun.star.drawing.Shape3DSphereObject"
96 : XmlShapeTypeDraw3DLatheObject, // "com.sun.star.drawing.Shape3DLatheObject"
97 : XmlShapeTypeDraw3DExtrudeObject, // "com.sun.star.drawing.Shape3DExtrudeObject"
98 :
99 : XmlShapeTypePresTitleTextShape, // "com.sun.star.presentation.TitleTextShape"
100 : XmlShapeTypePresOutlinerShape, // "com.sun.star.presentation.OutlinerShape"
101 : XmlShapeTypePresSubtitleShape, // "com.sun.star.presentation.SubtitleShape"
102 : XmlShapeTypePresGraphicObjectShape, // "com.sun.star.presentation.GraphicObjectShape"
103 : XmlShapeTypePresPageShape, // "com.sun.star.presentation.PageShape"
104 : XmlShapeTypePresOLE2Shape, // "com.sun.star.presentation.OLE2Shape"
105 : XmlShapeTypePresChartShape, // "com.sun.star.presentation.ChartShape"
106 : XmlShapeTypePresSheetShape, // "com.sun.star.presentation.CalcShape"
107 : XmlShapeTypePresTableShape, // "com.sun.star.presentation.TableShape"
108 : XmlShapeTypePresOrgChartShape, // "com.sun.star.presentation.OrgChartShape"
109 : XmlShapeTypePresNotesShape, // "com.sun.star.presentation.NotesShape"
110 : XmlShapeTypeHandoutShape, // "com.sun.star.presentation.HandoutShape"
111 :
112 : XmlShapeTypePresHeaderShape, // "com.sun.star.presentation.HeaderShape"
113 : XmlShapeTypePresFooterShape, // "com.sun.star.presentation.FooterShape"
114 : XmlShapeTypePresSlideNumberShape, // "com.sun.star.presentation.SlideNumberShape"
115 : XmlShapeTypePresDateTimeShape, // "com.sun.star.presentation.DateTimeShape"
116 :
117 : XmlShapeTypeDrawCustomShape, // "com.sun.star.drawing.CustomShape"
118 : XmlShapeTypeDrawMediaShape, // "com.sun.star.drawing.MediaShape"
119 : XmlShapeTypePresMediaShape, // "com.sun.star.presentation.MediaShape"
120 :
121 : XmlShapeTypeDrawTableShape, // "com.sun.star.drawing.TableShape"
122 :
123 : XmlShapeTypeNotYetSet
124 : };
125 :
126 : /** caches style and type info after a collectShapeAutostyle for later use in exportShape */
127 0 : struct ImplXMLShapeExportInfo
128 : {
129 : OUString msStyleName;
130 : OUString msTextStyleName;
131 : sal_Int32 mnFamily;
132 : XmlShapeType meShapeType;
133 :
134 : com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xCustomShapeReplacement;
135 :
136 0 : ImplXMLShapeExportInfo() : mnFamily( XML_STYLE_FAMILY_SD_GRAPHICS_ID ), meShapeType( XmlShapeTypeNotYetSet ) {}
137 : };
138 :
139 : /** a vector for shape style and type cache information */
140 : typedef std::vector< ImplXMLShapeExportInfo > ImplXMLShapeExportInfoVector;
141 :
142 : /** a map to store all cache data for already collected XShapes */
143 : typedef std::map< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes >, ImplXMLShapeExportInfoVector > ShapesInfos;
144 :
145 :
146 : // predeclarations
147 :
148 : class SvXMLExport;
149 : class SvXMLExportPropertyMapper;
150 :
151 : namespace basegfx
152 : {
153 : class B2DTuple;
154 : class B2DHomMatrix;
155 : } // end of namespace basegfx
156 :
157 : class XMLOFF_DLLPUBLIC XMLShapeExport : public UniRefBase
158 : {
159 : private:
160 :
161 : SvXMLExport& mrExport;
162 : UniReference< XMLPropertyHandlerFactory > mxSdPropHdlFactory;
163 : UniReference< SvXMLExportPropertyMapper > mxPropertySetMapper;
164 : UniReference< XMLAnimationsExporter > mxAnimationsExporter;
165 : ShapesInfos maShapesInfos;
166 : ShapesInfos::iterator maCurrentShapesIter;
167 : bool mbExportLayer;
168 : ImplXMLShapeExportInfoVector maShapeInfos;
169 : ImplXMLShapeExportInfoVector::iterator maCurrentInfo;
170 : OUString msPresentationStylePrefix;
171 :
172 : // #88546# possibility to swich progress bar handling on/off
173 : bool mbHandleProgressBar;
174 :
175 : rtl::Reference< XMLTableExport > mxShapeTableExport;
176 :
177 : protected:
178 0 : SvXMLExport& GetExport() { return mrExport; }
179 : const SvXMLExport& GetExport() const { return mrExport; }
180 : private:
181 :
182 0 : SAL_DLLPRIVATE UniReference< SvXMLExportPropertyMapper > GetPropertySetMapper() const { return mxPropertySetMapper; }
183 :
184 : const OUString msZIndex;
185 : const OUString msPrintable;
186 : const OUString msVisible;
187 :
188 : const OUString msEmptyPres;
189 : const OUString msModel;
190 : const OUString msStartShape;
191 : const OUString msEndShape;
192 : const OUString msOnClick;
193 : const OUString msEventType;
194 : const OUString msPresentation;
195 : const OUString msMacroName;
196 : const OUString msScript;
197 : const OUString msLibrary;
198 : const OUString msClickAction;
199 : const OUString msBookmark;
200 : const OUString msEffect;
201 : const OUString msPlayFull;
202 : const OUString msVerb;
203 : const OUString msSoundURL;
204 : const OUString msSpeed;
205 : const OUString msStarBasic;
206 :
207 : OUStringBuffer msBuffer;
208 :
209 : SAL_DLLPRIVATE void ImpCalcShapeType(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType& eShapeType);
210 :
211 : SAL_DLLPRIVATE void ImpExportNewTrans(const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet, sal_Int32 nFeatures, com::sun::star::awt::Point* pRefPoint);
212 : SAL_DLLPRIVATE void ImpExportNewTrans_GetB2DHomMatrix(::basegfx::B2DHomMatrix& rMatrix, const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet);
213 : SAL_DLLPRIVATE void ImpExportNewTrans_DecomposeAndRefPoint(const ::basegfx::B2DHomMatrix& rMat, ::basegfx::B2DTuple& rTRScale, double& fTRShear, double& fTRRotate, ::basegfx::B2DTuple& rTRTranslate, com::sun::star::awt::Point* pRefPoint);
214 : SAL_DLLPRIVATE void ImpExportNewTrans_FeaturesAndWrite(::basegfx::B2DTuple& rTRScale, double fTRShear, double fTRRotate, ::basegfx::B2DTuple& rTRTranslate, const sal_Int32 nFeatures);
215 : SAL_DLLPRIVATE bool ImpExportPresentationAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet, const OUString& rClass );
216 : SAL_DLLPRIVATE void ImpExportText( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
217 : SAL_DLLPRIVATE void ImpExportEvents( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
218 : SAL_DLLPRIVATE void ImpExportDescription( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape ); // #i68101#
219 : SAL_DLLPRIVATE void ImpExportGluePoints( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
220 :
221 : // single shape exporters
222 : SAL_DLLPRIVATE void ImpExportGroupShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
223 : SAL_DLLPRIVATE void ImpExport3DSceneShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
224 : SAL_DLLPRIVATE void ImpExportRectangleShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
225 : SAL_DLLPRIVATE void ImpExportLineShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
226 : SAL_DLLPRIVATE void ImpExportEllipseShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
227 : SAL_DLLPRIVATE void ImpExportPolygonShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
228 : SAL_DLLPRIVATE void ImpExportTextBoxShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
229 : SAL_DLLPRIVATE void ImpExportGraphicObjectShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
230 : SAL_DLLPRIVATE void ImpExportChartShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL, SvXMLAttributeList* pAttrList = NULL );
231 : SAL_DLLPRIVATE void ImpExportControlShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
232 : SAL_DLLPRIVATE void ImpExportConnectorShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
233 : SAL_DLLPRIVATE void ImpExportMeasureShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
234 : SAL_DLLPRIVATE void ImpExportOLE2Shape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL, SvXMLAttributeList* pAttrList = NULL );
235 : SAL_DLLPRIVATE void ImpExportPageShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
236 : SAL_DLLPRIVATE void ImpExportCaptionShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
237 : SAL_DLLPRIVATE void ImpExport3DShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
238 : SAL_DLLPRIVATE void ImpExportFrameShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
239 : SAL_DLLPRIVATE void ImpExportPluginShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
240 : SAL_DLLPRIVATE void ImpExportAppletShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
241 : SAL_DLLPRIVATE void ImpExportCustomShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
242 : SAL_DLLPRIVATE void ImpExportMediaShape( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
243 : SAL_DLLPRIVATE void ImpExportTableShape(const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, XmlShapeType eShapeType, sal_Int32 nFeatures = SEF_DEFAULT, com::sun::star::awt::Point* pRefPoint = NULL );
244 : public:
245 : XMLShapeExport(SvXMLExport& rExp, SvXMLExportPropertyMapper *pExtMapper=0 );
246 : virtual ~XMLShapeExport();
247 :
248 : // This method collects all automatic styles for the given XShape
249 : void collectShapeAutoStyles(
250 : const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape);
251 :
252 : // This method exports the given XShape
253 : void exportShape(
254 : const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape,
255 : sal_Int32 nFeatures = SEF_DEFAULT,
256 : com::sun::star::awt::Point* pRefPoint = NULL,
257 : SvXMLAttributeList* pAttrList = NULL
258 : );
259 :
260 : // This method collects all automatic styles for the shapes inside the given XShapes collection
261 : void collectShapesAutoStyles(
262 : const com::sun::star::uno::Reference < com::sun::star::drawing::XShapes >& xShapes);
263 :
264 : // This method exports all XShape inside the given XShapes collection
265 : void exportShapes(
266 : const com::sun::star::uno::Reference < com::sun::star::drawing::XShapes >& xShapes,
267 : sal_Int32 nFeatures = SEF_DEFAULT,
268 : com::sun::star::awt::Point* pRefPoint = NULL
269 : );
270 :
271 : /** initializes some internal structures for fast access to the given XShapes collection
272 :
273 : <p>This method has to be called before you use exportShape or collectShapeAutoStyles.
274 : It is automaticly called if you use collectShapesAutoStyles and exportShapes.
275 :
276 : @see collectShapeAutoStyles
277 : @see exportShape
278 : @see collectShapesAutoStyles
279 : @see exportShapes
280 : */
281 : void seekShapes(
282 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xShapes ) throw();
283 :
284 : void exportAutoStyles();
285 :
286 : /** sets a new reference to an XMLAnimationExporter.
287 : If this is a non NULL reference, the animation information from all shapes given to exportShape()
288 : from now on are collected.
289 : */
290 0 : void setAnimationsExporter( UniReference< XMLAnimationsExporter > xAnimExport ) { mxAnimationsExporter = xAnimExport; }
291 :
292 : /** returns the last set XMLAnimationExport */
293 0 : UniReference< XMLAnimationsExporter > getAnimationsExporter() const { return mxAnimationsExporter; }
294 :
295 : /// returns the export property mapper for external chaining
296 : static SvXMLExportPropertyMapper* CreateShapePropMapper( SvXMLExport& rExport );
297 :
298 0 : void enableLayerExport( bool bEnable = true ) { mbExportLayer = bEnable; }
299 0 : bool IsLayerExportEnabled() const { return mbExportLayer; }
300 :
301 : // #88546#
302 : /** defines if the export should increment the progress bar or not */
303 0 : void enableHandleProgressBar( bool bEnable = true ) { mbHandleProgressBar = bEnable; }
304 0 : bool IsHandleProgressBarEnabled() const { return mbHandleProgressBar; }
305 :
306 0 : void setPresentationStylePrefix( const OUString& rPrefix ) { msPresentationStylePrefix = rPrefix; }
307 :
308 : /** helper for chart that adds all attributes of a 3d scene element to the export */
309 : void export3DSceneAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet );
310 :
311 : /** helper for chart that exports all lamps from the propertyset */
312 : void export3DLamps( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet );
313 :
314 : /** sj: replacing CustomShapes with standard objects that are also supported in OpenOffice.org format */
315 : com::sun::star::uno::Reference < com::sun::star::drawing::XShape > checkForCustomShapeReplacement(
316 : const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& );
317 :
318 : /** helper to export the style for graphic defaults */
319 : void ExportGraphicDefaults();
320 :
321 : /** is called before a shape element for the given XShape is exported */
322 : virtual void onExport( const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape );
323 :
324 : const rtl::Reference< XMLTableExport >& GetShapeTableExport();
325 : };
326 :
327 :
328 : #endif
329 :
330 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|