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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 3 09:17:52 UTC 2020


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   46 ++++++++++++++++++--
 sd/qa/unit/data/pptx/smartart-linear-rule.pptx      |binary
 sd/qa/unit/import-tests-smartart.cxx                |    5 ++
 3 files changed, 48 insertions(+), 3 deletions(-)

New commits:
commit 880673412143a7db7ea1bf4766040662dfc085dc
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Aug 3 09:57:57 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Aug 3 11:17:17 2020 +0200

    oox smartart, linear layout: fix scaling of spacing without rules
    
    With this, finally the arrow shape has the correct horizontal position
    and width, even if the markup is as complex as the PowerPoint UI
    generates it (the previous version was a more minimal version).
    
    Change-Id: I59f237c582053067e890180a1ae40471e5f46dea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99894
    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 2fb4e60d2f2d..a48ffe3e4682 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -963,6 +963,8 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>&
                         {
                             fCount -= 1.0;
 
+                            bool bIsDependency = false;
+                            double fFactor = 0;
                             for (const auto& rConstraint : rConstraints)
                             {
                                 if (rConstraint.msForName != aCurrShape->getInternalName())
@@ -970,16 +972,25 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>&
                                     continue;
                                 }
 
-                                if (aChildrenToShrink.find(rConstraint.msRefForName) == aChildrenToShrink.end())
+                                if ((nDir == XML_fromL || nDir == XML_fromR) && rConstraint.mnType != XML_w)
                                 {
                                     continue;
                                 }
+                                if ((nDir == XML_fromL || nDir == XML_fromR) && rConstraint.mnType == XML_w)
+                                {
+                                    fFactor = rConstraint.mfFactor;
+                                }
 
-                                if ((nDir == XML_fromL || nDir == XML_fromR) && rConstraint.mnType != XML_w)
+                                if ((nDir == XML_fromT || nDir == XML_fromB) && rConstraint.mnType != XML_h)
                                 {
                                     continue;
                                 }
-                                if ((nDir == XML_fromT || nDir == XML_fromB) && rConstraint.mnType != XML_h)
+                                if ((nDir == XML_fromT || nDir == XML_fromB) && rConstraint.mnType == XML_h)
+                                {
+                                    fFactor = rConstraint.mfFactor;
+                                }
+
+                                if (aChildrenToShrink.find(rConstraint.msRefForName) == aChildrenToShrink.end())
                                 {
                                     continue;
                                 }
@@ -988,8 +999,29 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>&
                                 // other child which will be scaled.
                                 fCount += rConstraint.mfFactor;
                                 aChildrenToShrinkDeps.insert(aCurrShape->getInternalName());
+                                bIsDependency = true;
                                 break;
                             }
+
+                            if (!bIsDependency && aCurrShape->getServiceName() == "com.sun.star.drawing.GroupShape")
+                            {
+                                bool bScaleDownEmptySpacing = false;
+                                if (nDir == XML_fromL || nDir == XML_fromR)
+                                {
+                                    oox::OptValue<sal_Int32> oWidth = findProperty(aProperties, aCurrShape->getInternalName(), XML_w);
+                                    bScaleDownEmptySpacing = oWidth.has() && oWidth.get() > 0;
+                                }
+                                if (!bScaleDownEmptySpacing && (nDir == XML_fromT || nDir == XML_fromB))
+                                {
+                                    oox::OptValue<sal_Int32> oHeight = findProperty(aProperties, aCurrShape->getInternalName(), XML_h);
+                                    bScaleDownEmptySpacing = oHeight.has() && oHeight.get() > 0;
+                                }
+                                if (bScaleDownEmptySpacing && aCurrShape->getChildren().empty())
+                                {
+                                    fCount += fFactor;
+                                    aChildrenToShrinkDeps.insert(aCurrShape->getInternalName());
+                                }
+                            }
                         }
                     }
                 }
@@ -1083,6 +1115,14 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>&
                     aCurrPos.Y = (rShape->getSize().Height - aSize.Height) / 2;
                 if (nIncY)
                     aCurrPos.X = (rShape->getSize().Width - aSize.Width) / 2;
+                if (aCurrPos.X < 0)
+                {
+                    aCurrPos.X = 0;
+                }
+                if (aCurrPos.Y < 0)
+                {
+                    aCurrPos.Y = 0;
+                }
 
                 aCurrShape->setPosition(aCurrPos);
 
diff --git a/sd/qa/unit/data/pptx/smartart-linear-rule.pptx b/sd/qa/unit/data/pptx/smartart-linear-rule.pptx
index e76dfd9ee770..05905299ed27 100644
Binary files a/sd/qa/unit/data/pptx/smartart-linear-rule.pptx and b/sd/qa/unit/data/pptx/smartart-linear-rule.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 4bc60fc874c1..52909c1d5922 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -1545,6 +1545,11 @@ void SdImportTestSmartArt::testLinearRule()
     // - Expected: 3160
     // - Actual  : 8770
     // i.e. there was unexpected spacing on the left of the arrow.
+    // Then the imporoved version of the test document failed with:
+    // - Expected: 3160
+    // - Actual  : 19828
+    // i.e. the spacing on the left of the arrow was so large that the shape was mostly outside the
+    // slide.
     sal_Int32 nGroupLeft = xGroup->getPosition().X;
     sal_Int32 nArrowLeft = xShape->getPosition().X;
     CPPUNIT_ASSERT_EQUAL(nGroupLeft, nArrowLeft);


More information about the Libreoffice-commits mailing list