[Libreoffice-commits] core.git: oox/source sd/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Dec 1 01:05:09 UTC 2018


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   47 ++++++++++++++++++--
 oox/source/drawingml/diagram/diagramlayoutatoms.hxx |    2 
 oox/source/drawingml/diagram/layoutatomvisitors.cxx |    2 
 sd/qa/unit/import-tests-smartart.cxx                |    6 ++
 4 files changed, 51 insertions(+), 6 deletions(-)

New commits:
commit ddc2786831367577967e806d603f337a2e42806a
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 30 17:57:21 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Sat Dec 1 02:04:36 2018 +0100

    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 at collabora.com>
    Tested-by: Jenkins

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());


More information about the Libreoffice-commits mailing list