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>
33 #include <xmloff/animexp.hxx>
34 #include <xmloff/families.hxx>
35 #include <xmloff/txtparae.hxx>
36 #include <o3tl/typed_flags_set.hxx>
38 namespace com::sun::star::awt
{ struct Point
; }
39 namespace com::sun::star::beans
{ class XPropertySet
; }
40 namespace com::sun::star::drawing
{ class XShape
; }
41 namespace com::sun::star::drawing
{ class XShapes
; }
44 class SvXMLAttributeList
;
45 class XMLPropertyHandlerFactory
;
47 // shape export features are bits used for the nFeature
48 // parameter of XMLShapeExport::exportShape
49 enum class XMLShapeExportFlags
{
56 SIZE
= WIDTH
| HEIGHT
,
57 // When setting the flag below no ignorableWhiteSpace will be called around
58 // the drawing object elements
60 // When setting the flag below a callout shape is exported as office:annotation
65 template<> struct typed_flags
<XMLShapeExportFlags
> : is_typed_flags
<XMLShapeExportFlags
, 0x6f> {};
68 #define SEF_DEFAULT XMLShapeExportFlags::POSITION|XMLShapeExportFlags::SIZE
72 XmlShapeTypeUnknown
, // not known
74 XmlShapeTypeDrawRectangleShape
, // "com.sun.star.drawing.RectangleShape"
75 XmlShapeTypeDrawEllipseShape
, // "com.sun.star.drawing.EllipseShape"
76 XmlShapeTypeDrawControlShape
, // "com.sun.star.drawing.ControlShape"
77 XmlShapeTypeDrawConnectorShape
, // "com.sun.star.drawing.ConnectorShape"
78 XmlShapeTypeDrawMeasureShape
, // "com.sun.star.drawing.MeasureShape"
79 XmlShapeTypeDrawLineShape
, // "com.sun.star.drawing.LineShape"
80 XmlShapeTypeDrawPolyPolygonShape
, // "com.sun.star.drawing.PolyPolygonShape"
81 XmlShapeTypeDrawPolyLineShape
, // "com.sun.star.drawing.PolyLineShape"
82 XmlShapeTypeDrawOpenBezierShape
, // "com.sun.star.drawing.OpenBezierShape"
83 XmlShapeTypeDrawClosedBezierShape
, // "com.sun.star.drawing.ClosedBezierShape"
84 XmlShapeTypeDrawGraphicObjectShape
, // "com.sun.star.drawing.GraphicObjectShape"
85 XmlShapeTypeDrawGroupShape
, // "com.sun.star.drawing.GroupShape"
86 XmlShapeTypeDrawTextShape
, // "com.sun.star.drawing.TextShape"
87 XmlShapeTypeDrawOLE2Shape
, // "com.sun.star.drawing.OLE2Shape"
88 XmlShapeTypeDrawChartShape
, // embedded com.sun.star.chart
89 XmlShapeTypeDrawSheetShape
, // embedded com.sun.star.sheet
90 XmlShapeTypeDrawPageShape
, // "com.sun.star.drawing.PageShape"
91 XmlShapeTypeDrawFrameShape
, // "com.sun.star.drawing.FrameShape"
92 XmlShapeTypeDrawCaptionShape
, // "com.sun.star.drawing.CaptionShape"
93 XmlShapeTypeDrawAppletShape
, // "com.sun.star.drawing.AppletShape"
94 XmlShapeTypeDrawPluginShape
, // "com.sun.star.drawing.PlugginShape"
96 XmlShapeTypeDraw3DSceneObject
, // "com.sun.star.drawing.Shape3DSceneObject"
97 XmlShapeTypeDraw3DCubeObject
, // "com.sun.star.drawing.Shape3DCubeObject"
98 XmlShapeTypeDraw3DSphereObject
, // "com.sun.star.drawing.Shape3DSphereObject"
99 XmlShapeTypeDraw3DLatheObject
, // "com.sun.star.drawing.Shape3DLatheObject"
100 XmlShapeTypeDraw3DExtrudeObject
, // "com.sun.star.drawing.Shape3DExtrudeObject"
102 XmlShapeTypePresTitleTextShape
, // "com.sun.star.presentation.TitleTextShape"
103 XmlShapeTypePresOutlinerShape
, // "com.sun.star.presentation.OutlinerShape"
104 XmlShapeTypePresSubtitleShape
, // "com.sun.star.presentation.SubtitleShape"
105 XmlShapeTypePresGraphicObjectShape
, // "com.sun.star.presentation.GraphicObjectShape"
106 XmlShapeTypePresPageShape
, // "com.sun.star.presentation.PageShape"
107 XmlShapeTypePresOLE2Shape
, // "com.sun.star.presentation.OLE2Shape"
108 XmlShapeTypePresChartShape
, // "com.sun.star.presentation.ChartShape"
109 XmlShapeTypePresSheetShape
, // "com.sun.star.presentation.CalcShape"
110 XmlShapeTypePresTableShape
, // "com.sun.star.presentation.TableShape"
111 XmlShapeTypePresOrgChartShape
, // "com.sun.star.presentation.OrgChartShape"
112 XmlShapeTypePresNotesShape
, // "com.sun.star.presentation.NotesShape"
113 XmlShapeTypeHandoutShape
, // "com.sun.star.presentation.HandoutShape"
115 XmlShapeTypePresHeaderShape
, // "com.sun.star.presentation.HeaderShape"
116 XmlShapeTypePresFooterShape
, // "com.sun.star.presentation.FooterShape"
117 XmlShapeTypePresSlideNumberShape
, // "com.sun.star.presentation.SlideNumberShape"
118 XmlShapeTypePresDateTimeShape
, // "com.sun.star.presentation.DateTimeShape"
120 XmlShapeTypeDrawCustomShape
, // "com.sun.star.drawing.CustomShape"
121 XmlShapeTypeDrawMediaShape
, // "com.sun.star.drawing.MediaShape"
122 XmlShapeTypePresMediaShape
, // "com.sun.star.presentation.MediaShape"
124 XmlShapeTypeDrawTableShape
, // "com.sun.star.drawing.TableShape"
126 XmlShapeTypeNotYetSet
129 /** caches style and type info after a collectShapeAutostyle for later use in exportShape */
130 struct ImplXMLShapeExportInfo
132 OUString msStyleName
;
133 OUString msTextStyleName
;
134 XmlStyleFamily mnFamily
;
135 XmlShapeType meShapeType
;
137 css::uno::Reference
< css::drawing::XShape
> xCustomShapeReplacement
;
139 ImplXMLShapeExportInfo() : mnFamily( XmlStyleFamily::SD_GRAPHICS_ID
), meShapeType( XmlShapeTypeNotYetSet
) {}
142 /** a vector for shape style and type cache information */
143 typedef std::vector
< ImplXMLShapeExportInfo
> ImplXMLShapeExportInfoVector
;
145 /** a map to store all cache data for already collected XShapes */
146 typedef std::map
< css::uno::Reference
< css::drawing::XShapes
>, ImplXMLShapeExportInfoVector
> ShapesInfos
;
149 class SvXMLExportPropertyMapper
;
157 class XMLOFF_DLLPUBLIC XMLShapeExport
: public salhelper::SimpleReferenceObject
161 SvXMLExport
& mrExport
;
162 rtl::Reference
< SvXMLExportPropertyMapper
> mxPropertySetMapper
;
163 rtl::Reference
< XMLAnimationsExporter
> mxAnimationsExporter
;
164 ShapesInfos maShapesInfos
;
165 ShapesInfos::iterator maCurrentShapesIter
;
167 OUString msPresentationStylePrefix
;
169 // #88546# possibility to switch progress bar handling on/off
170 bool mbHandleProgressBar
;
172 rtl::Reference
< XMLTableExport
> mxShapeTableExport
;
175 SvXMLExport
& GetExport() { return mrExport
; }
176 const SvXMLExport
& GetExport() const { return mrExport
; }
179 SAL_DLLPRIVATE
const rtl::Reference
< SvXMLExportPropertyMapper
>& GetPropertySetMapper() const { return mxPropertySetMapper
; }
181 OUStringBuffer msBuffer
;
183 SAL_DLLPRIVATE
void ImpCalcShapeType(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType
& eShapeType
);
185 SAL_DLLPRIVATE
void ImpExportNewTrans(const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
, XMLShapeExportFlags nFeatures
, css::awt::Point
* pRefPoint
);
186 SAL_DLLPRIVATE
void ImpExportNewTrans_GetB2DHomMatrix(::basegfx::B2DHomMatrix
& rMatrix
, const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
187 SAL_DLLPRIVATE
static void ImpExportNewTrans_DecomposeAndRefPoint(const ::basegfx::B2DHomMatrix
& rMat
, ::basegfx::B2DTuple
& rTRScale
, double& fTRShear
, double& fTRRotate
, ::basegfx::B2DTuple
& rTRTranslate
, css::awt::Point
* pRefPoint
);
188 SAL_DLLPRIVATE
void ImpExportNewTrans_FeaturesAndWrite(::basegfx::B2DTuple
const & rTRScale
, double fTRShear
, double fTRRotate
, ::basegfx::B2DTuple
const & rTRTranslate
, const XMLShapeExportFlags nFeatures
);
189 SAL_DLLPRIVATE
bool ImpExportPresentationAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
, const OUString
& rClass
);
190 SAL_DLLPRIVATE
void ImpExportText( const css::uno::Reference
< css::drawing::XShape
>& xShape
, TextPNS eExtensionNS
= TextPNS::ODF
);
191 SAL_DLLPRIVATE
void ImpExportEvents( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
192 SAL_DLLPRIVATE
void ImpExportDescription( const css::uno::Reference
< css::drawing::XShape
>& xShape
); // #i68101#
193 SAL_DLLPRIVATE
void ImpExportGluePoints( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
194 SAL_DLLPRIVATE
void ImpExportSignatureLine(const css::uno::Reference
<css::drawing::XShape
>& xShape
);
195 SAL_DLLPRIVATE
void ImpExportQRCode(const css::uno::Reference
<css::drawing::XShape
>& xShape
);
197 // single shape exporters
198 SAL_DLLPRIVATE
void ImpExportGroupShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
199 SAL_DLLPRIVATE
void ImpExport3DSceneShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
200 SAL_DLLPRIVATE
void ImpExportRectangleShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
201 SAL_DLLPRIVATE
void ImpExportLineShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
202 SAL_DLLPRIVATE
void ImpExportEllipseShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
203 SAL_DLLPRIVATE
void ImpExportPolygonShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
204 SAL_DLLPRIVATE
void ImpExportTextBoxShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
205 SAL_DLLPRIVATE
void ImpExportGraphicObjectShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
206 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 );
207 SAL_DLLPRIVATE
void ImpExportControlShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
208 SAL_DLLPRIVATE
void ImpExportConnectorShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
209 SAL_DLLPRIVATE
void ImpExportMeasureShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
const * pRefPoint
= nullptr );
210 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 );
211 SAL_DLLPRIVATE
void ImpExportPageShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
212 SAL_DLLPRIVATE
void ImpExportCaptionShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
213 SAL_DLLPRIVATE
void ImpExport3DShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
);
214 SAL_DLLPRIVATE
void ImpExportFrameShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
215 SAL_DLLPRIVATE
void ImpExportPluginShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
216 SAL_DLLPRIVATE
void ImpExportAppletShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
217 SAL_DLLPRIVATE
void ImpExportCustomShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
218 SAL_DLLPRIVATE
void ImpExportMediaShape( const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
219 SAL_DLLPRIVATE
void ImpExportTableShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, XmlShapeType eShapeType
, XMLShapeExportFlags nFeatures
= SEF_DEFAULT
, css::awt::Point
* pRefPoint
= nullptr );
221 XMLShapeExport(SvXMLExport
& rExp
, SvXMLExportPropertyMapper
*pExtMapper
=nullptr );
222 virtual ~XMLShapeExport() override
;
224 // This method collects all automatic styles for the given XShape
225 void collectShapeAutoStyles(
226 const css::uno::Reference
< css::drawing::XShape
>& xShape
);
228 // This method exports the given XShape
230 const css::uno::Reference
< css::drawing::XShape
>& xShape
,
231 XMLShapeExportFlags nFeatures
= SEF_DEFAULT
,
232 css::awt::Point
* pRefPoint
= nullptr,
233 SvXMLAttributeList
* pAttrList
= nullptr
236 // This method collects all automatic styles for the shapes inside the given XShapes collection
237 void collectShapesAutoStyles(
238 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
);
240 // This method exports all XShape inside the given XShapes collection
242 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
,
243 XMLShapeExportFlags nFeatures
= SEF_DEFAULT
,
244 css::awt::Point
* pRefPoint
= nullptr
247 /** initializes some internal structures for fast access to the given XShapes collection
249 <p>This method has to be called before you use exportShape or collectShapeAutoStyles.
250 It is automatically called if you use collectShapesAutoStyles and exportShapes.
252 @see collectShapeAutoStyles
254 @see collectShapesAutoStyles
258 const css::uno::Reference
< css::drawing::XShapes
>& xShapes
) noexcept
;
260 void exportAutoStyles();
262 /** sets a new reference to an XMLAnimationExporter.
263 If this is a non NULL reference, the animation information from all shapes given to exportShape()
264 from now on are collected.
266 void setAnimationsExporter( rtl::Reference
< XMLAnimationsExporter
> const & xAnimExport
) { mxAnimationsExporter
= xAnimExport
; }
268 /** returns the last set XMLAnimationExport */
269 const rtl::Reference
< XMLAnimationsExporter
>& getAnimationsExporter() const { return mxAnimationsExporter
; }
271 /// returns the export property mapper for external chaining
272 static SvXMLExportPropertyMapper
* CreateShapePropMapper( SvXMLExport
& rExport
);
274 void enableLayerExport() { mbExportLayer
= true; }
276 /** defines if the export should increment the progress bar or not */
277 void enableHandleProgressBar() { mbHandleProgressBar
= true; }
278 bool IsHandleProgressBarEnabled() const { return mbHandleProgressBar
; }
280 void setPresentationStylePrefix( const OUString
& rPrefix
) { msPresentationStylePrefix
= rPrefix
; }
282 /** helper for chart that adds all attributes of a 3d scene element to the export */
283 void export3DSceneAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
285 /** helper for chart that exports all lamps from the propertyset */
286 void export3DLamps( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
288 /** sj: replacing CustomShapes with standard objects that are also supported in OpenOffice.org format */
289 css::uno::Reference
< css::drawing::XShape
> checkForCustomShapeReplacement(
290 const css::uno::Reference
< css::drawing::XShape
>& );
292 /** helper to export the style for graphic defaults */
293 void ExportGraphicDefaults();
295 /** is called before a shape element for the given XShape is exported */
296 virtual void onExport( const css::uno::Reference
< css::drawing::XShape
>& xShape
);
298 const rtl::Reference
< XMLTableExport
>& GetShapeTableExport();
303 XMLOFF_DLLPUBLIC
void FixZOrder(
304 css::uno::Reference
<css::drawing::XShapes
> const& xShapes
,
305 std::function
<unsigned int (css::uno::Reference
<css::beans::XPropertySet
> const&)> const& rGetLayer
);
307 } // namespace xmloff
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */