tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / oox / source / drawingml / shape.cxx
bloba32553c767a55ec323451c3b1a5100b07e6caea8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <config_wasm_strip.h>
22 #include <oox/drawingml/shape.hxx>
23 #include <drawingml/customshapeproperties.hxx>
24 #include <oox/drawingml/theme.hxx>
25 #include <drawingml/fillproperties.hxx>
26 #include <drawingml/fontworkhelpers.hxx>
27 #include <drawingml/graphicproperties.hxx>
28 #include <drawingml/lineproperties.hxx>
29 #include <drawingml/presetgeometrynames.hxx>
30 #include <drawingml/shape3dproperties.hxx>
31 #include <drawingml/scene3dhelper.hxx>
32 #include "effectproperties.hxx"
33 #include <oox/drawingml/shapepropertymap.hxx>
34 #include <drawingml/textbody.hxx>
35 #include <drawingml/textparagraph.hxx>
36 #include <drawingml/ThemeOverrideFragmentHandler.hxx>
37 #include <drawingml/table/tableproperties.hxx>
38 #include <oox/drawingml/chart/chartconverter.hxx>
39 #include <drawingml/chart/chartspacefragment.hxx>
40 #include <drawingml/chart/chartspacemodel.hxx>
41 #include <o3tl/safeint.hxx>
42 #include <o3tl/unit_conversion.hxx>
43 #include <oox/ppt/pptimport.hxx>
44 #include <oox/vml/vmldrawing.hxx>
45 #include <oox/vml/vmlshape.hxx>
46 #include <oox/vml/vmlshapecontainer.hxx>
47 #include <oox/core/xmlfilterbase.hxx>
48 #include <oox/helper/graphichelper.hxx>
49 #include <oox/helper/propertyset.hxx>
50 #include <oox/helper/modelobjecthelper.hxx>
51 #include <oox/mathml/imexport.hxx>
52 #include <oox/mathml/importutils.hxx>
53 #include <oox/token/properties.hxx>
54 #include "diagram/datamodel.hxx"
55 #include "diagram/diagramhelper.hxx"
57 #include <comphelper/classids.hxx>
58 #include <comphelper/propertysequence.hxx>
59 #include <comphelper/propertyvalue.hxx>
60 #include <comphelper/sequence.hxx>
61 #include <comphelper/diagnose_ex.hxx>
62 #include <tools/gen.hxx>
63 #include <tools/globname.hxx>
64 #include <tools/mapunit.hxx>
65 #include <editeng/unoprnms.hxx>
66 #include <com/sun/star/awt/FontSlant.hpp>
67 #include <com/sun/star/awt/Size.hpp>
68 #include <com/sun/star/awt/XBitmap.hpp>
69 #include <com/sun/star/awt/FontWeight.hpp>
70 #include <com/sun/star/graphic/XGraphic.hpp>
71 #include <com/sun/star/container/XNamed.hpp>
72 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
73 #include <com/sun/star/xml/dom/XDocument.hpp>
74 #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
75 #include <com/sun/star/drawing/FillStyle.hpp>
76 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
77 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
78 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
79 #include <com/sun/star/drawing/XShapes.hpp>
80 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
81 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
82 #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
83 #include <com/sun/star/drawing/ConnectorType.hpp>
84 #include <com/sun/star/embed/XEmbeddedObject.hpp>
85 #include <com/sun/star/text/XText.hpp>
86 #include <com/sun/star/table/BorderLine2.hpp>
87 #include <com/sun/star/table/ShadowFormat.hpp>
88 #include <com/sun/star/chart2/XChartDocument.hpp>
89 #include <com/sun/star/style/ParagraphAdjust.hpp>
90 #include <com/sun/star/io/XOutputStream.hpp>
91 #include <com/sun/star/lang/Locale.hpp>
92 #include <com/sun/star/i18n/ScriptType.hpp>
93 #include <com/sun/star/text/WritingMode2.hpp>
95 #include <basegfx/point/b2dpoint.hxx>
96 #include <basegfx/polygon/b2dpolygon.hxx>
97 #include <basegfx/matrix/b2dhommatrix.hxx>
98 #include <com/sun/star/document/XActionLockable.hpp>
99 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
100 #include <officecfg/Office/Common.hxx>
101 #include <svx/svdobj.hxx>
102 #include <svx/svdotable.hxx>
103 #include <svx/svdtrans.hxx>
104 #include <tools/stream.hxx>
105 #include <unotools/streamwrap.hxx>
106 #include <unotools/mediadescriptor.hxx>
107 #include <vcl/graph.hxx>
108 #include <vcl/graphicfilter.hxx>
109 #include <vcl/svapp.hxx>
110 #include <vcl/wmfexternal.hxx>
111 #include <sal/log.hxx>
112 #include <svx/sdtaitm.hxx>
113 #include <oox/drawingml/diagram/diagram.hxx>
114 #include <docmodel/theme/Theme.hxx>
115 #include <i18nlangtag/languagetag.hxx>
116 #include <i18nlangtag/mslangid.hxx>
118 using namespace ::oox::core;
119 using namespace ::com::sun::star;
120 using namespace ::com::sun::star::uno;
121 using namespace ::com::sun::star::beans;
122 using namespace ::com::sun::star::frame;
123 using namespace ::com::sun::star::text;
124 using namespace ::com::sun::star::drawing;
125 using namespace ::com::sun::star::style;
127 namespace oox::drawingml {
129 Shape::Shape()
130 : mpLinePropertiesPtr( std::make_shared<LineProperties>() )
131 , mpShapeRefLinePropPtr( std::make_shared<LineProperties>() )
132 , mpFillPropertiesPtr( std::make_shared<FillProperties>() )
133 , mpShapeRefFillPropPtr( std::make_shared<FillProperties>() )
134 , mpGraphicPropertiesPtr( std::make_shared<GraphicProperties>() )
135 , mpCustomShapePropertiesPtr( std::make_shared<CustomShapeProperties>() )
136 , mp3DPropertiesPtr( std::make_shared<Shape3DProperties>() )
137 , mpEffectPropertiesPtr( std::make_shared<EffectProperties>() )
138 , mpShapeRefEffectPropPtr( std::make_shared<EffectProperties>() )
139 , mpMasterTextListStyle( std::make_shared<TextListStyle>() )
140 , mnSubType( 0 )
141 , meFrameType( FRAMETYPE_GENERIC )
142 , mnRotation( 0 )
143 , mnDiagramRotation( 0 )
144 , mbFlipH( false )
145 , mbFlipV( false )
146 , mbHidden( false )
147 , mbHiddenMasterShape( false )
148 , mbLocked( false )
149 , mbWPGChild(false)
150 , mbLockedCanvas( false )
151 , mbWordprocessingCanvas(false)
152 , mbWps( false )
153 , mbTextBox( false )
154 , mbHasLinkedTxbx( false )
155 , maDiagramDoms( 0 )
156 , mpDiagramHelper( nullptr )
158 setDefaults(/*bDefaultHeight*/true);
162 Shape::Shape( const OUString& rServiceName, bool bDefaultHeight )
163 : mpLinePropertiesPtr( std::make_shared<LineProperties>() )
164 , mpShapeRefLinePropPtr( std::make_shared<LineProperties>() )
165 , mpFillPropertiesPtr( std::make_shared<FillProperties>() )
166 , mpShapeRefFillPropPtr( std::make_shared<FillProperties>() )
167 , mpGraphicPropertiesPtr( std::make_shared<GraphicProperties>() )
168 , mpCustomShapePropertiesPtr( std::make_shared<CustomShapeProperties>() )
169 , mp3DPropertiesPtr( std::make_shared<Shape3DProperties>() )
170 , mpEffectPropertiesPtr( std::make_shared<EffectProperties>() )
171 , mpShapeRefEffectPropPtr( std::make_shared<EffectProperties>() )
172 , mpMasterTextListStyle( std::make_shared<TextListStyle>() )
173 , mnSubType( 0 )
174 , meFrameType( FRAMETYPE_GENERIC )
175 , mnRotation( 0 )
176 , mnDiagramRotation( 0 )
177 , mbFlipH( false )
178 , mbFlipV( false )
179 , mbHidden( false )
180 , mbHiddenMasterShape( false )
181 , mbLocked( false )
182 , mbWPGChild(false)
183 , mbLockedCanvas( false )
184 , mbWordprocessingCanvas(false)
185 , mbWps( false )
186 , mbTextBox( false )
187 , mbHasLinkedTxbx( false )
188 , maDiagramDoms( 0 )
189 , mpDiagramHelper( nullptr )
191 msServiceName = rServiceName;
192 setDefaults(bDefaultHeight);
195 Shape::Shape( const ShapePtr& pSourceShape )
196 : mpTextBody(pSourceShape->mpTextBody)
197 , mpLinePropertiesPtr( pSourceShape->mpLinePropertiesPtr )
198 , mpShapeRefLinePropPtr( pSourceShape->mpShapeRefLinePropPtr )
199 , mpFillPropertiesPtr( pSourceShape->mpFillPropertiesPtr )
200 , mpShapeRefFillPropPtr( pSourceShape->mpShapeRefFillPropPtr )
201 , mpGraphicPropertiesPtr( pSourceShape->mpGraphicPropertiesPtr )
202 , mpCustomShapePropertiesPtr( pSourceShape->mpCustomShapePropertiesPtr )
203 , mpTablePropertiesPtr( pSourceShape->mpTablePropertiesPtr )
204 , mp3DPropertiesPtr( pSourceShape->mp3DPropertiesPtr )
205 , mpEffectPropertiesPtr (pSourceShape->mpEffectPropertiesPtr)
206 , mpShapeRefEffectPropPtr(pSourceShape->mpShapeRefEffectPropPtr)
207 , maShapeProperties( pSourceShape->maShapeProperties )
208 , mpMasterTextListStyle( pSourceShape->mpMasterTextListStyle )
209 , msServiceName( pSourceShape->msServiceName )
210 , msName( pSourceShape->msName )
211 , msInternalName( pSourceShape->msInternalName )
212 , msId( pSourceShape->msId )
213 , mnSubType( pSourceShape->mnSubType )
214 , moSubTypeIndex( pSourceShape->moSubTypeIndex )
215 , maShapeStyleRefs( pSourceShape->maShapeStyleRefs )
216 , maSize( pSourceShape->maSize )
217 , maPosition( pSourceShape->maPosition )
218 , meFrameType( pSourceShape->meFrameType )
219 , mnRotation( pSourceShape->mnRotation )
220 , mnDiagramRotation( pSourceShape->mnDiagramRotation )
221 , mbFlipH( pSourceShape->mbFlipH )
222 , mbFlipV( pSourceShape->mbFlipV )
223 , mbHidden( pSourceShape->mbHidden )
224 , mbHiddenMasterShape( pSourceShape->mbHiddenMasterShape )
225 , mbLocked( pSourceShape->mbLocked )
226 , mbWPGChild( pSourceShape->mbWPGChild )
227 , mbLockedCanvas( pSourceShape->mbLockedCanvas )
228 , mbWordprocessingCanvas(pSourceShape->mbWordprocessingCanvas)
229 , mbWps( pSourceShape->mbWps )
230 , mbTextBox( pSourceShape->mbTextBox )
231 , mbHasLinkedTxbx(false)
232 , maDiagramDoms( pSourceShape->maDiagramDoms )
233 , mnZOrder(pSourceShape->mnZOrder)
234 , mnZOrderOff(pSourceShape->mnZOrderOff)
235 , mnDataNodeType(pSourceShape->mnDataNodeType)
236 , mfAspectRatio(pSourceShape->mfAspectRatio)
237 , mpDiagramHelper( nullptr )
238 , msDiagramDataModelID(pSourceShape->msDiagramDataModelID)
241 Shape::~Shape()
243 // DiagramHelper should not be set here anymore, see
244 // propagateDiagramHelper below (maybe assert..?)
245 delete mpDiagramHelper;
248 void Shape::prepareDiagramHelper(
249 const std::shared_ptr< Diagram >& rDiagramPtr,
250 const std::shared_ptr<::oox::drawingml::Theme>& rTheme)
252 // Prepare Diagram data collecting for this Shape
253 if( nullptr == mpDiagramHelper && FRAMETYPE_DIAGRAM == meFrameType )
255 mpDiagramHelper = new AdvancedDiagramHelper(
256 rDiagramPtr,
257 rTheme,
258 getSize());
262 void Shape::propagateDiagramHelper()
264 // Propagate collected Diagram data to data holder
265 if (FRAMETYPE_DIAGRAM == meFrameType && nullptr != mpDiagramHelper)
267 SdrObjGroup* pAnchorObj = dynamic_cast<SdrObjGroup*>(SdrObject::getSdrObjectFromXShape(mxShape));
269 if(pAnchorObj)
271 mpDiagramHelper->doAnchor(*pAnchorObj, *this);
272 mpDiagramHelper = nullptr;
276 // If propagation failed, delete/cleanup here. Since the DiagramHelper
277 // holds a Diagram and that this Shape it is necessary - the destructor
278 // will not be called and will be too late
279 if (nullptr != mpDiagramHelper)
281 delete mpDiagramHelper;
282 mpDiagramHelper = nullptr;
286 void Shape::migrateDiagramHelperToNewShape(const ShapePtr& pTarget)
288 if(!mpDiagramHelper)
290 return;
293 if(!pTarget)
295 // no migrate target, but cleanup helper
296 delete mpDiagramHelper;
297 mpDiagramHelper = nullptr;
298 return;
301 if(pTarget->mpDiagramHelper)
303 // this should no happen, but if there is already a helper, clean it up
304 delete pTarget->mpDiagramHelper;
305 pTarget->mpDiagramHelper = nullptr;
308 // exchange and reset to nullptr
309 pTarget->mpDiagramHelper = mpDiagramHelper;
310 mpDiagramHelper = nullptr;
313 table::TablePropertiesPtr const & Shape::getTableProperties()
315 if ( !mpTablePropertiesPtr )
316 mpTablePropertiesPtr = std::make_shared<table::TableProperties>();
317 return mpTablePropertiesPtr;
320 void Shape::setDefaults(bool bHeight)
322 maDefaultShapeProperties.setProperty(PROP_TextAutoGrowHeight, false);
323 maDefaultShapeProperties.setProperty(PROP_TextWordWrap, true);
324 maDefaultShapeProperties.setProperty(PROP_TextLeftDistance, static_cast< sal_Int32 >( 250 ));
325 maDefaultShapeProperties.setProperty(PROP_TextUpperDistance, static_cast< sal_Int32 >( 125 ));
326 maDefaultShapeProperties.setProperty(PROP_TextRightDistance, static_cast< sal_Int32 >( 250 ));
327 maDefaultShapeProperties.setProperty(PROP_TextLowerDistance, static_cast< sal_Int32 >( 125 ));
328 if (bHeight)
329 maDefaultShapeProperties.setProperty(PROP_CharHeight, static_cast< float >( 18.0 ));
330 maDefaultShapeProperties.setProperty(PROP_TextVerticalAdjust, TextVerticalAdjust_TOP);
331 maDefaultShapeProperties.setProperty(PROP_ParaAdjust,
332 static_cast<sal_Int16>(ParagraphAdjust_LEFT));
335 ::oox::vml::OleObjectInfo& Shape::setOleObjectType()
337 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setOleObjectType - multiple frame types" );
338 meFrameType = FRAMETYPE_OLEOBJECT;
339 mxOleObjectInfo = std::make_shared<::oox::vml::OleObjectInfo>( true );
340 return *mxOleObjectInfo;
343 ChartShapeInfo& Shape::setChartType( bool bEmbedShapes )
345 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setChartType - multiple frame types" );
346 meFrameType = FRAMETYPE_CHART;
347 if (mbWps)
348 msServiceName = u"com.sun.star.drawing.temporaryForXMLImportOLE2Shape"_ustr;
349 else
350 msServiceName = u"com.sun.star.drawing.OLE2Shape"_ustr;
351 mxChartShapeInfo = std::make_shared<ChartShapeInfo>( bEmbedShapes );
352 return *mxChartShapeInfo;
355 void Shape::setDiagramType()
357 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setDiagramType - multiple frame types" );
358 meFrameType = FRAMETYPE_DIAGRAM;
359 msServiceName = u"com.sun.star.drawing.GroupShape"_ustr;
360 mnSubType = 0;
363 void Shape::setTableType()
365 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setTableType - multiple frame types" );
366 meFrameType = FRAMETYPE_TABLE;
367 msServiceName = u"com.sun.star.drawing.TableShape"_ustr;
368 mnSubType = 0;
371 const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const
373 ShapeStyleRefMap::const_iterator aIt = maShapeStyleRefs.find( nRefType );
374 return (aIt == maShapeStyleRefs.end()) ? nullptr : &aIt->second;
377 void Shape::addShape(
378 ::oox::core::XmlFilterBase& rFilterBase,
379 const Theme* pTheme,
380 const Reference< XShapes >& rxShapes,
381 const basegfx::B2DHomMatrix& aTransformation,
382 const FillProperties& rShapeOrParentShapeFillProps,
383 ShapeIdMap* pShapeMap,
384 oox::drawingml::ShapePtr pParentGroupShape)
386 SAL_INFO("oox.drawingml", "Shape::addShape: id='" << msId << "'");
390 OUString sServiceName( msServiceName );
391 if( !sServiceName.isEmpty() )
393 basegfx::B2DHomMatrix aMatrix( aTransformation );
394 Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, false, false, aMatrix, rShapeOrParentShapeFillProps, pParentGroupShape) );
396 if( pShapeMap && !msId.isEmpty() )
398 (*pShapeMap)[ msId ] = shared_from_this();
401 // if this is a group shape, we have to add also each child shape
402 Reference< XShapes > xShapes( xShape, UNO_QUERY );
403 if ( xShapes.is() )
404 addChildren( rFilterBase, *this, pTheme, xShapes, pShapeMap, aMatrix );
406 if (mbWordprocessingCanvas && !mbWPGChild)
408 // This is a drawing canvas. In case the canvas has no fill and no stroke, Word does
409 // not render shadow or glow, even if it is set for the canvas. Thus we disable shadow
410 // and glow in this case for the ersatz background shape of the drawing canvas.
413 oox::drawingml::ShapePtr pBgShape = getChildren().front();
414 const Reference<css::drawing::XShape>& xBgShape = pBgShape->getXShape();
415 Reference<XPropertySet> xBgProps(xBgShape, uno::UNO_QUERY);
416 drawing::FillStyle eFillStyle = drawing::FillStyle_NONE;
417 xBgProps->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle;
418 drawing::LineStyle eLineStyle = drawing::LineStyle_NONE;
419 xBgProps->getPropertyValue(u"LineStyle"_ustr) >>= eLineStyle;
420 if (eFillStyle == drawing::FillStyle_NONE
421 && eLineStyle == drawing::LineStyle_NONE)
423 xBgProps->setPropertyValue(UNO_NAME_SHADOW, uno::Any(false));
424 xBgProps->setPropertyValue(u"GlowEffectRadius"_ustr, uno::Any(sal_Int32(0)));
427 catch (const Exception&)
429 TOOLS_WARN_EXCEPTION("oox.drawingml", "Shape::addShape mbWordprocessingCanvas");
433 if (isWPGChild() && xShape)
435 // This is a wps shape and it is the child of the WPG, now copy the
436 // the text body properties to the xshape.
437 Reference<XPropertySet> xChildWPSProperties(xShape, uno::UNO_QUERY);
439 if (getTextBody() && xChildWPSProperties)
441 xChildWPSProperties->setPropertyValue(
442 UNO_NAME_TEXT_VERTADJUST,
443 uno::Any(getTextBody()->getTextProperties().meVA));
445 xChildWPSProperties->setPropertyValue(
446 UNO_NAME_TEXT_LEFTDIST,
447 uno::Any(getTextBody()->getTextProperties().moInsets[0].has_value()
448 ? *getTextBody()->getTextProperties().moInsets[0]
449 : 0));
450 xChildWPSProperties->setPropertyValue(
451 UNO_NAME_TEXT_UPPERDIST,
452 uno::Any(getTextBody()->getTextProperties().moInsets[1].has_value()
453 ? *getTextBody()->getTextProperties().moInsets[1]
454 : 0));
455 xChildWPSProperties->setPropertyValue(
456 UNO_NAME_TEXT_RIGHTDIST,
457 uno::Any(getTextBody()->getTextProperties().moInsets[2].has_value()
458 ? *getTextBody()->getTextProperties().moInsets[2]
459 : 0));
460 xChildWPSProperties->setPropertyValue(
461 UNO_NAME_TEXT_LOWERDIST,
462 uno::Any(getTextBody()->getTextProperties().moInsets[3].has_value()
463 ? *getTextBody()->getTextProperties().moInsets[3]
464 : 0));
467 // tdf#145147 Set the Hyperlink property to the child wps shape.
468 if (getShapeProperties().hasProperty(PROP_URL)) try
470 uno::Any aAny = getShapeProperties().getProperty(PROP_URL);
471 OUString sUrl = aAny.get<OUString>();
472 if (!sUrl.isEmpty())
473 xChildWPSProperties->setPropertyValue(UNO_NAME_HYPERLINK, aAny);
475 catch (const Exception&)
480 if( meFrameType == FRAMETYPE_DIAGRAM )
482 keepDiagramCompatibilityInfo();
484 // set DiagramHelper at SdrObjGroup
485 propagateDiagramHelper();
487 // Check if this is the PPTX import, so far converting SmartArt to a non-editable
488 // metafile is only implemented for DOCX.
489 bool bPowerPoint = dynamic_cast<oox::ppt::PowerPointImport*>(&rFilterBase) != nullptr;
491 if (!officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get() && !bPowerPoint)
492 convertSmartArtToMetafile( rFilterBase );
495 NamedShapePairs* pNamedShapePairs = rFilterBase.getDiagramFontHeights();
496 if (xShape.is() && pNamedShapePairs)
498 auto itPairs = pNamedShapePairs->find(getInternalName());
499 if (itPairs != pNamedShapePairs->end())
501 auto it = itPairs->second.find(shared_from_this());
502 if (it != itPairs->second.end())
504 // Our drawingml::Shape is in the list of an internal name, remember the now
505 // inserted XShape.
506 it->second = xShape;
512 catch( const Exception& )
514 TOOLS_WARN_EXCEPTION( "oox.drawingml", "Shape::addShape" );
518 void Shape::setLockedCanvas(bool bLockedCanvas)
520 mbLockedCanvas = bLockedCanvas;
523 void Shape::setWordprocessingCanvas(bool bWordprocessingCanvas)
525 mbWordprocessingCanvas = bWordprocessingCanvas;
528 void Shape::setWPGChild(bool bWPG)
530 mbWPGChild = bWPG;
533 void Shape::setWps(bool bWps)
535 mbWps = bWps;
538 void Shape::setTextBox(bool bTextBox)
540 mbTextBox = bTextBox;
543 void Shape::applyShapeReference( const Shape& rReferencedShape, bool bUseText )
545 SAL_INFO("oox.drawingml", "Shape::applyShapeReference: apply '" << rReferencedShape.msId << "' to '" << msId << "'");
547 if ( rReferencedShape.mpTextBody && bUseText )
548 mpTextBody = std::make_shared<TextBody>( *rReferencedShape.mpTextBody );
549 else
550 mpTextBody.reset();
551 maShapeProperties = rReferencedShape.maShapeProperties;
552 mpShapeRefLinePropPtr = std::make_shared<LineProperties>( rReferencedShape.getActualLineProperties(nullptr) );
553 mpShapeRefFillPropPtr = std::make_shared<FillProperties>( rReferencedShape.getActualFillProperties(nullptr, nullptr) );
554 mpCustomShapePropertiesPtr = std::make_shared<CustomShapeProperties>( *rReferencedShape.mpCustomShapePropertiesPtr );
555 mpTablePropertiesPtr = rReferencedShape.mpTablePropertiesPtr ? std::make_shared<table::TableProperties>( *rReferencedShape.mpTablePropertiesPtr ) : nullptr;
556 mpShapeRefEffectPropPtr = std::make_shared<EffectProperties>( rReferencedShape.getActualEffectProperties(nullptr) );
557 mpMasterTextListStyle = std::make_shared<TextListStyle>( *rReferencedShape.mpMasterTextListStyle );
558 maSize = rReferencedShape.maSize;
559 maPosition = rReferencedShape.maPosition;
560 mnRotation = rReferencedShape.mnRotation;
561 mbFlipH = rReferencedShape.mbFlipH;
562 mbFlipV = rReferencedShape.mbFlipV;
563 mbHidden = rReferencedShape.mbHidden;
564 mbLocked = rReferencedShape.mbLocked;
567 namespace {
569 struct ActionLockGuard
571 explicit ActionLockGuard(Reference<drawing::XShape> const& xShape)
572 : m_xLockable(xShape, UNO_QUERY)
574 if (m_xLockable.is()) {
575 m_xLockable->addActionLock();
578 ~ActionLockGuard()
580 if (m_xLockable.is()) {
581 m_xLockable->removeActionLock();
584 private:
585 Reference<document::XActionLockable> m_xLockable;
590 // for group shapes, the following method is also adding each child
591 void Shape::addChildren(
592 XmlFilterBase& rFilterBase,
593 Shape& rMaster,
594 const Theme* pTheme,
595 const Reference< XShapes >& rxShapes,
596 ShapeIdMap* pShapeMap,
597 const basegfx::B2DHomMatrix& aTransformation )
599 for (auto const& child : rMaster.maChildren)
601 child->setMasterTextListStyle( mpMasterTextListStyle );
602 child->addShape( rFilterBase, pTheme, rxShapes, aTransformation, getFillProperties(), pShapeMap, rMaster.shared_from_this());
606 static SdrTextHorzAdjust lcl_convertAdjust( ParagraphAdjust eAdjust )
608 if (eAdjust == ParagraphAdjust_LEFT)
609 return SDRTEXTHORZADJUST_LEFT;
610 else if (eAdjust == ParagraphAdjust_RIGHT)
611 return SDRTEXTHORZADJUST_RIGHT;
612 else if (eAdjust == ParagraphAdjust_CENTER)
613 return SDRTEXTHORZADJUST_CENTER;
614 return SDRTEXTHORZADJUST_LEFT;
617 // LO does not interpret properties in styles belonging to the text content of a FontWork shape,
618 // but only those in the shape style. This method copies properties from the text content styles to
619 // the shape style.
620 static void lcl_copyCharPropsToShape(const uno::Reference<drawing::XShape>& xShape,
621 const TextBodyPtr& pTextBody,
622 const ::oox::core::XmlFilterBase& rFilter)
624 if (!xShape.is() || !pTextBody)
625 return;
627 Reference<XPropertySet> xSet(xShape, UNO_QUERY);
628 if (!xSet.is())
629 return;
631 // Content stretches or scales to given width and height, thus disable autogrow.
632 xSet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT, uno::Any(false));
633 xSet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWWIDTH, uno::Any(false));
635 // LibreOffice is not able (as of Nov 2022) to use different styles for the paragraphs or
636 // characters in FontWork, since that was not allowed in old binary WordArt. We use the
637 // properties of the first non empty paragraph for now.
638 const TextParagraphVector& rParagraphs = pTextBody->getParagraphs();
639 auto aParaIt = std::find_if_not(rParagraphs.cbegin(), rParagraphs.cend(),
640 [](const std::shared_ptr<TextParagraph> pParagraph) {
641 return pParagraph->getRuns().empty();
643 if (aParaIt != rParagraphs.cend())
645 std::shared_ptr<TextParagraph> pParagraph = *aParaIt;
646 const TextRunVector& rRuns = pParagraph->getRuns();
647 auto aRunIt = std::find_if_not(
648 rRuns.cbegin(), rRuns.cend(),
649 [](const std::shared_ptr<TextRun> pRun) { return pRun->getText().isEmpty(); });
650 if (aRunIt != rRuns.cend())
652 std::shared_ptr<TextRun> pRun = *aRunIt;
653 TextCharacterProperties& rCharProps = pRun->getTextCharacterProperties();
655 // set language
656 if (rCharProps.moLang.has_value() && !rCharProps.moLang.value().isEmpty())
658 LanguageTag aTag(rCharProps.moLang.value());
659 css::lang::Locale aLocale(aTag.getLocale(false));
660 switch (MsLangId::getScriptType(aTag.getLanguageType()))
662 case css::i18n::ScriptType::LATIN:
663 xSet->setPropertyValue(u"CharLocale"_ustr, uno::Any(aLocale));
664 break;
665 case css::i18n::ScriptType::ASIAN:
666 xSet->setPropertyValue(u"CharLocaleAsian"_ustr, uno::Any(aLocale));
667 break;
668 case css::i18n::ScriptType::COMPLEX:
669 xSet->setPropertyValue(u"CharLocaleComplex"_ustr, uno::Any(aLocale));
670 break;
671 default:;
675 // Font Weight, Posture, Height
676 if (rCharProps.moBold.has_value() && rCharProps.moBold.value())
678 xSet->setPropertyValue(UNO_NAME_CHAR_WEIGHT, uno::Any(css::awt::FontWeight::BOLD));
680 if (rCharProps.moItalic.has_value() && rCharProps.moItalic.value())
682 xSet->setPropertyValue(UNO_NAME_CHAR_POSTURE,
683 uno::Any(css::awt::FontSlant::FontSlant_ITALIC));
685 if (rCharProps.moHeight.has_value())
687 sal_Int32 nHeight = rCharProps.moHeight.value() / 100;
688 xSet->setPropertyValue(UNO_NAME_CHAR_HEIGHT, uno::Any(nHeight));
691 // Put theme fonts into shape properties
692 OUString sFontName;
693 sal_Int16 nFontPitch = 0;
694 sal_Int16 nFontFamily = 0;
695 bool bRet(false);
696 if (const Theme* pTheme = rFilter.getCurrentTheme())
698 // minor Latin
699 if (const TextFont* pFont = pTheme->resolveFont(u"+mn-lt"))
701 bRet = pFont->getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
702 if (bRet)
704 xSet->setPropertyValue(u"CharFontName"_ustr, uno::Any(sFontName));
705 xSet->setPropertyValue(u"CharFontPitch"_ustr, uno::Any(nFontPitch));
706 xSet->setPropertyValue(u"CharFontFamily"_ustr, uno::Any(nFontFamily));
709 // minor Asian
710 if (const TextFont* pFont = pTheme->resolveFont(u"+mn-ea"))
712 bRet = pFont->getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
713 if (bRet)
715 xSet->setPropertyValue(u"CharFontNameAsian"_ustr, uno::Any(sFontName));
716 xSet->setPropertyValue(u"CharFontPitchAsian"_ustr, uno::Any(nFontPitch));
717 xSet->setPropertyValue(u"CharFontFamilyAsian"_ustr, uno::Any(nFontFamily));
720 // minor Complex
721 if (const TextFont* pFont = pTheme->resolveFont(u"+mn-cs"))
723 bRet = pFont->getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
724 if (bRet)
726 xSet->setPropertyValue(u"CharFontNameComplex"_ustr, uno::Any(sFontName));
727 xSet->setPropertyValue(u"CharFontPitchComplex"_ustr, uno::Any(nFontPitch));
728 xSet->setPropertyValue(u"CharFontFamilyComplex"_ustr, uno::Any(nFontFamily));
733 // Replace theme fonts with formatting at run if any. ToDo: Inspect paragraph too?
734 // Latin
735 bRet = rCharProps.maLatinFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
736 if (!bRet)
737 // In case there is no direct font, try to look it up as a theme reference.
738 bRet = rCharProps.maLatinThemeFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr,
739 rFilter);
741 if (bRet)
743 xSet->setPropertyValue(u"CharFontName"_ustr, uno::Any(sFontName));
744 xSet->setPropertyValue(u"CharFontPitch"_ustr, uno::Any(nFontPitch));
745 xSet->setPropertyValue(u"CharFontFamily"_ustr, uno::Any(nFontFamily));
747 // Asian
748 bRet = rCharProps.maAsianFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
749 if (!bRet)
750 // In case there is no direct font, try to look it up as a theme reference.
751 bRet = rCharProps.maAsianThemeFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr,
752 rFilter);
753 if (bRet)
755 xSet->setPropertyValue(u"CharFontNameAsian"_ustr, uno::Any(sFontName));
756 xSet->setPropertyValue(u"CharFontPitchAsian"_ustr, uno::Any(nFontPitch));
757 xSet->setPropertyValue(u"CharFontFamilyAsian"_ustr, uno::Any(nFontFamily));
759 // Complex
760 bRet
761 = rCharProps.maComplexFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr, rFilter);
762 if (!bRet)
763 // In case there is no direct font, try to look it up as a theme reference.
764 bRet = rCharProps.maComplexThemeFont.getFontData(sFontName, nFontPitch, nFontFamily, nullptr,
765 rFilter);
766 if (bRet)
768 xSet->setPropertyValue(u"CharFontNameComplex"_ustr, uno::Any(sFontName));
769 xSet->setPropertyValue(u"CharFontPitchComplex"_ustr, uno::Any(nFontPitch));
770 xSet->setPropertyValue(u"CharFontFamilyComplex"_ustr, uno::Any(nFontFamily));
773 // LO uses shape properties, MS Office character properties. Copy them from char to shape.
774 // Outline
775 if (rCharProps.moTextOutlineProperties.has_value())
777 oox::drawingml::ShapePropertyMap aStrokeShapeProps(rFilter.getModelObjectHelper());
778 rCharProps.moTextOutlineProperties.value().pushToPropMap(
779 aStrokeShapeProps, rFilter.getGraphicHelper());
780 for (const auto& rProp : aStrokeShapeProps.makePropertyValueSequence())
782 xSet->setPropertyValue(rProp.Name, rProp.Value);
785 else
787 xSet->setPropertyValue(UNO_NAME_LINESTYLE, uno::Any(drawing::LineStyle_NONE));
790 // Fill
791 // ToDo: Replace flip and rotate constants in parameters with actual values.
792 // tdf#155327 If color is not explicitly set, MS Office uses scheme color 'tx1'.
793 oox::drawingml::ShapePropertyMap aFillShapeProps(rFilter.getModelObjectHelper());
794 if (!rCharProps.maFillProperties.moFillType.has_value())
795 rCharProps.maFillProperties.moFillType = XML_solidFill;
796 if (!rCharProps.maFillProperties.maFillColor.isUsed())
797 rCharProps.maFillProperties.maFillColor.setSchemeClr(XML_tx1);
798 rCharProps.maFillProperties.pushToPropMap(aFillShapeProps, rFilter.getGraphicHelper(),
799 /*nShapeRotation*/ 0,
800 /*nPhClr*/ API_RGB_TRANSPARENT,
801 /*aShapeSize*/ css::awt::Size(0, 0),
802 /*nPhClrTheme*/ -1,
803 /*bFlipH*/ false, /*bFlipV*/ false,
804 /*bIsCustomShape*/ true);
805 for (const auto& rProp : aFillShapeProps.makePropertyValueSequence())
807 xSet->setPropertyValue(rProp.Name, rProp.Value);
810 // ToDo: Import WordArt glow and simple shadow effects. They are available in LO.
813 // LO does not evaluate paragraph alignment in text path mode. Use text area anchor instead.
815 ParagraphAdjust eAdjust = ParagraphAdjust_LEFT;
816 if (pParagraph->getProperties().getParaAdjust())
817 eAdjust = *pParagraph->getProperties().getParaAdjust();
818 xSet->setPropertyValue(u"ParaAdjust"_ustr, uno::Any(eAdjust));
819 SdrObject* pShape = SdrObject::getSdrObjectFromXShape(xShape);
820 assert(pShape);
821 SdrTextHorzAdjust eHorzAdjust = lcl_convertAdjust(eAdjust);
822 pShape->SetMergedItem(SdrTextHorzAdjustItem(eHorzAdjust));
826 // Vertical adjustment is only meaningful for OOXML WordArt shapes of 'Follow Path' kinds. We set
827 // it so, that text position is approximately same as in MS Office.
828 const OUString sMSPresetType = pTextBody->getTextProperties().msPrst;
829 const OUString sFontworkType = PresetGeometryTypeNames::GetFontworkType(sMSPresetType);
830 SdrObject* pShape = SdrObject::getSdrObjectFromXShape(xShape);
831 assert(pShape);
832 if (sFontworkType == "fontwork-arch-up-curve" || sFontworkType == "fontwork-circle-curve")
833 pShape->SetMergedItem(SdrTextVertAdjustItem(SdrTextVertAdjust::SDRTEXTVERTADJUST_BOTTOM));
834 else if (sFontworkType == "fontwork-arch-down-curve")
835 pShape->SetMergedItem(SdrTextVertAdjustItem(SdrTextVertAdjust::SDRTEXTVERTADJUST_TOP));
836 else
837 pShape->SetMergedItem(SdrTextVertAdjustItem(SdrTextVertAdjust::SDRTEXTVERTADJUST_CENTER));
840 // Some helper methods for createAndInsert
841 namespace
843 // mirrors aTransformation at its center axis
844 // only valid if neither rotation or shear included
845 void lcl_mirrorAtCenter(basegfx::B2DHomMatrix& aTransformation, bool bFlipH, bool bFlipV)
847 if (!bFlipH && !bFlipV)
848 return;
849 basegfx::B2DPoint aCenter(0.5, 0.5);
850 aCenter *= aTransformation;
851 aTransformation.translate(-aCenter);
852 aTransformation.scale(bFlipH ? -1.0 : 1.0, bFlipV ? -1.0 : 1.0);
853 aTransformation.translate(aCenter);
854 return;
857 // only valid if neither rotation or shear included
858 void lcl_doSpecialMSOWidthHeightToggle(basegfx::B2DHomMatrix& aTransformation)
860 // The values are directly set at the matrix without any matrix multiplication.
861 // That way it is valid for lines too. Those have zero width or height.
862 const double fSx(aTransformation.get(0, 0));
863 const double fSy(aTransformation.get(1, 1));
864 const double fTx(aTransformation.get(0, 2));
865 const double fTy(aTransformation.get(1, 2));
866 aTransformation.set(0, 0, fSy);
867 aTransformation.set(1, 1, fSx);
868 aTransformation.set(0, 2, fTx + 0.5 * (fSx - fSy));
869 aTransformation.set(1, 2, fTy + 0.5 * (fSy - fSx));
870 return;
873 void lcl_RotateAtCenter(basegfx::B2DHomMatrix& aTransformation, sal_Int32 nMSORotationAngle)
875 if (nMSORotationAngle == 0)
876 return;
877 double fRad = basegfx::deg2rad<60000>(nMSORotationAngle);
878 basegfx::B2DPoint aCenter(0.5, 0.5);
879 aCenter *= aTransformation;
880 aTransformation.translate(-aCenter);
881 aTransformation.rotate(fRad);
882 aTransformation.translate(aCenter);
883 return;
886 Degree100 lcl_MSORotateAngleToAPIAngle(const sal_Int32 nMSORotationAngle)
888 // Converts a shape rotation angle from MSO to angle for API property RotateAngle
889 // from unit 1/60000 deg to unit 1/100 deg
890 Degree100 nAngle(nMSORotationAngle / 600);
891 // API RotateAngle has opposite direction than nMSORotationAngle, thus 'minus'.
892 return NormAngle36000(-nAngle);
896 Reference< XShape > const & Shape::createAndInsert(
897 ::oox::core::XmlFilterBase& rFilterBase,
898 const OUString& rServiceName,
899 const Theme* pTheme,
900 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
901 bool bClearText,
902 bool bDoNotInsertEmptyTextBody,
903 basegfx::B2DHomMatrix& aParentTransformation,
904 const FillProperties& rShapeOrParentShapeFillProps,
905 oox::drawingml::ShapePtr pParentGroupShape)
907 bool bIsEmbMedia = false;
908 SAL_INFO("oox.drawingml", "Shape::createAndInsert: id='" << msId << "' service='" << rServiceName << "'");
910 formulaimport::XmlStreamBuilder * pMathXml(nullptr);
911 if (mpTextBody)
913 for (auto const& it : mpTextBody->getParagraphs())
915 if (it->HasMathXml())
917 if (!mpTextBody->isEmpty() || pMathXml != nullptr)
919 SAL_WARN("oox.drawingml", "losing a Math object...");
921 else
923 pMathXml = &it->GetMathXml();
929 // tdf#90403 PowerPoint ignores a:ext cx and cy values of p:xfrm, and uses real table width and height
930 if ( mpTablePropertiesPtr && rServiceName == "com.sun.star.drawing.TableShape" )
932 maSize.Width = 0;
933 for (auto const& elem : mpTablePropertiesPtr->getTableGrid())
935 maSize.Width = o3tl::saturating_add(maSize.Width, static_cast<sal_Int32>(elem));
937 maSize.Height = 0;
938 for (auto const& elem : mpTablePropertiesPtr->getTableRows())
940 // WARN: If some rows can't fit the content, this is not the final height
941 maSize.Height = o3tl::saturating_add(maSize.Height, elem.getHeight());
945 awt::Rectangle aShapeRectHmm(
946 o3tl::convert(maPosition.X, o3tl::Length::emu, o3tl::Length::mm100),
947 o3tl::convert(maPosition.Y, o3tl::Length::emu, o3tl::Length::mm100),
948 o3tl::convert(maSize.Width, o3tl::Length::emu, o3tl::Length::mm100),
949 o3tl::convert(maSize.Height, o3tl::Length::emu, o3tl::Length::mm100));
951 OUString aServiceName;
952 if (pMathXml)
954 // convert this shape to OLE
955 aServiceName = u"com.sun.star.drawing.OLE2Shape"_ustr;
956 msServiceName = aServiceName;
957 meFrameType = FRAMETYPE_GENERIC; // not OLEOBJECT, no stream in package
958 mnSubType = 0;
960 else if (rServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
961 mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->m_sMediaPackageURL.isEmpty())
963 aServiceName = finalizeServiceName( rFilterBase, u"com.sun.star.presentation.MediaShape"_ustr, aShapeRectHmm );
964 bIsEmbMedia = true;
966 else
968 aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm );
970 // Use custom shape instead of GraphicObjectShape if the image is cropped to
971 // shape. Except rectangle, which does not require further cropping
972 bool bIsCroppedGraphic = (aServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
973 !mpCustomShapePropertiesPtr->representsDefaultShape());
975 bool bIsCustomShape = (aServiceName == "com.sun.star.drawing.CustomShape" || bIsCroppedGraphic);
976 bool bIsConnectorShape = (aServiceName == "com.sun.star.drawing.ConnectorShape");
978 // Look for 3D. Its z-rotation and extrusion color become shape properties. We consider a
979 // z-rotation of an image even we currently do not extrude an image to 3D-scene.
980 bool bBlockExtrusion = !bIsCustomShape && mp3DPropertiesPtr->mnPreset.has_value();
981 double fShapeRotateInclCamera = 0.0; // unit rad; same orientation as shape property RotateAngle
982 Color aExtrusionColor;
983 Scene3DHelper aScene3DHelper;
984 bool bHas3DEffect = aScene3DHelper.setExtrusionProperties(
985 mp3DPropertiesPtr, mnRotation, getCustomShapeProperties()->getExtrusionPropertyMap(),
986 fShapeRotateInclCamera, aExtrusionColor, bBlockExtrusion);
987 // Currently the other places use unit 1/60000deg and MSO shape rotate orientation.
988 sal_Int32 nShapeRotateInclCamera = -basegfx::rad2deg<60000>(fShapeRotateInclCamera);
989 bool bIs3DGraphic = aServiceName == "com.sun.star.drawing.GraphicObjectShape" && bHas3DEffect;
990 bIsCustomShape |= bIs3DGraphic;
992 // The extrusion color does not belong to the extrusion properties but is secondary color in
993 // the style of the shape, FillColor2 in API. The case that no extrusion color was set is handled
994 // further down when FillProperties and LineProperties are handled.
995 if (aExtrusionColor.isUsed())
997 // FillColor2 is not yet transformed to ComplexColor.
998 ::Color aColor = aExtrusionColor.getColor(rFilterBase.getGraphicHelper());
999 maShapeProperties.setProperty(PROP_FillColor2, aColor);
1002 if (bHas3DEffect)
1004 aScene3DHelper.setLightingProperties(mp3DPropertiesPtr, fShapeRotateInclCamera,
1005 getCustomShapeProperties()->getExtrusionPropertyMap());
1006 oox::Scene3DHelper::setMaterialProperties(
1007 mp3DPropertiesPtr, getCustomShapeProperties()->getExtrusionPropertyMap());
1010 if (bIsCroppedGraphic || bIs3DGraphic)
1012 aServiceName = "com.sun.star.drawing.CustomShape";
1013 mpGraphicPropertiesPtr->mbIsCustomShape = true;
1014 mpGraphicPropertiesPtr->mbIsExtruded = bIs3DGraphic;
1016 bool bUseRotationTransform = ( !mbWps ||
1017 aServiceName == "com.sun.star.drawing.LineShape" ||
1018 aServiceName == "com.sun.star.drawing.GroupShape" ||
1019 mbFlipH ||
1020 mbFlipV );
1022 basegfx::B2DHomMatrix aTransformation; // will be cumulative transformation of this object
1024 // Special for SmartArt import. Rotate diagram's shape around object's center before sizing.
1025 if (bUseRotationTransform && mnDiagramRotation != 0)
1027 aTransformation.translate(-0.5, -0.5);
1028 aTransformation.rotate(basegfx::deg2rad<60000>(mnDiagramRotation));
1029 aTransformation.translate(0.5, 0.5);
1032 // Build object matrix from shape size and position; corresponds to MSO ext and off
1033 // Only LineShape and ConnectorShape may have zero width or height.
1034 if (aServiceName == "com.sun.star.drawing.LineShape"
1035 || aServiceName == "com.sun.star.drawing.ConnectorShape")
1036 aTransformation.scale(maSize.Width, maSize.Height);
1037 else
1039 aTransformation.scale(maSize.Width ? maSize.Width : 1.0,
1040 maSize.Height ? maSize.Height : 1.0);
1043 // Evaluate object flip. Other shapes than custom shapes have no attribute for flip but use
1044 // negative scale. Flip in MSO is at object center.
1045 if (!bIsCustomShape && (mbFlipH || mbFlipV))
1046 lcl_mirrorAtCenter(aTransformation, mbFlipH, mbFlipV);
1048 // Evaluate parent flip.
1049 // A CustomShape has mirror not as negative scale, but as attributes.
1050 basegfx::B2DVector aParentScale(1.0, 1.0);
1051 basegfx::B2DVector aParentTranslate(0.0, 0.0);
1052 double fParentRotate(0.0);
1053 double fParentShearX(0.0);
1054 if (pParentGroupShape)
1056 aParentTransformation.decompose(aParentScale, aParentTranslate, fParentRotate, fParentShearX);
1057 if (bIsCustomShape)
1059 lcl_mirrorAtCenter(aTransformation, aParentScale.getX() < 0, aParentScale.getY() < 0);
1060 if(aParentScale.getX() < 0)
1061 mbFlipH = !mbFlipH;
1062 if(aParentScale.getY() < 0)
1063 mbFlipV = !mbFlipV;
1067 if (maPosition.X != 0 || maPosition.Y != 0)
1069 // if global position is used, add it to transformation
1070 if (mbWps && pParentGroupShape == nullptr)
1071 aTransformation.translate(
1072 o3tl::convert(maPosition.X, o3tl::Length::mm100, o3tl::Length::emu),
1073 o3tl::convert(maPosition.Y, o3tl::Length::mm100, o3tl::Length::emu));
1074 else
1075 aTransformation.translate(maPosition.X, maPosition.Y);
1078 // Apply further parent transformations. First scale object then rotate. Other way round would
1079 // introduce shearing.
1081 // The attributes chExt and chOff of the group in oox file contain the values on which the size
1082 // and position of the child is based on. If they differ from the actual size of the group as
1083 // given in its ext and off attributes, the child has to be transformed according the new values.
1084 if (pParentGroupShape)
1086 // ToDo: A diagram in a group might need special handling because it cannot flip and only
1087 // resize uniformly. But currently it is imported with zero size, see tdf#139575. That needs
1088 // to be fixed beforehand.
1090 // Scaling is done from left/top edges of the group. So these need to become coordinate axes.
1091 aTransformation.translate(-pParentGroupShape->maChPosition.X,
1092 -pParentGroupShape->maChPosition.Y);
1094 // oox allows zero or missing attribute chExt. In that case the scaling factor is 1.
1095 // Transform2DContext::onCreateContext has set maChSize to maSize for groups in oox file in
1096 // such cases. For own made groups (e.g. diagrams) that is missing.
1097 // The factors cumulate on the way through the parent groups, so we do not use maSize of the
1098 // direct parent group but the cumulated value from aParentScale.
1099 double fFactorX = 1.0;
1100 double fFactorY = 1.0;
1101 if (pParentGroupShape->maChSize.Width != 0)
1102 fFactorX = aParentScale.getX() / pParentGroupShape->maChSize.Width;
1103 if (pParentGroupShape->maChSize.Height != 0)
1104 fFactorY = aParentScale.getY() / pParentGroupShape->maChSize.Height;
1105 if (fFactorX != 1 || fFactorY != 1)
1107 // It depends on the object rotation angle whether scaling is applied to switched
1108 // width and height. MSO acts strange in that case (as of May 2021).
1109 const sal_Int32 nDeg(mnRotation / 60000);
1110 const bool bNeedsMSOWidthHeightToggle
1111 = (nDeg >= 45 && nDeg < 135) || (nDeg >= 225 && nDeg < 315);
1112 if (bNeedsMSOWidthHeightToggle)
1113 lcl_doSpecialMSOWidthHeightToggle(aTransformation);
1115 aTransformation.scale(fFactorX, fFactorY);
1117 if (bNeedsMSOWidthHeightToggle)
1119 lcl_doSpecialMSOWidthHeightToggle(aTransformation);
1120 // In case of flip the special case needs an additional 180deg rotation.
1121 if ((aParentScale.getX() < 0) != (aParentScale.getY() < 0))
1122 lcl_RotateAtCenter(aTransformation, 10800000);
1127 // Apply object rotation at current object center
1128 // The flip contained in aParentScale will affect orientation of object rotation angle.
1129 sal_Int16 nOrientation = ((aParentScale.getX() < 0) != (aParentScale.getY() < 0)) ? -1 : 1;
1130 // ToDo: Not sure about the restrictions given by bUseRotationTransform.
1131 if (bUseRotationTransform && nShapeRotateInclCamera != 0)
1133 lcl_RotateAtCenter(aTransformation, nOrientation * nShapeRotateInclCamera);
1136 if (fParentRotate != 0.0)
1137 aTransformation.rotate(fParentRotate);
1138 if (!aParentTranslate.equalZero())
1139 aTransformation.translate(aParentTranslate);
1141 aParentTransformation = aTransformation;
1143 constexpr double fEmuToMm100 = o3tl::convert(1.0, o3tl::Length::emu, o3tl::Length::mm100);
1144 aTransformation.scale(fEmuToMm100, fEmuToMm100);
1146 // OOXML flips shapes before rotating them, so the rotation needs to be inverted
1147 if( bIsCustomShape && mbFlipH != mbFlipV )
1149 basegfx::B2DVector aScale, aTranslate;
1150 double fRotate, fShearX;
1151 aTransformation.decompose(aScale, aTranslate, fRotate, fShearX);
1153 if(fRotate != 0)
1155 basegfx::B2DPoint aCenter(0.5, 0.5);
1156 aCenter *= aTransformation;
1157 aTransformation.translate( -aCenter.getX(), -aCenter.getY() );
1158 aTransformation.rotate( fRotate * -2.0 );
1159 aTransformation.translate( aCenter.getX(), aCenter.getY() );
1163 // special for lineshape
1164 if ( aServiceName == "com.sun.star.drawing.LineShape" )
1166 ::basegfx::B2DPolygon aPoly;
1167 aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
1168 aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
1169 aPoly.transform( aTransformation );
1171 // now creating the corresponding PolyPolygon
1172 sal_Int32 i, nNumPoints = aPoly.count();
1173 uno::Sequence< awt::Point > aPointSequence( nNumPoints );
1174 awt::Point* pPoints = aPointSequence.getArray();
1175 for( i = 0; i < nNumPoints; ++i )
1177 basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) );
1179 // Guard against zero width or height.
1180 if (i)
1182 const basegfx::B2DPoint& rPreviousPoint = aPoly.getB2DPoint(i - 1);
1183 if (aPoint.getX() - rPreviousPoint.getX() == 0)
1184 aPoint.setX(aPoint.getX() + 1);
1185 if (aPoint.getY() - rPreviousPoint.getY() == 0)
1186 aPoint.setY(aPoint.getY() + 1);
1189 pPoints[i] = awt::Point(static_cast<sal_Int32>(aPoint.getX()), static_cast<sal_Int32>(aPoint.getY()));
1191 uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 );
1192 aPolyPolySequence.getArray()[ 0 ] = aPointSequence;
1194 maShapeProperties.setProperty(PROP_PolyPolygon, aPolyPolySequence);
1196 else if ( aServiceName == "com.sun.star.drawing.ConnectorShape" )
1198 ::basegfx::B2DPolygon aPoly;
1199 aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
1200 aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
1201 aPoly.transform( aTransformation );
1203 basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) );
1204 basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) );
1205 awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) );
1206 awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) );
1208 maShapeProperties.setProperty(PROP_StartPosition, aAWTStartPosition);
1209 maShapeProperties.setProperty(PROP_EndPosition, aAWTEndPosition);
1211 else
1213 // now set transformation for this object
1214 HomogenMatrix3 aMatrix;
1216 aMatrix.Line1.Column1 = aTransformation.get(0,0);
1217 aMatrix.Line1.Column2 = aTransformation.get(0,1);
1218 aMatrix.Line1.Column3 = aTransformation.get(0,2);
1220 aMatrix.Line2.Column1 = aTransformation.get(1,0);
1221 aMatrix.Line2.Column2 = aTransformation.get(1,1);
1222 aMatrix.Line2.Column3 = aTransformation.get(1,2);
1224 aMatrix.Line3.Column1 = 0;
1225 aMatrix.Line3.Column2 = 0;
1226 aMatrix.Line3.Column3 = 1;
1228 maShapeProperties.setProperty(PROP_Transformation, aMatrix);
1231 Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
1232 if ( !mxShape.is() )
1234 mxShape.set( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW );
1237 Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
1238 if (xSet.is())
1240 if( !msName.isEmpty() )
1242 Reference< container::XNamed > xNamed( mxShape, UNO_QUERY );
1243 if( xNamed.is() )
1244 xNamed->setName( msName );
1246 if( !msDescription.isEmpty() )
1248 xSet->setPropertyValue( u"Description"_ustr, Any( msDescription ) );
1250 if (m_isDecorative)
1252 xSet->setPropertyValue(u"Decorative"_ustr, Any(m_isDecorative));
1255 // set the placeholder height to "0" if it has the 'TextAutoGrowHeight' property
1256 // the placeholder height is set later to the correct size.
1257 bool bAutoGrowHeight = false;
1258 xSet->getPropertyValue(u"TextAutoGrowHeight"_ustr) >>= bAutoGrowHeight;
1259 if (bAutoGrowHeight && mxShape->getShapeType().startsWith("com.sun.star.presentation."))
1261 awt::Size aSize(mxShape->getSize().Width, 0);
1262 mxShape->setSize(aSize);
1265 if (aServiceName != "com.sun.star.text.TextFrame")
1266 rxShapes->add( mxShape );
1268 if ( mbHidden || mbHiddenMasterShape )
1270 SAL_INFO("oox.drawingml", "Shape::createAndInsert: invisible shape with id='" << msId << "'");
1271 xSet->setPropertyValue( u"Visible"_ustr, Any( false ) );
1272 // In Excel hidden means not printed, let's use visibility for now until that's handled separately
1273 xSet->setPropertyValue( u"Printable"_ustr, Any( false ) );
1276 if (mbLocked)
1278 xSet->setPropertyValue(u"MoveProtect"_ustr, Any(true));
1279 xSet->setPropertyValue(u"SizeProtect"_ustr, Any(true));
1282 ActionLockGuard const alg(mxShape);
1284 // sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape
1285 if ( bClearText )
1287 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
1288 if ( xText.is() )
1290 xText->setString( u""_ustr );
1294 if (pMathXml)
1296 // the "EmbeddedObject" property is read-only, so we have to create
1297 // the shape first, and it can be read only after the shape is
1298 // inserted into the document, so delay the actual import until here
1299 SvGlobalName name(SO3_SM_CLASSID);
1300 xSet->setPropertyValue(u"CLSID"_ustr, uno::Any(name.GetHexName()));
1301 uno::Reference<embed::XEmbeddedObject> const xObj(
1302 xSet->getPropertyValue(u"EmbeddedObject"_ustr), uno::UNO_QUERY);
1303 if (xObj.is())
1305 uno::Reference<uno::XInterface> const xMathModel(xObj->getComponent());
1306 oox::FormulaImExportBase *const pMagic(
1307 dynamic_cast<oox::FormulaImExportBase*>(xMathModel.get()));
1308 assert(pMagic);
1309 pMagic->readFormulaOoxml(*pMathXml);
1313 const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
1315 ::Color nLinePhClr(ColorTransparency, 0xffffffff);
1316 ::Color nFillPhClr(ColorTransparency, 0xffffffff);
1317 sal_Int16 nFillPhClrTheme = -1;
1318 sal_Int16 nLinePhClrTheme = -1;
1319 // TODO: use ph color when applying effect properties
1320 //sal_Int32 nEffectPhClr = -1;
1322 // dmapper needs the original rotation angle for calculating square wrap. This angle is not
1323 // available as property there, so store it in InteropGrabBag.
1324 putPropertyToGrabBag(u"mso-rotation-angle"_ustr, Any(mnRotation));
1326 if( pTheme )
1328 if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
1330 LineProperties aLineProperties;
1331 aLineProperties.maLineFill.moFillType = XML_noFill;
1332 if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
1333 aLineProperties.assignUsed( *pLineProps );
1334 nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
1335 nLinePhClrTheme = pLineRef->maPhClr.getSchemeColorIndex();
1337 // Store style-related properties to InteropGrabBag to be able to export them back
1338 uno::Sequence<beans::PropertyValue> aProperties = comphelper::InitPropertySequence(
1340 {"SchemeClr", uno::Any(pLineRef->maPhClr.getSchemeColorName())},
1341 {"Idx", uno::Any(pLineRef->mnThemedIdx)},
1342 {"Color", uno::Any(nLinePhClr)},
1343 {"LineStyle", uno::Any(aLineProperties.getLineStyle())},
1344 {"LineCap", uno::Any(aLineProperties.getLineCap())},
1345 {"LineJoint", uno::Any(aLineProperties.getLineJoint())},
1346 {"LineWidth", uno::Any(aLineProperties.getLineWidth())},
1347 {"Transformations", uno::Any(pLineRef->maPhClr.getTransformations())}
1349 putPropertyToGrabBag( u"StyleLnRef"_ustr, Any( aProperties ) );
1351 if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
1353 if (!getFillProperties().moUseBgFill.value_or(false))
1355 nFillPhClr = pFillRef->maPhClr.getColor(rGraphicHelper);
1356 nFillPhClrTheme = pFillRef->maPhClr.getSchemeColorIndex();
1359 OUString sColorScheme = pFillRef->maPhClr.getSchemeColorName();
1360 if( !sColorScheme.isEmpty() )
1362 uno::Sequence<beans::PropertyValue> aProperties = comphelper::InitPropertySequence(
1364 {"SchemeClr", uno::Any(sColorScheme)},
1365 {"Idx", uno::Any(pFillRef->mnThemedIdx)},
1366 {"Color", uno::Any(nFillPhClr)},
1367 {"Transformations", uno::Any(pFillRef->maPhClr.getTransformations())}
1370 putPropertyToGrabBag( u"StyleFillRef"_ustr, Any( aProperties ) );
1373 if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_effectRef ) )
1375 // TODO: use ph color when applying effect properties
1376 // nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper );
1378 // Store style-related properties to InteropGrabBag to be able to export them back
1379 uno::Sequence<beans::PropertyValue> aProperties = comphelper::InitPropertySequence(
1381 {"SchemeClr", uno::Any(pEffectRef->maPhClr.getSchemeColorName())},
1382 {"Idx", uno::Any(pEffectRef->mnThemedIdx)},
1383 {"Transformations", uno::Any(pEffectRef->maPhClr.getTransformations())}
1385 putPropertyToGrabBag( u"StyleEffectRef"_ustr, Any( aProperties ) );
1388 ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() );
1390 // add properties from textbody to shape properties
1391 if( mpTextBody )
1393 // tdf#67347: In case of Stacked, PP calculates in the vertical direction with the
1394 // horizontal alignment.
1395 // In LO, we simulate it by setting TextVerticalAdjust based on the ParagraphAdjust
1396 // of the 1. paragraph
1397 // It is not perfect, because we have 1 TextVerticalAdjust / 1 shape, and it
1398 // does not support justified, while we can have many ParagraphAdjust / 1 shape
1399 // (if the shape have more paragraphs)
1400 if (mpTextBody->getTextProperties().maPropertyMap.hasProperty(PROP_WritingMode)
1401 && mpTextBody->getTextProperties().maPropertyMap.getProperty(PROP_WritingMode)
1402 == uno::Any(text::WritingMode2::STACKED)
1403 && mpTextBody->getParagraphs().size() > 0
1404 && aServiceName != "com.sun.star.drawing.GroupShape")
1406 std::optional<css::style::ParagraphAdjust>& oParaAdjust
1407 = mpTextBody->getParagraphs()[0]->getProperties().getParaAdjust();
1409 if (oParaAdjust)
1411 switch (*oParaAdjust)
1413 case ParagraphAdjust::ParagraphAdjust_LEFT:
1414 mpTextBody->getTextProperties().meVA
1415 = TextVerticalAdjust::TextVerticalAdjust_TOP;
1416 break;
1417 case ParagraphAdjust::ParagraphAdjust_CENTER:
1418 mpTextBody->getTextProperties().meVA
1419 = TextVerticalAdjust::TextVerticalAdjust_CENTER;
1420 break;
1421 case ParagraphAdjust::ParagraphAdjust_RIGHT:
1422 mpTextBody->getTextProperties().meVA
1423 = TextVerticalAdjust::TextVerticalAdjust_BOTTOM;
1424 break;
1425 default:
1426 break;
1428 mpTextBody->getTextProperties().maPropertyMap.setProperty(
1429 PROP_TextVerticalAdjust, mpTextBody->getTextProperties().meVA);
1433 mpTextBody->getTextProperties().pushTextDistances(Size(aShapeRectHmm.Width, aShapeRectHmm.Height));
1434 aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
1435 // Push char properties as well - specifically useful when this is a placeholder
1436 if( mpMasterTextListStyle && mpMasterTextListStyle->getListStyle()[0].getTextCharacterProperties().moHeight.has_value() )
1437 aShapeProps.setProperty(PROP_CharHeight, GetFontHeight( mpMasterTextListStyle->getListStyle()[0].getTextCharacterProperties().moHeight.value() ));
1440 // applying properties
1441 aShapeProps.assignUsed( getShapeProperties() );
1442 aShapeProps.assignUsed( maDefaultShapeProperties );
1443 if(nShapeRotateInclCamera != 0 && bIsCustomShape)
1444 aShapeProps.setProperty(PROP_RotateAngle,
1445 sal_Int32(lcl_MSORotateAngleToAPIAngle(nShapeRotateInclCamera)));
1446 if( bIsEmbMedia ||
1447 bIsCustomShape ||
1448 aServiceName == "com.sun.star.drawing.GraphicObjectShape" ||
1449 aServiceName == "com.sun.star.drawing.OLE2Shape")
1451 mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper, mbFlipH, mbFlipV );
1453 if ( mpTablePropertiesPtr && aServiceName == "com.sun.star.drawing.TableShape" )
1455 mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle );
1456 if ( auto* pTableShape = dynamic_cast<sdr::table::SdrTableObj*>(SdrObject::getSdrObjectFromXShape(mxShape)) )
1458 // Disable layouting until table height is expanded to fit the content
1459 pTableShape->SetSkipChangeLayout(true);
1463 FillProperties aFillProperties = getActualFillProperties(pTheme, &rShapeOrParentShapeFillProps);
1464 if (getFillProperties().moFillType.has_value() && getFillProperties().moFillType.value() == XML_grpFill)
1465 getFillProperties().assignUsed(aFillProperties);
1466 if(!bIsCroppedGraphic && !bIs3DGraphic)
1467 aFillProperties.pushToPropMap(aShapeProps, rGraphicHelper, mnRotation, nFillPhClr,
1468 css::awt::Size(aShapeRectHmm.Width, aShapeRectHmm.Height),
1469 nFillPhClrTheme, mbFlipH, mbFlipV, bIsCustomShape);
1471 LineProperties aLineProperties = getActualLineProperties(pTheme);
1472 aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr, nLinePhClrTheme);
1473 EffectProperties aEffectProperties = getActualEffectProperties(pTheme);
1474 // TODO: use ph color when applying effect properties
1475 aEffectProperties.pushToPropMap( aShapeProps, rGraphicHelper );
1477 // applying autogrowheight property before setting shape size, because
1478 // the shape size might be changed if currently autogrowheight is true
1479 // we must also check that the PropertySet supports the property.
1480 Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
1481 const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight );
1482 if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) )
1483 if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
1484 xSet->setPropertyValue( rPropName, Any( false ) );
1486 // For extruded shapes, MSO uses the line color if no extrusion color is specified. LO uses
1487 // fill color in 'automatic' case. Thus we set extrusion color explicitly.
1488 if (bHas3DEffect && !aExtrusionColor.isUsed())
1490 const OUString& rFillColor2PropName = PropertyMap::getPropertyName(PROP_FillColor2);
1491 if (xSetInfo.is() && xSetInfo->hasPropertyByName(rFillColor2PropName))
1493 Color aComplexColor;
1494 if (aLineProperties.maLineFill.moFillType.has_value()
1495 && aLineProperties.maLineFill.moFillType.value() != XML_noFill)
1496 aComplexColor = aLineProperties.maLineFill.getBestSolidColor();
1497 else if (aFillProperties.moFillType.has_value()
1498 && aFillProperties.moFillType.value() != XML_noFill)
1499 aComplexColor = aFillProperties.getBestSolidColor();
1500 if (aComplexColor.isUsed())
1502 const ::Color aSimpleColor = aComplexColor.getColor(rFilterBase.getGraphicHelper());
1503 xSet->setPropertyValue(rFillColor2PropName, Any(aSimpleColor));
1508 // do not set properties at a group shape (this causes
1509 // assertions from svx) ...
1510 if( aServiceName != "com.sun.star.drawing.GroupShape" )
1512 if (aServiceName == "com.sun.star.text.TextFrame")
1514 if (mpCustomShapePropertiesPtr && mpCustomShapePropertiesPtr->getShapeTypeOverride())
1516 uno::Reference<beans::XPropertySet> propertySet (mxShape, uno::UNO_QUERY);
1517 uno::Sequence<beans::PropertyValue> aGrabBag;
1518 propertySet->getPropertyValue(u"FrameInteropGrabBag"_ustr) >>= aGrabBag;
1519 sal_Int32 length = aGrabBag.getLength();
1520 aGrabBag.realloc( length+1);
1521 auto pGrabBag = aGrabBag.getArray();
1522 pGrabBag[length].Name = "mso-orig-shape-type";
1523 pGrabBag[length].Value <<= mpCustomShapePropertiesPtr->getShapePresetTypeName();
1524 propertySet->setPropertyValue(u"FrameInteropGrabBag"_ustr,uno::Any(aGrabBag));
1526 //If the text box has links then save the link information so that
1527 //it can be accessed in DomainMapper_Impl.cxx while chaining the text frames.
1528 if (isLinkedTxbx())
1530 uno::Reference<beans::XPropertySet> propertySet (mxShape, uno::UNO_QUERY);
1531 uno::Sequence<beans::PropertyValue> aGrabBag;
1532 propertySet->getPropertyValue(u"FrameInteropGrabBag"_ustr) >>= aGrabBag;
1533 sal_Int32 length = aGrabBag.getLength();
1534 aGrabBag.realloc( length + 3 );
1535 auto pGrabBag = aGrabBag.getArray();
1536 pGrabBag[length].Name = "TxbxHasLink";
1537 pGrabBag[length].Value <<= isLinkedTxbx();
1538 pGrabBag[length + 1 ].Name = "Txbx-Id";
1539 pGrabBag[length + 1 ].Value <<= getLinkedTxbxAttributes().id;
1540 pGrabBag[length + 2 ].Name = "Txbx-Seq";
1541 pGrabBag[length + 2 ].Value <<= getLinkedTxbxAttributes().seq;
1542 propertySet->setPropertyValue(u"FrameInteropGrabBag"_ustr,uno::Any(aGrabBag));
1545 // TextFrames have BackColor, not FillColor
1546 if (aShapeProps.hasProperty(PROP_FillColor))
1548 aShapeProps.setAnyProperty(PROP_BackColor, aShapeProps.getProperty(PROP_FillColor));
1549 aShapeProps.erase(PROP_FillColor);
1551 // TextFrames have BackColorTransparency, not FillTransparence
1552 if (aShapeProps.hasProperty(PROP_FillTransparence))
1554 aShapeProps.setAnyProperty(PROP_BackColorTransparency, aShapeProps.getProperty(PROP_FillTransparence));
1555 aShapeProps.erase(PROP_FillTransparence);
1557 // TextFrames have BackGraphic, not FillBitmap
1558 if (aShapeProps.hasProperty(PROP_FillBitmap))
1560 aShapeProps.setAnyProperty(PROP_BackGraphic, aShapeProps.getProperty(PROP_FillBitmap));
1561 aShapeProps.erase(PROP_FillBitmap);
1563 if (aShapeProps.hasProperty(PROP_FillBitmapName))
1565 uno::Any aAny = aShapeProps.getProperty(PROP_FillBitmapName);
1566 OUString aFillBitmapName = aAny.get<OUString>();
1567 uno::Reference<awt::XBitmap> xBitmap = rFilterBase.getModelObjectHelper().getFillBitmap(aFillBitmapName);
1568 uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY);
1569 aShapeProps.setProperty(PROP_BackGraphic, xGraphic);
1570 // aShapeProps.erase(PROP_FillBitmapName); // Maybe, leave the name as well
1572 // And no LineColor property; individual borders can have colors
1573 if (aShapeProps.hasProperty(PROP_LineColor))
1575 uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
1576 static const sal_Int32 aBorders[] =
1578 PROP_TopBorder, PROP_LeftBorder, PROP_BottomBorder, PROP_RightBorder
1580 for (sal_Int32 nBorder : aBorders)
1582 css::table::BorderLine2 aBorderLine = xPropertySet->getPropertyValue(PropertyMap::getPropertyName(nBorder)).get<css::table::BorderLine2>();
1583 aBorderLine.Color = aShapeProps.getProperty(PROP_LineColor).get<sal_Int32>();
1584 if (aLineProperties.moLineWidth.has_value())
1585 aBorderLine.LineWidth = convertEmuToHmm(aLineProperties.moLineWidth.value());
1586 aShapeProps.setProperty(nBorder, aBorderLine);
1588 aShapeProps.erase(PROP_LineColor);
1590 if(mnRotation)
1592 uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
1593 static constexpr OUString aGrabBagPropName = u"FrameInteropGrabBag"_ustr;
1594 uno::Sequence<beans::PropertyValue> aGrabBag;
1595 xPropertySet->getPropertyValue(aGrabBagPropName) >>= aGrabBag;
1596 beans::PropertyValue aPair(comphelper::makePropertyValue(u"mso-rotation-angle"_ustr,
1597 mnRotation));
1598 if (aGrabBag.hasElements())
1600 sal_Int32 nLength = aGrabBag.getLength();
1601 aGrabBag.realloc(nLength + 1);
1602 aGrabBag.getArray()[nLength] = aPair;
1604 else
1606 aGrabBag = { aPair };
1608 xPropertySet->setPropertyValue(aGrabBagPropName, uno::Any(aGrabBag));
1610 // TextFrames have ShadowFormat, not individual shadow properties.
1611 std::optional<sal_Int32> oShadowDistance;
1612 if (aShapeProps.hasProperty(PROP_ShadowXDistance))
1614 oShadowDistance = aShapeProps.getProperty(PROP_ShadowXDistance).get<sal_Int32>();
1615 aShapeProps.erase(PROP_ShadowXDistance);
1617 if (aShapeProps.hasProperty(PROP_ShadowYDistance))
1619 // There is a single 'dist' attribute, so no need to count the avg of x and y.
1620 aShapeProps.erase(PROP_ShadowYDistance);
1622 std::optional<sal_Int32> oShadowColor;
1623 if (aShapeProps.hasProperty(PROP_ShadowColor))
1625 oShadowColor = aShapeProps.getProperty(PROP_ShadowColor).get<sal_Int32>();
1626 aShapeProps.erase(PROP_ShadowColor);
1628 if (aShapeProps.hasProperty(PROP_Shadow))
1629 aShapeProps.erase(PROP_Shadow);
1631 if (oShadowDistance || oShadowColor || aEffectProperties.maShadow.moShadowDir.has_value())
1633 css::table::ShadowFormat aFormat;
1634 if (oShadowColor)
1635 aFormat.Color = *oShadowColor;
1636 if (aEffectProperties.maShadow.moShadowDir.has_value())
1638 css::table::ShadowLocation nLocation = css::table::ShadowLocation_NONE;
1639 switch (aEffectProperties.maShadow.moShadowDir.value())
1641 case 13500000:
1642 nLocation = css::table::ShadowLocation_TOP_LEFT;
1643 break;
1644 case 18900000:
1645 nLocation = css::table::ShadowLocation_TOP_RIGHT;
1646 break;
1647 case 8100000:
1648 nLocation = css::table::ShadowLocation_BOTTOM_LEFT;
1649 break;
1650 case 2700000:
1651 nLocation = css::table::ShadowLocation_BOTTOM_RIGHT;
1652 break;
1654 aFormat.Location = nLocation;
1656 aFormat.ShadowWidth = *oShadowDistance;
1657 aShapeProps.setProperty(PROP_ShadowFormat, aFormat);
1661 else if (mbTextBox)
1663 // This introduces a TextBox in a shape in Writer. ToDo: Can we restrict it to cases
1664 // where the TextBox edit engine is really needed? tdf#82627
1665 aShapeProps.setProperty(PROP_TextBox, true);
1668 if (aServiceName != "com.sun.star.text.TextFrame" && isLinkedTxbx())
1670 uno::Reference<beans::XPropertySet> propertySet (mxShape, uno::UNO_QUERY);
1671 uno::Sequence<beans::PropertyValue> aGrabBag;
1672 propertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBag;
1673 sal_Int32 length = aGrabBag.getLength();
1674 aGrabBag.realloc( length + 3 );
1675 auto pGrabBag = aGrabBag.getArray();
1676 pGrabBag[length].Name = "TxbxHasLink";
1677 pGrabBag[length].Value <<= isLinkedTxbx();
1678 pGrabBag[length + 1 ].Name = "Txbx-Id";
1679 pGrabBag[length + 1 ].Value <<= getLinkedTxbxAttributes().id;
1680 pGrabBag[length + 2 ].Name = "Txbx-Seq";
1681 pGrabBag[length + 2 ].Value <<= getLinkedTxbxAttributes().seq;
1682 propertySet->setPropertyValue(u"InteropGrabBag"_ustr,uno::Any(aGrabBag));
1685 PropertySet( xSet ).setProperties( aShapeProps );
1687 if (mpTablePropertiesPtr && aServiceName == "com.sun.star.drawing.TableShape")
1689 // Powerpoint exports desired row heights (i.e. what user attempted to set it as, not how it appears visually)
1690 // Expand table height if there are rows that can't fit the content
1691 if (auto* pTableShape = dynamic_cast<sdr::table::SdrTableObj*>(SdrObject::getSdrObjectFromXShape(mxShape)))
1693 tools::Rectangle aArea{};
1694 pTableShape->LayoutTableHeight(aArea);
1695 sal_Int32 nCorrectedHeight = aArea.GetHeight();
1696 const auto& aShapeSize = mxShape->getSize();
1697 if( nCorrectedHeight > aShapeSize.Height )
1698 mxShape->setSize( {aShapeSize.Width, nCorrectedHeight} );
1699 pTableShape->SetSkipChangeLayout(false);
1703 if (mbLockedCanvas)
1705 putPropertyToGrabBag( u"LockedCanvas"_ustr, Any( true ) );
1706 if (aServiceName == "com.sun.star.drawing.LineShape")
1708 // It seems the position and size for lines inside a locked canvas is absolute.
1709 mxShape->setPosition(awt::Point(aShapeRectHmm.X, aShapeRectHmm.Y));
1710 mxShape->setSize(awt::Size(aShapeRectHmm.Width, aShapeRectHmm.Height));
1714 if (mbWordprocessingCanvas)
1716 putPropertyToGrabBag(u"WordprocessingCanvas"_ustr, Any(true));
1719 // Store original fill and line colors of the shape and the theme color name to InteropGrabBag
1720 std::vector<beans::PropertyValue> aProperties
1722 comphelper::makePropertyValue(u"EmuLineWidth"_ustr, aLineProperties.moLineWidth.value_or(0)),
1723 comphelper::makePropertyValue(u"OriginalSolidFillClr"_ustr, aShapeProps.getProperty(PROP_FillColor)),
1724 comphelper::makePropertyValue(u"OriginalLnSolidFillClr"_ustr, aShapeProps.getProperty(PROP_LineColor))
1726 OUString sColorFillScheme = aFillProperties.maFillColor.getSchemeColorName();
1727 if( !aFillProperties.maFillColor.isPlaceHolder() && !sColorFillScheme.isEmpty() )
1729 aProperties.push_back(comphelper::makePropertyValue(u"SpPrSolidFillSchemeClr"_ustr, sColorFillScheme));
1730 aProperties.push_back(comphelper::makePropertyValue(u"SpPrSolidFillSchemeClrTransformations"_ustr, aFillProperties.maFillColor.getTransformations()));
1732 OUString sLnColorFillScheme = aLineProperties.maLineFill.maFillColor.getSchemeColorName();
1733 if( !aLineProperties.maLineFill.maFillColor.isPlaceHolder() && !sLnColorFillScheme.isEmpty() )
1735 aProperties.push_back(comphelper::makePropertyValue(u"SpPrLnSolidFillSchemeClr"_ustr, sLnColorFillScheme));
1736 auto aResolvedSchemeClr = aLineProperties.maLineFill.maFillColor;
1737 aResolvedSchemeClr.clearTransformations();
1738 aProperties.push_back(comphelper::makePropertyValue(u"SpPrLnSolidFillResolvedSchemeClr"_ustr, aResolvedSchemeClr.getColor(rGraphicHelper, nFillPhClr)));
1739 aProperties.push_back(comphelper::makePropertyValue(u"SpPrLnSolidFillSchemeClrTransformations"_ustr, aLineProperties.maLineFill.maFillColor.getTransformations()));
1741 putPropertiesToGrabBag(comphelper::containerToSequence(aProperties));
1743 // Store original gradient fill of the shape to InteropGrabBag
1744 // LibreOffice doesn't support all the kinds of gradient so we save its complete definition
1745 if( aShapeProps.hasProperty( PROP_FillGradient ) )
1747 std::vector<beans::PropertyValue> aGradientStops;
1748 size_t i = 0;
1749 for( const auto& [rPos, rColor] : aFillProperties.maGradientProps.maGradientStops )
1750 { // for each stop in the gradient definition:
1752 // save position
1753 std::vector<beans::PropertyValue> aGradientStop
1755 comphelper::makePropertyValue(u"Pos"_ustr, rPos)
1758 OUString sStopColorScheme = rColor.getSchemeColorName();
1759 if( sStopColorScheme.isEmpty() )
1761 // save RGB color
1762 aGradientStop.push_back(comphelper::makePropertyValue(u"RgbClr"_ustr, rColor.getColor(rGraphicHelper, nFillPhClr)));
1763 // in the case of a RGB color, transformations are already applied to
1764 // the color with the exception of alpha transformations. We only need
1765 // to keep the transparency value to calculate the alpha value later.
1766 if( rColor.hasTransparency() )
1767 aGradientStop.push_back(comphelper::makePropertyValue(u"Transparency"_ustr, rColor.getTransparency()));
1769 else
1771 // save color with scheme name
1772 aGradientStop.push_back(comphelper::makePropertyValue(u"SchemeClr"_ustr, sStopColorScheme));
1773 // save all color transformations
1774 aGradientStop.push_back(comphelper::makePropertyValue(u"Transformations"_ustr, rColor.getTransformations()));
1777 aGradientStops.push_back(comphelper::makePropertyValue(OUString::number(i), comphelper::containerToSequence(aGradientStop)));
1778 ++i;
1780 // If getFillProperties.moFillType is unused that means gradient is defined by a theme
1781 // which is already saved into StyleFillRef property, so no need to save the explicit values too
1782 if( getFillProperties().moFillType.has_value() )
1783 putPropertyToGrabBag( u"GradFillDefinition"_ustr, uno::Any(comphelper::containerToSequence(aGradientStops)));
1784 putPropertyToGrabBag( u"OriginalGradFill"_ustr, aShapeProps.getProperty(PROP_FillGradient) );
1787 // store unsupported effect attributes in the grab bag
1788 if (!aEffectProperties.m_Effects.empty())
1790 std::vector<beans::PropertyValue> aEffects;
1791 for (auto const& it : aEffectProperties.m_Effects)
1793 PropertyValue aEffect = it->getEffect();
1794 if( !aEffect.Name.isEmpty() )
1796 std::vector<beans::PropertyValue> aEffectsGrabBag
1798 comphelper::makePropertyValue(u"Attribs"_ustr, aEffect.Value)
1801 Color& aColor( it->moColor );
1802 OUString sColorScheme = aColor.getSchemeColorName();
1803 if( sColorScheme.isEmpty() )
1805 // RGB color and transparency value
1806 aEffectsGrabBag.push_back(comphelper::makePropertyValue(u"RgbClr"_ustr, aColor.getColor(rGraphicHelper, nFillPhClr)));
1807 aEffectsGrabBag.push_back(comphelper::makePropertyValue(u"RgbClrTransparency"_ustr, aColor.getTransparency()));
1809 else
1811 // scheme color with name and transformations
1812 aEffectsGrabBag.push_back(comphelper::makePropertyValue(u"SchemeClr"_ustr, sColorScheme));
1813 aEffectsGrabBag.push_back(comphelper::makePropertyValue(u"SchemeClrTransformations"_ustr, aColor.getTransformations()));
1815 aEffects.push_back(comphelper::makePropertyValue(aEffect.Name, comphelper::containerToSequence(aEffectsGrabBag)));
1818 putPropertyToGrabBag(u"EffectProperties"_ustr, uno::Any(comphelper::containerToSequence(aEffects)));
1821 // add 3D effects if any to GrabBag. They are still used in export.
1822 Sequence< PropertyValue > aCamera3DEffects = get3DProperties().getCameraAttributes();
1823 Sequence< PropertyValue > aLightRig3DEffects = get3DProperties().getLightRigAttributes();
1824 Sequence< PropertyValue > aShape3DEffects = get3DProperties().getShape3DAttributes( rGraphicHelper, nFillPhClr );
1825 if( aCamera3DEffects.hasElements() || aLightRig3DEffects.hasElements() || aShape3DEffects.hasElements() )
1827 uno::Sequence<beans::PropertyValue> a3DEffectsGrabBag = comphelper::InitPropertySequence(
1829 {"Camera", uno::Any(aCamera3DEffects)},
1830 {"LightRig", uno::Any(aLightRig3DEffects)},
1831 {"Shape3D", uno::Any(aShape3DEffects)}
1833 putPropertyToGrabBag( u"3DEffectProperties"_ustr, Any( a3DEffectsGrabBag ) );
1836 if( bIsCustomShape && getTextBody())
1839 Sequence< PropertyValue > aTextCamera3DEffects = getTextBody()->get3DProperties().getCameraAttributes();
1840 Sequence< PropertyValue > aTextLightRig3DEffects = getTextBody()->get3DProperties().getLightRigAttributes();
1841 Sequence< PropertyValue > aTextShape3DEffects = getTextBody()->get3DProperties().getShape3DAttributes( rGraphicHelper, nFillPhClr );
1842 if( aTextCamera3DEffects.hasElements() || aTextLightRig3DEffects.hasElements() || aTextShape3DEffects.hasElements() )
1844 uno::Sequence<beans::PropertyValue> aText3DEffectsGrabBag = comphelper::InitPropertySequence(
1846 {"Camera", uno::Any(aTextCamera3DEffects)},
1847 {"LightRig", uno::Any(aTextLightRig3DEffects)},
1848 {"Shape3D", uno::Any(aTextShape3DEffects)}
1850 putPropertyToGrabBag( u"Text3DEffectProperties"_ustr, Any( aText3DEffectsGrabBag ) );
1854 // store bitmap artistic effects in the grab bag
1855 if( !mpGraphicPropertiesPtr->maBlipProps.maEffect.isEmpty() )
1856 putPropertyToGrabBag( u"ArtisticEffectProperties"_ustr,
1857 Any( mpGraphicPropertiesPtr->maBlipProps.maEffect.getEffect() ) );
1860 else if( mbLockedCanvas )
1862 //If we have aServiceName as "com.sun.star.drawing.GroupShape" and lockedCanvas
1863 putPropertyToGrabBag( u"LockedCanvas"_ustr, Any( true ) );
1865 else if (mbWordprocessingCanvas)
1867 putPropertyToGrabBag(u"WordprocessingCanvas"_ustr, Any(true));
1868 putPropertyToGrabBag(u"mso-edit-as"_ustr, Any(u"canvas"_ustr)); // for export VML Fallback
1871 // These can have a custom geometry, so position should be set here,
1872 // after creation but before custom shape handling, using the position
1873 // we got from the caller.
1874 if (mbWps && aServiceName == "com.sun.star.drawing.LineShape" && !pParentGroupShape)
1875 mxShape->setPosition(maPosition);
1877 if (bIsConnectorShape)
1879 msConnectorName = mpCustomShapePropertiesPtr->getShapePresetTypeName();
1881 const auto& aAdjustmentList = mpCustomShapePropertiesPtr->getAdjustmentGuideList();
1882 for (size_t i = 0; i < aAdjustmentList.size(); i++)
1883 maConnectorAdjustmentList.push_back(aAdjustmentList[i].maFormula);
1885 sal_Int32 nType = mpCustomShapePropertiesPtr->getShapePresetType();
1886 switch (nType)
1888 case XML_line:
1889 case XML_straightConnector1:
1890 xSet->setPropertyValue(u"EdgeKind"_ustr, Any(ConnectorType_LINE));
1891 break;
1892 case XML_bentConnector2:
1893 case XML_bentConnector3:
1894 case XML_bentConnector4:
1895 case XML_bentConnector5:
1896 xSet->setPropertyValue(u"EdgeKind"_ustr, Any(ConnectorType_STANDARD));
1897 break;
1898 case XML_curvedConnector2:
1899 case XML_curvedConnector3:
1900 case XML_curvedConnector4:
1901 case XML_curvedConnector5:
1902 xSet->setPropertyValue(u"EdgeKind"_ustr, Any(ConnectorType_CURVE));
1903 break;
1904 default:
1905 break;
1909 if( bIsCustomShape )
1911 if ( mbFlipH )
1912 mpCustomShapePropertiesPtr->setMirroredX( true );
1913 if ( mbFlipV )
1914 mpCustomShapePropertiesPtr->setMirroredY( true );
1915 if( getTextBody() )
1917 sal_Int32 nTextCameraZRotation = getTextBody()->get3DProperties().maCameraRotation.mnRevolution.value_or(0);
1918 mpCustomShapePropertiesPtr->setTextCameraZRotateAngle( nTextCameraZRotation / 60000 );
1920 // TextPreRotateAngle. Text rotates inside the text area. Might be used for diagram layout 'upr' and 'grav'.
1921 sal_Int32 nTextPreRotateAngle = static_cast< sal_Int32 >( getTextBody()->getTextProperties().moTextPreRotation.value_or( 0 ) );
1923 nTextPreRotateAngle -= mnDiagramRotation; // Use of mnDiagramRotation is unclear. It seems to be always 0 here.
1925 // TextRotateAngle. The text area rotates.
1926 sal_Int32 nTextAreaRotateAngle = getTextBody()->getTextProperties().moTextAreaRotation.value_or(0);
1927 if (getTextBody()->getTextProperties().moUpright)
1929 // When upright is set, any text area transformation and shape rotation is ignored
1930 // in MS Office. To simulate this behaviour, we rotate the text area into the
1931 // opposite direction of the shape rotation by as much as the shape was rotated
1932 // and so compensate the shape rotation, which is added in rendering.
1933 nTextAreaRotateAngle = -mnRotation;
1934 // If 45° <= shape rotation < 135° or 225° <= shape rotation < 315°,
1935 // then MS Office adds an additional 90° rotation to the text area.
1936 const sal_Int32 nDeg(mnRotation / 60000);
1937 if ((nDeg >= 45 && nDeg < 135) || (nDeg >= 225 && nDeg < 315))
1939 nTextAreaRotateAngle += 5400000;
1940 nTextPreRotateAngle -= 5400000; // compensate the additional text area rotation
1942 putPropertyToGrabBag(u"Upright"_ustr, Any(true));
1944 /* OOX measures text rotation clockwise in 1/60000th degrees,
1945 relative to the containing shape. set*Angle wants degrees counter-clockwise. */
1946 mpCustomShapePropertiesPtr->setTextPreRotateAngle(-nTextPreRotateAngle / 60000);
1947 if (nTextAreaRotateAngle != 0)
1948 mpCustomShapePropertiesPtr->setTextAreaRotateAngle(-nTextAreaRotateAngle / 60000);
1950 auto sHorzOverflow = getTextBody()->getTextProperties().msHorzOverflow;
1951 if (!sHorzOverflow.isEmpty())
1952 putPropertyToGrabBag(u"horzOverflow"_ustr, uno::Any(getTextBody()->getTextProperties().msHorzOverflow));
1953 if (XML_ellipsis == getTextBody()->getTextProperties().moVertOverflow)
1954 putPropertyToGrabBag(u"vertOverflow"_ustr, uno::Any(u"ellipsis"_ustr));
1957 // Note that the script oox/source/drawingml/customshapes/generatePresetsData.pl looks
1958 // for these ==cscode== and ==csdata== markers, so don't "clean up" these SAL_INFOs
1959 SAL_INFO("oox.cscode", "==cscode== shape name: '" << msName << "'");
1960 SAL_INFO("oox.csdata", "==csdata== shape name: '" << msName << "'");
1962 mpCustomShapePropertiesPtr->pushToPropSet(xSet, maSize);
1964 // Consider WordArt
1965 if (mpTextBody && !mpTextBody->getTextProperties().msPrst.isEmpty()
1966 && mpTextBody->getTextProperties().msPrst != u"textNoShape")
1968 bool bFromWordArt(aShapeProps.hasProperty(PROP_FromWordArt)
1969 ? aShapeProps.getProperty(PROP_FromWordArt).get<bool>()
1970 : false);
1971 FontworkHelpers::putCustomShapeIntoTextPathMode(
1972 mxShape, mpCustomShapePropertiesPtr, mpTextBody->getTextProperties().msPrst,
1973 bFromWordArt);
1976 else if( getTextBody() )
1977 getTextBody()->getTextProperties().pushVertSimulation();
1979 // tdf#133037: a bit hackish: force Shape to rotate in the opposite direction the camera would rotate
1980 PropertySet aPropertySet(mxShape);
1981 if ( !bUseRotationTransform && (nShapeRotateInclCamera !=0) )
1983 Degree100 nAngle(lcl_MSORotateAngleToAPIAngle(nShapeRotateInclCamera));
1984 aPropertySet.setAnyProperty(PROP_RotateAngle, Any( sal_Int32(nAngle)));
1985 aPropertySet.setAnyProperty( PROP_HoriOrientPosition, Any( maPosition.X ) );
1986 aPropertySet.setAnyProperty( PROP_VertOrientPosition, Any( maPosition.Y ) );
1989 // Make sure to not set text to placeholders. Doing it here would eventually call
1990 // SvxTextEditSourceImpl::UpdateData, SdrObject::SetEmptyPresObj(false), and that
1991 // would make the object behave like a standard outline object.
1992 // TODO/FIXME: support custom prompt text in placeholders.
1993 if (rServiceName == "com.sun.star.presentation.GraphicObjectShape")
1994 mpTextBody.reset();
1996 // in some cases, we don't have any text body.
1997 if( mpTextBody && ( !bDoNotInsertEmptyTextBody || !mpTextBody->isEmpty() ) )
1999 Reference < XText > xText( mxShape, UNO_QUERY );
2000 if ( xText.is() ) // not every shape is supporting an XText interface (e.g. GroupShape)
2002 TextCharacterProperties aCharStyleProperties;
2003 if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) )
2005 if( pFontRef->mnThemedIdx != 0 )
2007 if( pTheme )
2008 if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) )
2009 aCharStyleProperties.assignUsed( *pCharProps );
2010 SAL_INFO("oox.drawingml", "Shape::createAndInsert: use font color");
2011 if ( pFontRef->maPhClr.isUsed() )
2013 aCharStyleProperties.maFillProperties.maFillColor = pFontRef->maPhClr;
2014 aCharStyleProperties.maFillProperties.moFillType = XML_solidFill;
2018 xText->setString(u""_ustr);
2019 Reference < XTextCursor > xAt = xText->createTextCursor();
2020 getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
2022 const TextParagraphVector& rParagraphs = getTextBody()->getParagraphs();
2023 if (!rParagraphs.empty())
2025 const std::shared_ptr<TextParagraph>& pParagraph = rParagraphs[0];
2026 if (pParagraph->getProperties().getParaAdjust())
2028 style::ParagraphAdjust eAdjust = *pParagraph->getProperties().getParaAdjust();
2029 if (eAdjust == style::ParagraphAdjust_CENTER)
2031 // If the first paragraph is centered, then set the para adjustment of
2032 // the shape itself to centered as well.
2033 aPropertySet.setAnyProperty(PROP_ParaAdjust, uno::Any(eAdjust));
2037 // tdf#144092 For empty textboxes push character styles &
2038 // endParaRPr into the Shape's properties
2039 if (rParagraphs.size() == 1 && pParagraph->getRuns().empty())
2041 TextCharacterProperties aTextCharacterProps{ pParagraph->getCharacterStyle(
2042 aCharStyleProperties, *mpMasterTextListStyle,
2043 getTextBody()->getTextListStyle()) };
2044 aTextCharacterProps.assignUsed(pParagraph->getEndProperties());
2045 aTextCharacterProps.pushToPropSet(aPropertySet, rFilterBase);
2049 // MS Office has e.g. fill and stroke of WordArt in the character properties,
2050 // LibreOffice uses shape properties.
2051 if (!mpTextBody->getTextProperties().msPrst.isEmpty()
2052 && mpTextBody->getTextProperties().msPrst != u"textNoShape")
2054 lcl_copyCharPropsToShape(mxShape, mpTextBody, rFilterBase);
2058 else if (mbTextBox)
2060 // No drawingML text, but WPS text is expected: save the theme
2061 // character color on the shape, then.
2062 if(const ShapeStyleRef* pFontRef = getShapeStyleRef(XML_fontRef))
2064 ::Color nCharColor = pFontRef->maPhClr.getColor(rGraphicHelper);
2065 aPropertySet.setAnyProperty(PROP_CharColor, uno::Any(nCharColor));
2069 // Set glow effect properties
2070 if (aEffectProperties.maGlow.moGlowRad.has_value()
2071 && aServiceName != "com.sun.star.drawing.GroupShape")
2073 uno::Reference<beans::XPropertySet> propertySet (mxShape, uno::UNO_QUERY);
2074 propertySet->setPropertyValue(u"GlowEffectRadius"_ustr, Any(convertEmuToHmm(aEffectProperties.maGlow.moGlowRad.value())));
2075 propertySet->setPropertyValue(u"GlowEffectColor"_ustr, Any(aEffectProperties.maGlow.moGlowColor.getColor(rGraphicHelper)));
2076 propertySet->setPropertyValue(u"GlowEffectTransparency"_ustr, Any(aEffectProperties.maGlow.moGlowColor.getTransparency()));
2079 // Set soft edge effect properties
2080 if (aEffectProperties.maSoftEdge.moRad.has_value())
2082 uno::Reference<beans::XPropertySet> propertySet(mxShape, uno::UNO_QUERY);
2083 propertySet->setPropertyValue(
2084 u"SoftEdgeRadius"_ustr, Any(convertEmuToHmm(aEffectProperties.maSoftEdge.moRad.value())));
2087 // Set the stroke and fill-color properties of the OLE shape
2088 if (aServiceName == "com.sun.star.drawing.OLE2Shape" && mxOleObjectInfo
2089 && !mxOleObjectInfo->maShapeId.isEmpty())
2090 if (::oox::vml::Drawing* pVmlDrawing = rFilterBase.getVmlDrawing())
2091 if (const ::oox::vml::ShapeBase* pVmlShape
2092 = pVmlDrawing->getShapes().getShapeById(mxOleObjectInfo->maShapeId))
2094 // Apply stroke props from the type model of the related VML shape.
2095 ShapePropertyMap aPropMap(rFilterBase.getModelObjectHelper());
2096 pVmlShape->getTypeModel().maStrokeModel.pushToPropMap(
2097 aPropMap, rFilterBase.getGraphicHelper());
2098 // And, fill-color properties as well...
2099 pVmlShape->getTypeModel().maFillModel.pushToPropMap(
2100 aPropMap, rFilterBase.getGraphicHelper());
2101 PropertySet(xSet).setProperties(aPropMap);
2105 if (mxShape.is())
2107 finalizeXShape( rFilterBase, rxShapes );
2109 if (mpTextBody)
2111 // tdf#151518. The method readjustTextDistances is fix for tdf#148321, but conflicts with
2112 // text position in some of the SmartArt types in Writer. So exclude Writer here.
2113 OUString sDocumentService;
2114 rFilterBase.getMediaDescriptor()[utl::MediaDescriptor::PROP_DOCUMENTSERVICE] >>= sDocumentService;
2115 if (sDocumentService != u"com.sun.star.text.TextDocument")
2116 mpTextBody->getTextProperties().readjustTextDistances(mxShape);
2119 return mxShape;
2122 void Shape::keepDiagramDrawing(XmlFilterBase& rFilterBase, const OUString& rFragmentPath)
2125 sal_Int32 length = maDiagramDoms.getLength();
2126 maDiagramDoms.realloc(length + 1);
2128 // drawingValue[0] => dom, drawingValue[1] => Sequence of associated relationships
2129 uno::Sequence<uno::Any> diagramDrawing{
2130 uno::Any(rFilterBase.importFragment(rFragmentPath)),
2131 uno::Any(resolveRelationshipsOfTypeFromOfficeDoc(rFilterBase, rFragmentPath, u"image"))
2134 beans::PropertyValue* pValue = maDiagramDoms.getArray();
2135 pValue[length].Name = "OOXDrawing";
2136 pValue[length].Value <<= diagramDrawing;
2139 void Shape::keepDiagramCompatibilityInfo()
2143 if( !maDiagramDoms.hasElements() )
2144 return;
2146 Reference < XPropertySet > xSet( mxShape, UNO_QUERY_THROW );
2147 Reference < XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
2148 if ( !xSetInfo.is() )
2149 return;
2151 const OUString aGrabBagPropName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
2152 if( !xSetInfo->hasPropertyByName( aGrabBagPropName ) )
2153 return;
2155 Sequence < PropertyValue > aGrabBag;
2156 xSet->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
2158 // We keep the previous items, if present
2159 if ( aGrabBag.hasElements() )
2160 xSet->setPropertyValue( aGrabBagPropName, Any( comphelper::concatSequences(aGrabBag, maDiagramDoms) ) );
2161 else
2162 xSet->setPropertyValue( aGrabBagPropName, Any( maDiagramDoms ) );
2164 catch( const Exception& )
2166 TOOLS_WARN_EXCEPTION( "oox.drawingml", "Shape::keepDiagramCompatibilityInfo" );
2170 void Shape::convertSmartArtToMetafile(XmlFilterBase const & rFilterBase)
2174 Reference<XPropertySet> xSet(mxShape, UNO_QUERY_THROW);
2176 xSet->setPropertyValue(u"MoveProtect"_ustr, Any(true));
2177 xSet->setPropertyValue(u"SizeProtect"_ustr, Any(true));
2179 // Replace existing shapes with a new Graphic Object rendered
2180 // from them
2181 Reference<XShape> xShape(renderDiagramToGraphic(rFilterBase));
2182 Reference<XShapes> xShapes(mxShape, UNO_QUERY_THROW);
2183 tools::Rectangle aBackgroundRect
2184 = SdrObject::getSdrObjectFromXShape(
2185 Reference<XShape>(xShapes->getByIndex(0), UNO_QUERY_THROW))
2186 ->GetLogicRect();
2187 while (xShapes->hasElements())
2188 xShapes->remove(Reference<XShape>(xShapes->getByIndex(0), UNO_QUERY_THROW));
2189 xShapes->add(xShape);
2190 SdrObject::getSdrObjectFromXShape(
2191 Reference<XShape>(xShapes->getByIndex(0), UNO_QUERY_THROW))
2192 ->NbcSetLogicRect(aBackgroundRect);
2194 catch (const Exception&)
2196 TOOLS_WARN_EXCEPTION("oox.drawingml", "Shape::convertSmartArtToMetafile");
2200 Reference < XShape > Shape::renderDiagramToGraphic( XmlFilterBase const & rFilterBase )
2202 Reference< XShape > xShape;
2206 if( !maDiagramDoms.hasElements() )
2207 return xShape;
2209 // Stream in which to place the rendered shape
2210 SvMemoryStream aTempStream;
2211 Reference < io::XStream > xStream( new utl::OStreamWrapper( aTempStream ) );
2212 Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() );
2214 // Size of the rendering
2215 awt::Size aActualSize = mxShape->getSize();
2216 Size aResolution(Application::GetDefaultDevice()->LogicToPixel(Size(100, 100), MapMode(MapUnit::MapCM)));
2217 double fPixelsPer100thmm = static_cast < double > ( aResolution.Width() ) / 100000.0;
2218 awt::Size aSize( static_cast < sal_Int32 > ( ( fPixelsPer100thmm * aActualSize.Width ) + 0.5 ),
2219 static_cast < sal_Int32 > ( ( fPixelsPer100thmm * aActualSize.Height ) + 0.5 ) );
2221 Sequence< PropertyValue > aFilterData{
2222 comphelper::makePropertyValue(u"PixelWidth"_ustr, aSize.Width),
2223 comphelper::makePropertyValue(u"PixelHeight"_ustr, aSize.Height),
2224 comphelper::makePropertyValue(u"LogicalWidth"_ustr, aActualSize.Width),
2225 comphelper::makePropertyValue(u"LogicalHeight"_ustr, aActualSize.Height)
2228 Sequence < PropertyValue > aDescriptor{
2229 comphelper::makePropertyValue(u"OutputStream"_ustr, xOutputStream),
2230 comphelper::makePropertyValue(u"FilterName"_ustr, u"SVM"_ustr), // Rendering format
2231 comphelper::makePropertyValue(u"FilterData"_ustr, aFilterData)
2234 Reference < lang::XComponent > xSourceDoc( mxShape, UNO_QUERY_THROW );
2235 Reference < XGraphicExportFilter > xGraphicExporter = GraphicExportFilter::create( rFilterBase.getComponentContext() );
2236 xGraphicExporter->setSourceDocument( xSourceDoc );
2237 xGraphicExporter->filter( aDescriptor );
2239 aTempStream.Seek( STREAM_SEEK_TO_BEGIN );
2241 Graphic aGraphic;
2242 GraphicFilter aFilter( false );
2243 if ( aFilter.ImportGraphic( aGraphic, u"", aTempStream, GRFILTER_FORMAT_NOTFOUND, nullptr, GraphicFilterImportFlags::NONE ) != ERRCODE_NONE )
2245 SAL_WARN( "oox.drawingml", "Shape::renderDiagramToGraphic: Unable to import rendered stream into graphic object" );
2246 return xShape;
2249 Reference < graphic::XGraphic > xGraphic( aGraphic.GetXGraphic() );
2250 Reference < lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
2251 xShape.set( xServiceFact->createInstance( u"com.sun.star.drawing.GraphicObjectShape"_ustr ), UNO_QUERY_THROW );
2252 Reference < XPropertySet > xPropSet( xShape, UNO_QUERY_THROW );
2253 xPropSet->setPropertyValue( u"Graphic"_ustr, Any( xGraphic ) );
2254 xPropSet->setPropertyValue( u"MoveProtect"_ustr, Any( true ) );
2255 xPropSet->setPropertyValue( u"SizeProtect"_ustr, Any( true ) );
2256 xPropSet->setPropertyValue( u"Name"_ustr, Any( u"RenderedShapes"_ustr ) );
2258 catch( const Exception& )
2260 TOOLS_WARN_EXCEPTION( "oox.drawingml", "Shape::renderDiagramToGraphic" );
2263 return xShape;
2266 void Shape::setTextBody(const TextBodyPtr & pTextBody)
2268 mpTextBody = pTextBody;
2271 void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle )
2273 SAL_INFO("oox.drawingml", "Shape::setMasterTextListStyle: Set master text list style to shape id='" << msId << "'");
2275 mpMasterTextListStyle = pMasterTextListStyle;
2278 OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const awt::Rectangle& rShapeRect )
2280 OUString aServiceName = rServiceName;
2281 switch( meFrameType )
2283 case FRAMETYPE_OLEOBJECT:
2285 awt::Size aOleSize( rShapeRect.Width, rShapeRect.Height );
2286 if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) )
2287 aServiceName = "com.sun.star.drawing.OLE2Shape";
2289 // get the path to the representation graphic
2290 OUString aGraphicPath;
2291 if( !mxOleObjectInfo->maShapeId.isEmpty() )
2292 if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() )
2293 if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId ) )
2294 aGraphicPath = pVmlShape->getGraphicPath();
2296 // import and store the graphic
2297 if( !aGraphicPath.isEmpty() )
2299 // Transfer shape's width and height to graphicsfilter (can be used by WMF/EMF)
2300 WmfExternal aExtHeader;
2301 aExtHeader.mapMode = 8; // MM_ANISOTROPIC
2302 aExtHeader.xExt = rShapeRect.Width;
2303 aExtHeader.yExt = rShapeRect.Height;
2305 Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath, &aExtHeader );
2306 if( xGraphic.is() )
2307 maShapeProperties.setProperty(PROP_Graphic, xGraphic);
2310 break;
2312 default:;
2314 return aServiceName;
2317 void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
2319 switch( meFrameType )
2321 case FRAMETYPE_CHART:
2323 OSL_ENSURE( !mxChartShapeInfo->maFragmentPath.isEmpty(), "Shape::finalizeXShape - missing chart fragment" );
2324 if( mxShape.is() && !mxChartShapeInfo->maFragmentPath.isEmpty() ) try
2326 // set the chart2 OLE class ID at the OLE shape
2327 PropertySet aShapeProp( mxShape );
2328 aShapeProp.setProperty( PROP_CLSID, u"12dcae26-281f-416f-a234-c3086127382e"_ustr );
2330 // get the XModel interface of the embedded object from the OLE shape
2331 Reference< frame::XModel > xDocModel;
2332 aShapeProp.getProperty( xDocModel, PROP_Model );
2333 Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW );
2335 // load the chart data from the XML fragment
2336 #if ENABLE_WASM_STRIP_CHART
2337 (void) rFilter;
2338 (void) rxShapes;
2339 #else
2340 // WASM_CHART change
2341 // TODO: Instead of using convertFromModel an alternative may be
2342 // added to convert not to Chart/OLE SdrObejct, but to GraphicObject
2343 // with the Chart visualization. There should be a preview available
2344 // in the imported chart data
2345 bool bMSO2007Doc = rFilter.isMSO2007Document();
2346 chart::ChartSpaceModel aModel(bMSO2007Doc);
2347 oox::ppt::PowerPointImport* pPowerPointImport
2348 = dynamic_cast<oox::ppt::PowerPointImport*>(&rFilter);
2350 ClrMapPtr pClrMap; // The original color map
2351 if (pPowerPointImport)
2353 // Use a copy of current color map, which the fragment may override locally
2354 pClrMap = pPowerPointImport->getActualSlidePersist()->getClrMap();
2355 aModel.mpClrMap = pClrMap ? std::make_shared<ClrMap>(*pClrMap)
2356 : std::make_shared<ClrMap>();
2357 pPowerPointImport->getActualSlidePersist()->setClrMap(aModel.mpClrMap);
2360 rtl::Reference<chart::ChartSpaceFragment> pChartSpaceFragment = new chart::ChartSpaceFragment(
2361 rFilter, mxChartShapeInfo->maFragmentPath, aModel );
2362 const OUString aThemeOverrideFragmentPath( pChartSpaceFragment->
2363 getFragmentPathFromFirstTypeFromOfficeDoc(u"themeOverride") );
2364 rFilter.importFragment( pChartSpaceFragment );
2366 // The original theme.
2367 ThemePtr pTheme;
2369 if (!aThemeOverrideFragmentPath.isEmpty() && pPowerPointImport)
2371 // Handle theme override.
2372 uno::Reference< xml::sax::XFastSAXSerializable > xDoc(
2373 rFilter.importFragment(aThemeOverrideFragmentPath), uno::UNO_QUERY_THROW);
2374 pTheme = pPowerPointImport->getActualSlidePersist()->getTheme();
2375 auto pThemeOverride = std::make_shared<Theme>(*pTheme);
2376 rFilter.importFragment(
2377 new ThemeOverrideFragmentHandler(rFilter, aThemeOverrideFragmentPath, *pThemeOverride, *pThemeOverride->getTheme()),
2378 xDoc);
2379 pPowerPointImport->getActualSlidePersist()->setTheme(pThemeOverride);
2382 // convert imported chart model to chart document
2383 Reference< drawing::XShapes > xExternalPage;
2384 if( !mxChartShapeInfo->mbEmbedShapes )
2385 xExternalPage = rxShapes;
2386 if( rFilter.getChartConverter() )
2388 rFilter.getChartConverter()->convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
2389 if( !xChartDoc->hasInternalDataProvider() )
2391 Reference< chart2::data::XDataReceiver > xDataRec( xChartDoc, UNO_QUERY );
2392 Reference< chart2::data::XDataSource > xData = xDataRec->getUsedData();
2393 if( !xData->getDataSequences().hasElements() || !xData->getDataSequences()[0]->getValues().is() ||
2394 !xData->getDataSequences()[0]->getValues()->getData().hasElements() )
2396 rFilter.useInternalChartDataTable( true );
2397 rFilter.getChartConverter()->convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
2398 rFilter.useInternalChartDataTable( false );
2404 if (pPowerPointImport)
2406 if (!aThemeOverrideFragmentPath.isEmpty())
2408 // Restore the original theme.
2409 pPowerPointImport->getActualSlidePersist()->setTheme(pTheme);
2411 // Restore the original color map
2412 pPowerPointImport->getActualSlidePersist()->setClrMap(pClrMap);
2414 #endif
2416 catch( Exception& )
2420 break;
2422 default:;
2426 void Shape::putPropertyToGrabBag( const OUString& sPropertyName, const Any& aPropertyValue )
2428 PropertyValue aNewProperty;
2429 aNewProperty.Name = sPropertyName;
2430 aNewProperty.Value = aPropertyValue;
2431 putPropertyToGrabBag( aNewProperty );
2434 void Shape::putPropertyToGrabBag( const PropertyValue& pProperty )
2436 Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
2437 Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
2438 const OUString aGrabBagPropName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
2439 if( mxShape.is() && xSet.is() && xSetInfo.is() && xSetInfo->hasPropertyByName( aGrabBagPropName ) )
2441 Sequence< PropertyValue > aGrabBag;
2442 xSet->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
2444 sal_Int32 length = aGrabBag.getLength();
2445 aGrabBag.realloc( length + 1 );
2446 aGrabBag.getArray()[length] = pProperty;
2448 xSet->setPropertyValue( aGrabBagPropName, Any( aGrabBag ) );
2452 void Shape::putPropertiesToGrabBag( const Sequence< PropertyValue >& aProperties )
2454 Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
2455 Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
2456 const OUString aGrabBagPropName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
2457 if( !(mxShape.is() && xSet.is() && xSetInfo.is() && xSetInfo->hasPropertyByName( aGrabBagPropName )) )
2458 return;
2460 // get existing grab bag
2461 Sequence< PropertyValue > aGrabBag;
2462 xSet->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
2464 std::vector<PropertyValue> aVec;
2465 aVec.reserve(aProperties.getLength());
2467 // put the new items
2468 std::transform(aProperties.begin(), aProperties.end(), std::back_inserter(aVec),
2469 [](const PropertyValue& rProp) {
2470 PropertyValue aProp;
2471 aProp.Name = rProp.Name;
2472 aProp.Value = rProp.Value;
2473 return aProp;
2476 // put it back to the shape
2477 xSet->setPropertyValue( aGrabBagPropName, Any( comphelper::concatSequences(aGrabBag, aVec) ) );
2480 FillProperties Shape::getActualFillProperties(const Theme* pTheme, const FillProperties* pParentShapeFillProps) const
2482 FillProperties aFillProperties;
2483 aFillProperties.moFillType = XML_noFill;
2485 // Reference shape properties
2486 aFillProperties.assignUsed( *mpShapeRefFillPropPtr );
2488 // Theme
2489 if( pTheme != nullptr )
2491 if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
2493 if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) )
2494 aFillProperties.assignUsed( *pFillProps );
2498 // Properties specified directly for this shape
2499 aFillProperties.assignUsed(getFillProperties());
2501 // Parent shape's properties
2502 if ( pParentShapeFillProps != nullptr)
2503 if( getFillProperties().moFillType.has_value() && getFillProperties().moFillType.value() == XML_grpFill )
2504 aFillProperties.assignUsed( *pParentShapeFillProps );
2506 return aFillProperties;
2509 LineProperties Shape::getActualLineProperties(const Theme* pTheme) const
2511 LineProperties aLineProperties;
2512 aLineProperties.maLineFill.moFillType = XML_noFill;
2514 // Reference shape properties
2515 aLineProperties.assignUsed( *mpShapeRefLinePropPtr );
2517 // Theme
2518 if( pTheme != nullptr )
2520 if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
2522 if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
2523 aLineProperties.assignUsed( *pLineProps );
2527 // Properties specified directly for this shape
2528 aLineProperties.assignUsed( getLineProperties() );
2530 return aLineProperties;
2533 EffectProperties Shape::getActualEffectProperties(const Theme* pTheme) const
2535 EffectProperties aEffectProperties;
2537 // Reference shape properties
2538 aEffectProperties.assignUsed( *mpShapeRefEffectPropPtr );
2540 // Theme
2541 if( pTheme != nullptr )
2543 if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_effectRef ) )
2545 if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) )
2546 aEffectProperties.assignUsed( *pEffectProps );
2550 // Properties specified directly for this shape
2551 aEffectProperties.assignUsed ( getEffectProperties() );
2553 return aEffectProperties;
2556 uno::Sequence< uno::Sequence< uno::Any > > Shape::resolveRelationshipsOfTypeFromOfficeDoc(core::XmlFilterBase& rFilter, const OUString& sFragment, std::u16string_view sType )
2558 uno::Sequence< uno::Sequence< uno::Any > > xRelListTemp;
2559 sal_Int32 counter = 0;
2561 core::RelationsRef xRels = rFilter.importRelations( sFragment );
2562 if ( xRels )
2564 core::RelationsRef xImageRels = xRels->getRelationsFromTypeFromOfficeDoc( sType );
2565 if ( xImageRels )
2567 xRelListTemp.realloc( xImageRels->size() );
2568 auto pxRelListTemp = xRelListTemp.getArray();
2569 for (auto const& imageRel : *xImageRels)
2571 uno::Sequence< uno::Any > diagramRelTuple (3);
2572 auto pdiagramRelTuple = diagramRelTuple.getArray();
2573 // [0] => RID, [1] => InputStream [2] => extension
2574 OUString sRelId = imageRel.second.maId;
2576 pdiagramRelTuple[0] <<= sRelId;
2577 OUString sTarget = xImageRels->getFragmentPathFromRelId( sRelId );
2579 uno::Reference< io::XInputStream > xImageInputStrm( rFilter.openInputStream( sTarget ), uno::UNO_SET_THROW );
2580 StreamDataSequence dataSeq;
2581 if ( rFilter.importBinaryData( dataSeq, sTarget ) )
2583 pdiagramRelTuple[1] <<= dataSeq;
2586 pdiagramRelTuple[2] <<= sTarget.copy( sTarget.lastIndexOf(".") );
2588 pxRelListTemp[counter] = diagramRelTuple;
2589 ++counter;
2591 xRelListTemp.realloc(counter);
2595 return xRelListTemp;
2598 void Shape::cloneFillProperties()
2600 auto pFillProperties = std::make_shared<FillProperties>();
2601 pFillProperties->assignUsed(*mpFillPropertiesPtr);
2602 mpFillPropertiesPtr = pFillProperties;
2606 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */