diff options
author | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-05-30 13:29:08 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-06-03 14:15:55 +0200 |
commit | 55e531de9c1fecc73b8a42e18dda34aa4de02f8b (patch) | |
tree | 3de09b4e37b56ccee799ccda97d7d9aefbed5771 /oox | |
parent | 83d101158ef3726d005ae7bd47437ab22ad2a036 (diff) |
SmartArt: more constraints used in linear algorithm
* both width and height of children and space is taken from constraints
* better handling of space between children (not lost in some cases)
* children centered in the other axis
Change-Id: I25b8360790de0292b2b5c313dfa55e58dc042193
Reviewed-on: https://gerrit.libreoffice.org/73201
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/73259
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index e27c573b3d28..d7d6fda1e1e0 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -788,7 +788,8 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, const sal_Int32 nIncY = nDir==XML_fromT ? 1 : (nDir==XML_fromB ? -1 : 0); sal_Int32 nCount = rShape->getChildren().size(); - double fSpace = 0.3; + + awt::Size aSpaceSize; // Find out which constraint is relevant for which (internal) name. LayoutPropertyMap aProperties; @@ -800,17 +801,25 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, LayoutProperty& rProperty = aProperties[rConstraint.msForName]; if (rConstraint.mnType == XML_w) rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor; + if (rConstraint.mnType == XML_h) + rProperty[XML_h] = rShape->getSize().Height * rConstraint.mfFactor; // TODO: get values from differently named constraints as well - if (rConstraint.msForName == "sibTrans" && rConstraint.mnType == XML_w) - fSpace = rConstraint.mfFactor; + if (rConstraint.msForName == "sp" || rConstraint.msForName == "space" || rConstraint.msForName == "sibTrans") + { + if (rConstraint.mnType == XML_w) + aSpaceSize.Width = rShape->getSize().Width * rConstraint.mfFactor; + if (rConstraint.mnType == XML_h) + aSpaceSize.Height = rShape->getSize().Height * rConstraint.mfFactor; + } } + // first approximation of children size awt::Size aChildSize = rShape->getSize(); if (nDir == XML_fromL || nDir == XML_fromR) - aChildSize.Width /= (nCount + (nCount-1)*fSpace); + aChildSize.Width /= nCount; else if (nDir == XML_fromT || nDir == XML_fromB) - aChildSize.Height /= (nCount + (nCount-1)*fSpace); + aChildSize.Height /= nCount; awt::Point aCurrPos(0, 0); if (nIncX == -1) @@ -820,51 +829,58 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, // See if children requested more than 100% space in total: scale // down in that case. - sal_Int32 nTotalWidth = 0; - bool bSpaceFromConstraints = false; + awt::Size aTotalSize; for (auto & aCurrShape : rShape->getChildren()) { - oox::OptValue<sal_Int32> oWidth - = findProperty(aProperties, aCurrShape->getInternalName(), XML_w); - + oox::OptValue<sal_Int32> oWidth = findProperty(aProperties, aCurrShape->getInternalName(), XML_w); + oox::OptValue<sal_Int32> oHeight = findProperty(aProperties, aCurrShape->getInternalName(), XML_h); awt::Size aSize = aChildSize; if (oWidth.has()) - { aSize.Width = oWidth.get(); - bSpaceFromConstraints = true; - } - if (nDir == XML_fromL || nDir == XML_fromR) - nTotalWidth += aSize.Width; + if (oHeight.has()) + aSize.Height = oHeight.get(); + aTotalSize.Width += aSize.Width; + aTotalSize.Height += aSize.Height; } - double fWidthScale = 1.0; - if (nTotalWidth > rShape->getSize().Width && nTotalWidth) - { - fWidthScale = rShape->getSize().Width; - fWidthScale /= nTotalWidth; - } + aTotalSize.Width += (nCount-1) * aSpaceSize.Width; + aTotalSize.Height += (nCount-1) * aSpaceSize.Height; - // Don't add automatic space if we take space from constraints. - if (bSpaceFromConstraints) - fSpace = 0; + double fWidthScale = 1.0; + double fHeightScale = 1.0; + if (nIncX && aTotalSize.Width > rShape->getSize().Width) + fWidthScale = static_cast<double>(rShape->getSize().Width) / aTotalSize.Width; + if (nIncY && aTotalSize.Height > rShape->getSize().Height) + fHeightScale = static_cast<double>(rShape->getSize().Height) / aTotalSize.Height; + aSpaceSize.Width *= fWidthScale; + aSpaceSize.Height *= fHeightScale; for (auto& aCurrShape : rShape->getChildren()) { // Extract properties relevant for this shape from constraints. - oox::OptValue<sal_Int32> oWidth - = findProperty(aProperties, aCurrShape->getInternalName(), XML_w); - - aCurrShape->setPosition(aCurrPos); + oox::OptValue<sal_Int32> oWidth = findProperty(aProperties, aCurrShape->getInternalName(), XML_w); + oox::OptValue<sal_Int32> oHeight = findProperty(aProperties, aCurrShape->getInternalName(), XML_h); awt::Size aSize = aChildSize; if (oWidth.has()) aSize.Width = oWidth.get(); + if (oHeight.has()) + aSize.Height = oHeight.get(); aSize.Width *= fWidthScale; + aSize.Height *= fHeightScale; aCurrShape->setSize(aSize); - aCurrShape->setChildSize(aSize); - aCurrPos.X += nIncX * (aSize.Width + fSpace*aSize.Width); - aCurrPos.Y += nIncY * (aChildSize.Height + fSpace*aChildSize.Height); + + // center in the other axis - probably some parameter controls it + if (nIncX) + aCurrPos.Y = (rShape->getSize().Height - aSize.Height) / 2; + if (nIncY) + aCurrPos.X = (rShape->getSize().Width - aSize.Width) / 2; + + aCurrShape->setPosition(aCurrPos); + + aCurrPos.X += nIncX * (aSize.Width + aSpaceSize.Width); + aCurrPos.Y += nIncY * (aSize.Height + aSpaceSize.Height); } break; } |