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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 16 19:43:50 UTC 2018


 include/oox/drawingml/shape.hxx                     |   14 ++++++++
 oox/source/drawingml/diagram/layoutatomvisitors.cxx |   32 ++++++++++++++++++++
 oox/source/drawingml/diagram/layoutnodecontext.cxx  |    2 +
 oox/source/drawingml/shape.cxx                      |    2 +
 sd/qa/unit/import-tests-smartart.cxx                |    5 +--
 5 files changed, 53 insertions(+), 2 deletions(-)

New commits:
commit cd348a6244a092c251a8e1362cd78de562d7bef6
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 16 17:34:46 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 16 20:43:26 2018 +0100

    oox smartart, accent process: add support for zorder offsets
    
    The oox::drawingml::Shape -> css::drawing::XShape converter doesn't
    support ZOrder, so just give each drawingml::Shape a default ZOrder.
    This way the offsets can be applied, and sorting can move the shapes to
    their correct place.
    
    This makes parent text of the bugdoc readable.
    
    Change-Id: Ib87a096fba66aad4a4f35d19473ea88dab340fd0
    Reviewed-on: https://gerrit.libreoffice.org/63478
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx
index 4940a90c3977..646fe01daa27 100644
--- a/include/oox/drawingml/shape.hxx
+++ b/include/oox/drawingml/shape.hxx
@@ -206,6 +206,14 @@ public:
     const LinkedTxbxAttr&     getLinkedTxbxAttributes() { return maLinkedTxbxAttr; };
     bool                isLinkedTxbx() { return mbHasLinkedTxbx; };
 
+    void setZOrder(sal_Int32 nZOrder) { mnZOrder = nZOrder; }
+
+    sal_Int32 getZOrder() const { return mnZOrder; }
+
+    void setZOrderOff(sal_Int32 nZOrderOff) { mnZOrderOff = nZOrderOff; }
+
+    sal_Int32 getZOrderOff() const { return mnZOrderOff; }
+
 protected:
 
     css::uno::Reference< css::drawing::XShape > const &
@@ -319,6 +327,12 @@ private:
     bool                            mbHasLinkedTxbx; // this text box has linked text box ?
 
     css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms;
+
+    /// Z-Order.
+    sal_Int32 mnZOrder = 0;
+
+    /// Z-Order offset.
+    sal_Int32 mnZOrderOff = 0;
 };
 
 } }
diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.cxx b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
index b85b5228407d..700b48080bc6 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitors.cxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
@@ -168,6 +168,38 @@ void ShapeCreationVisitor::visit(LayoutNode& rAtom)
         std::remove_if(pCurrParent->getChildren().begin(), pCurrParent->getChildren().end(),
             [] (const ShapePtr & aChild) { return aChild->getServiceName() == "com.sun.star.drawing.GroupShape" && aChild->getChildren().empty(); }),
         pCurrParent->getChildren().end());
+
+    // Offset the children from their default z-order stacking, if necessary.
+    std::vector<ShapePtr>& rChildren = pCurrParent->getChildren();
+    for (size_t i = 0; i < rChildren.size(); ++i)
+        rChildren[i]->setZOrder(i);
+
+    for (size_t i = 0; i < rChildren.size(); ++i)
+    {
+        const ShapePtr& pChild = rChildren[i];
+        sal_Int32 nZOrderOff = pChild->getZOrderOff();
+        if (nZOrderOff <= 0)
+            continue;
+
+        // Increase my ZOrder by nZOrderOff.
+        pChild->setZOrder(pChild->getZOrder() + nZOrderOff);
+        pChild->setZOrderOff(0);
+
+        for (sal_Int32 j = 0; j < nZOrderOff; ++j)
+        {
+            size_t nIndex = i + j + 1;
+            if (nIndex >= rChildren.size())
+                break;
+
+            // Decrease the ZOrder of the next nZOrderOff elements by one.
+            const ShapePtr& pNext = rChildren[nIndex];
+            pNext->setZOrder(pNext->getZOrder() - 1);
+        }
+    }
+
+    // Now that the ZOrders are adjusted, sort the children.
+    std::sort(rChildren.begin(), rChildren.end(),
+              [](const ShapePtr& a, const ShapePtr& b) { return a->getZOrder() < b->getZOrder(); });
 }
 
 void ShapeCreationVisitor::visit(ShapeAtom& /*rAtom*/)
diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx
index d81cbdf74ae0..2cfeec2e8db6 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -210,6 +210,8 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
 
         pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
 
+        pShape->setZOrderOff(rAttribs.getInteger(XML_zOrderOff, 0));
+
         ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) );
         LayoutAtom::connect(mpNode, pAtom);
         return new ShapeContext( *this, ShapePtr(), pShape );
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index 1d1e4d8be5a1..2c3348fcf159 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -175,6 +175,8 @@ Shape::Shape( const ShapePtr& pSourceShape )
 , maLinkedTxbxAttr()
 , mbHasLinkedTxbx(false)
 , maDiagramDoms( pSourceShape->maDiagramDoms )
+, mnZOrder(pSourceShape->mnZOrder)
+, mnZOrderOff(pSourceShape->mnZOrderOff)
 {}
 
 Shape::~Shape()
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 898350abfba5..56c504e40b72 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -462,12 +462,13 @@ void SdImportTestSmartArt::testAccentProcess()
     uno::Reference<drawing::XShape> xGroupShape(xGroup, uno::UNO_QUERY);
     CPPUNIT_ASSERT(xGroupShape.is());
 
-    // The pair if a parent (text + shape) and a child, so 3 shapes in total.
+    // The pair is a parent (shape + text) and a child, so 3 shapes in total.
+    // The order is importent, first is at the back, last is at the front.
     uno::Reference<drawing::XShapes> xFirstPair(xGroup->getByIndex(0), uno::UNO_QUERY);
     CPPUNIT_ASSERT(xFirstPair.is());
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xFirstPair->getCount());
 
-    uno::Reference<text::XText> xFirstParentText(xFirstPair->getByIndex(0), uno::UNO_QUERY);
+    uno::Reference<text::XText> xFirstParentText(xFirstPair->getByIndex(1), uno::UNO_QUERY);
     CPPUNIT_ASSERT(xFirstParentText.is());
     CPPUNIT_ASSERT_EQUAL(OUString("a"), xFirstParentText->getString());
     uno::Reference<drawing::XShape> xFirstParent(xFirstParentText, uno::UNO_QUERY);


More information about the Libreoffice-commits mailing list