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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Feb 18 20:39:03 UTC 2019


 oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   30 ++++++++++++++++----
 oox/source/drawingml/diagram/diagramlayoutatoms.hxx |    4 ++
 oox/source/drawingml/diagram/layoutnodecontext.cxx  |   16 ++++++++--
 sd/qa/unit/import-tests-smartart.cxx                |    6 ++++
 4 files changed, 46 insertions(+), 10 deletions(-)

New commits:
commit 34383064ac061497b0c46c449313877c6b6a2087
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Feb 18 18:14:05 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Feb 18 21:38:39 2019 +0100

    oox smartart, cycle matrix: handle aspect ratio in composite algo
    
    This way the 4 quadrant shapes in the center of the SmartArt form a
    circle, as width is shrinking.
    
    It's not height growing, as OOXML spec clearly says "ar" always just
    shrinks one axis.
    
    (>1 and <1 "ar" is to be handled when they are seen in action in an
    actual document.)
    
    Change-Id: I69f2390ee881253151cccc336ecbf1806a1216dc
    Reviewed-on: https://gerrit.libreoffice.org/67980
    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 dc526803f8fe..e57a0115e129 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -489,12 +489,29 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
 
             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;
+
+            sal_Int32 nParentXOffset = 0;
+            if (mfAspectRatio != 1.0)
+            {
+                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;
+            }
+            else
+            {
+                // Shrink width to be only as large as height.
+                rParent[XML_w] = std::min(rShape->getSize().Width, rShape->getSize().Height);
+                rParent[XML_h] = rShape->getSize().Height;
+                if (rParent[XML_w] < rShape->getSize().Width)
+                    nParentXOffset = (rShape->getSize().Width - rParent[XML_w]) / 2;
+                rParent[XML_l] = nParentXOffset;
+                rParent[XML_t] = 0;
+                rParent[XML_r] = rShape->getSize().Width - rParent[XML_l];
+                rParent[XML_b] = rShape->getSize().Height;
+            }
 
             for (const auto & rConstr : rConstraints)
             {
@@ -556,6 +573,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
                     if ( (it = rProp.find(XML_t)) != rProp.end() && (it2 = rProp.find(XML_b)) != rProp.end() )
                         aSize.Height = it2->second - it->second;
 
+                    aPos.X += nParentXOffset;
                     aSize.Width = std::min(aSize.Width, rShape->getSize().Width - aPos.X);
                     aSize.Height = std::min(aSize.Height, rShape->getSize().Height - aPos.Y);
                 }
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
index 440db0ef21ed..f056e4f7e637 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -169,9 +169,13 @@ public:
     /// Gives access to <dgm:param type="..." val="..."/>.
     const ParamMap& getMap() const { return maMap; }
 
+    void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
+
 private:
     sal_Int32 mnType;
     ParamMap  maMap;
+    /// Aspect ratio is not integer, so not part of maMap.
+    double mfAspectRatio = 0;
 };
 
 typedef std::shared_ptr< AlgAtom > AlgAtomPtr;
diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx
index 2cfeec2e8db6..ff508a24fcae 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -67,10 +67,18 @@ public:
             {
                 case DGM_TOKEN( param ):
                 {
-                    const sal_Int32 nValTok = rAttribs.getToken( XML_val, 0 );
-                    mpNode->addParam(
-                        rAttribs.getToken( XML_type, 0 ),
-                        nValTok>0 ? nValTok : rAttribs.getInteger( XML_val, 0 ) );
+                    sal_Int32 nType = rAttribs.getToken(XML_type, 0);
+                    switch (nType)
+                    {
+                        case XML_ar:
+                            mpNode->setAspectRatio(rAttribs.getDouble(XML_val, 0));
+                            break;
+                        default:
+                            const sal_Int32 nValTok = rAttribs.getToken(XML_val, 0);
+                            mpNode->addParam(nType, nValTok > 0 ? nValTok
+                                                                : rAttribs.getInteger(XML_val, 0));
+                            break;
+                    }
                     break;
                 }
                 default:
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 9acf64ebe306..29b8ae2d7469 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -874,6 +874,12 @@ void SdImportTestSmartArt::testCycleMatrix()
     CPPUNIT_ASSERT_EQUAL(xA2Shape->getPosition().X, xD2Shape->getPosition().X);
     CPPUNIT_ASSERT_GREATER(xA2Shape->getPosition().Y, xD2Shape->getPosition().Y);
 
+    // Without the accompanying fix in place, this test would have failed: width was expected to be
+    // 4887, was actually 7331.
+    uno::Reference<drawing::XShape> xA1Shape(xA1, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xA1Shape.is());
+    CPPUNIT_ASSERT_EQUAL(xA1Shape->getSize().Height, xA1Shape->getSize().Width);
+
     xDocShRef->DoClose();
 }
 


More information about the Libreoffice-commits mailing list