diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-05-27 14:04:58 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-27 16:21:18 +0200 |
commit | acdde3c643fde015214c546b1567727272ea799e (patch) | |
tree | 78d6d1a0a78d7c723b7f59874ebd2c648dfd1deb /oox | |
parent | 3c0eaef5001ec155ad2f379e12440d822300dc13 (diff) |
oox smartart import, composite alg: implement vertical centering
The bugdoc's case was that the total height would be used by 2 shapes,
but then a constraint decreases the height of one shape, so not all
vertical space is used.
We used to just count from the top, need to center vertically, as
PowerPoint does it.
Change-Id: I436019e9e837b73130e387c9bcd309e20045b0f9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94948
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index 5e36f08d06ab..36b361db9a3b 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -478,6 +478,11 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, LayoutProperty& rParent = aProperties[""]; sal_Int32 nParentXOffset = 0; + + // Track min/max vertical positions, so we can center everything at the end, if needed. + sal_Int32 nVertMin = std::numeric_limits<sal_Int32>::max(); + sal_Int32 nVertMax = 0; + if (mfAspectRatio != 1.0) { rParent[XML_w] = rShape->getSize().Width; @@ -613,6 +618,24 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, aCurrShape->setSize(aSize); aCurrShape->setChildSize(aSize); aCurrShape->setPosition(aPos); + + nVertMin = std::min(aPos.Y, nVertMin); + nVertMax = std::max(aPos.Y + aSize.Height, nVertMax); + } + + // See if all vertical space is used or we have to center the content. + if (nVertMin >= 0 && nVertMax <= rParent[XML_h]) + { + sal_Int32 nDiff = rParent[XML_h] - (nVertMax - nVertMin); + if (nDiff > 0) + { + for (auto& aCurrShape : rShape->getChildren()) + { + awt::Point aPosition = aCurrShape->getPosition(); + aPosition.Y += nDiff / 2; + aCurrShape->setPosition(aPosition); + } + } } break; } |