summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-10-26 15:33:43 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-10-26 17:45:39 +0200
commitb083b0808121d19f398a9f6ead195ae7e14ed047 (patch)
tree676ccded3777e41ef9404d88525dfcfe3bb42de1
parente21ece71a70906526e2c3eceaac3bc0c93bb7831 (diff)
oox smartart, linear layout: take width from constraints
Finally the "parent text" of the test document now has correct width. Change-Id: I05c552dda66ad91f19cfc335b464549920269f69 Reviewed-on: https://gerrit.libreoffice.org/62395 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx33
-rw-r--r--sd/qa/unit/import-tests-smartart.cxx9
2 files changed, 40 insertions, 2 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index eeaa0812383d..e8665542b876 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -225,7 +225,7 @@ void AlgAtom::accept( LayoutAtomVisitor& rVisitor )
}
void AlgAtom::layoutShape( const ShapePtr& rShape,
- const std::vector<Constraint>& rConstraints ) const
+ const std::vector<Constraint>& rOwnConstraints ) const
{
// Algorithm result may depend on the parent constraints as well.
std::vector<Constraint> aParentConstraints;
@@ -239,6 +239,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
pConstraintAtom->parseConstraint(aParentConstraints);
}
}
+ const std::vector<Constraint>& rConstraints = rOwnConstraints.empty() ? aParentConstraints : rOwnConstraints;
switch(mnType)
{
@@ -381,10 +382,38 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
if (nIncY == -1)
aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
+ // Find out which contraint is relevant for which (internal) name.
+ LayoutPropertyMap aProperties;
+ for (const auto& rConstraint : rConstraints)
+ {
+ if (rConstraint.msForName.isEmpty())
+ continue;
+
+ LayoutProperty& rProperty = aProperties[rConstraint.msForName];
+ if (rConstraint.mnType == XML_w)
+ rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor;
+ }
+
for (auto & aCurrShape : rShape->getChildren())
{
+ // Extract properties relevant for this shape from constraints.
+ oox::OptValue<sal_Int32> oWidth;
+ auto it = aProperties.find(aCurrShape->getInternalName());
+ if (it != aProperties.end())
+ {
+ LayoutProperty& rProperty = it->second;
+ auto itProperty = rProperty.find(XML_w);
+ if (itProperty != rProperty.end())
+ oWidth = itProperty->second;
+ }
+
aCurrShape->setPosition(aCurrPos);
- aCurrShape->setSize(aChildSize);
+
+ awt::Size aSize = aChildSize;
+ if (oWidth.has())
+ aSize.Width = oWidth.get();
+ aCurrShape->setSize(aSize);
+
aCurrShape->setChildSize(aChildSize);
aCurrPos.X += nIncX * (aChildSize.Width + fSpace*aChildSize.Width);
aCurrPos.Y += nIncY * (aChildSize.Height + fSpace*aChildSize.Height);
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 9ffb432ce104..864fc1ad11f5 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -371,6 +371,15 @@ void SdImportTestSmartArt::testVertialBoxList()
// 'actual: 0'.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xShapeGroup->getCount());
+ uno::Reference<drawing::XShapes> xFirstChild(xShapeGroup->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFirstChild.is());
+ uno::Reference<drawing::XShape> xParentText(xFirstChild->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xParentText.is());
+ // Without the accompanying fix in place, this test would have failed with
+ // 'actual: 7361', i.e. the width was not the 70% of the parent as the
+ // constraint wanted.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11852), xParentText->getSize().Width);
+
uno::Reference<drawing::XShape> xSecondChild(xShapeGroup->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT(xSecondChild.is());
// Without the accompanying fix in place, this test would have failed with