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