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 .
19 #ifndef INCLUDED_XMLOFF_SHAPEEXPORT_HXX
20 #define INCLUDED_XMLOFF_SHAPEEXPORT_HXX
22 #include <sal/config.h>
23 #include <xmloff/dllapi.h>
24 #include <sal/types.h>
26 #include <rtl/ref.hxx>
27 #include <rtl/ustring.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <salhelper/simplereferenceobject.hxx>
32 #include <xmloff/animexp.hxx>
33 #include <xmloff/families.hxx>
34 #include <xmloff/txtparae.hxx>
35 #include <o3tl/typed_flags_set.hxx>
37 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{ struct Point
; } } } }
38 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{ class XPropertySet
; } } } }
39 namespace com
{ namespace sun
{ namespace star
{ namespace drawing
{ class XShape
; } } } }
40 namespace com
{ namespace sun
{ namespace star
{ namespace drawing
{ class XShapes
; } } } }
43 class SvXMLAttributeList
;
44 class XMLPropertyHandlerFactory
;
46 // shape export features are bits used for the nFeature
47 // parameter of XMLShapeExport::exportShape
48 enum class XMLShapeExportFlags
{
55 SIZE
= WIDTH
| HEIGHT
,
56 // When setting the flag below no ignorableWhiteSpace will be called around
57 // the drawing object elements
59 // When setting the flag below a callout shape is exported as office:annotation
64 template<> struct typed_flags
<XMLShapeExportFlags
> : is_typed_flags
<XMLShapeExportFlags
, 0x6f> {};
67 #define SEF_DEFAULT XMLShapeExportFlags::POSITION|XMLShapeExportFlags::SIZE
71 XmlShapeTypeUnknown
, // not known
73 XmlShapeTypeDrawRectangleShape
, // "com.sun.star.drawing.RectangleShape"
74 XmlShapeTypeDrawEllipseShape
, // "com.sun.star.drawing.EllipseShape"
75 XmlShapeTypeDrawControlShape
, // "com.sun.star.drawing.ControlShape"
76 XmlShapeTypeDrawConnectorShape
, // "com.sun.star.drawing.ConnectorShape"
77 XmlShapeTypeDrawMeasureShape
, // "com.sun.star.drawing.MeasureShape"
78 XmlShapeTypeDrawLineShape
, // "com.sun.star.drawing.LineShape"
79 XmlShapeTypeDrawPolyPolygonShape
, // "com.sun.star.drawing.PolyPolygonShape"
80 XmlShapeTypeDrawPolyLineShape
, // "com.sun.star.drawing.PolyLineShape"
81 XmlShapeTypeDrawOpenBezierShape
, // "com.sun.star.drawing.OpenBezierShape"
82 XmlShapeTypeDrawClosedBezierShape
, // "com.sun.star.drawing.ClosedBezierShape"
83 XmlShapeTypeDrawGraphicObjectShape
, // "com.sun.star.drawing.GraphicObjectShape"
84 XmlShapeTypeDrawGroupShape
, // "com.sun.star.drawing.GroupShape"
85 XmlShapeTypeDrawTextShape
, // "com.sun.star.drawing.TextShape"
86 XmlShapeTypeDrawOLE2Shape
, // "com.sun.star.drawing.OLE2Shape"
87 XmlShapeTypeDrawChartShape
, // embedded com.sun.star.chart
88 XmlShapeTypeDrawSheetShape
, // embedded com.sun.star.sheet
89 XmlShapeTypeDrawPageShape
, // "com.sun.star.drawing.PageShape"
90 XmlShapeTypeDrawFrameShape
, // "com.sun.star.drawing.FrameShape"
91 XmlShapeTypeDrawCaptionShape
, // "com.sun.star.drawing.CaptionShape"
92 XmlShapeTypeDrawAppletShape
, // "com.sun.star.drawing.AppletShape"
93 XmlShapeTypeDrawPluginShape
, // "com.sun.star.drawing.PlugginShape"
95 XmlShapeTypeDraw3DSceneObject
, // "com.sun.star.drawing.Shape3DSceneObject"
96 XmlShapeTypeDraw3DCubeObject
, // "com.sun.star.drawing.Shape3DCubeObject"
97 XmlShapeTypeDraw3DSphereObject
, // "com.sun.star.drawing.Shape3DSphereObject"
98 XmlShapeTypeDraw3DLatheObject
, // "com.sun.star.drawing.Shape3DLatheObject"
99 XmlShapeTypeDraw3DExtrudeObject
, // "com.sun.star.drawing.Shape3DExtrudeObject"
101 XmlShapeTypePresTitleTextShape
, // "com.sun.star.presentation.TitleTextShape"
102 XmlShapeTypePresOutlinerShape
, // "com.sun.star.presentation.OutlinerShape"
103 XmlShapeTypePresSubtitleShape
, // "com.sun.star.presentation.SubtitleShape"
104 XmlShapeTypePresGraphicObjectShape
, // "com.sun.star.presentation.GraphicObjectShape"
105 XmlShapeTypePresPageShape
, // "com.sun.star.presentation.PageShape"
106 XmlShapeTypePresOLE2Shape
, // "com.sun.star.presentation.OLE2Shape"
107 XmlShapeTypePresChartShape
, // "com.sun.star.presentation.ChartShape"
108 XmlShapeTypePresSheetShape
, // "com.sun.star.presentation.CalcShape"
109 XmlShapeTypePresTableShape
, // "com.sun.star.presentation.TableShape"
110 XmlShapeTypePresOrgChartShape
, // "com.sun.star.presentation.OrgChartShape"
111 XmlShapeTypePresNotesShape
, // "com.sun.star.presentation.NotesShape"
112 XmlShapeTypeHandoutShape
, // "com.sun.star.presentation.HandoutShape"
114 XmlShapeTypePresHeaderShape
, // "com.sun.star.presentation.HeaderShape"
115 XmlShapeTypePresFooterShape
, // "com.sun.star.presentation.FooterShape"
116 XmlShapeTypePresSlideNumberShape
, // "com.sun.star.presentation.SlideNumberShape"
117 XmlShapeTypePresDateTimeShape
, // "com.sun.star.presentation.DateTimeShape"
119 XmlShapeTypeDrawCustomShape
, // "com.sun.star.drawing.CustomShape"
120 XmlShapeTypeDrawMediaShape
, // "com.sun.star.drawing.MediaShape"
121 XmlShapeTypePresMediaShape
, // "com.sun.star.presentation.MediaShape"
123 XmlShapeTypeDrawTableShape
, // "com.sun.star.drawing.TableShape"
125 XmlShapeTypeNotYetSet
128 /** caches style and type info after a collectShapeAutostyle for later use in exportShape */
129 struct ImplXMLShapeExportInfo
131 OUString msStyleName
;
132 OUString msTextStyleName
;
134 XmlShapeType meShapeType
;
136 css::uno::Reference
< css::drawing::XShape
> xCustomShapeReplacement
;
138 ImplXMLShapeExportInfo() : mnFamily( XML_STYLE_FAMILY_SD_GRAPHICS_ID
), meShapeType( XmlShapeTypeNotYetSet
) {}
141 /** a vector for shape style and type cache information */
142 typedef std::vector
< ImplXMLShapeExportInfo
> ImplXMLShapeExportInfoVector
;
144 /** a map to store all cache data for already collected XShapes */
145 typedef std::map
< css::uno::Reference
< css::drawing::XShapes
>, ImplXMLShapeExportInfoVector
> ShapesInfos
;
148 class SvXMLExportPropertyMapper
;
156 class XMLOFF_DLLPUBLIC XMLShapeExport
: public salhelper::SimpleReferenceObject
160 SvXMLExport
& mrExport
;
161 rtl::Reference
< SvXMLExportPropertyMapper
> mxPropertySetMapper
;
162 rtl::Reference
< XMLAnimationsExporter
> mxAnimationsExporter
;
163 ShapesInfos maShapesInfos
;
164 ShapesInfos::iterator maCurrentShapesIter
;
166 OUString msPresentationStylePrefix
;
168 // #88546# possibility to switch progress bar handling on/off
169 bool mbHandleProgressBar
;
171 rtl::Reference
< XMLTableExport
> mxShapeTableExport
;
174 SvXMLExport
& GetExport() { return mrExport
; }
175 const SvXMLExport
& GetExport() const { return mrExport
; }
178 SAL_DLLPRIVATE
const rtl::Reference
< SvXMLExportPropertyMapper
>& GetPropertySetMapper() const { return mxPropertySetMapper
; }
180 OUStringBuffer msBuffer
;
182 SAL_DLLPRIVATE
void ImpCalcShapeType(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType
& eShapeType
);
184 SAL_DLLPRIVATE
void ImpExportNewTrans(const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
, XMLShapeExportFlags nFeatures
, css::awt::Point
* pRefPoint
);
185 SAL_DLLPRIVATE
void ImpExportNewTrans_GetB2DHomMatrix(::basegfx::B2DHomMatrix
& rMatrix
, const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
186 SAL_DLLPRIVATE
static void ImpExportNewTrans_DecomposeAndRefPoint(const ::basegfx::B2DHomMatrix
& rMat
, ::basegfx::B2DTuple
& rTRScale
, double& fTRShear
, double& fTRRotate
, ::basegfx::B2DTuple
& rTRTranslate
, css::awt::Point
* pRefPoint
);
187 SAL_DLLPRIVATE
void ImpExportNewTrans_FeaturesAndWrite(::basegfx::B2DTuple
const & rTRScale
, double fTRShear
, double fTRRotate
, ::basegfx::B2DTuple
const & rTRTranslate
, const XMLShapeExportFlags nFeatures
);
188 SAL_DLLPRIVATE
bool ImpExportPresentationAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
, const OUString
& rClass
);
189 SAL_DLLPRIVATE
void ImpExportText( const css::uno::Reference
< css::drawing::XShape
>& xShape
, TextPNS eExtensionNS
= TextPNS::ODF
);
190 SAL_DLLPRIVATE
void ImpExportEvents( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
191 SAL_DLLPRIVATE
void ImpExportDescription( const css::uno::Reference
< css::drawing::XShape
>& xShape
); // #i68101#
192 SAL_DLLPRIVATE
void ImpExportGluePoints( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
193 SAL_DLLPRIVATE
void ImpExportSignatureLine(const css::uno::Reference
<css::drawing::XShape
>& xShape
);
195 // single shape exporters
196 SAL_DLLPRIVATE
void ImpExportGroupShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
197 SAL_DLLPRIVATE
void ImpExport3DSceneShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
198 SAL_DLLPRIVATE
void ImpExportRectangleShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
199 SAL_DLLPRIVATE
void ImpExportLineShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
200 SAL_DLLPRIVATE
void ImpExportEllipseShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
201 SAL_DLLPRIVATE
void ImpExportPolygonShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
202 SAL_DLLPRIVATE
void ImpExportTextBoxShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
203 SAL_DLLPRIVATE
void ImpExportGraphicObjectShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
204 SAL_DLLPRIVATE
void ImpExportChartShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr, SvXMLAttributeList
* pAttrList
= nullptr );
205 SAL_DLLPRIVATE
void ImpExportControlShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
206 SAL_DLLPRIVATE
void ImpExportConnectorShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
207 SAL_DLLPRIVATE
void ImpExportMeasureShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
const * pRefPoint
= nullptr );
208 SAL_DLLPRIVATE
void ImpExportOLE2Shape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr, SvXMLAttributeList
* pAttrList
= nullptr );
209 SAL_DLLPRIVATE
void ImpExportPageShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
210 SAL_DLLPRIVATE
void ImpExportCaptionShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
211 SAL_DLLPRIVATE
void ImpExport3DShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
);
212 SAL_DLLPRIVATE
void ImpExportFrameShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
213 SAL_DLLPRIVATE
void ImpExportPluginShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
214 SAL_DLLPRIVATE
void ImpExportAppletShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
215 SAL_DLLPRIVATE
void ImpExportCustomShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
216 SAL_DLLPRIVATE
void ImpExportMediaShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
217 SAL_DLLPRIVATE
void ImpExportTableShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
219 XMLShapeExport(SvXMLExport
& rExp
, SvXMLExportPropertyMapper
*pExtMapper
=nullptr );
220 virtual ~XMLShapeExport() override
;
222 // This method collects all automatic styles for the given XShape
223 void collectShapeAutoStyles(
224 const css::uno::Reference
< css::drawing::XShape
>& xShape
);
226 // This method exports the given XShape
228 const css::uno::Reference
< css::drawing::XShape
>& xShape
,
229 XMLShapeExportFlags nFeatures
= SEF_DEFAULT
,
230 css::awt::Point
* pRefPoint
= nullptr,
231 SvXMLAttributeList
* pAttrList
= nullptr
234 // This method collects all automatic styles for the shapes inside the given XShapes collection
235 void collectShapesAutoStyles(
236 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
);
238 // This method exports all XShape inside the given XShapes collection
240 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
,
241 XMLShapeExportFlags nFeatures
= SEF_DEFAULT
,
242 css::awt::Point
* pRefPoint
= nullptr
245 /** initializes some internal structures for fast access to the given XShapes collection
247 <p>This method has to be called before you use exportShape or collectShapeAutoStyles.
248 It is automatically called if you use collectShapesAutoStyles and exportShapes.
250 @see collectShapeAutoStyles
252 @see collectShapesAutoStyles
256 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
) throw();
258 void exportAutoStyles();
260 /** sets a new reference to an XMLAnimationExporter.
261 If this is a non NULL reference, the animation information from all shapes given to exportShape()
262 from now on are collected.
264 void setAnimationsExporter( rtl::Reference
< XMLAnimationsExporter
> const & xAnimExport
) { mxAnimationsExporter
= xAnimExport
; }
266 /** returns the last set XMLAnimationExport */
267 const rtl::Reference
< XMLAnimationsExporter
>& getAnimationsExporter() const { return mxAnimationsExporter
; }
269 /// returns the export property mapper for external chaining
270 static SvXMLExportPropertyMapper
* CreateShapePropMapper( SvXMLExport
& rExport
);
272 void enableLayerExport() { mbExportLayer
= true; }
274 /** defines if the export should increment the progress bar or not */
275 void enableHandleProgressBar() { mbHandleProgressBar
= true; }
276 bool IsHandleProgressBarEnabled() const { return mbHandleProgressBar
; }
278 void setPresentationStylePrefix( const OUString
& rPrefix
) { msPresentationStylePrefix
= rPrefix
; }
280 /** helper for chart that adds all attributes of a 3d scene element to the export */
281 void export3DSceneAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
283 /** helper for chart that exports all lamps from the propertyset */
284 void export3DLamps( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
286 /** sj: replacing CustomShapes with standard objects that are also supported in OpenOffice.org format */
287 css::uno::Reference
< css::drawing::XShape
> checkForCustomShapeReplacement(
288 const css::uno::Reference
< css::drawing::XShape
>& );
290 /** helper to export the style for graphic defaults */
291 void ExportGraphicDefaults();
293 /** is called before a shape element for the given XShape is exported */
294 virtual void onExport( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
296 const rtl::Reference
< XMLTableExport
>& GetShapeTableExport();
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */