diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-07-31 15:59:10 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-08-05 10:45:38 +0200 |
commit | b193ca37569f0e916a9d827e8a78ebbba4577a5b (patch) | |
tree | ab85a3b7b021aeeaf9de391456cc35b923ab8ac3 /oox | |
parent | 34b0e97c25a943c2e4ba98750b970bee542f5819 (diff) |
oox smartart, linear layout: correctly scale spacings wrt constraints and rules
When constraints request a width which is larger than 100%, we scale
down. Then rules decide which children should be scaled down and which
ones stay as-is.
This commit adjusts the size of children which have no rule, but their
size has a constraint that they're a fraction of a scaled down child.
(cherry picked from commit 91f0f7e5e0a55cb1dbd729a1d7de52388b1cfb15)
Change-Id: I0a007d82f49f18951215afb1bfe8c0f1328ecd41
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100111
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index b748298f7c1c..fc1b58e24d27 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -906,7 +906,7 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>& const sal_Int32 nIncX = nDir==XML_fromL ? 1 : (nDir==XML_fromR ? -1 : 0); const sal_Int32 nIncY = nDir==XML_fromT ? 1 : (nDir==XML_fromB ? -1 : 0); - sal_Int32 nCount = rShape->getChildren().size(); + double fCount = rShape->getChildren().size(); sal_Int32 nConnectorAngle = 0; switch (nDir) { @@ -953,18 +953,50 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>& if (!aChildrenToShrink.empty()) { // Have scaling info from rules: then only count scaled children. + // Also count children which are a fraction of a scaled child. + std::set<OUString> aChildrenToShrinkDeps; for (auto& aCurrShape : rShape->getChildren()) { if (aChildrenToShrink.find(aCurrShape->getInternalName()) == aChildrenToShrink.end()) { - if (nCount > 1) + if (fCount > 1.0) { - --nCount; + fCount -= 1.0; + + for (const auto& rConstraint : rConstraints) + { + if (rConstraint.msForName != aCurrShape->getInternalName()) + { + continue; + } + + if (aChildrenToShrink.find(rConstraint.msRefForName) == aChildrenToShrink.end()) + { + continue; + } + + if ((nDir == XML_fromL || nDir == XML_fromR) && rConstraint.mnType != XML_w) + { + continue; + } + if ((nDir == XML_fromT || nDir == XML_fromB) && rConstraint.mnType != XML_h) + { + continue; + } + + // At this point we have a child with a size which is a factor of an + // other child which will be scaled. + fCount += rConstraint.mfFactor; + aChildrenToShrinkDeps.insert(aCurrShape->getInternalName()); + break; + } } } } + aChildrenToShrink.insert(aChildrenToShrinkDeps.begin(), aChildrenToShrinkDeps.end()); + // No manual spacing: spacings are children as well. aSpaceSize = awt::Size(); } @@ -979,13 +1011,13 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>& && aChild->getChildren().empty(); }), rShape->getChildren().end()); - nCount = rShape->getChildren().size(); + fCount = rShape->getChildren().size(); } awt::Size aChildSize = rShape->getSize(); if (nDir == XML_fromL || nDir == XML_fromR) - aChildSize.Width /= nCount; + aChildSize.Width /= fCount; else if (nDir == XML_fromT || nDir == XML_fromB) - aChildSize.Height /= nCount; + aChildSize.Height /= fCount; awt::Point aCurrPos(0, 0); if (nIncX == -1) @@ -1009,8 +1041,8 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>& aTotalSize.Height += aSize.Height; } - aTotalSize.Width += (nCount-1) * aSpaceSize.Width; - aTotalSize.Height += (nCount-1) * aSpaceSize.Height; + aTotalSize.Width += (fCount-1) * aSpaceSize.Width; + aTotalSize.Height += (fCount-1) * aSpaceSize.Height; double fWidthScale = 1.0; double fHeightScale = 1.0; |