LibreOffice Module oox (master) 1
drawingml.hxx
Go to the documentation of this file.
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_OOX_EXPORT_DRAWINGML_HXX
21#define INCLUDED_OOX_EXPORT_DRAWINGML_HXX
22
23#include <map>
24#include <stack>
25#include <string_view>
26#include <unordered_map>
27#include <utility>
28#include <vector>
29
30#include <com/sun/star/beans/PropertyState.hpp>
31#include <com/sun/star/uno/Any.hxx>
32#include <com/sun/star/uno/Reference.hxx>
33#include <com/sun/star/uno/Sequence.hxx>
34#include <com/sun/star/style/ParagraphAdjust.hpp>
35#include <com/sun/star/drawing/Hatch.hpp>
36#include <com/sun/star/i18n/ScriptType.hpp>
37#include <oox/dllapi.h>
39#include <oox/token/tokens.hxx>
40#include <oox/export/utils.hxx>
41#include <rtl/string.hxx>
42#include <rtl/ustring.hxx>
43#include <sal/types.h>
44#include <sax/fshelper.hxx>
45#include <svx/msdffdef.hxx>
46#include <vcl/checksum.hxx>
47#include <vcl/graph.hxx>
48#include <tools/gen.hxx>
49#include <tools/color.hxx>
50#include <vcl/mapmod.hxx>
52
53class Graphic;
55enum class SvxDateFormat;
56enum class SvxTimeFormat;
57
58namespace com::sun::star {
59namespace awt {
60 struct FontDescriptor;
61 struct Gradient;
62}
63namespace beans {
64 struct PropertyValue;
65 class XPropertySet;
66 class XPropertyState;
67}
68namespace drawing {
69 class XShape;
70 struct EnhancedCustomShapeParameterPair;
71 struct EnhancedCustomShapeParameter;
72}
73namespace graphic {
74 class XGraphic;
75}
76namespace style {
77 struct LineSpacing;
78}
79namespace text {
80 class XTextContent;
81 class XTextRange;
82 class XTextFrame;
83}
84namespace io {
85 class XOutputStream;
86}
87namespace uno {
88 class XInterface;
89}
90namespace frame {
91 class XModel;
92}
93}
94
97namespace tools { class Rectangle; }
98
99namespace tools {
100 class PolyPolygon;
101}
102
103namespace oox {
104namespace core {
105 class XmlFilterBase;
106}
107
108namespace drawingml {
109
111{
112public:
113 virtual ~URLTransformer();
114
115 virtual OUString getTransformedString(const OUString& rURL) const;
116
117 virtual bool isExternalURL(const OUString& rURL) const;
118};
119
120// Our rotation is counter-clockwise and is in 100ths of a degree.
121// drawingML rotation is clockwise and is in 60000ths of a degree.
122inline sal_Int32 ExportRotateClockwisify(Degree100 input)
123{
124 return ((21600000 - input.get() * 600) % 21600000);
125}
126
129{
130public:
131 virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0;
133 virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0;
135 virtual css::uno::Reference<css::text::XTextFrame> GetUnoTextFrame(
136 css::uno::Reference<css::drawing::XShape> xShape) = 0;
137protected:
139 virtual ~DMLTextExport() {}
140};
141
143{
144
145private:
146 static std::stack<sal_Int32> mnImageCounter;
147 static std::stack<sal_Int32> mnWdpImageCounter;
148 static std::stack<std::map<OUString, OUString>> maWdpCache;
149 static sal_Int32 mnDrawingMLCount;
150 static sal_Int32 mnVmlCount;
151 static std::stack<std::unordered_map<BitmapChecksum, OUString>> maExportGraphics;
152
157
158
159protected:
160 css::uno::Any mAny;
164 css::uno::Reference<css::drawing::XShape> m_xParent;
166
169
170 bool GetProperty( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, const OUString& aName );
171 bool GetPropertyAndState( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
172 const css::uno::Reference< css::beans::XPropertyState >& rXPropState,
173 const OUString& aName, css::beans::PropertyState& eState );
174 OUString GetFieldValue( const css::uno::Reference< css::text::XTextRange >& rRun, bool& bIsURLField );
179 static OUString GetDatetimeTypeFromDate(SvxDateFormat eDate);
184 static OUString GetDatetimeTypeFromTime(SvxTimeFormat eTime);
190 static OUString GetDatetimeTypeFromDateTime(SvxDateFormat eDate, SvxTimeFormat eTime);
191
193 void WriteMediaNonVisualProperties(const css::uno::Reference<css::drawing::XShape>& xShape);
194
195 void WriteStyleProperties( sal_Int32 nTokenId, const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
196
197 const char* GetComponentDir() const;
198 const char* GetRelationCompPrefix() const;
199
200 static bool EqualGradients( css::awt::Gradient aGradient1, css::awt::Gradient aGradient2 );
201 bool IsFontworkShape(const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet);
202
203 void WriteGlowEffect(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
204 void WriteSoftEdgeEffect(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
205 void WriteCustomGeometryPoint(const css::drawing::EnhancedCustomShapeParameterPair& rParamPair,
206 const EnhancedCustomShape2d& rCustomShape2d,
207 const bool bReplaceGeoWidth, const bool bReplaceGeoHeight);
208 bool WriteCustomGeometrySegment(
209 const sal_Int16 eCommand, const sal_Int32 nCount,
210 const css::uno::Sequence<css::drawing::EnhancedCustomShapeParameterPair>& rPairs,
211 sal_Int32& rnPairIndex, double& rfCurrentX, double& rfCurrentY, bool& rbCurrentValid,
212 const EnhancedCustomShape2d& rCustomShape2d,
213 const bool bReplaceGeoWidth, const bool bReplaceGeoHeight);
214
215public:
217 : meDocumentType( eDocumentType ), mpTextExport(pTextExport), mpFS(std::move( pFS )), mpFB( pFB ), mbIsBackgroundDark( false ), mbPlaceholder(false) {}
218 void SetFS( ::sax_fastparser::FSHelperPtr pFS ) { mpFS = pFS; }
219 const ::sax_fastparser::FSHelperPtr& GetFS() const { return mpFS; }
221 DocumentType GetDocumentType() const { return meDocumentType; }
223 DMLTextExport* GetTextExport() { return mpTextExport; }
224
225 void SetBackgroundDark(bool bIsDark) { mbIsBackgroundDark = bIsDark; }
227 OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false );
228
229 void WriteColor( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT );
230 void WriteColor( const OUString& sColorSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
231 void WriteColor( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
232 void WriteColorTransformations( const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
233 void WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT);
234 void WriteLineArrow( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, bool bLineStart );
235 void WriteConnectorConnections( sal_Int32 nStartGlueId, sal_Int32 nEndGlueId, sal_Int32 nStartID, sal_Int32 nEndID );
236
237 bool WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet);
238 bool WriteSchemeColor(OUString const& rPropertyName, const css::uno::Reference<css::beans::XPropertySet>& xPropertySet);
239
240 void WriteSolidFill( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT );
241 void WriteSolidFill( const OUString& sSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
242 void WriteSolidFill( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
243 void WriteSolidFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
244 void WriteGradientFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
245
246 void WriteGradientFill( css::awt::Gradient rGradient, css::awt::Gradient rTransparenceGradient,
247 const css::uno::Reference<css::beans::XPropertySet>& rXPropSet = css::uno::Reference<css::beans::XPropertySet>());
248
249 void WriteGrabBagGradientFill( const css::uno::Sequence< css::beans::PropertyValue >& aGradientStops, css::awt::Gradient rGradient);
250
251 void WriteBlipOrNormalFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet,
252 const OUString& rURLPropName, const css::awt::Size& rSize = {});
253 void WriteBlipFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet,
254 const OUString& sURLPropName, const css::awt::Size& rSize = {});
255 void WriteBlipFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet,
256 const css::awt::Size& rSize, const OUString& sURLPropName,
257 sal_Int32 nXmlNamespace);
258
259 void WriteXGraphicBlipFill(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
260 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
261 sal_Int32 nXmlNamespace, bool bWriteMode,
262 bool bRelPathToMedia = false, css::awt::Size const& rSize = {});
263
264 void WritePattFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
265 void WritePattFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet,
266 const css::drawing::Hatch& rHatch);
267
268 void WriteGraphicCropProperties(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet,
269 Size const & rOriginalSize, MapMode const & rMapMode);
270
271 void WriteSrcRectXGraphic(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet,
272 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
273
274 void WriteOutline( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
275 css::uno::Reference< css::frame::XModel> const & xModel = nullptr );
276
277 void WriteXGraphicStretch(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
278 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
279
280 void WriteXGraphicTile(css::uno::Reference<css::beans::XPropertySet> const& rXPropSet,
281 css::uno::Reference<css::graphic::XGraphic> const& rxGraphic,
282 css::awt::Size const& rSize);
283
284 void WriteLinespacing(const css::style::LineSpacing& rLineSpacing, float fFirstCharHeight);
285
286 OUString WriteXGraphicBlip(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
287 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
288 bool bRelPathToMedia);
289
290 void WriteImageBrightnessContrastTransparence(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet);
291
292 void WriteXGraphicBlipMode(css::uno::Reference<css::beans::XPropertySet> const& rXPropSet,
293 css::uno::Reference<css::graphic::XGraphic> const& rxGraphic,
294 css::awt::Size const& rSize);
295
296 void WriteShapeTransformation(const css::uno::Reference< css::drawing::XShape >& rXShape,
297 sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, bool bSuppressRotation = false, bool bSuppressFlipping = false, bool bFlippedBeforeRotation = false);
298 void WriteTransformation(const css::uno::Reference< css::drawing::XShape >& xShape, const tools::Rectangle& rRectangle,
299 sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0, bool bIsGroupShape = false);
300
301 void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0, bool bWritePropertiesAsLstStyles = false);
302
304 void WriteLstStyles(const css::uno::Reference<css::text::XTextContent>& rParagraph,
305 bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
306 const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet);
307 void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph,
308 bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet);
313 bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet, float fFirstCharHeight, sal_Int32 nElement);
314 void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight,
315 sal_Int16 nLevel );
316 void WriteParagraphTabStops(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
317 void WriteRun( const css::uno::Reference< css::text::XTextRange >& rRun,
318 bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
319 const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet);
320 void WriteRunProperties( const css::uno::Reference< css::beans::XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect,
321 bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
322 sal_Int16 nScriptType = css::i18n::ScriptType::LATIN,
323 const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet = {});
324
325 void WritePresetShape( const OString& pShape , std::vector< std::pair<sal_Int32,sal_Int32>> & rAvList );
326 void WritePresetShape( const OString& pShape );
327 void WritePresetShape( const OString& pShape, MSO_SPT eShapeType, bool bPredefinedHandlesUsed, const css::beans::PropertyValue& rProp );
328 bool WriteCustomGeometry(
329 const css::uno::Reference<css::drawing::XShape>& rXShape,
330 const SdrObjCustomShape& rSdrObjCustomShape);
331 void WriteEmptyCustomGeometry();
332 void WritePolyPolygon(const css::uno::Reference<css::drawing::XShape>& rXShape,
333 const bool bClosed);
334 void WriteFill(const css::uno::Reference<css::beans::XPropertySet>& xPropSet,
335 const css::awt::Size& rSize = {});
336 void WriteShapeStyle( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
337 void WriteShapeEffects( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
338 void WriteShapeEffect( std::u16string_view sName, const css::uno::Sequence< css::beans::PropertyValue >& aEffectProps );
343 void Write3DEffects(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet, bool bIsText);
344 void WriteArtisticEffect( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
345 OString WriteWdpPicture( const OUString& rFileId, const css::uno::Sequence< sal_Int8 >& rPictureData );
346 void WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape, int nDiagramId);
347 void writeDiagramRels(const css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& xRelSeq,
348 const css::uno::Reference<css::io::XOutputStream>& xOutStream,
349 std::u16string_view sGrabBagProperyName, int nDiagramId);
350 static void WriteFromTo(const css::uno::Reference<css::drawing::XShape>& rXShape, const css::awt::Size& aPageSize,
351 const sax_fastparser::FSHelperPtr& pDrawing);
352
353 static bool IsGroupShape( const css::uno::Reference< css::drawing::XShape >& rXShape );
354 sal_Int32 getBulletMarginIndentation (const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,sal_Int16 nLevel, std::u16string_view propName);
355
356 static void ResetMlCounters();
357
358 static void PushExportGraphics();
359 static void PopExportGraphics();
360
361 static sal_Int32 getNewDrawingUniqueId() { return ++mnDrawingMLCount; }
362 static sal_Int32 getNewVMLUniqueId() { return ++mnVmlCount; }
363
364 // A Helper to decide the script type for given text in order to call WriteRunProperties.
365 static sal_Int16 GetScriptType(const OUString& rStr);
366
367 static sal_Unicode SubstituteBullet( sal_Unicode cBulletId, css::awt::FontDescriptor& rFontDesc );
368
369 static ::Color ColorWithIntensity( sal_uInt32 nColor, sal_uInt32 nIntensity );
370
371 static const char* GetAlignment( css::style::ParagraphAdjust nAlignment );
372
373 sax_fastparser::FSHelperPtr CreateOutputStream (
374 const OUString& sFullStream,
375 std::u16string_view sRelativeStream,
376 const css::uno::Reference< css::io::XOutputStream >& xParentRelation,
377 const char* sContentType,
378 const char* sRelationshipType,
379 OUString* pRelationshipId );
380
381};
382
383}
384}
385
386#endif
387
388/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface to be implemented by the parent exporter that knows how to handle shape text.
Definition: drawingml.hxx:129
virtual void WriteTextBox(css::uno::Reference< css::drawing::XShape > xShape)=0
Write the contents of the textbox that is associated to this shape.
virtual css::uno::Reference< css::text::XTextFrame > GetUnoTextFrame(css::uno::Reference< css::drawing::XShape > xShape)=0
Get textbox which belongs to the shape.
virtual void WriteOutliner(const OutlinerParaObject &rParaObj)=0
DrawingML(::sax_fastparser::FSHelperPtr pFS, ::oox::core::XmlFilterBase *pFB, DocumentType eDocumentType=DOCUMENT_PPTX, DMLTextExport *pTextExport=nullptr)
Definition: drawingml.hxx:216
static sal_Int32 getNewDrawingUniqueId()
Definition: drawingml.hxx:361
::oox::core::XmlFilterBase * mpFB
Definition: drawingml.hxx:162
bool WriteCharColor(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet)
static sal_Int32 mnDrawingMLCount
Definition: drawingml.hxx:149
void WriteGradientFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet)
void WriteSolidFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet)
DMLTextExport * GetTextExport()
The application-specific text exporter callback, if there is one.
Definition: drawingml.hxx:223
void WritePresetShape(const OString &pShape, MSO_SPT eShapeType, bool bPredefinedHandlesUsed, const css::beans::PropertyValue &rProp)
::sax_fastparser::FSHelperPtr mpFS
Definition: drawingml.hxx:161
static sal_Int32 mnVmlCount
Definition: drawingml.hxx:150
DocumentType meDocumentType
To specify where write eg. the images to (like 'ppt', or 'word' - according to the OPC).
Definition: drawingml.hxx:154
void SetFS(::sax_fastparser::FSHelperPtr pFS)
Definition: drawingml.hxx:218
void WriteBlipFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet, const OUString &sURLPropName, const css::awt::Size &rSize={})
void WriteGradientFill(css::awt::Gradient rGradient, css::awt::Gradient rTransparenceGradient, const css::uno::Reference< css::beans::XPropertySet > &rXPropSet=css::uno::Reference< css::beans::XPropertySet >())
const ::sax_fastparser::FSHelperPtr & GetFS() const
Definition: drawingml.hxx:219
::oox::core::XmlFilterBase * GetFB()
Definition: drawingml.hxx:220
DocumentType GetDocumentType() const
Definition: drawingml.hxx:221
void WriteColor(const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue > &aTransformations, sal_Int32 nAlpha=MAX_PERCENT)
static sal_Int32 getNewVMLUniqueId()
Definition: drawingml.hxx:362
css::uno::Reference< css::drawing::XShape > m_xParent
If set, this is the parent of the currently handled shape.
Definition: drawingml.hxx:164
void WriteSolidFill(const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue > &aTransformations, sal_Int32 nAlpha=MAX_PERCENT)
static std::stack< sal_Int32 > mnWdpImageCounter
Definition: drawingml.hxx:147
void WriteBlipFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet, const css::awt::Size &rSize, const OUString &sURLPropName, sal_Int32 nXmlNamespace)
void WriteColor(const OUString &sColorSchemeName, const css::uno::Sequence< css::beans::PropertyValue > &aTransformations, sal_Int32 nAlpha=MAX_PERCENT)
void WritePattFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet)
void WritePattFill(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet, const css::drawing::Hatch &rHatch)
bool mbPlaceholder
True when exporting presentation placeholder shape.
Definition: drawingml.hxx:168
static std::stack< sal_Int32 > mnImageCounter
Definition: drawingml.hxx:146
void SetBackgroundDark(bool bIsDark)
Definition: drawingml.hxx:225
static std::stack< std::unordered_map< BitmapChecksum, OUString > > maExportGraphics
Definition: drawingml.hxx:151
void WriteSolidFill(const OUString &sSchemeName, const css::uno::Sequence< css::beans::PropertyValue > &aTransformations, sal_Int32 nAlpha=MAX_PERCENT)
static std::stack< std::map< OUString, OUString > > maWdpCache
Definition: drawingml.hxx:148
DMLTextExport * mpTextExport
Parent exporter, used for text callback.
Definition: drawingml.hxx:156
int nCount
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
OString sName
Definition: drawingml.cxx:4177
SvxTimeFormat
SvxDateFormat
MSO_SPT
def text(shape, orig_st)
class SAL_NO_VTABLE XPropertySet
sal_Int32 ExportRotateClockwisify(Degree100 input)
Definition: drawingml.hxx:122
const sal_Int32 MAX_PERCENT
std::shared_ptr< FastSerializerHelper > FSHelperPtr
SvStream & WritePolyPolygon(SvStream &rOStream, const tools::PolyPolygon &rPolyPoly)
UNOTOOLS_DLLPUBLIC css::uno::Any GetProperty(OUString const &url, OUString const &property)
UNDERLYING_TYPE get() const
sal_uInt16 sal_Unicode