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 <string_view>
25 #include <vector>
26 
27 #include <com/sun/star/beans/PropertyState.hpp>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/style/ParagraphAdjust.hpp>
32 #include <com/sun/star/drawing/Hatch.hpp>
33 #include <com/sun/star/i18n/ScriptType.hpp>
34 #include <oox/dllapi.h>
36 #include <oox/token/tokens.hxx>
37 #include <oox/export/utils.hxx>
38 #include <rtl/string.hxx>
39 #include <rtl/ustring.hxx>
40 #include <sal/types.h>
41 #include <sax/fshelper.hxx>
42 #include <svx/msdffdef.hxx>
43 #include <vcl/checksum.hxx>
44 #include <tools/gen.hxx>
45 #include <vcl/mapmod.hxx>
46 
47 class Graphic;
48 class SdrObjCustomShape;
49 enum class SvxDateFormat;
50 enum class SvxTimeFormat;
51 
52 namespace com::sun::star {
53 namespace awt {
54  struct FontDescriptor;
55  struct Gradient;
56 }
57 namespace beans {
58  struct PropertyValue;
59  class XPropertySet;
60  class XPropertyState;
61 }
62 namespace drawing {
63  class XShape;
64  struct EnhancedCustomShapeParameterPair;
65  struct EnhancedCustomShapeParameter;
66 }
67 namespace graphic {
68  class XGraphic;
69 }
70 namespace style {
71  struct LineSpacing;
72 }
73 namespace text {
74  class XTextContent;
75  class XTextRange;
76  class XTextFrame;
77 }
78 namespace io {
79  class XOutputStream;
80 }
81 namespace uno {
82  class XInterface;
83 }
84 namespace frame {
85  class XModel;
86 }
87 }
88 
90 class OutlinerParaObject;
91 namespace tools { class Rectangle; }
92 
93 namespace tools {
94  class PolyPolygon;
95 }
96 
97 namespace oox {
98 namespace core {
99  class XmlFilterBase;
100 }
101 
102 namespace drawingml {
103 
105 {
106 public:
107  virtual ~URLTransformer();
108 
109  virtual OUString getTransformedString(const OUString& rURL) const;
110 
111  virtual bool isExternalURL(const OUString& rURL) const;
112 };
113 
114 // Our rotation is counter-clockwise and is in 100ths of a degree.
115 // drawingML rotation is clockwise and is in 60000ths of a degree.
116 inline sal_Int32 ExportRotateClockwisify(Degree100 input)
117 {
118  return ((21600000 - input.get() * 600) % 21600000);
119 }
120 
123 {
124 public:
125  virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0;
127  virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0;
129  virtual OUString FindRelId(BitmapChecksum nChecksum) = 0;
131  virtual OUString FindFileName(BitmapChecksum nChecksum) = 0;
133  virtual void CacheRelId(BitmapChecksum nChecksum, const OUString& rRelId, const OUString& rFileName) = 0;
135  virtual css::uno::Reference<css::text::XTextFrame> GetUnoTextFrame(
136  css::uno::Reference<css::drawing::XShape> xShape) = 0;
137 protected:
139  virtual ~DMLTextExport() {}
140 };
141 
143 {
144 
145 private:
146  static int mnImageCounter;
147  static int mnWdpImageCounter;
148  static std::map<OUString, OUString> maWdpCache;
149  static sal_Int32 mnDrawingMLCount;
150  static sal_Int32 mnVmlCount;
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  bool HasEnhancedCustomShapeSegmentCommand(const css::uno::Reference<css::drawing::XShape>& rXShape, const sal_Int16 nCommand);
202 
203 public:
205  : meDocumentType( eDocumentType ), mpTextExport(pTextExport), mpFS( pFS ), mpFB( pFB ), mbIsBackgroundDark( false ) {}
206  void SetFS( ::sax_fastparser::FSHelperPtr pFS ) { mpFS = pFS; }
207  const ::sax_fastparser::FSHelperPtr& GetFS() const { return mpFS; }
208  ::oox::core::XmlFilterBase* GetFB() { return mpFB; }
209  DocumentType GetDocumentType() const { return meDocumentType; }
211  DMLTextExport* GetTextExport() { return mpTextExport; }
212 
213  void SetBackgroundDark(bool bIsDark) { mbIsBackgroundDark = bIsDark; }
215  OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false, OUString* pFileName = nullptr );
216 
217  void WriteColor( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT );
218  void WriteColor( const OUString& sColorSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
219  void WriteColor( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
220  void WriteColorTransformations( const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
221  void WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT);
222  void WriteLineArrow( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, bool bLineStart );
223  void WriteConnectorConnections( EscherConnectorListEntry& rConnectorEntry, sal_Int32 nStartID, sal_Int32 nEndID );
224 
225  void WriteSolidFill( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT );
226  void WriteSolidFill( const OUString& sSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
227  void WriteSolidFill( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT );
228  void WriteSolidFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
229  void WriteGradientFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
230 
231  void WriteGradientFill( css::awt::Gradient rGradient, css::awt::Gradient rTransparenceGradient,
232  const css::uno::Reference<css::beans::XPropertySet>& rXPropSet = css::uno::Reference<css::beans::XPropertySet>());
233 
234  void WriteGrabBagGradientFill( const css::uno::Sequence< css::beans::PropertyValue >& aGradientStops, css::awt::Gradient rGradient);
235 
236  void WriteBlipOrNormalFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
237  const OUString& rURLPropName );
238  void WriteBlipFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
239  const OUString& sURLPropName );
240  void WriteBlipFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
241  const OUString& sURLPropName, sal_Int32 nXmlNamespace );
242 
243  void WriteXGraphicBlipFill(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
244  css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
245  sal_Int32 nXmlNamespace, bool bWriteMode, bool bRelPathToMedia = false);
246 
247  void WritePattFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
248  void WritePattFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet,
249  const css::drawing::Hatch& rHatch);
250 
251  void WriteGraphicCropProperties(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet,
252  Size const & rOriginalSize, MapMode const & rMapMode);
253 
254  void WriteSrcRectXGraphic(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet,
255  css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
256 
257  void WriteOutline( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,
258  css::uno::Reference< css::frame::XModel> const & xModel = nullptr );
259 
260  void WriteXGraphicStretch(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
261  css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
262 
263  void WriteLinespacing( const css::style::LineSpacing& rLineSpacing );
264 
265  OUString WriteXGraphicBlip(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
266  css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
267  bool bRelPathToMedia);
268 
269  void WriteImageBrightnessContrastTransparence(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet);
270 
271  void WriteXGraphicBlipMode(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet,
272  css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
273 
274  void WriteShapeTransformation(const css::uno::Reference< css::drawing::XShape >& rXShape,
275  sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, bool bSuppressRotation = false, bool bSuppressFlipping = false, bool bFlippedBeforeRotation = false);
276  void WriteTransformation(const css::uno::Reference< css::drawing::XShape >& xShape, const tools::Rectangle& rRectangle,
277  sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0, bool bIsGroupShape = false);
278 
279  void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0, bool bWritePropertiesAsLstStyles = false);
280 
282  void WriteLstStyles(const css::uno::Reference<css::text::XTextContent>& rParagraph,
283  bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
284  const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet);
285  void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph,
286  bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet);
291  bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, float fFirstCharHeight, sal_Int32 nElement);
292  void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight,
293  sal_Int16 nLevel );
294  void WriteParagraphTabStops(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet);
295  void WriteRun( const css::uno::Reference< css::text::XTextRange >& rRun,
296  bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
297  const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet);
298  void WriteRunProperties( const css::uno::Reference< css::beans::XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect,
299  bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
300  sal_Int16 nScriptType = css::i18n::ScriptType::LATIN,
301  const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet = {});
302 
303  void WritePresetShape( const char* pShape , std::vector< std::pair<sal_Int32,sal_Int32>> & rAvList );
304  void WritePresetShape( const char* pShape );
305  void WritePresetShape( const char* pShape, MSO_SPT eShapeType, bool bPredefinedHandlesUsed, const css::beans::PropertyValue& rProp );
306  bool WriteCustomGeometry(
307  const css::uno::Reference<css::drawing::XShape>& rXShape,
308  const SdrObjCustomShape& rSdrObjCustomShape);
309  void WriteCustomGeometryPoint(
310  const css::drawing::EnhancedCustomShapeParameterPair& rParamPair,
311  const SdrObjCustomShape& rSdrObjCustomShape);
312  static sal_Int32 GetCustomGeometryPointValue(
313  const css::drawing::EnhancedCustomShapeParameter& rParam,
314  const SdrObjCustomShape& rSdrObjCustomShape);
315  void WritePolyPolygon(const css::uno::Reference<css::drawing::XShape>& rXShape,
316  const tools::PolyPolygon& rPolyPolygon, const bool bClosed);
317  void WriteFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
318  void WriteShapeStyle( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
319  void WriteShapeEffects( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
320  void WriteShapeEffect( std::u16string_view sName, const css::uno::Sequence< css::beans::PropertyValue >& aEffectProps );
321  void WriteShape3DEffects( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
322  void WriteArtisticEffect( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
323  OString WriteWdpPicture( const OUString& rFileId, const css::uno::Sequence< sal_Int8 >& rPictureData );
324  void WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape, int nDiagramId);
325  void writeDiagramRels(const css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& xRelSeq,
326  const css::uno::Reference<css::io::XOutputStream>& xOutStream,
327  std::u16string_view sGrabBagProperyName, int nDiagramId);
328  static void WriteFromTo(const css::uno::Reference<css::drawing::XShape>& rXShape, const css::awt::Size& aPageSize,
329  const sax_fastparser::FSHelperPtr& pDrawing);
330 
331  static bool IsGroupShape( const css::uno::Reference< css::drawing::XShape >& rXShape );
332  static bool IsDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape);
333  sal_Int32 getBulletMarginIndentation (const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,sal_Int16 nLevel, std::u16string_view propName);
334 
335  static void ResetCounters();
336 
337  static void ResetMlCounters();
338 
339  static sal_Int32 getNewDrawingUniqueId() { return ++mnDrawingMLCount; }
340  static sal_Int32 getNewVMLUniqueId() { return ++mnVmlCount; }
341 
342  // A Helper to decide the script type for given text in order to call WriteRunProperties.
343  static sal_Int16 GetScriptType(const OUString& rStr);
344 
345  static sal_Unicode SubstituteBullet( sal_Unicode cBulletId, css::awt::FontDescriptor& rFontDesc );
346 
347  static ::Color ColorWithIntensity( sal_uInt32 nColor, sal_uInt32 nIntensity );
348 
349  static const char* GetAlignment( css::style::ParagraphAdjust nAlignment );
350 
351  sax_fastparser::FSHelperPtr CreateOutputStream (
352  const OUString& sFullStream,
353  std::u16string_view sRelativeStream,
354  const css::uno::Reference< css::io::XOutputStream >& xParentRelation,
355  const char* sContentType,
356  const char* sRelationshipType,
357  OUString* pRelationshipId );
358 
359 };
360 
361 }
362 }
363 
364 #endif
365 
366 /* 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:122
sal_uInt64 BitmapChecksum
const char * sName
Definition: olehelper.cxx:92
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:116
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:150
sal_uInt16 sal_Unicode
static std::map< OUString, OUString > maWdpCache
Definition: drawingml.hxx:148
DrawingML(::sax_fastparser::FSHelperPtr pFS,::oox::core::XmlFilterBase *pFB, DocumentType eDocumentType=DOCUMENT_PPTX, DMLTextExport *pTextExport=nullptr)
Definition: drawingml.hxx:204
MSO_SPT
exports com.sun.star. frame
exports com.sun.star. drawing
const ::sax_fastparser::FSHelperPtr & GetFS() const
Definition: drawingml.hxx:207
exports com.sun.star. text
static sal_Int32 getNewVMLUniqueId()
Definition: drawingml.hxx:340
DocumentType GetDocumentType() const
Definition: drawingml.hxx:209
UNDERLYING_TYPE get() const
class SAL_NO_VTABLE XPropertySet
const sal_Int32 MAX_PERCENT
static sal_Int32 getNewDrawingUniqueId()
Definition: drawingml.hxx:339
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:206
::oox::core::XmlFilterBase * GetFB()
Definition: drawingml.hxx:208
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:211
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
void SetBackgroundDark(bool bIsDark)
Definition: drawingml.hxx:213
::oox::core::XmlFilterBase * mpFB
Definition: drawingml.hxx:161
SvxTimeFormat
static sal_Int32 mnDrawingMLCount
Definition: drawingml.hxx:149
DMLTextExport * mpTextExport
Parent exporter, used for text callback.
Definition: drawingml.hxx:155