[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - oox/source sd/qa
Grzegorz Araminowicz (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 3 12:16:48 UTC 2019
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 78 ++++++++++++--------
sd/qa/unit/import-tests-smartart.cxx | 10 +-
2 files changed, 54 insertions(+), 34 deletions(-)
New commits:
commit 55e531de9c1fecc73b8a42e18dda34aa4de02f8b
Author: Grzegorz Araminowicz <grzegorz.araminowicz at collabora.com>
AuthorDate: Thu May 30 13:29:08 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 3 14:15:55 2019 +0200
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 at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/73259
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;
}
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index ea83eb74a782..5a0cd7679ea1 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -1054,9 +1054,9 @@ void SdImportTestSmartArt::testVerticalBlockList()
// BC shape is rotated 90*, so width and height is swapped
CPPUNIT_ASSERT_GREATER(xShapeA->getSize().Width, xShapeBC->getSize().Height);
- CPPUNIT_ASSERT_LESSEQUAL(xShapeA->getSize().Height, xShapeBC->getSize().Width);
+ CPPUNIT_ASSERT_LESS(xShapeA->getSize().Height, xShapeBC->getSize().Width);
CPPUNIT_ASSERT_GREATER(xShapeA->getPosition().X, xShapeBC->getPosition().X);
- CPPUNIT_ASSERT_GREATEREQUAL(xShapeA->getPosition().Y, xShapeBC->getPosition().Y);
+ CPPUNIT_ASSERT_GREATER(xShapeA->getPosition().Y, xShapeBC->getPosition().Y);
uno::Reference<drawing::XShapes> xGroup3(xGroup->getByIndex(3), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xGroup3->getCount());
@@ -1067,7 +1067,11 @@ void SdImportTestSmartArt::testVerticalBlockList()
CPPUNIT_ASSERT_EQUAL(xShapeA->getSize().Width, xShapeEmpty->getSize().Width);
CPPUNIT_ASSERT_EQUAL(xShapeA->getSize().Height, xShapeEmpty->getSize().Height);
CPPUNIT_ASSERT_EQUAL(xShapeA->getPosition().X, xShapeEmpty->getPosition().X);
- CPPUNIT_ASSERT_GREATEREQUAL(xShapeA->getPosition().Y + 2*xShapeA->getSize().Height, xShapeEmpty->getPosition().Y);
+ CPPUNIT_ASSERT_GREATER(xShapeA->getPosition().Y + 2*xShapeA->getSize().Height, xShapeEmpty->getPosition().Y);
+
+ uno::Reference<drawing::XShape> xGroupShape(xGroup, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(xGroupShape->getPosition().Y + xGroupShape->getSize().Height,
+ xShapeEmpty->getPosition().Y + xShapeEmpty->getSize().Height);
xDocShRef->DoClose();
}
More information about the Libreoffice-commits
mailing list