[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - oox/source sd/qa

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri May 29 15:24:32 UTC 2020


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   23 ++++++++++++++++++++
 sd/qa/unit/import-tests-smartart.cxx                |    8 ++++++
 2 files changed, 31 insertions(+)

New commits:
commit d2cb2ecff3cce10f47a9ae1b1ba80e0eff23745c
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed May 27 14:04:58 2020 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri May 29 17:23:59 2020 +0200

    oox smartart import, composite alg: implement vertical centering
    
    The bugdoc's case was that the total height would be used by 2 shapes,
    but then a constraint decreases the height of one shape, so not all
    vertical space is used.
    
    We used to just count from the top, need to center vertically, as
    PowerPoint does it.
    
    (cherry picked from commit acdde3c643fde015214c546b1567727272ea799e)
    
    Change-Id: I436019e9e837b73130e387c9bcd309e20045b0f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95017
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 33f858386999..19b1d10679f4 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -479,6 +479,11 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
             LayoutProperty& rParent = aProperties[""];
 
             sal_Int32 nParentXOffset = 0;
+
+            // Track min/max vertical positions, so we can center everything at the end, if needed.
+            sal_Int32 nVertMin = std::numeric_limits<sal_Int32>::max();
+            sal_Int32 nVertMax = 0;
+
             if (mfAspectRatio != 1.0)
             {
                 rParent[XML_w] = rShape->getSize().Width;
@@ -614,6 +619,24 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
                 aCurrShape->setSize(aSize);
                 aCurrShape->setChildSize(aSize);
                 aCurrShape->setPosition(aPos);
+
+                nVertMin = std::min(aPos.Y, nVertMin);
+                nVertMax = std::max(aPos.Y + aSize.Height, nVertMax);
+            }
+
+            // See if all vertical space is used or we have to center the content.
+            if (nVertMin >= 0 && nVertMax <= rParent[XML_h])
+            {
+                sal_Int32 nDiff = rParent[XML_h] - (nVertMax - nVertMin);
+                if (nDiff > 0)
+                {
+                    for (auto& aCurrShape : rShape->getChildren())
+                    {
+                        awt::Point aPosition = aCurrShape->getPosition();
+                        aPosition.Y += nDiff / 2;
+                        aCurrShape->setPosition(aPosition);
+                    }
+                }
             }
             break;
         }
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 327645fddc3f..4b110f740e11 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -1480,6 +1480,14 @@ void SdImportTestSmartArt::testFillColorList()
     awt::Size aActualSize = xShape->getSize();
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2239), aActualSize.Height);
 
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected greater than: 1738 (2766)
+    // - Actual  : 1738
+    // i.e. the columns were not centered vertically.
+    sal_Int32 nGroupTop = xGroup->getPosition().Y;
+    sal_Int32 nShapeTop = xShape->getPosition().Y;
+    CPPUNIT_ASSERT_GREATER(nGroupTop, nShapeTop);
+
     xDocShRef->DoClose();
 }
 


More information about the Libreoffice-commits mailing list