diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2018-11-30 17:57:21 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2018-12-01 02:04:36 +0100 |
commit | ddc2786831367577967e806d603f337a2e42806a (patch) | |
tree | 4635e4baa41944d13bfd1ee556d40a887b6a3ae6 /oox | |
parent | d43e48cabce7fa8235207288e66a06fce1c58975 (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
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 47 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/layoutatomvisitors.cxx | 2 |
3 files changed, 45 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) |