Kaydet (Commit) cd348a62 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/63478Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst d28bea8b
...@@ -206,6 +206,14 @@ public: ...@@ -206,6 +206,14 @@ public:
const LinkedTxbxAttr& getLinkedTxbxAttributes() { return maLinkedTxbxAttr; }; const LinkedTxbxAttr& getLinkedTxbxAttributes() { return maLinkedTxbxAttr; };
bool isLinkedTxbx() { return mbHasLinkedTxbx; }; 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: protected:
css::uno::Reference< css::drawing::XShape > const & css::uno::Reference< css::drawing::XShape > const &
...@@ -319,6 +327,12 @@ private: ...@@ -319,6 +327,12 @@ private:
bool mbHasLinkedTxbx; // this text box has linked text box ? bool mbHasLinkedTxbx; // this text box has linked text box ?
css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms; css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms;
/// Z-Order.
sal_Int32 mnZOrder = 0;
/// Z-Order offset.
sal_Int32 mnZOrderOff = 0;
}; };
} } } }
......
...@@ -168,6 +168,38 @@ void ShapeCreationVisitor::visit(LayoutNode& rAtom) ...@@ -168,6 +168,38 @@ void ShapeCreationVisitor::visit(LayoutNode& rAtom)
std::remove_if(pCurrParent->getChildren().begin(), pCurrParent->getChildren().end(), std::remove_if(pCurrParent->getChildren().begin(), pCurrParent->getChildren().end(),
[] (const ShapePtr & aChild) { return aChild->getServiceName() == "com.sun.star.drawing.GroupShape" && aChild->getChildren().empty(); }), [] (const ShapePtr & aChild) { return aChild->getServiceName() == "com.sun.star.drawing.GroupShape" && aChild->getChildren().empty(); }),
pCurrParent->getChildren().end()); 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*/) void ShapeCreationVisitor::visit(ShapeAtom& /*rAtom*/)
......
...@@ -210,6 +210,8 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, ...@@ -210,6 +210,8 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE); pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
pShape->setZOrderOff(rAttribs.getInteger(XML_zOrderOff, 0));
ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) ); ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) );
LayoutAtom::connect(mpNode, pAtom); LayoutAtom::connect(mpNode, pAtom);
return new ShapeContext( *this, ShapePtr(), pShape ); return new ShapeContext( *this, ShapePtr(), pShape );
......
...@@ -175,6 +175,8 @@ Shape::Shape( const ShapePtr& pSourceShape ) ...@@ -175,6 +175,8 @@ Shape::Shape( const ShapePtr& pSourceShape )
, maLinkedTxbxAttr() , maLinkedTxbxAttr()
, mbHasLinkedTxbx(false) , mbHasLinkedTxbx(false)
, maDiagramDoms( pSourceShape->maDiagramDoms ) , maDiagramDoms( pSourceShape->maDiagramDoms )
, mnZOrder(pSourceShape->mnZOrder)
, mnZOrderOff(pSourceShape->mnZOrderOff)
{} {}
Shape::~Shape() Shape::~Shape()
......
...@@ -462,12 +462,13 @@ void SdImportTestSmartArt::testAccentProcess() ...@@ -462,12 +462,13 @@ void SdImportTestSmartArt::testAccentProcess()
uno::Reference<drawing::XShape> xGroupShape(xGroup, uno::UNO_QUERY); uno::Reference<drawing::XShape> xGroupShape(xGroup, uno::UNO_QUERY);
CPPUNIT_ASSERT(xGroupShape.is()); 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); uno::Reference<drawing::XShapes> xFirstPair(xGroup->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xFirstPair.is()); CPPUNIT_ASSERT(xFirstPair.is());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xFirstPair->getCount()); 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(xFirstParentText.is());
CPPUNIT_ASSERT_EQUAL(OUString("a"), xFirstParentText->getString()); CPPUNIT_ASSERT_EQUAL(OUString("a"), xFirstParentText->getString());
uno::Reference<drawing::XShape> xFirstParent(xFirstParentText, uno::UNO_QUERY); uno::Reference<drawing::XShape> xFirstParent(xFirstParentText, uno::UNO_QUERY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment