summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2018-11-30 17:57:21 +0100
committerMiklos Vajna <vmiklos@collabora.com>2018-12-17 15:39:55 +0100
commit967f2ac350330a28a3fc2ec0993cbaf976e6cf60 (patch)
treeca473824002bf9b12064ce73d7082aa08ed11a1d
parentbe78a50a883e646e9d4830e3024554395dd12b9e (diff)
oox smartart, accent process: adjust size of connector from constraints
The constraints explicitly said that the width should be larger than the height, but it was the opposite as constraints were not parsed. Unfortunately it would be too brave for globally start handling all constraints which lack a forName, so add a switch to opt in for this, and use that with the conn algorithm. All clients should migrate to bRequireForName=true at some stage, though. Change-Id: I24ae79b141c0f7a11e4d19f141759fc1dd2169b0 Reviewed-on: https://gerrit.libreoffice.org/64350 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins (cherry picked from commit ddc2786831367577967e806d603f337a2e42806a) Reviewed-on: https://gerrit.libreoffice.org/65252
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx47
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.hxx2
-rw-r--r--oox/source/drawingml/diagram/layoutatomvisitors.cxx2
-rw-r--r--sd/qa/unit/import-tests-smartart.cxx6
4 files changed, 51 insertions, 6 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index f5a7b410de03..74cd2ed7d06c 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -314,11 +314,14 @@ void ConstraintAtom::accept( LayoutAtomVisitor& rVisitor )
rVisitor.visit(*this);
}
-void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints) const
+void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints,
+ bool bRequireForName) const
{
+ if (bRequireForName && maConstraint.msForName.isEmpty())
+ return;
+
// accepting only basic equality constraints
- if (!maConstraint.msForName.isEmpty()
- && (maConstraint.mnOperator == XML_none || maConstraint.mnOperator == XML_equ)
+ if ((maConstraint.mnOperator == XML_none || maConstraint.mnOperator == XML_equ)
&& maConstraint.mnType != XML_none)
{
rConstraints.push_back(maConstraint);
@@ -342,7 +345,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
{
auto pConstraintAtom = dynamic_cast<ConstraintAtom*>(pChild.get());
if (pConstraintAtom)
- pConstraintAtom->parseConstraint(aMergedConstraints);
+ pConstraintAtom->parseConstraint(aMergedConstraints, /*bRequireForName=*/true);
}
}
aMergedConstraints.insert(aMergedConstraints.end(), rOwnConstraints.begin(),
@@ -444,6 +447,42 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
rShape->setSubType(nType);
rShape->getCustomShapeProperties()->setShapePresetType(nType);
}
+
+ // Parse constraints to adjust the size.
+ std::vector<Constraint> aDirectConstraints;
+ const LayoutNode& rLayoutNode = getLayoutNode();
+ for (const auto& pChild : rLayoutNode.getChildren())
+ {
+ auto pConstraintAtom = dynamic_cast<ConstraintAtom*>(pChild.get());
+ if (pConstraintAtom)
+ pConstraintAtom->parseConstraint(aDirectConstraints, /*bRequireForName=*/false);
+ }
+
+ LayoutPropertyMap aProperties;
+ LayoutProperty& rParent = aProperties[""];
+ rParent[XML_w] = rShape->getSize().Width;
+ rParent[XML_h] = rShape->getSize().Height;
+ rParent[XML_l] = 0;
+ rParent[XML_t] = 0;
+ rParent[XML_r] = rShape->getSize().Width;
+ rParent[XML_b] = rShape->getSize().Height;
+ for (const auto& rConstr : aDirectConstraints)
+ {
+ const LayoutPropertyMap::const_iterator aRef
+ = aProperties.find(rConstr.msRefForName);
+ if (aRef != aProperties.end())
+ {
+ const LayoutProperty::const_iterator aRefType
+ = aRef->second.find(rConstr.mnRefType);
+ if (aRefType != aRef->second.end())
+ aProperties[rConstr.msForName][rConstr.mnType]
+ = aRefType->second * rConstr.mfFactor;
+ }
+ }
+ awt::Size aSize;
+ aSize.Width = rParent[XML_w];
+ aSize.Height = rParent[XML_h];
+ rShape->setSize(aSize);
break;
}
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
index 024cdaa1b61a..440db0ef21ed 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -141,7 +141,7 @@ public:
virtual void accept( LayoutAtomVisitor& ) override;
Constraint& getConstraint()
{ return maConstraint; }
- void parseConstraint(std::vector<Constraint>& rConstraints) const;
+ void parseConstraint(std::vector<Constraint>& rConstraints, bool bRequireForName) const;
private:
Constraint maConstraint;
};
diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.cxx b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
index ced94784aff4..79af89808e36 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitors.cxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
@@ -283,7 +283,7 @@ void ShapeLayoutingVisitor::defaultVisit(LayoutAtom const & rAtom)
void ShapeLayoutingVisitor::visit(ConstraintAtom& rAtom)
{
if (meLookFor == CONSTRAINT)
- rAtom.parseConstraint(maConstraints);
+ rAtom.parseConstraint(maConstraints, /*bRequireForName=*/true);
}
void ShapeLayoutingVisitor::visit(AlgAtom& rAtom)
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index be8ac42d3b45..fe24ff486fa3 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -503,6 +503,12 @@ void SdImportTestSmartArt::testAccentProcess()
OUString aType = aCustomShapeGeometry["Type"].get<OUString>();
CPPUNIT_ASSERT_EQUAL(OUString("ooxml-rightArrow"), aType);
+ // Make sure that height of the arrow is less than its width.
+ uno::Reference<drawing::XShape> xArrowShape(xArrow, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xArrowShape.is());
+ awt::Size aArrowSize = xArrowShape->getSize();
+ CPPUNIT_ASSERT_LESS(aArrowSize.Width, aArrowSize.Height);
+
uno::Reference<drawing::XShapes> xSecondPair(xGroup->getByIndex(2), uno::UNO_QUERY);
CPPUNIT_ASSERT(xSecondPair.is());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xSecondPair->getCount());