1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "diagramlayoutatoms.hxx"
24 #include "layoutatomvisitorbase.hxx"
26 #include <basegfx/numeric/ftools.hxx>
27 #include <sal/log.hxx>
29 #include <o3tl/unit_conversion.hxx>
30 #include <oox/helper/attributelist.hxx>
31 #include <oox/token/properties.hxx>
32 #include <drawingml/fillproperties.hxx>
33 #include <drawingml/lineproperties.hxx>
34 #include <drawingml/textbody.hxx>
35 #include <drawingml/textparagraph.hxx>
36 #include <drawingml/textrun.hxx>
37 #include <drawingml/customshapeproperties.hxx>
38 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::xml::sax
;
43 using namespace ::oox::core
;
47 /// Looks up the value of the rInternalName -> nProperty key in rProperties.
48 std::optional
<sal_Int32
> findProperty(const oox::drawingml::LayoutPropertyMap
& rProperties
,
49 const OUString
& rInternalName
, sal_Int32 nProperty
)
51 std::optional
<sal_Int32
> oRet
;
53 auto it
= rProperties
.find(rInternalName
);
54 if (it
!= rProperties
.end())
56 const oox::drawingml::LayoutProperty
& rProperty
= it
->second
;
57 auto itProperty
= rProperty
.find(nProperty
);
58 if (itProperty
!= rProperty
.end())
59 oRet
= itProperty
->second
;
66 * Determines if nUnit is a font unit (measured in points) or not (measured in
69 bool isFontUnit(sal_Int32 nUnit
)
71 return nUnit
== oox::XML_primFontSz
|| nUnit
== oox::XML_secFontSz
;
74 /// Determines which UNO property should be set for a given constraint type.
75 sal_Int32
getPropertyFromConstraint(sal_Int32 nConstraint
)
80 return oox::PROP_TextLeftDistance
;
82 return oox::PROP_TextRightDistance
;
84 return oox::PROP_TextUpperDistance
;
86 return oox::PROP_TextLowerDistance
;
93 * Determines if pShape is (or contains) a presentation of a data node of type
96 bool containsDataNodeType(const oox::drawingml::ShapePtr
& pShape
, sal_Int32 nType
)
98 if (pShape
->getDataNodeType() == nType
)
101 for (const auto& pChild
: pShape
->getChildren())
103 if (containsDataNodeType(pChild
, nType
))
111 namespace oox::drawingml
{
112 void SnakeAlg::layoutShapeChildren(const AlgAtom
& rAlg
, const ShapePtr
& rShape
,
113 const std::vector
<Constraint
>& rConstraints
)
115 if (rShape
->getChildren().empty() || rShape
->getSize().Width
== 0
116 || rShape
->getSize().Height
== 0)
119 // Parse constraints.
120 double fChildAspectRatio
= rShape
->getChildren()[0]->getAspectRatio();
121 double fShapeHeight
= rShape
->getSize().Height
;
122 double fShapeWidth
= rShape
->getSize().Width
;
123 // Check if we have a child aspect ratio. If so, need to shrink one dimension to
124 // achieve that ratio.
125 if (fChildAspectRatio
&& fShapeHeight
&& fChildAspectRatio
< (fShapeWidth
/ fShapeHeight
))
127 fShapeWidth
= fShapeHeight
* fChildAspectRatio
;
130 double fSpaceFromConstraint
= 1.0;
131 LayoutPropertyMap aPropertiesByName
;
132 std::map
<sal_Int32
, LayoutProperty
> aPropertiesByType
;
133 LayoutProperty
& rParent
= aPropertiesByName
[u
""_ustr
];
134 rParent
[XML_w
] = fShapeWidth
;
135 rParent
[XML_h
] = fShapeHeight
;
136 for (const auto& rConstr
: rConstraints
)
138 if (rConstr
.mnRefType
== XML_w
|| rConstr
.mnRefType
== XML_h
)
140 if (rConstr
.mnType
== XML_sp
&& rConstr
.msForName
.isEmpty())
141 fSpaceFromConstraint
= rConstr
.mfFactor
;
144 auto itRefForName
= aPropertiesByName
.find(rConstr
.msRefForName
);
145 if (itRefForName
== aPropertiesByName
.end())
150 auto it
= itRefForName
->second
.find(rConstr
.mnRefType
);
151 if (it
== itRefForName
->second
.end())
156 if (rConstr
.mfValue
!= 0.0)
161 sal_Int32 nValue
= it
->second
* rConstr
.mfFactor
;
163 if (rConstr
.mnPointType
== XML_none
)
165 aPropertiesByName
[rConstr
.msForName
][rConstr
.mnType
] = nValue
;
169 aPropertiesByType
[rConstr
.mnPointType
][rConstr
.mnType
] = nValue
;
173 std::vector
<sal_Int32
> aShapeWidths(rShape
->getChildren().size());
174 for (size_t i
= 0; i
< rShape
->getChildren().size(); ++i
)
176 ShapePtr pChild
= rShape
->getChildren()[i
];
177 if (!pChild
->getDataNodeType())
179 // TODO handle the case when the requirement applies by name, not by point type.
180 aShapeWidths
[i
] = fShapeWidth
;
184 auto itNodeType
= aPropertiesByType
.find(pChild
->getDataNodeType());
185 if (itNodeType
== aPropertiesByType
.end())
187 aShapeWidths
[i
] = fShapeWidth
;
191 auto it
= itNodeType
->second
.find(XML_w
);
192 if (it
== itNodeType
->second
.end())
194 aShapeWidths
[i
] = fShapeWidth
;
198 aShapeWidths
[i
] = it
->second
;
201 bool bSpaceFromConstraints
= fSpaceFromConstraint
!= 1.0;
203 const AlgAtom::ParamMap
& rMap
= rAlg
.getMap();
204 const sal_Int32 nDir
= rMap
.count(XML_grDir
) ? rMap
.find(XML_grDir
)->second
: XML_tL
;
207 bool bHorizontal
= true;
230 sal_Int32 nCount
= rShape
->getChildren().size();
231 // Defaults in case not provided by constraints.
232 double fSpace
= bSpaceFromConstraints
? fSpaceFromConstraint
: 0.3;
233 double fAspectRatio
= 0.54; // diagram should not spill outside, earlier it was 0.6
237 sal_Int32 nMaxRowWidth
= 0;
238 if (nCount
<= fChildAspectRatio
)
239 // Child aspect ratio request (width/height) is N, and we have at most N shapes.
240 // This means we don't need multiple columns.
244 for (; nRow
< nCount
; nRow
++)
246 nCol
= std::ceil(static_cast<double>(nCount
) / nRow
);
247 sal_Int32 nRowWidth
= 0;
248 for (sal_Int32 i
= 0; i
< nCol
; ++i
)
255 nRowWidth
+= aShapeWidths
[i
];
257 double fTotalShapesHeight
= fShapeHeight
* nRow
;
258 if (nRowWidth
&& fTotalShapesHeight
/ nRowWidth
>= fAspectRatio
)
260 if (nRowWidth
> nMaxRowWidth
)
262 nMaxRowWidth
= nRowWidth
;
269 SAL_INFO("oox.drawingml", "Snake layout grid: " << nCol
<< "x" << nRow
);
271 sal_Int32 nWidth
= rShape
->getSize().Width
/ (nCol
+ (nCol
- 1) * fSpace
);
272 awt::Size
aChildSize(nWidth
, nWidth
* fAspectRatio
);
273 if (nCol
== 1 && nRow
> 1)
275 // We have a single column, so count the height based on the parent height, not
277 // Space occurs inside children; also double amount of space is needed outside (on
278 // both sides), if the factor comes from a constraint.
279 sal_Int32 nNumSpaces
= -1;
280 if (bSpaceFromConstraints
)
282 sal_Int32 nHeight
= rShape
->getSize().Height
/ (nRow
+ (nRow
+ nNumSpaces
) * fSpace
);
284 if (fChildAspectRatio
> 1)
286 // Shrink width if the aspect ratio requires it.
287 nWidth
= std::min(rShape
->getSize().Width
,
288 static_cast<sal_Int32
>(nHeight
* fChildAspectRatio
));
289 aChildSize
= awt::Size(nWidth
, nHeight
);
295 awt::Point
aCurrPos(0, 0);
297 aCurrPos
.X
= rShape
->getSize().Width
- aChildSize
.Width
;
299 aCurrPos
.Y
= rShape
->getSize().Height
- aChildSize
.Height
;
300 else if (bSpaceFromConstraints
)
304 // Initial vertical offset to have upper spacing (outside, so double amount).
305 aCurrPos
.Y
= aChildSize
.Height
* fSpace
* 2;
309 sal_Int32 nStartX
= aCurrPos
.X
;
310 sal_Int32 nColIdx
= 0, index
= 0;
312 const sal_Int32 aContDir
313 = rMap
.count(XML_contDir
) ? rMap
.find(XML_contDir
)->second
: XML_sameDir
;
319 sal_Int32 nRowHeight
= 0;
320 for (auto& aCurrShape
: rShape
->getChildren())
322 aCurrShape
->setPosition(aCurrPos
);
323 awt::Size
aCurrSize(aChildSize
);
324 // aShapeWidths items are a portion of nMaxRowWidth. We want the same ratio,
325 // based on the original parent width, ignoring the aspect ratio request.
326 bool bWidthsFromConstraints
327 = nCount
>= 2 && rShape
->getChildren()[1]->getDataNodeType() == XML_sibTrans
;
328 if (bWidthsFromConstraints
&& nMaxRowWidth
)
330 double fWidthFactor
= static_cast<double>(aShapeWidths
[index
]) / nMaxRowWidth
;
331 // We can only work from constraints if spacing is represented by a real
333 aCurrSize
.Width
= rShape
->getSize().Width
* fWidthFactor
;
335 if (fChildAspectRatio
)
337 aCurrSize
.Height
= aCurrSize
.Width
/ fChildAspectRatio
;
339 // Child shapes are not allowed to leave their parent.
340 aCurrSize
.Height
= std::min
<sal_Int32
>(
341 aCurrSize
.Height
, rShape
->getSize().Height
/ (nRow
+ (nRow
- 1) * fSpace
));
343 if (aCurrSize
.Height
> nRowHeight
)
345 nRowHeight
= aCurrSize
.Height
;
347 aCurrShape
->setSize(aCurrSize
);
348 aCurrShape
->setChildSize(aCurrSize
);
350 index
++; // counts index of child, helpful for positioning.
352 if (index
% nCol
== 0 || ((index
/ nCol
) + 1) != nRow
)
353 aCurrPos
.X
+= nIncX
* (aCurrSize
.Width
+ fSpace
* aCurrSize
.Width
);
355 if (++nColIdx
== nCol
) // condition for next row
357 // if last row, then position children according to number of shapes.
358 if ((index
+ 1) % nCol
!= 0 && (index
+ 1) >= 3
359 && ((index
+ 1) / nCol
+ 1) == nRow
&& nCount
!= nRow
* nCol
)
361 // position first child of last row
362 if (bWidthsFromConstraints
)
364 aCurrPos
.X
= nStartX
;
368 // Can assume that all child shape has the same width.
371 + (nIncX
* (aCurrSize
.Width
+ fSpace
* aCurrSize
.Width
)) / 2;
375 // if not last row, positions first child of that row
376 aCurrPos
.X
= nStartX
;
377 aCurrPos
.Y
+= nIncY
* (nRowHeight
+ fSpace
* nRowHeight
);
382 // positions children in the last row.
383 if (index
% nCol
!= 0 && index
>= 3 && ((index
/ nCol
) + 1) == nRow
)
384 aCurrPos
.X
+= (nIncX
* (aCurrSize
.Width
+ fSpace
* aCurrSize
.Width
));
389 for (auto& aCurrShape
: rShape
->getChildren())
391 aCurrShape
->setPosition(aCurrPos
);
392 aCurrShape
->setSize(aChildSize
);
393 aCurrShape
->setChildSize(aChildSize
);
395 index
++; // counts index of child, helpful for positioning.
398 index%col -> tests node is at last column
399 ((index/nCol)+1)!=nRow) -> tests node is at last row or not
400 ((index/nCol)+1)%2!=0 -> tests node is at row which is multiple of 2, important for revDir
401 num!=nRow*nCol -> tests how last row nodes should be spread.
404 if ((index
% nCol
== 0 || ((index
/ nCol
) + 1) != nRow
)
405 && ((index
/ nCol
) + 1) % 2 != 0)
406 aCurrPos
.X
+= (aChildSize
.Width
+ fSpace
* aChildSize
.Width
);
407 else if (index
% nCol
!= 0
408 && ((index
/ nCol
) + 1) != nRow
) // child other than placed at last column
409 aCurrPos
.X
-= (aChildSize
.Width
+ fSpace
* aChildSize
.Width
);
411 if (++nColIdx
== nCol
) // condition for next row
413 // if last row, then position children according to number of shapes.
414 if ((index
+ 1) % nCol
!= 0 && (index
+ 1) >= 4
415 && ((index
+ 1) / nCol
+ 1) == nRow
&& nCount
!= nRow
* nCol
416 && ((index
/ nCol
) + 1) % 2 == 0)
417 // position first child of last row
418 aCurrPos
.X
-= aChildSize
.Width
* 3 / 2;
419 else if ((index
+ 1) % nCol
!= 0 && (index
+ 1) >= 4
420 && ((index
+ 1) / nCol
+ 1) == nRow
&& nCount
!= nRow
* nCol
421 && ((index
/ nCol
) + 1) % 2 != 0)
423 + (nIncX
* (aChildSize
.Width
+ fSpace
* aChildSize
.Width
)) / 2;
424 else if (((index
/ nCol
) + 1) % 2 != 0)
425 aCurrPos
.X
= nStartX
;
427 aCurrPos
.Y
+= nIncY
* (aChildSize
.Height
+ fSpace
* aChildSize
.Height
);
431 // positions children in the last row.
432 if (index
% nCol
!= 0 && index
>= 3 && ((index
/ nCol
) + 1) == nRow
433 && ((index
/ nCol
) + 1) % 2 == 0)
434 //if row%2=0 then start from left else
435 aCurrPos
.X
-= (nIncX
* (aChildSize
.Width
+ fSpace
* aChildSize
.Width
));
436 else if (index
% nCol
!= 0 && index
>= 3 && ((index
/ nCol
) + 1) == nRow
437 && ((index
/ nCol
) + 1) % 2 != 0)
439 aCurrPos
.X
+= (nIncX
* (aChildSize
.Width
+ fSpace
* aChildSize
.Width
));
445 void PyraAlg::layoutShapeChildren(const ShapePtr
& rShape
)
447 if (rShape
->getChildren().empty() || rShape
->getSize().Width
== 0
448 || rShape
->getSize().Height
== 0)
451 // const sal_Int32 nDir = maMap.count(XML_linDir) ? maMap.find(XML_linDir)->second : XML_fromT;
452 // const sal_Int32 npyraAcctPos = maMap.count(XML_pyraAcctPos) ? maMap.find(XML_pyraAcctPos)->second : XML_bef;
453 // const sal_Int32 ntxDir = maMap.count(XML_txDir) ? maMap.find(XML_txDir)->second : XML_fromT;
454 // const sal_Int32 npyraLvlNode = maMap.count(XML_pyraLvlNode) ? maMap.find(XML_pyraLvlNode)->second : XML_level;
455 // uncomment when use in code.
457 sal_Int32 nCount
= rShape
->getChildren().size();
458 double fAspectRatio
= 0.32;
460 awt::Size aChildSize
= rShape
->getSize();
461 aChildSize
.Width
/= nCount
;
462 aChildSize
.Height
/= nCount
;
464 awt::Point
aCurrPos(0, 0);
465 aCurrPos
.X
= fAspectRatio
* aChildSize
.Width
* (nCount
- 1);
466 aCurrPos
.Y
= fAspectRatio
* aChildSize
.Height
;
468 for (auto& aCurrShape
: rShape
->getChildren())
470 aCurrShape
->setPosition(aCurrPos
);
473 aCurrPos
.X
-= aChildSize
.Height
/ (nCount
- 1);
475 aChildSize
.Width
+= aChildSize
.Height
;
476 aCurrShape
->setSize(aChildSize
);
477 aCurrShape
->setChildSize(aChildSize
);
478 aCurrPos
.Y
+= (aChildSize
.Height
);
482 bool CompositeAlg::inferFromLayoutProperty(const LayoutProperty
& rMap
, sal_Int32 nRefType
,
489 auto it
= rMap
.find(XML_l
);
490 if (it
== rMap
.end())
494 sal_Int32 nLeft
= it
->second
;
495 it
= rMap
.find(XML_w
);
496 if (it
== rMap
.end())
500 rValue
= nLeft
+ it
->second
;
510 void CompositeAlg::applyConstraintToLayout(const Constraint
& rConstraint
,
511 LayoutPropertyMap
& rProperties
)
513 // TODO handle the case when we have ptType="...", not forName="...".
514 if (rConstraint
.msForName
.isEmpty())
519 const LayoutPropertyMap::const_iterator aRef
= rProperties
.find(rConstraint
.msRefForName
);
520 if (aRef
== rProperties
.end())
523 const LayoutProperty::const_iterator aRefType
= aRef
->second
.find(rConstraint
.mnRefType
);
524 sal_Int32 nInferredValue
= 0;
525 if (aRefType
!= aRef
->second
.end())
527 // Reference is found directly.
528 rProperties
[rConstraint
.msForName
][rConstraint
.mnType
]
529 = aRefType
->second
* rConstraint
.mfFactor
;
531 else if (inferFromLayoutProperty(aRef
->second
, rConstraint
.mnRefType
, nInferredValue
))
533 // Reference can be inferred.
534 rProperties
[rConstraint
.msForName
][rConstraint
.mnType
]
535 = nInferredValue
* rConstraint
.mfFactor
;
539 // Reference not found, assume a fixed value.
540 // Values are never in EMU, while oox::drawingml::Shape position and size are always in
542 const double fValue
= o3tl::convert(rConstraint
.mfValue
,
543 isFontUnit(rConstraint
.mnRefType
) ? o3tl::Length::pt
546 rProperties
[rConstraint
.msForName
][rConstraint
.mnType
] = fValue
;
550 void CompositeAlg::layoutShapeChildren(AlgAtom
& rAlg
, const ShapePtr
& rShape
,
551 const std::vector
<Constraint
>& rConstraints
)
553 LayoutPropertyMap aProperties
;
554 LayoutProperty
& rParent
= aProperties
[u
""_ustr
];
556 sal_Int32 nParentXOffset
= 0;
558 // Track min/max vertical positions, so we can center everything at the end, if needed.
559 sal_Int32 nVertMin
= std::numeric_limits
<sal_Int32
>::max();
560 sal_Int32 nVertMax
= 0;
562 if (rAlg
.getAspectRatio() != 1.0)
564 rParent
[XML_w
] = rShape
->getSize().Width
;
565 rParent
[XML_h
] = rShape
->getSize().Height
;
568 rParent
[XML_r
] = rShape
->getSize().Width
;
569 rParent
[XML_b
] = rShape
->getSize().Height
;
573 // Shrink width to be only as large as height.
574 rParent
[XML_w
] = std::min(rShape
->getSize().Width
, rShape
->getSize().Height
);
575 rParent
[XML_h
] = rShape
->getSize().Height
;
576 if (rParent
[XML_w
] < rShape
->getSize().Width
)
577 nParentXOffset
= (rShape
->getSize().Width
- rParent
[XML_w
]) / 2;
578 rParent
[XML_l
] = nParentXOffset
;
580 rParent
[XML_r
] = rShape
->getSize().Width
- rParent
[XML_l
];
581 rParent
[XML_b
] = rShape
->getSize().Height
;
584 for (const auto& rConstr
: rConstraints
)
586 // Apply direct constraints for all layout nodes.
587 applyConstraintToLayout(rConstr
, aProperties
);
590 for (auto& aCurrShape
: rShape
->getChildren())
592 // Apply constraints from the current layout node for this child shape.
593 // Previous child shapes may have changed aProperties.
594 for (const auto& rConstr
: rConstraints
)
596 if (rConstr
.msForName
!= aCurrShape
->getInternalName())
601 applyConstraintToLayout(rConstr
, aProperties
);
604 // Apply constraints from the child layout node for this child shape.
605 // This builds on top of the own parent state + the state of previous shapes in the
606 // same composite algorithm.
607 const LayoutNode
& rLayoutNode
= rAlg
.getLayoutNode();
608 for (const auto& pDirectChild
: rLayoutNode
.getChildren())
610 auto pLayoutNode
= dynamic_cast<LayoutNode
*>(pDirectChild
.get());
616 if (pLayoutNode
->getName() != aCurrShape
->getInternalName())
621 for (const auto& pChild
: pLayoutNode
->getChildren())
623 auto pConstraintAtom
= dynamic_cast<ConstraintAtom
*>(pChild
.get());
624 if (!pConstraintAtom
)
629 const Constraint
& rConstraint
= pConstraintAtom
->getConstraint();
630 if (!rConstraint
.msForName
.isEmpty())
635 if (!rConstraint
.msRefForName
.isEmpty())
640 // Either an absolute value or a factor of a property.
641 if (rConstraint
.mfValue
== 0.0 && rConstraint
.mnRefType
== XML_none
)
646 Constraint
aConstraint(rConstraint
);
647 aConstraint
.msForName
= pLayoutNode
->getName();
648 aConstraint
.msRefForName
= pLayoutNode
->getName();
650 applyConstraintToLayout(aConstraint
, aProperties
);
654 awt::Size aSize
= rShape
->getSize();
655 awt::Point
aPos(0, 0);
657 const LayoutPropertyMap::const_iterator aPropIt
658 = aProperties
.find(aCurrShape
->getInternalName());
659 if (aPropIt
!= aProperties
.end())
661 const LayoutProperty
& rProp
= aPropIt
->second
;
662 LayoutProperty::const_iterator it
, it2
;
664 if ((it
= rProp
.find(XML_w
)) != rProp
.end())
665 aSize
.Width
= std::min(it
->second
, rShape
->getSize().Width
);
666 if ((it
= rProp
.find(XML_h
)) != rProp
.end())
667 aSize
.Height
= std::min(it
->second
, rShape
->getSize().Height
);
669 if ((it
= rProp
.find(XML_l
)) != rProp
.end())
671 else if ((it
= rProp
.find(XML_ctrX
)) != rProp
.end())
672 aPos
.X
= it
->second
- aSize
.Width
/ 2;
673 else if ((it
= rProp
.find(XML_r
)) != rProp
.end())
674 aPos
.X
= it
->second
- aSize
.Width
;
676 if ((it
= rProp
.find(XML_t
)) != rProp
.end())
678 else if ((it
= rProp
.find(XML_ctrY
)) != rProp
.end())
679 aPos
.Y
= it
->second
- aSize
.Height
/ 2;
680 else if ((it
= rProp
.find(XML_b
)) != rProp
.end())
681 aPos
.Y
= it
->second
- aSize
.Height
;
683 if ((it
= rProp
.find(XML_l
)) != rProp
.end() && (it2
= rProp
.find(XML_r
)) != rProp
.end())
684 aSize
.Width
= it2
->second
- it
->second
;
685 if ((it
= rProp
.find(XML_t
)) != rProp
.end() && (it2
= rProp
.find(XML_b
)) != rProp
.end())
686 aSize
.Height
= it2
->second
- it
->second
;
688 aPos
.X
+= nParentXOffset
;
689 aSize
.Width
= std::min(aSize
.Width
, rShape
->getSize().Width
- aPos
.X
);
690 aSize
.Height
= std::min(aSize
.Height
, rShape
->getSize().Height
- aPos
.Y
);
693 SAL_WARN("oox.drawingml", "composite layout properties not found for shape "
694 << aCurrShape
->getInternalName());
696 aCurrShape
->setSize(aSize
);
697 aCurrShape
->setChildSize(aSize
);
698 aCurrShape
->setPosition(aPos
);
700 nVertMin
= std::min(aPos
.Y
, nVertMin
);
701 nVertMax
= std::max(aPos
.Y
+ aSize
.Height
, nVertMax
);
703 NamedShapePairs
& rDiagramFontHeights
704 = rAlg
.getLayoutNode().getDiagram().getDiagramFontHeights();
705 auto it
= rDiagramFontHeights
.find(aCurrShape
->getInternalName());
706 if (it
!= rDiagramFontHeights
.end())
708 // Internal name matches: put drawingml::Shape to the relevant group, for
709 // synchronized font height handling.
710 it
->second
.insert({ aCurrShape
, {} });
714 // See if all vertical space is used or we have to center the content.
715 if (!(nVertMin
>= 0 && nVertMin
<= nVertMax
&& nVertMax
<= rParent
[XML_h
]))
718 sal_Int32 nDiff
= rParent
[XML_h
] - (nVertMax
- nVertMin
);
721 for (auto& aCurrShape
: rShape
->getChildren())
723 awt::Point aPosition
= aCurrShape
->getPosition();
724 aPosition
.Y
+= nDiff
/ 2;
725 aCurrShape
->setPosition(aPosition
);
730 IteratorAttr::IteratorAttr( )
732 , mbHideLastTrans( true )
739 void IteratorAttr::loadFromXAttr( const Reference
< XFastAttributeList
>& xAttr
)
741 AttributeList
attr( xAttr
);
742 maAxis
= attr
.getTokenList(XML_axis
);
743 mnCnt
= attr
.getInteger( XML_cnt
, -1 );
744 mbHideLastTrans
= attr
.getBool( XML_hideLastTrans
, true );
745 mnSt
= attr
.getInteger( XML_st
, 0 );
746 mnStep
= attr
.getInteger( XML_step
, 1 );
748 // better to keep first token instead of error when multiple values
749 std::vector
<sal_Int32
> aPtTypes
= attr
.getTokenList(XML_ptType
);
750 mnPtType
= aPtTypes
.empty() ? XML_all
: aPtTypes
.front();
753 ConditionAttr::ConditionAttr()
761 void ConditionAttr::loadFromXAttr( const Reference
< XFastAttributeList
>& xAttr
)
763 mnFunc
= xAttr
->getOptionalValueToken( XML_func
, 0 );
764 mnArg
= xAttr
->getOptionalValueToken( XML_arg
, XML_none
);
765 mnOp
= xAttr
->getOptionalValueToken( XML_op
, 0 );
766 msVal
= xAttr
->getOptionalValue( XML_val
);
767 mnVal
= xAttr
->getOptionalValueToken( XML_val
, 0 );
770 void LayoutAtom::dump(int level
)
772 SAL_INFO("oox.drawingml", "level = " << level
<< " - " << msName
<< " of type " << typeid(*this).name() );
773 for (const auto& pAtom
: getChildren())
774 pAtom
->dump(level
+ 1);
777 ForEachAtom::ForEachAtom(LayoutNode
& rLayoutNode
, const Reference
< XFastAttributeList
>& xAttributes
) :
778 LayoutAtom(rLayoutNode
)
780 maIter
.loadFromXAttr(xAttributes
);
783 void ForEachAtom::accept( LayoutAtomVisitor
& rVisitor
)
785 rVisitor
.visit(*this);
788 LayoutAtomPtr
ForEachAtom::getRefAtom()
790 if (!msRef
.isEmpty())
792 const LayoutAtomMap
& rLayoutAtomMap
= getLayoutNode().getDiagram().getLayout()->getLayoutAtomMap();
793 LayoutAtomMap::const_iterator pRefAtom
= rLayoutAtomMap
.find(msRef
);
794 if (pRefAtom
!= rLayoutAtomMap
.end())
795 return pRefAtom
->second
;
797 SAL_WARN("oox.drawingml", "ForEach reference \"" << msRef
<< "\" not found");
799 return LayoutAtomPtr();
802 void ChooseAtom::accept( LayoutAtomVisitor
& rVisitor
)
804 rVisitor
.visit(*this);
807 ConditionAtom::ConditionAtom(LayoutNode
& rLayoutNode
, bool isElse
, const Reference
< XFastAttributeList
>& xAttributes
) :
808 LayoutAtom(rLayoutNode
),
811 maIter
.loadFromXAttr( xAttributes
);
812 maCond
.loadFromXAttr( xAttributes
);
815 bool ConditionAtom::compareResult(sal_Int32 nOperator
, sal_Int32 nFirst
, sal_Int32 nSecond
)
819 case XML_equ
: return nFirst
== nSecond
;
820 case XML_gt
: return nFirst
> nSecond
;
821 case XML_gte
: return nFirst
>= nSecond
;
822 case XML_lt
: return nFirst
< nSecond
;
823 case XML_lte
: return nFirst
<= nSecond
;
824 case XML_neq
: return nFirst
!= nSecond
;
826 SAL_WARN("oox.drawingml", "unsupported operator: " << nOperator
);
834 * Takes the connection list from rLayoutNode, navigates from rFrom on an edge
835 * of type nType, using a direction determined by bSourceToDestination.
837 OUString
navigate(LayoutNode
& rLayoutNode
, svx::diagram::TypeConstant nType
, std::u16string_view rFrom
,
838 bool bSourceToDestination
)
840 for (const auto& rConnection
: rLayoutNode
.getDiagram().getData()->getConnections())
842 if (rConnection
.mnXMLType
!= nType
)
845 if (bSourceToDestination
)
847 if (rConnection
.msSourceId
== rFrom
)
848 return rConnection
.msDestId
;
852 if (rConnection
.msDestId
== rFrom
)
853 return rConnection
.msSourceId
;
860 sal_Int32
calcMaxDepth(std::u16string_view rNodeName
, const svx::diagram::Connections
& rConnections
)
862 sal_Int32 nMaxLength
= 0;
863 for (auto const& aCxn
: rConnections
)
864 if (aCxn
.mnXMLType
== svx::diagram::TypeConstant::XML_parOf
&& aCxn
.msSourceId
== rNodeName
)
865 nMaxLength
= std::max(nMaxLength
, calcMaxDepth(aCxn
.msDestId
, rConnections
) + 1);
871 sal_Int32
ConditionAtom::getNodeCount(const svx::diagram::Point
* pPresPoint
) const
873 sal_Int32 nCount
= 0;
874 OUString sNodeId
= pPresPoint
->msPresentationAssociationId
;
876 // HACK: special case - count children of first child
877 if (maIter
.maAxis
.size() == 2 && maIter
.maAxis
[0] == XML_ch
&& maIter
.maAxis
[1] == XML_ch
)
878 sNodeId
= navigate(mrLayoutNode
, svx::diagram::TypeConstant::XML_parOf
, sNodeId
, /*bSourceToDestination*/ true);
880 if (!sNodeId
.isEmpty())
882 for (const auto& aCxn
: mrLayoutNode
.getDiagram().getData()->getConnections())
883 if (aCxn
.mnXMLType
== svx::diagram::TypeConstant::XML_parOf
&& aCxn
.msSourceId
== sNodeId
)
890 bool ConditionAtom::getDecision(const svx::diagram::Point
* pPresPoint
) const
897 switch (maCond
.mnFunc
)
901 if (maCond
.mnArg
== XML_dir
)
902 return compareResult(maCond
.mnOp
, pPresPoint
->mnDirection
, maCond
.mnVal
);
903 else if (maCond
.mnArg
== XML_hierBranch
)
905 sal_Int32 nHierarchyBranch
= pPresPoint
->moHierarchyBranch
.value_or(XML_std
);
906 if (!pPresPoint
->moHierarchyBranch
.has_value())
908 // If <dgm:hierBranch> is missing in the current presentation
909 // point, ask the parent.
910 OUString aParent
= navigate(mrLayoutNode
, svx::diagram::TypeConstant::XML_presParOf
, pPresPoint
->msModelId
,
911 /*bSourceToDestination*/ false);
912 DiagramData::PointNameMap
& rPointNameMap
913 = mrLayoutNode
.getDiagram().getData()->getPointNameMap();
914 auto it
= rPointNameMap
.find(aParent
);
915 if (it
!= rPointNameMap
.end())
917 const svx::diagram::Point
* pParent
= it
->second
;
918 if (pParent
->moHierarchyBranch
.has_value())
919 nHierarchyBranch
= pParent
->moHierarchyBranch
.value();
922 return compareResult(maCond
.mnOp
, nHierarchyBranch
, maCond
.mnVal
);
928 return compareResult(maCond
.mnOp
, getNodeCount(pPresPoint
), maCond
.msVal
.toInt32());
932 sal_Int32 nMaxDepth
= calcMaxDepth(pPresPoint
->msPresentationAssociationId
, mrLayoutNode
.getDiagram().getData()->getConnections());
933 return compareResult(maCond
.mnOp
, nMaxDepth
, maCond
.msVal
.toInt32());
943 SAL_WARN("oox.drawingml", "unknown function " << maCond
.mnFunc
);
950 void ConditionAtom::accept( LayoutAtomVisitor
& rVisitor
)
952 rVisitor
.visit(*this);
955 void ConstraintAtom::accept( LayoutAtomVisitor
& rVisitor
)
957 rVisitor
.visit(*this);
960 void RuleAtom::accept( LayoutAtomVisitor
& rVisitor
)
962 rVisitor
.visit(*this);
965 void ConstraintAtom::parseConstraint(std::vector
<Constraint
>& rConstraints
,
966 bool bRequireForName
) const
968 // Allowlist for cases where empty forName is handled.
971 switch (maConstraint
.mnType
)
978 bRequireForName
= false;
981 switch (maConstraint
.mnPointType
)
984 bRequireForName
= false;
989 if (bRequireForName
&& maConstraint
.msForName
.isEmpty())
992 // accepting only basic equality constraints
993 if ((maConstraint
.mnOperator
== XML_none
|| maConstraint
.mnOperator
== XML_equ
)
994 && maConstraint
.mnType
!= XML_none
)
996 rConstraints
.push_back(maConstraint
);
1000 void RuleAtom::parseRule(std::vector
<Rule
>& rRules
) const
1002 if (!maRule
.msForName
.isEmpty())
1004 rRules
.push_back(maRule
);
1008 void AlgAtom::accept( LayoutAtomVisitor
& rVisitor
)
1010 rVisitor
.visit(*this);
1013 sal_Int32
AlgAtom::getConnectorType()
1015 sal_Int32 nConnRout
= 0;
1016 sal_Int32 nBegSty
= 0;
1017 sal_Int32 nEndSty
= 0;
1018 if (maMap
.count(oox::XML_connRout
))
1019 nConnRout
= maMap
.find(oox::XML_connRout
)->second
;
1020 if (maMap
.count(oox::XML_begSty
))
1021 nBegSty
= maMap
.find(oox::XML_begSty
)->second
;
1022 if (maMap
.count(oox::XML_endSty
))
1023 nEndSty
= maMap
.find(oox::XML_endSty
)->second
;
1025 if (nConnRout
== oox::XML_bend
)
1026 return 0; // was oox::XML_bentConnector3 - connectors are hidden in org chart as they don't work anyway
1027 if (nBegSty
== oox::XML_arr
&& nEndSty
== oox::XML_arr
)
1028 return oox::XML_leftRightArrow
;
1029 if (nBegSty
== oox::XML_arr
)
1030 return oox::XML_leftArrow
;
1031 if (nEndSty
== oox::XML_arr
)
1032 return oox::XML_rightArrow
;
1034 return oox::XML_rightArrow
;
1037 sal_Int32
AlgAtom::getVerticalShapesCount(const ShapePtr
& rShape
)
1039 if (rShape
->getChildren().empty())
1040 return (rShape
->getSubType() != XML_conn
) ? 1 : 0;
1042 sal_Int32 nDir
= XML_fromL
;
1043 if (mnType
== XML_hierRoot
)
1045 else if (maMap
.count(XML_linDir
))
1046 nDir
= maMap
.find(XML_linDir
)->second
;
1048 const sal_Int32 nSecDir
= maMap
.count(XML_secLinDir
) ? maMap
.find(XML_secLinDir
)->second
: 0;
1050 sal_Int32 nCount
= 0;
1051 if (nDir
== XML_fromT
|| nDir
== XML_fromB
)
1053 for (const ShapePtr
& pChild
: rShape
->getChildren())
1054 nCount
+= pChild
->getVerticalShapesCount();
1056 else if ((nDir
== XML_fromL
|| nDir
== XML_fromR
) && nSecDir
== XML_fromT
)
1058 for (const ShapePtr
& pChild
: rShape
->getChildren())
1059 nCount
+= pChild
->getVerticalShapesCount();
1060 nCount
= (nCount
+ 1) / 2;
1064 for (const ShapePtr
& pChild
: rShape
->getChildren())
1065 nCount
= std::max(nCount
, pChild
->getVerticalShapesCount());
1073 /// Does the first data node of this shape have customized text properties?
1074 bool HasCustomText(const ShapePtr
& rShape
, LayoutNode
& rLayoutNode
)
1076 const PresPointShapeMap
& rPresPointShapeMap
1077 = rLayoutNode
.getDiagram().getLayout()->getPresPointShapeMap();
1078 const DiagramData::StringMap
& rPresOfNameMap
1079 = rLayoutNode
.getDiagram().getData()->getPresOfNameMap();
1080 const DiagramData::PointNameMap
& rPointNameMap
1081 = rLayoutNode
.getDiagram().getData()->getPointNameMap();
1082 // Get the first presentation node of the shape.
1083 const svx::diagram::Point
* pPresNode
= nullptr;
1084 for (const auto& rPair
: rPresPointShapeMap
)
1086 if (rPair
.second
== rShape
)
1088 pPresNode
= rPair
.first
;
1092 // Get the first data node of the presentation node.
1093 svx::diagram::Point
* pDataNode
= nullptr;
1096 auto itPresToData
= rPresOfNameMap
.find(pPresNode
->msModelId
);
1097 if (itPresToData
!= rPresOfNameMap
.end())
1099 for (const auto& rPair
: itPresToData
->second
)
1101 const DiagramData::SourceIdAndDepth
& rItem
= rPair
.second
;
1102 auto it
= rPointNameMap
.find(rItem
.msSourceId
);
1103 if (it
!= rPointNameMap
.end())
1105 pDataNode
= it
->second
;
1112 // If we have a data node, see if its text is customized or not.
1115 return pDataNode
->mbCustomText
;
1122 void AlgAtom::layoutShape(const ShapePtr
& rShape
, const std::vector
<Constraint
>& rConstraints
,
1123 const std::vector
<Rule
>& rRules
)
1125 if (mnType
!= XML_lin
)
1127 // TODO Handle spacing from constraints for non-lin algorithms as well.
1129 rShape
->getChildren(),
1130 [](const ShapePtr
& aChild
) {
1131 return aChild
->getServiceName() == "com.sun.star.drawing.GroupShape"
1132 && aChild
->getChildren().empty();
1140 CompositeAlg::layoutShapeChildren(*this, rShape
, rConstraints
);
1146 if (rShape
->getSubType() == XML_conn
)
1148 // There is no shape type "conn", replace it by an arrow based
1149 // on the direction of the parent linear layout.
1150 sal_Int32 nType
= getConnectorType();
1152 rShape
->setSubType(nType
);
1153 rShape
->getCustomShapeProperties()->setShapePresetType(nType
);
1156 // Parse constraints to adjust the size.
1157 std::vector
<Constraint
> aDirectConstraints
;
1158 const LayoutNode
& rLayoutNode
= getLayoutNode();
1159 for (const auto& pChild
: rLayoutNode
.getChildren())
1161 auto pConstraintAtom
= dynamic_cast<ConstraintAtom
*>(pChild
.get());
1162 if (pConstraintAtom
)
1163 pConstraintAtom
->parseConstraint(aDirectConstraints
, /*bRequireForName=*/false);
1166 LayoutPropertyMap aProperties
;
1167 LayoutProperty
& rParent
= aProperties
[u
""_ustr
];
1168 rParent
[XML_w
] = rShape
->getSize().Width
;
1169 rParent
[XML_h
] = rShape
->getSize().Height
;
1172 rParent
[XML_r
] = rShape
->getSize().Width
;
1173 rParent
[XML_b
] = rShape
->getSize().Height
;
1174 for (const auto& rConstr
: aDirectConstraints
)
1176 const LayoutPropertyMap::const_iterator aRef
1177 = aProperties
.find(rConstr
.msRefForName
);
1178 if (aRef
!= aProperties
.end())
1180 const LayoutProperty::const_iterator aRefType
1181 = aRef
->second
.find(rConstr
.mnRefType
);
1182 if (aRefType
!= aRef
->second
.end())
1183 aProperties
[rConstr
.msForName
][rConstr
.mnType
]
1184 = aRefType
->second
* rConstr
.mfFactor
;
1188 aSize
.Width
= rParent
[XML_w
];
1189 aSize
.Height
= rParent
[XML_h
];
1190 // keep center position
1191 awt::Point aPos
= rShape
->getPosition();
1192 aPos
.X
+= (rShape
->getSize().Width
- aSize
.Width
) / 2;
1193 aPos
.Y
+= (rShape
->getSize().Height
- aSize
.Height
) / 2;
1194 rShape
->setPosition(aPos
);
1195 rShape
->setSize(aSize
);
1201 if (rShape
->getChildren().empty())
1204 const sal_Int32 nStartAngle
= maMap
.count(XML_stAng
) ? maMap
.find(XML_stAng
)->second
: 0;
1205 const sal_Int32 nSpanAngle
= maMap
.count(XML_spanAng
) ? maMap
.find(XML_spanAng
)->second
: 360;
1206 const sal_Int32 nRotationPath
= maMap
.count(XML_rotPath
) ? maMap
.find(XML_rotPath
)->second
: XML_none
;
1207 const sal_Int32 nctrShpMap
= maMap
.count(XML_ctrShpMap
) ? maMap
.find(XML_ctrShpMap
)->second
: XML_none
;
1208 const awt::Size
aCenter(rShape
->getSize().Width
/ 2, rShape
->getSize().Height
/ 2);
1209 const awt::Size
aChildSize(rShape
->getSize().Width
/ 4, rShape
->getSize().Height
/ 4);
1210 const awt::Size
aConnectorSize(rShape
->getSize().Width
/ 12, rShape
->getSize().Height
/ 12);
1211 const sal_Int32 nRadius
= std::min(
1212 (rShape
->getSize().Width
- aChildSize
.Width
) / 2,
1213 (rShape
->getSize().Height
- aChildSize
.Height
) / 2);
1215 std::vector
<oox::drawingml::ShapePtr
> aCycleChildren
= rShape
->getChildren();
1217 if (nctrShpMap
== XML_fNode
)
1219 // first node placed in center, others around
1220 oox::drawingml::ShapePtr pCenterShape
= aCycleChildren
.front();
1221 aCycleChildren
.erase(aCycleChildren
.begin());
1222 const awt::Point
aCurrPos(aCenter
.Width
- aChildSize
.Width
/ 2,
1223 aCenter
.Height
- aChildSize
.Height
/ 2);
1224 pCenterShape
->setPosition(aCurrPos
);
1225 pCenterShape
->setSize(aChildSize
);
1226 pCenterShape
->setChildSize(aChildSize
);
1229 const sal_Int32 nShapes
= aCycleChildren
.size();
1232 const sal_Int32 nConnectorRadius
= nRadius
* cos(basegfx::deg2rad(nSpanAngle
/ nShapes
));
1233 const sal_Int32 nConnectorAngle
= nSpanAngle
> 0 ? 0 : 180;
1236 for (auto & aCurrShape
: aCycleChildren
)
1238 const double fAngle
= static_cast<double>(idx
)*nSpanAngle
/nShapes
+ nStartAngle
;
1239 awt::Size aCurrSize
= aChildSize
;
1240 sal_Int32 nCurrRadius
= nRadius
;
1241 if (aCurrShape
->getSubType() == XML_conn
)
1243 aCurrSize
= aConnectorSize
;
1244 nCurrRadius
= nConnectorRadius
;
1246 const awt::Point
aCurrPos(
1247 aCenter
.Width
+ nCurrRadius
*sin(basegfx::deg2rad(fAngle
)) - aCurrSize
.Width
/2,
1248 aCenter
.Height
- nCurrRadius
*cos(basegfx::deg2rad(fAngle
)) - aCurrSize
.Height
/2);
1250 aCurrShape
->setPosition(aCurrPos
);
1251 aCurrShape
->setSize(aCurrSize
);
1252 aCurrShape
->setChildSize(aCurrSize
);
1254 if (nRotationPath
== XML_alongPath
)
1255 aCurrShape
->setRotation(fAngle
* PER_DEGREE
);
1257 // connectors should be handled in conn, but we don't have
1258 // reference to previous and next child, so it's easier here
1259 if (aCurrShape
->getSubType() == XML_conn
)
1260 aCurrShape
->setRotation((nConnectorAngle
+ fAngle
) * PER_DEGREE
);
1271 if (rShape
->getChildren().empty() || rShape
->getSize().Width
== 0 || rShape
->getSize().Height
== 0)
1274 // hierRoot is the manager -> employees vertical linear path,
1275 // hierChild is the first employee -> last employee horizontal
1277 sal_Int32 nDir
= XML_fromL
;
1278 if (mnType
== XML_hierRoot
)
1280 else if (maMap
.count(XML_linDir
))
1281 nDir
= maMap
.find(XML_linDir
)->second
;
1283 const sal_Int32 nSecDir
= maMap
.count(XML_secLinDir
) ? maMap
.find(XML_secLinDir
)->second
: 0;
1285 sal_Int32 nCount
= rShape
->getChildren().size();
1287 if (mnType
== XML_hierChild
)
1289 // Connectors should not influence the size of non-connect shapes.
1290 nCount
= std::count_if(
1291 rShape
->getChildren().begin(), rShape
->getChildren().end(),
1292 [](const ShapePtr
& pShape
) { return pShape
->getSubType() != XML_conn
; });
1295 const double fSpaceWidth
= 0.1;
1296 const double fSpaceHeight
= 0.3;
1298 if (mnType
== XML_hierRoot
&& nCount
== 3)
1300 // Order assistant nodes above employee nodes.
1301 std::vector
<ShapePtr
>& rChildren
= rShape
->getChildren();
1302 if (!containsDataNodeType(rChildren
[1], XML_asst
)
1303 && containsDataNodeType(rChildren
[2], XML_asst
))
1304 std::swap(rChildren
[1], rChildren
[2]);
1307 sal_Int32 nHorizontalShapesCount
= 1;
1308 if (nSecDir
== XML_fromT
)
1309 nHorizontalShapesCount
= 2;
1310 else if (nDir
== XML_fromL
|| nDir
== XML_fromR
)
1311 nHorizontalShapesCount
= nCount
;
1313 awt::Size aChildSize
= rShape
->getSize();
1314 aChildSize
.Height
/= (rShape
->getVerticalShapesCount() + (rShape
->getVerticalShapesCount() - 1) * fSpaceHeight
);
1315 aChildSize
.Width
/= (nHorizontalShapesCount
+ (nHorizontalShapesCount
- 1) * fSpaceWidth
);
1317 awt::Size aConnectorSize
= aChildSize
;
1318 aConnectorSize
.Width
= 1;
1320 awt::Point
aChildPos(0, 0);
1322 // indent children to show they are descendants, not siblings
1323 if (mnType
== XML_hierChild
&& nHorizontalShapesCount
== 1)
1325 const double fChildIndent
= 0.1;
1326 aChildPos
.X
= aChildSize
.Width
* fChildIndent
;
1327 aChildSize
.Width
*= (1 - 2 * fChildIndent
);
1331 sal_Int32 nRowHeight
= 0;
1332 for (auto& pChild
: rShape
->getChildren())
1334 pChild
->setPosition(aChildPos
);
1336 if (mnType
== XML_hierChild
&& pChild
->getSubType() == XML_conn
)
1338 // Connectors should not influence the position of
1339 // non-connect shapes.
1340 pChild
->setSize(aConnectorSize
);
1341 pChild
->setChildSize(aConnectorSize
);
1345 awt::Size aCurrSize
= aChildSize
;
1346 aCurrSize
.Height
*= pChild
->getVerticalShapesCount() + (pChild
->getVerticalShapesCount() - 1) * fSpaceHeight
;
1348 pChild
->setSize(aCurrSize
);
1349 pChild
->setChildSize(aCurrSize
);
1351 if (nDir
== XML_fromT
|| nDir
== XML_fromB
)
1352 aChildPos
.Y
+= aCurrSize
.Height
+ aChildSize
.Height
* fSpaceHeight
;
1354 aChildPos
.X
+= aCurrSize
.Width
+ aCurrSize
.Width
* fSpaceWidth
;
1356 nRowHeight
= std::max(nRowHeight
, aCurrSize
.Height
);
1358 if (nSecDir
== XML_fromT
&& nIdx
% 2 == 1)
1361 aChildPos
.Y
+= nRowHeight
+ aChildSize
.Height
* fSpaceHeight
;
1373 // spread children evenly across one axis, stretch across second
1375 if (rShape
->getChildren().empty() || rShape
->getSize().Width
== 0 || rShape
->getSize().Height
== 0)
1378 const sal_Int32 nDir
= maMap
.count(XML_linDir
) ? maMap
.find(XML_linDir
)->second
: XML_fromL
;
1379 const sal_Int32 nIncX
= nDir
==XML_fromL
? 1 : (nDir
==XML_fromR
? -1 : 0);
1380 const sal_Int32 nIncY
= nDir
==XML_fromT
? 1 : (nDir
==XML_fromB
? -1 : 0);
1382 double fCount
= rShape
->getChildren().size();
1383 sal_Int32 nConnectorAngle
= 0;
1386 case XML_fromL
: nConnectorAngle
= 0; break;
1387 case XML_fromR
: nConnectorAngle
= 180; break;
1388 case XML_fromT
: nConnectorAngle
= 270; break;
1389 case XML_fromB
: nConnectorAngle
= 90; break;
1392 awt::Size aSpaceSize
;
1394 // Find out which constraint is relevant for which (internal) name.
1395 LayoutPropertyMap aProperties
;
1396 for (const auto& rConstraint
: rConstraints
)
1398 if (rConstraint
.msForName
.isEmpty())
1401 LayoutProperty
& rProperty
= aProperties
[rConstraint
.msForName
];
1402 if (rConstraint
.mnType
== XML_w
)
1404 rProperty
[XML_w
] = rShape
->getSize().Width
* rConstraint
.mfFactor
;
1405 if (rProperty
[XML_w
] > rShape
->getSize().Width
)
1407 rProperty
[XML_w
] = rShape
->getSize().Width
;
1410 if (rConstraint
.mnType
== XML_h
)
1412 rProperty
[XML_h
] = rShape
->getSize().Height
* rConstraint
.mfFactor
;
1413 if (rProperty
[XML_h
] > rShape
->getSize().Height
)
1415 rProperty
[XML_h
] = rShape
->getSize().Height
;
1419 if (rConstraint
.mnType
== XML_primFontSz
&& rConstraint
.mnFor
== XML_des
1420 && rConstraint
.mnOperator
== XML_equ
)
1422 NamedShapePairs
& rDiagramFontHeights
1423 = getLayoutNode().getDiagram().getDiagramFontHeights();
1424 auto it
= rDiagramFontHeights
.find(rConstraint
.msForName
);
1425 if (it
== rDiagramFontHeights
.end())
1427 // Start tracking all shapes with this internal name: they'll have the same
1429 rDiagramFontHeights
[rConstraint
.msForName
] = {};
1433 // TODO: get values from differently named constraints as well
1434 if (rConstraint
.msForName
== "sp" || rConstraint
.msForName
== "space" || rConstraint
.msForName
== "sibTrans")
1436 if (rConstraint
.mnType
== XML_w
)
1437 aSpaceSize
.Width
= rShape
->getSize().Width
* rConstraint
.mfFactor
;
1438 if (rConstraint
.mnType
== XML_h
)
1439 aSpaceSize
.Height
= rShape
->getSize().Height
* rConstraint
.mfFactor
;
1443 // first approximation of children size
1444 std::set
<OUString
> aChildrenToShrink
;
1445 for (const auto& rRule
: rRules
)
1447 // Consider rules: when scaling down, only change children where the rule allows
1449 aChildrenToShrink
.insert(rRule
.msForName
);
1452 if (nDir
== XML_fromT
|| nDir
== XML_fromB
)
1454 // TODO consider rules for vertical linear layout as well.
1455 aChildrenToShrink
.clear();
1458 if (!aChildrenToShrink
.empty())
1460 // Have scaling info from rules: then only count scaled children.
1461 // Also count children which are a fraction of a scaled child.
1462 std::set
<OUString
> aChildrenToShrinkDeps
;
1463 for (auto& aCurrShape
: rShape
->getChildren())
1465 if (aChildrenToShrink
.find(aCurrShape
->getInternalName())
1466 == aChildrenToShrink
.end())
1472 bool bIsDependency
= false;
1474 for (const auto& rConstraint
: rConstraints
)
1476 if (rConstraint
.msForName
!= aCurrShape
->getInternalName())
1481 if ((nDir
== XML_fromL
|| nDir
== XML_fromR
) && rConstraint
.mnType
!= XML_w
)
1485 if ((nDir
== XML_fromL
|| nDir
== XML_fromR
) && rConstraint
.mnType
== XML_w
)
1487 fFactor
= rConstraint
.mfFactor
;
1490 if ((nDir
== XML_fromT
|| nDir
== XML_fromB
) && rConstraint
.mnType
!= XML_h
)
1494 if ((nDir
== XML_fromT
|| nDir
== XML_fromB
) && rConstraint
.mnType
== XML_h
)
1496 fFactor
= rConstraint
.mfFactor
;
1499 if (aChildrenToShrink
.find(rConstraint
.msRefForName
) == aChildrenToShrink
.end())
1504 // At this point we have a child with a size which is a factor of an
1505 // other child which will be scaled.
1506 fCount
+= rConstraint
.mfFactor
;
1507 aChildrenToShrinkDeps
.insert(aCurrShape
->getInternalName());
1508 bIsDependency
= true;
1512 if (!bIsDependency
&& aCurrShape
->getServiceName() == "com.sun.star.drawing.GroupShape")
1514 bool bScaleDownEmptySpacing
= false;
1515 if (nDir
== XML_fromL
|| nDir
== XML_fromR
)
1517 std::optional
<sal_Int32
> oWidth
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_w
);
1518 bScaleDownEmptySpacing
= oWidth
.has_value() && oWidth
.value() > 0;
1520 if (!bScaleDownEmptySpacing
&& (nDir
== XML_fromT
|| nDir
== XML_fromB
))
1522 std::optional
<sal_Int32
> oHeight
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_h
);
1523 bScaleDownEmptySpacing
= oHeight
.has_value() && oHeight
.value() > 0;
1525 if (bScaleDownEmptySpacing
&& aCurrShape
->getChildren().empty())
1528 aChildrenToShrinkDeps
.insert(aCurrShape
->getInternalName());
1535 aChildrenToShrink
.insert(aChildrenToShrinkDeps
.begin(), aChildrenToShrinkDeps
.end());
1537 // No manual spacing: spacings are children as well.
1538 aSpaceSize
= awt::Size();
1542 // TODO Handle spacing from constraints without rules as well.
1544 rShape
->getChildren(),
1545 [](const ShapePtr
& aChild
) {
1546 return aChild
->getServiceName()
1547 == "com.sun.star.drawing.GroupShape"
1548 && aChild
->getChildren().empty();
1550 fCount
= rShape
->getChildren().size();
1552 awt::Size aChildSize
= rShape
->getSize();
1553 if (nDir
== XML_fromL
|| nDir
== XML_fromR
)
1554 aChildSize
.Width
/= fCount
;
1555 else if (nDir
== XML_fromT
|| nDir
== XML_fromB
)
1556 aChildSize
.Height
/= fCount
;
1558 awt::Point
aCurrPos(0, 0);
1560 aCurrPos
.X
= rShape
->getSize().Width
- aChildSize
.Width
;
1562 aCurrPos
.Y
= rShape
->getSize().Height
- aChildSize
.Height
;
1564 // See if children requested more than 100% space in total: scale
1565 // down in that case.
1566 awt::Size aTotalSize
;
1567 for (const auto & aCurrShape
: rShape
->getChildren())
1569 std::optional
<sal_Int32
> oWidth
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_w
);
1570 std::optional
<sal_Int32
> oHeight
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_h
);
1571 awt::Size aSize
= aChildSize
;
1572 if (oWidth
.has_value())
1573 aSize
.Width
= oWidth
.value();
1574 if (oHeight
.has_value())
1575 aSize
.Height
= oHeight
.value();
1576 aTotalSize
.Width
+= aSize
.Width
;
1577 aTotalSize
.Height
+= aSize
.Height
;
1580 aTotalSize
.Width
+= (fCount
-1) * aSpaceSize
.Width
;
1581 aTotalSize
.Height
+= (fCount
-1) * aSpaceSize
.Height
;
1583 double fWidthScale
= 1.0;
1584 double fHeightScale
= 1.0;
1585 if (nIncX
&& aTotalSize
.Width
> rShape
->getSize().Width
)
1586 fWidthScale
= static_cast<double>(rShape
->getSize().Width
) / aTotalSize
.Width
;
1587 if (nIncY
&& aTotalSize
.Height
> rShape
->getSize().Height
)
1588 fHeightScale
= static_cast<double>(rShape
->getSize().Height
) / aTotalSize
.Height
;
1589 aSpaceSize
.Width
*= fWidthScale
;
1590 aSpaceSize
.Height
*= fHeightScale
;
1592 for (auto& aCurrShape
: rShape
->getChildren())
1594 // Extract properties relevant for this shape from constraints.
1595 std::optional
<sal_Int32
> oWidth
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_w
);
1596 std::optional
<sal_Int32
> oHeight
= findProperty(aProperties
, aCurrShape
->getInternalName(), XML_h
);
1598 awt::Size aSize
= aChildSize
;
1599 if (oWidth
.has_value())
1600 aSize
.Width
= oWidth
.value();
1601 if (oHeight
.has_value())
1602 aSize
.Height
= oHeight
.value();
1603 if (aChildrenToShrink
.empty()
1604 || aChildrenToShrink
.find(aCurrShape
->getInternalName())
1605 != aChildrenToShrink
.end())
1607 aSize
.Width
*= fWidthScale
;
1609 if (aChildrenToShrink
.empty()
1610 || aChildrenToShrink
.find(aCurrShape
->getInternalName())
1611 != aChildrenToShrink
.end())
1613 aSize
.Height
*= fHeightScale
;
1615 aCurrShape
->setSize(aSize
);
1616 aCurrShape
->setChildSize(aSize
);
1618 // center in the other axis - probably some parameter controls it
1620 aCurrPos
.Y
= (rShape
->getSize().Height
- aSize
.Height
) / 2;
1622 aCurrPos
.X
= (rShape
->getSize().Width
- aSize
.Width
) / 2;
1632 aCurrShape
->setPosition(aCurrPos
);
1634 aCurrPos
.X
+= nIncX
* (aSize
.Width
+ aSpaceSize
.Width
);
1635 aCurrPos
.Y
+= nIncY
* (aSize
.Height
+ aSpaceSize
.Height
);
1637 // connectors should be handled in conn, but we don't have
1638 // reference to previous and next child, so it's easier here
1639 if (aCurrShape
->getSubType() == XML_conn
)
1640 aCurrShape
->setRotation(nConnectorAngle
* PER_DEGREE
);
1643 // Newer shapes are behind older ones by default. Reverse this if requested.
1644 sal_Int32 nChildOrder
= XML_b
;
1645 const LayoutNode
* pParentLayoutNode
= nullptr;
1646 for (LayoutAtomPtr pAtom
= getParent(); pAtom
; pAtom
= pAtom
->getParent())
1648 auto pLayoutNode
= dynamic_cast<LayoutNode
*>(pAtom
.get());
1651 pParentLayoutNode
= pLayoutNode
;
1655 if (pParentLayoutNode
)
1657 nChildOrder
= pParentLayoutNode
->getChildOrder();
1659 if (nChildOrder
== XML_t
)
1661 std::reverse(rShape
->getChildren().begin(), rShape
->getChildren().end());
1669 PyraAlg::layoutShapeChildren(rShape
);
1675 SnakeAlg::layoutShapeChildren(*this, rShape
, rConstraints
);
1681 // HACK: Handled one level higher. Or rather, planned to
1682 // HACK: text should appear only in tx node; we're assigning it earlier, so let's remove it here
1683 rShape
->setTextBody(TextBodyPtr());
1689 // adjust text alignment
1691 // Parse constraints, only self margins as a start.
1692 double fFontSize
= 0;
1693 for (const auto& rConstr
: rConstraints
)
1695 if (rConstr
.mnRefType
== XML_w
)
1697 if (!rConstr
.msForName
.isEmpty())
1700 sal_Int32 nProperty
= getPropertyFromConstraint(rConstr
.mnType
);
1704 // PowerPoint takes size as points, but gives margin as MMs.
1705 double fFactor
= convertPointToMms(rConstr
.mfFactor
);
1707 // DrawingML works in EMUs, UNO API works in MM100s.
1708 sal_Int32 nValue
= o3tl::convert(rShape
->getSize().Width
* fFactor
,
1709 o3tl::Length::emu
, o3tl::Length::mm100
);
1711 rShape
->getShapeProperties().setProperty(nProperty
, nValue
);
1713 if (rConstr
.mnType
== XML_primFontSz
)
1714 fFontSize
= rConstr
.mfValue
;
1717 TextBodyPtr pTextBody
= rShape
->getTextBody();
1718 if (!pTextBody
|| pTextBody
->isEmpty())
1721 // adjust text size to fit shape
1724 for (auto& aParagraph
: pTextBody
->getParagraphs())
1725 for (auto& aRun
: aParagraph
->getRuns())
1726 if (!aRun
->getTextCharacterProperties().moHeight
.has_value())
1727 aRun
->getTextCharacterProperties().moHeight
= fFontSize
* 100;
1730 if (!HasCustomText(rShape
, getLayoutNode()))
1732 // No customized text properties: enable autofit.
1733 pTextBody
->getTextProperties().maPropertyMap
.setProperty(
1734 PROP_TextFitToSize
, drawing::TextFitToSizeType_AUTOFIT
);
1737 // ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text Rotation)
1738 const sal_Int32 nautoTxRot
= maMap
.count(XML_autoTxRot
) ? maMap
.find(XML_autoTxRot
)->second
: XML_upr
;
1739 sal_Int32 nShapeRot
= rShape
->getRotation();
1740 while (nShapeRot
< 0)
1741 nShapeRot
+= 360 * PER_DEGREE
;
1742 while (nShapeRot
> 360 * PER_DEGREE
)
1743 nShapeRot
-= 360 * PER_DEGREE
;
1750 if (nShapeRot
>= 315 * PER_DEGREE
)
1752 else if (nShapeRot
> 225 * PER_DEGREE
)
1754 else if (nShapeRot
>= 135 * PER_DEGREE
)
1756 else if (nShapeRot
> 45 * PER_DEGREE
)
1758 pTextBody
->getTextProperties().moTextPreRotation
= n90x
* 90 * PER_DEGREE
;
1763 if (nShapeRot
> (90 * PER_DEGREE
) && nShapeRot
< (270 * PER_DEGREE
))
1764 pTextBody
->getTextProperties().moTextPreRotation
= -180 * PER_DEGREE
;
1771 const sal_Int32 atxAnchorVert
= maMap
.count(XML_txAnchorVert
) ? maMap
.find(XML_txAnchorVert
)->second
: XML_mid
;
1773 switch(atxAnchorVert
)
1776 pTextBody
->getTextProperties().meVA
= css::drawing::TextVerticalAdjust_TOP
;
1779 pTextBody
->getTextProperties().meVA
= css::drawing::TextVerticalAdjust_BOTTOM
;
1782 // text centered vertically by default
1784 pTextBody
->getTextProperties().meVA
= css::drawing::TextVerticalAdjust_CENTER
;
1788 pTextBody
->getTextProperties().maPropertyMap
.setProperty(PROP_TextVerticalAdjust
, pTextBody
->getTextProperties().meVA
);
1790 // normalize list level
1791 sal_Int32 nBaseLevel
= pTextBody
->getParagraphs().front()->getProperties().getLevel();
1792 for (auto & aParagraph
: pTextBody
->getParagraphs())
1794 if (aParagraph
->getProperties().getLevel() < nBaseLevel
)
1795 nBaseLevel
= aParagraph
->getProperties().getLevel();
1798 // Start bullets at:
1800 // 2 - with children (default)
1801 int nStartBulletsAtLevel
= 2;
1802 ParamMap::const_iterator aBulletLvl
= maMap
.find(XML_stBulletLvl
);
1803 if (aBulletLvl
!= maMap
.end())
1804 nStartBulletsAtLevel
= aBulletLvl
->second
;
1805 nStartBulletsAtLevel
--;
1807 bool isBulletList
= false;
1808 for (auto & aParagraph
: pTextBody
->getParagraphs())
1810 sal_Int32 nLevel
= aParagraph
->getProperties().getLevel() - nBaseLevel
;
1811 aParagraph
->getProperties().setLevel(nLevel
);
1812 if (nLevel
>= nStartBulletsAtLevel
)
1814 if (!aParagraph
->getProperties().getParaLeftMargin().has_value())
1816 sal_Int32 nLeftMargin
1817 = o3tl::convert(285750 * (nLevel
- nStartBulletsAtLevel
+ 1),
1818 o3tl::Length::emu
, o3tl::Length::mm100
);
1819 aParagraph
->getProperties().getParaLeftMargin() = nLeftMargin
;
1822 if (!aParagraph
->getProperties().getFirstLineIndentation().has_value())
1823 aParagraph
->getProperties().getFirstLineIndentation()
1824 = o3tl::convert(-285750, o3tl::Length::emu
, o3tl::Length::mm100
);
1826 // It is not possible to change the bullet style for text.
1827 aParagraph
->getProperties().getBulletList().setBulletChar(u
"•"_ustr
);
1828 aParagraph
->getProperties().getBulletList().setSuffixNone();
1829 isBulletList
= true;
1833 // explicit alignment
1834 ParamMap::const_iterator aDir
= maMap
.find(XML_parTxLTRAlign
);
1835 // TODO: XML_parTxRTLAlign
1836 if (aDir
!= maMap
.end())
1838 css::style::ParagraphAdjust aAlignment
= GetParaAdjust(aDir
->second
);
1839 for (auto & aParagraph
: pTextBody
->getParagraphs())
1840 aParagraph
->getProperties().setParaAdjust(aAlignment
);
1842 else if (!isBulletList
)
1844 // if not list use default alignment - centered
1845 for (auto & aParagraph
: pTextBody
->getParagraphs())
1846 aParagraph
->getProperties().setParaAdjust(css::style::ParagraphAdjust::ParagraphAdjust_CENTER
);
1857 "Layouting shape " << rShape
->getInternalName() << ", alg type: " << mnType
<< ", ("
1858 << rShape
->getPosition().X
<< "," << rShape
->getPosition().Y
<< ","
1859 << rShape
->getSize().Width
<< "," << rShape
->getSize().Height
<< ")");
1862 void LayoutNode::accept( LayoutAtomVisitor
& rVisitor
)
1864 rVisitor
.visit(*this);
1867 bool LayoutNode::setupShape( const ShapePtr
& rShape
, const svx::diagram::Point
* pPresNode
, sal_Int32 nCurrIdx
) const
1871 "Filling content from layout node named \"" << msName
1872 << "\", modelId \"" << pPresNode
->msModelId
<< "\"");
1874 // have the presentation node - now, need the actual data node:
1875 const DiagramData::StringMap::const_iterator aNodeName
= mrDgm
.getData()->getPresOfNameMap().find(
1876 pPresNode
->msModelId
);
1877 if( aNodeName
!= mrDgm
.getData()->getPresOfNameMap().end() )
1879 // Calculate the depth of what is effectively the topmost element.
1880 sal_Int32 nMinDepth
= std::numeric_limits
<sal_Int32
>::max();
1881 for (const auto& rPair
: aNodeName
->second
)
1883 if (rPair
.second
.mnDepth
< nMinDepth
)
1884 nMinDepth
= rPair
.second
.mnDepth
;
1887 for (const auto& rPair
: aNodeName
->second
)
1889 const DiagramData::SourceIdAndDepth
& rItem
= rPair
.second
;
1890 DiagramData::PointNameMap
& rMap
= mrDgm
.getData()->getPointNameMap();
1891 // pPresNode is the presentation node of the aDataNode2 data node.
1892 DiagramData::PointNameMap::const_iterator aDataNode2
= rMap
.find(rItem
.msSourceId
);
1893 if (aDataNode2
== rMap
.end())
1899 Shape
* pDataNode2Shape(mrDgm
.getData()->getOrCreateAssociatedShape(*aDataNode2
->second
));
1900 if (nullptr == pDataNode2Shape
)
1906 rShape
->setDataNodeType(aDataNode2
->second
->mnXMLType
);
1908 if (rItem
.mnDepth
== 0)
1910 // grab shape attr from topmost element(s)
1911 rShape
->getShapeProperties() = pDataNode2Shape
->getShapeProperties();
1912 rShape
->getLineProperties() = pDataNode2Shape
->getLineProperties();
1913 rShape
->getFillProperties() = pDataNode2Shape
->getFillProperties();
1914 rShape
->getCustomShapeProperties() = pDataNode2Shape
->getCustomShapeProperties();
1915 rShape
->setMasterTextListStyle( pDataNode2Shape
->getMasterTextListStyle() );
1919 "Custom shape with preset type "
1920 << (rShape
->getCustomShapeProperties()
1921 ->getShapePresetType())
1922 << " added for layout node named \"" << msName
1925 else if (rItem
.mnDepth
== nMinDepth
)
1927 // If no real topmost element, then take properties from the one that's the closest
1929 rShape
->getLineProperties() = pDataNode2Shape
->getLineProperties();
1930 rShape
->getFillProperties() = pDataNode2Shape
->getFillProperties();
1933 // append text with right outline level
1934 if( pDataNode2Shape
->getTextBody() &&
1935 !pDataNode2Shape
->getTextBody()->getParagraphs().empty() &&
1936 !pDataNode2Shape
->getTextBody()->getParagraphs().front()->getRuns().empty() )
1938 TextBodyPtr pTextBody
=rShape
->getTextBody();
1941 pTextBody
= std::make_shared
<TextBody
>();
1943 // also copy text attrs
1944 pTextBody
->getTextListStyle() =
1945 pDataNode2Shape
->getTextBody()->getTextListStyle();
1946 pTextBody
->getTextProperties() =
1947 pDataNode2Shape
->getTextBody()->getTextProperties();
1949 rShape
->setTextBody(pTextBody
);
1952 const TextParagraphVector
& rSourceParagraphs
1953 = pDataNode2Shape
->getTextBody()->getParagraphs();
1954 for (const auto& pSourceParagraph
: rSourceParagraphs
)
1956 TextParagraph
& rPara
= pTextBody
->addParagraph();
1957 if (rItem
.mnDepth
!= -1)
1958 rPara
.getProperties().setLevel(rItem
.mnDepth
);
1960 for (const auto& pRun
: pSourceParagraph
->getRuns())
1962 const TextBodyPtr
& rBody
= pDataNode2Shape
->getTextBody();
1963 rPara
.getProperties().apply(rBody
->getParagraphs().front()->getProperties());
1972 "ShapeCreationVisitor::visit: no data node name found while"
1973 " processing shape type "
1974 << rShape
->getCustomShapeProperties()->getShapePresetType()
1975 << " for layout node named \"" << msName
<< "\"");
1976 Shape
* pPresNodeShape(mrDgm
.getData()->getOrCreateAssociatedShape(*pPresNode
));
1977 if (nullptr != pPresNodeShape
)
1978 rShape
->getFillProperties().assignUsed(pPresNodeShape
->getFillProperties());
1981 // TODO(Q1): apply styling & coloring - take presentation
1982 // point's presStyleLbl for both style & color
1983 // if not found use layout node's styleLbl
1984 // however, docs are a bit unclear on this
1985 OUString aStyleLabel
= pPresNode
->msPresentationLayoutStyleLabel
;
1986 if (aStyleLabel
.isEmpty())
1987 aStyleLabel
= msStyleLabel
;
1988 if( !aStyleLabel
.isEmpty() )
1990 const DiagramQStyleMap::const_iterator aStyle
= mrDgm
.getStyles().find(aStyleLabel
);
1991 if( aStyle
!= mrDgm
.getStyles().end() )
1993 const DiagramStyle
& rStyle
= aStyle
->second
;
1994 rShape
->getShapeStyleRefs()[XML_fillRef
] = rStyle
.maFillStyle
;
1995 rShape
->getShapeStyleRefs()[XML_lnRef
] = rStyle
.maLineStyle
;
1996 rShape
->getShapeStyleRefs()[XML_effectRef
] = rStyle
.maEffectStyle
;
1997 rShape
->getShapeStyleRefs()[XML_fontRef
] = rStyle
.maTextStyle
;
2001 SAL_WARN("oox.drawingml", "Style " << aStyleLabel
<< " not found");
2004 const DiagramColorMap::const_iterator aColor
= mrDgm
.getColors().find(aStyleLabel
);
2005 if( aColor
!= mrDgm
.getColors().end() )
2007 // Take the nth color from the color list in case we are the nth shape in a
2008 // <dgm:forEach> loop.
2009 const DiagramColor
& rColor
=aColor
->second
;
2010 if( !rColor
.maFillColors
.empty() )
2011 rShape
->getShapeStyleRefs()[XML_fillRef
].maPhClr
= DiagramColor::getColorByIndex(rColor
.maFillColors
, nCurrIdx
);
2012 if( !rColor
.maLineColors
.empty() )
2013 rShape
->getShapeStyleRefs()[XML_lnRef
].maPhClr
= DiagramColor::getColorByIndex(rColor
.maLineColors
, nCurrIdx
);
2014 if( !rColor
.maEffectColors
.empty() )
2015 rShape
->getShapeStyleRefs()[XML_effectRef
].maPhClr
= DiagramColor::getColorByIndex(rColor
.maEffectColors
, nCurrIdx
);
2016 if( !rColor
.maTextFillColors
.empty() )
2017 rShape
->getShapeStyleRefs()[XML_fontRef
].maPhClr
= DiagramColor::getColorByIndex(rColor
.maTextFillColors
, nCurrIdx
);
2021 // even if no data node found, successful anyway. it's
2022 // contained at the layoutnode
2026 const LayoutNode
* LayoutNode::getParentLayoutNode() const
2028 for (LayoutAtomPtr pAtom
= getParent(); pAtom
; pAtom
= pAtom
->getParent())
2030 auto pLayoutNode
= dynamic_cast<LayoutNode
*>(pAtom
.get());
2038 void ShapeAtom::accept( LayoutAtomVisitor
& rVisitor
)
2040 rVisitor
.visit(*this);
2045 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */