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 .
20 #ifndef INCLUDED_OOX_EXPORT_DRAWINGML_HXX
21 #define INCLUDED_OOX_EXPORT_DRAWINGML_HXX
25 #include <string_view>
26 #include <unordered_map>
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>
38 #include <oox/drawingml/drawingmltypes.hxx>
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>
51 #include <svx/EnhancedCustomShape2d.hxx>
52 #include <basegfx/utils/bgradient.hxx>
55 class SdrObjCustomShape
;
56 enum class SvxDateFormat
;
57 enum class SvxTimeFormat
;
59 namespace com::sun::star
{
61 struct FontDescriptor
;
71 struct EnhancedCustomShapeParameterPair
;
72 struct EnhancedCustomShapeParameter
;
96 struct EscherConnectorListEntry
;
97 class OutlinerParaObject
;
98 namespace tools
{ class Rectangle
; }
109 namespace drawingml
{
111 class OOX_DLLPUBLIC URLTransformer
114 virtual ~URLTransformer();
116 virtual OUString
getTransformedString(const OUString
& rURL
) const;
118 virtual bool isExternalURL(const OUString
& rURL
) const;
121 // Our rotation is counter-clockwise and is in 100ths of a degree.
122 // drawingML rotation is clockwise and is in 60000ths of a degree.
123 inline sal_Int32
ExportRotateClockwisify(Degree100 input
)
125 return ((21600000 - input
.get() * 600) % 21600000);
128 /// Interface to be implemented by the parent exporter that knows how to handle shape text.
129 class OOX_DLLPUBLIC DMLTextExport
132 virtual void WriteOutliner(const OutlinerParaObject
& rParaObj
) = 0;
133 /// Write the contents of the textbox that is associated to this shape.
134 virtual void WriteTextBox(css::uno::Reference
<css::drawing::XShape
> xShape
) = 0;
135 /// Get textbox which belongs to the shape.
136 virtual css::uno::Reference
<css::text::XTextFrame
> GetUnoTextFrame(
137 css::uno::Reference
<css::drawing::XShape
> xShape
) = 0;
140 virtual ~DMLTextExport() {}
143 constexpr const char* getComponentDir(DocumentType eDocumentType
)
145 switch (eDocumentType
)
147 case DOCUMENT_DOCX
: return "word";
148 case DOCUMENT_PPTX
: return "ppt";
149 case DOCUMENT_XLSX
: return "xl";
155 constexpr const char* getRelationCompPrefix(DocumentType eDocumentType
)
157 switch (eDocumentType
)
159 case DOCUMENT_DOCX
: return "";
161 case DOCUMENT_XLSX
: return "../";
167 class OOX_DLLPUBLIC GraphicExportCache
170 std::stack
<sal_Int32
> mnImageCounter
;
171 std::stack
<std::unordered_map
<BitmapChecksum
, OUString
>> maExportGraphics
;
172 std::stack
<sal_Int32
> mnWdpImageCounter
;
173 std::stack
<std::map
<OUString
, OUString
>> maWdpCache
;
175 GraphicExportCache() = default;
177 static GraphicExportCache
& get();
181 mnImageCounter
.push(1);
182 maExportGraphics
.emplace();
183 mnWdpImageCounter
.push(1);
184 maWdpCache
.emplace();
189 mnImageCounter
.pop();
190 maExportGraphics
.pop();
191 mnWdpImageCounter
.pop();
195 bool hasExportGraphics()
197 return !maExportGraphics
.empty();
200 void addExportGraphics(BitmapChecksum aChecksum
, OUString
const& sPath
)
202 maExportGraphics
.top()[aChecksum
] = sPath
;
205 OUString
findExportGraphics(BitmapChecksum aChecksum
)
208 if (!hasExportGraphics())
211 auto aIterator
= maExportGraphics
.top().find(aChecksum
);
212 if (aIterator
!= maExportGraphics
.top().end())
213 sPath
= aIterator
->second
;
217 sal_Int32
nextImageCount()
219 sal_Int32 nCount
= mnImageCounter
.top();
220 mnImageCounter
.top()++;
226 return !maWdpCache
.empty();
229 OUString
findWdpID(OUString
const& rFileId
)
234 auto aCachedItem
= maWdpCache
.top().find(rFileId
);
235 if (aCachedItem
!= maWdpCache
.top().end())
236 aPath
= aCachedItem
->second
;
240 void addToWdpCache(OUString
const& rFileId
, OUString
const& rId
)
243 maWdpCache
.top()[rFileId
] = rId
;
246 sal_Int32
nextWdpImageCount()
248 sal_Int32 nCount
= mnWdpImageCounter
.top();
249 mnWdpImageCounter
.top()++;
256 sax_fastparser::FSHelperPtr mpFS
;
257 oox::core::XmlFilterBase
* mpFilterBase
;
258 DocumentType meDocumentType
;
261 GraphicExport(sax_fastparser::FSHelperPtr pFS
, ::oox::core::XmlFilterBase
* pFilterBase
, DocumentType eDocumentType
)
263 , mpFilterBase(pFilterBase
)
264 , meDocumentType(eDocumentType
)
267 OUString
writeToStorage(Graphic
const& rGraphic
, bool bRelPathToMedia
= false);
268 OUString
writeBlip(Graphic
const& rGraphic
, std::vector
<model::BlipEffect
> const& rEffects
, bool bRelPathToMedia
= false);
271 class OOX_DLLPUBLIC DrawingML
275 static sal_Int32 mnDrawingMLCount
;
276 static sal_Int32 mnVmlCount
;
278 /// To specify where write eg. the images to (like 'ppt', or 'word' - according to the OPC).
279 DocumentType meDocumentType
;
280 /// Parent exporter, used for text callback.
281 DMLTextExport
* mpTextExport
;
286 ::sax_fastparser::FSHelperPtr mpFS
;
287 ::oox::core::XmlFilterBase
* mpFB
;
288 /// If set, this is the parent of the currently handled shape.
289 css::uno::Reference
<css::drawing::XShape
> m_xParent
;
290 bool mbIsBackgroundDark
;
291 static sal_Int32 mnChartCount
;
293 /// True when exporting presentation placeholder shape.
296 bool GetProperty( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
, const OUString
& aName
);
297 bool GetPropertyAndState( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
,
298 const css::uno::Reference
< css::beans::XPropertyState
>& rXPropState
,
299 const OUString
& aName
, css::beans::PropertyState
& eState
);
300 OUString
GetFieldValue( const css::uno::Reference
< css::text::XTextRange
>& rRun
, bool& bIsURLField
);
301 /** Gets OOXML datetime field type from LO Date format
303 @param eDate LO Date format
305 static OUString
GetDatetimeTypeFromDate(SvxDateFormat eDate
);
306 /** Gets OOXML datetime field type from LO Time format
308 @param eTime LO Time format
310 static OUString
GetDatetimeTypeFromTime(SvxTimeFormat eTime
);
311 /** Gets OOXML datetime field type from combination of LO Time and Date formats
313 @param eDate LO Date format
314 @param eTime LO Time format
316 static OUString
GetDatetimeTypeFromDateTime(SvxDateFormat eDate
, SvxTimeFormat eTime
);
318 /// Output the media (including copying a video from vnd.sun.star.Package: to the output if necessary).
319 void WriteMediaNonVisualProperties(const css::uno::Reference
<css::drawing::XShape
>& xShape
);
321 void WriteStyleProperties( sal_Int32 nTokenId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aProperties
);
323 const char* GetComponentDir() const;
324 const char* GetRelationCompPrefix() const;
326 static bool EqualGradients( const css::awt::Gradient2
& rGradient1
, const css::awt::Gradient2
& rGradient2
);
327 bool IsFontworkShape(const css::uno::Reference
< css::beans::XPropertySet
>& rXShapePropSet
);
329 void WriteGlowEffect(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
);
330 void WriteSoftEdgeEffect(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
);
331 void WriteCustomGeometryPoint(const css::drawing::EnhancedCustomShapeParameterPair
& rParamPair
,
332 const EnhancedCustomShape2d
& rCustomShape2d
,
333 const bool bReplaceGeoWidth
, const bool bReplaceGeoHeight
);
334 bool WriteCustomGeometrySegment(
335 const sal_Int16 eCommand
, const sal_Int32 nCount
,
336 const css::uno::Sequence
<css::drawing::EnhancedCustomShapeParameterPair
>& rPairs
,
337 sal_Int32
& rnPairIndex
, double& rfCurrentX
, double& rfCurrentY
, bool& rbCurrentValid
,
338 const EnhancedCustomShape2d
& rCustomShape2d
,
339 const bool bReplaceGeoWidth
, const bool bReplaceGeoHeight
);
342 DrawingML( ::sax_fastparser::FSHelperPtr pFS
, ::oox::core::XmlFilterBase
* pFB
, DocumentType eDocumentType
= DOCUMENT_PPTX
, DMLTextExport
* pTextExport
= nullptr )
343 : meDocumentType( eDocumentType
), mpTextExport(pTextExport
), mpFS(std::move( pFS
)), mpFB( pFB
), mbIsBackgroundDark( false ), mbPlaceholder(false) {}
344 void SetFS( ::sax_fastparser::FSHelperPtr pFS
) { mpFS
= pFS
; }
345 const ::sax_fastparser::FSHelperPtr
& GetFS() const { return mpFS
; }
346 ::oox::core::XmlFilterBase
* GetFB() { return mpFB
; }
347 DocumentType
GetDocumentType() const { return meDocumentType
; }
348 /// The application-specific text exporter callback, if there is one.
349 DMLTextExport
* GetTextExport() { return mpTextExport
; }
351 void SetBackgroundDark(bool bIsDark
) { mbIsBackgroundDark
= bIsDark
; }
352 /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
353 OUString
WriteImage( const Graphic
&rGraphic
, bool bRelPathToMedia
= false );
355 void WriteColor( ::Color nColor
, sal_Int32 nAlpha
= MAX_PERCENT
);
356 void WriteColor( const OUString
& sColorSchemeName
, const css::uno::Sequence
< css::beans::PropertyValue
>& aTransformations
, sal_Int32 nAlpha
= MAX_PERCENT
);
357 void WriteColor( const ::Color nColor
, const css::uno::Sequence
< css::beans::PropertyValue
>& aTransformations
, sal_Int32 nAlpha
= MAX_PERCENT
);
358 void WriteColorTransformations( const css::uno::Sequence
< css::beans::PropertyValue
>& aTransformations
, sal_Int32 nAlpha
= MAX_PERCENT
);
359 void WriteGradientStop(double fOffset
, const basegfx::BColor
& rColor
, const basegfx::BColor
& rAlpha
);
360 void WriteLineArrow( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
, bool bLineStart
);
361 void WriteConnectorConnections( sal_Int32 nStartGlueId
, sal_Int32 nEndGlueId
, sal_Int32 nStartID
, sal_Int32 nEndID
);
363 bool WriteCharColor(const css::uno::Reference
<css::beans::XPropertySet
>& xPropertySet
);
364 bool WriteSchemeColor(OUString
const& rPropertyName
, const css::uno::Reference
<css::beans::XPropertySet
>& xPropertySet
);
366 void WriteSolidFill( ::Color nColor
, sal_Int32 nAlpha
= MAX_PERCENT
);
367 void WriteSolidFill( const OUString
& sSchemeName
, const css::uno::Sequence
< css::beans::PropertyValue
>& aTransformations
, sal_Int32 nAlpha
= MAX_PERCENT
);
368 void WriteSolidFill( const ::Color nColor
, const css::uno::Sequence
< css::beans::PropertyValue
>& aTransformations
, sal_Int32 nAlpha
= MAX_PERCENT
);
369 void WriteSolidFill( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
370 void WriteGradientFill( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
372 /* New API for WriteGradientFill:
373 If a BGradient is given, it will be used. Else, the 'Fix' entry will be used for
374 Color or Transparency. That way, less Pseudo(Color|Transparency)Gradients have to be
375 created at caller side.
376 NOTE: Giving no Gradient at all (both nullptr) is an error.
378 void WriteGradientFill(
379 const basegfx::BGradient
* pColorGradient
, sal_Int32 nFixColor
,
380 const basegfx::BGradient
* pTransparenceGradient
, double fFixTransparence
= 0.0);
382 void WriteGrabBagGradientFill( const css::uno::Sequence
< css::beans::PropertyValue
>& aGradientStops
, const basegfx::BGradient
& rGradient
);
384 void WriteBlipOrNormalFill(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
,
385 const OUString
& rURLPropName
, const css::awt::Size
& rSize
= {});
386 void WriteBlipFill(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
,
387 const OUString
& sURLPropName
, const css::awt::Size
& rSize
= {});
388 void WriteBlipFill(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
,
389 const css::awt::Size
& rSize
, const OUString
& sURLPropName
,
390 sal_Int32 nXmlNamespace
);
392 void WriteXGraphicBlipFill(css::uno::Reference
<css::beans::XPropertySet
> const & rXPropSet
,
393 css::uno::Reference
<css::graphic::XGraphic
> const & rxGraphic
,
394 sal_Int32 nXmlNamespace
, bool bWriteMode
,
395 bool bRelPathToMedia
= false, css::awt::Size
const& rSize
= {});
397 void WritePattFill( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
398 void WritePattFill(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
,
399 const css::drawing::Hatch
& rHatch
);
401 void WriteGraphicCropProperties(css::uno::Reference
<css::beans::XPropertySet
> const & rxPropertySet
,
402 Size
const & rOriginalSize
, MapMode
const & rMapMode
);
404 void WriteSrcRectXGraphic(css::uno::Reference
<css::beans::XPropertySet
> const & rxPropertySet
,
405 css::uno::Reference
<css::graphic::XGraphic
> const & rxGraphic
);
407 void WriteOutline( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
,
408 css::uno::Reference
< css::frame::XModel
> const & xModel
= nullptr );
410 void WriteXGraphicStretch(css::uno::Reference
<css::beans::XPropertySet
> const & rXPropSet
,
411 css::uno::Reference
<css::graphic::XGraphic
> const & rxGraphic
);
413 void WriteXGraphicTile(css::uno::Reference
<css::beans::XPropertySet
> const& rXPropSet
,
414 css::uno::Reference
<css::graphic::XGraphic
> const& rxGraphic
,
415 css::awt::Size
const& rSize
);
417 void WriteXGraphicCustomPosition(css::uno::Reference
<css::beans::XPropertySet
> const& rXPropSet
,
418 css::uno::Reference
<css::graphic::XGraphic
> const& rxGraphic
,
419 css::awt::Size
const& rSize
);
421 void WriteLinespacing(const css::style::LineSpacing
& rLineSpacing
, float fFirstCharHeight
);
423 OUString
WriteXGraphicBlip(css::uno::Reference
<css::beans::XPropertySet
> const & rXPropSet
,
424 css::uno::Reference
<css::graphic::XGraphic
> const & rxGraphic
,
425 bool bRelPathToMedia
);
427 void WriteImageBrightnessContrastTransparence(css::uno::Reference
<css::beans::XPropertySet
> const & rXPropSet
);
429 void WriteXGraphicBlipMode(css::uno::Reference
<css::beans::XPropertySet
> const& rXPropSet
,
430 css::uno::Reference
<css::graphic::XGraphic
> const& rxGraphic
,
431 css::awt::Size
const& rSize
);
433 void WriteShapeTransformation(const css::uno::Reference
< css::drawing::XShape
>& rXShape
,
434 sal_Int32 nXmlNamespace
, bool bFlipH
= false, bool bFlipV
= false, bool bSuppressRotation
= false, bool bSuppressFlipping
= false, bool bFlippedBeforeRotation
= false);
435 void WriteTransformation(const css::uno::Reference
< css::drawing::XShape
>& xShape
, const tools::Rectangle
& rRectangle
,
436 sal_Int32 nXmlNamespace
, bool bFlipH
= false, bool bFlipV
= false, sal_Int32 nRotation
= 0, bool bIsGroupShape
= false);
438 void WriteText( const css::uno::Reference
< css::uno::XInterface
>& rXIface
, bool bBodyPr
, bool bText
= true, sal_Int32 nXmlNamespace
= 0, bool bWritePropertiesAsLstStyles
= false);
440 /** Populates the lstStyle with the shape's text run and paragraph properties */
441 void WriteLstStyles(const css::uno::Reference
<css::text::XTextContent
>& rParagraph
,
442 bool& rbOverridingCharHeight
, sal_Int32
& rnCharHeight
,
443 const css::uno::Reference
<css::beans::XPropertySet
>& rXShapePropSet
);
444 void WriteParagraph( const css::uno::Reference
< css::text::XTextContent
>& rParagraph
,
445 bool& rbOverridingCharHeight
, sal_Int32
& rnCharHeight
, const css::uno::Reference
< css::beans::XPropertySet
>& rXShapePropSet
);
446 /** Writes paragraph properties
448 @returns true if any paragraph properties were written
450 bool WriteParagraphProperties(const css::uno::Reference
< css::text::XTextContent
>& rParagraph
, float fFirstCharHeight
, sal_Int32 nElement
);
451 void WriteParagraphNumbering(const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
, float fFirstCharHeight
,
453 void WriteParagraphTabStops(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
);
454 void WriteRun( const css::uno::Reference
< css::text::XTextRange
>& rRun
,
455 bool& rbOverridingCharHeight
, sal_Int32
& rnCharHeight
,
456 const css::uno::Reference
< css::beans::XPropertySet
>& rXShapePropSet
);
457 void WriteRunProperties( const css::uno::Reference
< css::beans::XPropertySet
>& rRun
, bool bIsField
, sal_Int32 nElement
, bool bCheckDirect
,
458 bool& rbOverridingCharHeight
, sal_Int32
& rnCharHeight
,
459 sal_Int16 nScriptType
= css::i18n::ScriptType::LATIN
,
460 const css::uno::Reference
< css::beans::XPropertySet
>& rXShapePropSet
= {});
462 void WritePresetShape( const OString
& pShape
, std::vector
< std::pair
<sal_Int32
,sal_Int32
>> & rAvList
);
463 void WritePresetShape( const OString
& pShape
);
464 void WritePresetShape( const OString
& pShape
, MSO_SPT eShapeType
, bool bPredefinedHandlesUsed
, const css::beans::PropertyValue
& rProp
);
465 bool WriteCustomGeometry(
466 const css::uno::Reference
<css::drawing::XShape
>& rXShape
,
467 const SdrObjCustomShape
& rSdrObjCustomShape
);
468 void WriteEmptyCustomGeometry();
469 void WritePolyPolygon(const css::uno::Reference
<css::drawing::XShape
>& rXShape
,
471 void WriteFill(const css::uno::Reference
<css::beans::XPropertySet
>& xPropSet
,
472 const css::awt::Size
& rSize
= {});
473 void WriteShapeStyle( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
474 void WriteShapeEffects( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
475 void WriteShapeEffect( std::u16string_view sName
, const css::uno::Sequence
< css::beans::PropertyValue
>& aEffectProps
);
476 /** Populates scene3d tag
477 @param rXPropSet Prop set
478 @param bIsText True if the 3D effects are for a text body, false if it is for a shape
480 void Write3DEffects(const css::uno::Reference
<css::beans::XPropertySet
>& rXPropSet
, bool bIsText
);
481 void WriteArtisticEffect( const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
);
482 OString
WriteWdpPicture( const OUString
& rFileId
, const css::uno::Sequence
< sal_Int8
>& rPictureData
);
483 void WriteDiagram(const css::uno::Reference
<css::drawing::XShape
>& rXShape
, int nDiagramId
);
484 void writeDiagramRels(const css::uno::Sequence
<css::uno::Sequence
<css::uno::Any
>>& xRelSeq
,
485 const css::uno::Reference
<css::io::XOutputStream
>& xOutStream
,
486 std::u16string_view sGrabBagProperyName
, int nDiagramId
);
487 static void WriteFromTo(const css::uno::Reference
<css::drawing::XShape
>& rXShape
, const css::awt::Size
& aPageSize
,
488 const sax_fastparser::FSHelperPtr
& pDrawing
);
490 static bool IsGroupShape( const css::uno::Reference
< css::drawing::XShape
>& rXShape
);
491 sal_Int32
getBulletMarginIndentation (const css::uno::Reference
< css::beans::XPropertySet
>& rXPropSet
,sal_Int16 nLevel
, std::u16string_view propName
);
493 static void ResetMlCounters();
495 static sal_Int32
getNewDrawingUniqueId() { return ++mnDrawingMLCount
; }
496 static sal_Int32
getNewVMLUniqueId() { return ++mnVmlCount
; }
497 static sal_Int32
getNewChartUniqueId() { return ++mnChartCount
; }
499 // A Helper to decide the script type for given text in order to call WriteRunProperties.
500 static sal_Int16
GetScriptType(const OUString
& rStr
);
502 static sal_Unicode
SubstituteBullet( sal_Unicode cBulletId
, css::awt::FontDescriptor
& rFontDesc
);
504 static ::Color
ColorWithIntensity( sal_uInt32 nColor
, sal_uInt32 nIntensity
);
506 static const char* GetAlignment( css::style::ParagraphAdjust nAlignment
);
508 sax_fastparser::FSHelperPtr
CreateOutputStream (
509 const OUString
& sFullStream
,
510 std::u16string_view sRelativeStream
,
511 const css::uno::Reference
< css::io::XOutputStream
>& xParentRelation
,
512 const OUString
& sContentType
,
513 const OUString
& sRelationshipType
,
514 OUString
* pRelationshipId
);
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */