summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-01-13 15:10:48 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-01-20 14:56:51 +0100
commit26fc0fb9b2c66c94078c27ac07ded465cdc50325 (patch)
tree26649bd02a1018d9ec40a8d103b374c89bd37bc8
parent08d45119cfb875fa8a5c03d6e946a47f0f680932 (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. (cherry picked from commit 318438a680e6bf5c2c592d5e997f6f45a4ae8e5f) Change-Id: I097ac9ed6110536bbeb8a26ab35a8ee8a79d5b33 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109701 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx70
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.hxx10
2 files changed, 48 insertions, 32 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 6a33148a7993..58f6da680f97 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 571cca641d78..80f6b2d9bb0d 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -210,6 +210,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
{