diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-01-13 15:10:48 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-01-13 19:07:32 +0100 |
commit | 318438a680e6bf5c2c592d5e997f6f45a4ae8e5f (patch) | |
tree | ec35d62b62197d5f7effa461df3491ec8acac085 /oox | |
parent | 2b157a5bd6731ce213411806a39344365a56af71 (diff) |
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 <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 70 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 10 |
2 files changed, 48 insertions, 32 deletions
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 { |