oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 70 ++++++++++---------- oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 10 ++ 2 files changed, 48 insertions(+), 32 deletions(-)
New commits: commit 318438a680e6bf5c2c592d5e997f6f45a4ae8e5f Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 13 15:10:48 2021 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 13 19:07:32 2021 +0100 oox smartart: extract pyra algo from AlgAtom::layoutShape() AlgAtom::layoutShape() is more or less the single function where all layouting happens for all algoritms. Extract the pyra algorithm part from it to a separate PyraAlg::layoutShapeChildren() before that function grows too large. Change-Id: I097ac9ed6110536bbeb8a26ab35a8ee8a79d5b33 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109231 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index 8e65a2161180..5a9fad2a3e73 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -440,6 +440,43 @@ void SnakeAlg::layoutShapeChildren(const AlgAtom::ParamMap& rMap, const ShapePtr } } +void PyraAlg::layoutShapeChildren(const ShapePtr& rShape) +{ + if (rShape->getChildren().empty() || rShape->getSize().Width == 0 + || rShape->getSize().Height == 0) + return; + + // const sal_Int32 nDir = maMap.count(XML_linDir) ? maMap.find(XML_linDir)->second : XML_fromT; + // const sal_Int32 npyraAcctPos = maMap.count(XML_pyraAcctPos) ? maMap.find(XML_pyraAcctPos)->second : XML_bef; + // const sal_Int32 ntxDir = maMap.count(XML_txDir) ? maMap.find(XML_txDir)->second : XML_fromT; + // const sal_Int32 npyraLvlNode = maMap.count(XML_pyraLvlNode) ? maMap.find(XML_pyraLvlNode)->second : XML_level; + // uncomment when use in code. + + sal_Int32 nCount = rShape->getChildren().size(); + double fAspectRatio = 0.32; + + awt::Size aChildSize = rShape->getSize(); + aChildSize.Width /= nCount; + aChildSize.Height /= nCount; + + awt::Point aCurrPos(0, 0); + aCurrPos.X = fAspectRatio * aChildSize.Width * (nCount - 1); + aCurrPos.Y = fAspectRatio * aChildSize.Height; + + for (auto& aCurrShape : rShape->getChildren()) + { + aCurrShape->setPosition(aCurrPos); + if (nCount > 1) + { + aCurrPos.X -= aChildSize.Height / (nCount - 1); + } + aChildSize.Width += aChildSize.Height; + aCurrShape->setSize(aChildSize); + aCurrShape->setChildSize(aChildSize); + aCurrPos.Y += (aChildSize.Height); + } +} + IteratorAttr::IteratorAttr( ) : mnCnt( -1 ) , mbHideLastTrans( true ) @@ -1594,38 +1631,7 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>& case XML_pyra: { - if (rShape->getChildren().empty() || rShape->getSize().Width == 0 || rShape->getSize().Height == 0) - break; - - // const sal_Int32 nDir = maMap.count(XML_linDir) ? maMap.find(XML_linDir)->second : XML_fromT; - // const sal_Int32 npyraAcctPos = maMap.count(XML_pyraAcctPos) ? maMap.find(XML_pyraAcctPos)->second : XML_bef; - // const sal_Int32 ntxDir = maMap.count(XML_txDir) ? maMap.find(XML_txDir)->second : XML_fromT; - // const sal_Int32 npyraLvlNode = maMap.count(XML_pyraLvlNode) ? maMap.find(XML_pyraLvlNode)->second : XML_level; - // uncomment when use in code. - - sal_Int32 nCount = rShape->getChildren().size(); - double fAspectRatio = 0.32; - - awt::Size aChildSize = rShape->getSize(); - aChildSize.Width /= nCount; - aChildSize.Height /= nCount; - - awt::Point aCurrPos(0, 0); - aCurrPos.X = fAspectRatio*aChildSize.Width*(nCount-1); - aCurrPos.Y = fAspectRatio*aChildSize.Height; - - for (auto & aCurrShape : rShape->getChildren()) - { - aCurrShape->setPosition(aCurrPos); - if (nCount > 1) - { - aCurrPos.X -= aChildSize.Height / (nCount - 1); - } - aChildSize.Width += aChildSize.Height; - aCurrShape->setSize(aChildSize); - aCurrShape->setChildSize(aChildSize); - aCurrPos.Y += (aChildSize.Height); - } + PyraAlg::layoutShapeChildren(rShape); break; } diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx index bc59e3ab307a..149be2c97338 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx @@ -209,6 +209,16 @@ public: const std::vector<Constraint>& rConstraints); }; +/** + * Lays out child layout nodes along a vertical path and works with the trapezoid shape to create a + * pyramid. + */ +class PyraAlg +{ +public: + static void layoutShapeChildren(const ShapePtr& rShape); +}; + class ForEachAtom : public LayoutAtom { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits