summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-07-24 15:52:10 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-08-04 18:49:15 +0200
commit92262649a0511146a21a5171b8ff33d4994d75b3 (patch)
tree2242f7578af92767f1bddfbb2e5144bb38e0c88d /oox/source
parent9c12947404d60aa779242d3fc1f2cccaaf8b5f51 (diff)
oox smartart: start parsing rule lists
I have a linear algorithm where some elements should be scaled down, but not all of them. These requirements are described using rules. This commit just adds the parsing for them, so that later AlgAtom::layoutShape() can create an improved layout, taking rules into account. (cherry picked from commit 6ca5412bac9e3da5cd20f315fc853c7733f10858) Change-Id: I5f0f9ffcaff75a804796851e48a9ce10583ec362 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100109 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx16
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.hxx24
-rw-r--r--oox/source/drawingml/diagram/layoutatomvisitorbase.cxx5
-rw-r--r--oox/source/drawingml/diagram/layoutatomvisitorbase.hxx4
-rw-r--r--oox/source/drawingml/diagram/layoutatomvisitors.cxx20
-rw-r--r--oox/source/drawingml/diagram/layoutatomvisitors.hxx4
-rw-r--r--oox/source/drawingml/diagram/layoutnodecontext.cxx4
-rw-r--r--oox/source/drawingml/diagram/rulelistcontext.cxx58
-rw-r--r--oox/source/drawingml/diagram/rulelistcontext.hxx42
9 files changed, 171 insertions, 6 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 72e334e80608..82e826da0dda 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -338,6 +338,11 @@ void ConstraintAtom::accept( LayoutAtomVisitor& rVisitor )
rVisitor.visit(*this);
}
+void RuleAtom::accept( LayoutAtomVisitor& rVisitor )
+{
+ rVisitor.visit(*this);
+}
+
void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints,
bool bRequireForName) const
{
@@ -367,6 +372,14 @@ void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints,
}
}
+void RuleAtom::parseRule(std::vector<Rule>& rRules) const
+{
+ if (!maRule.msForName.isEmpty())
+ {
+ rRules.push_back(maRule);
+ }
+}
+
void AlgAtom::accept( LayoutAtomVisitor& rVisitor )
{
rVisitor.visit(*this);
@@ -467,7 +480,8 @@ void ApplyConstraintToLayout(const Constraint& rConstraint, LayoutPropertyMap& r
}
void AlgAtom::layoutShape( const ShapePtr& rShape,
- const std::vector<Constraint>& rConstraints )
+ const std::vector<Constraint>& rConstraints,
+ const std::vector<Rule>& /*rRules*/ )
{
switch(mnType)
{
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
index 2e4551642389..8904e525a181 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -63,6 +63,7 @@ struct ConditionAttr
sal_Int32 mnVal;
};
+/// Constraints allow you to specify an ideal (or starting point) size for each shape.
struct Constraint
{
sal_Int32 mnFor;
@@ -78,6 +79,12 @@ struct Constraint
sal_Int32 mnOperator;
};
+/// Rules allow you to specify what to do when constraints can't be fully satisfied.
+struct Rule
+{
+ OUString msForName;
+};
+
typedef std::map<sal_Int32, sal_Int32> LayoutProperty;
typedef std::map<OUString, LayoutProperty> LayoutPropertyMap;
@@ -146,6 +153,20 @@ private:
Constraint maConstraint;
};
+/// Represents one <dgm:rule> element.
+class RuleAtom
+ : public LayoutAtom
+{
+public:
+ RuleAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode) {}
+ virtual void accept( LayoutAtomVisitor& ) override;
+ Rule& getRule()
+ { return maRule; }
+ void parseRule(std::vector<Rule>& rRules) const;
+private:
+ Rule maRule;
+};
+
class AlgAtom
: public LayoutAtom
{
@@ -162,7 +183,8 @@ public:
{ maMap[nType]=nVal; }
sal_Int32 getVerticalShapesCount(const ShapePtr& rShape);
void layoutShape( const ShapePtr& rShape,
- const std::vector<Constraint>& rConstraints );
+ const std::vector<Constraint>& rConstraints,
+ const std::vector<Rule>& rRules );
void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
diff --git a/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx b/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx
index 98206433653a..d9df0403a6e7 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitorbase.cxx
@@ -142,6 +142,11 @@ void ShallowPresNameVisitor::visit(ConstraintAtom& /*rAtom*/)
// stop processing
}
+void ShallowPresNameVisitor::visit(RuleAtom& /*rAtom*/)
+{
+ // stop processing
+}
+
void ShallowPresNameVisitor::visit(AlgAtom& /*rAtom*/)
{
// stop processing
diff --git a/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx b/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx
index ff12f82e2f96..4069a732ebef 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx
@@ -32,6 +32,7 @@ struct LayoutAtomVisitor
{
virtual ~LayoutAtomVisitor() {}
virtual void visit(ConstraintAtom& rAtom) = 0;
+ virtual void visit(RuleAtom& rAtom) = 0;
virtual void visit(AlgAtom& rAtom) = 0;
virtual void visit(ForEachAtom& rAtom) = 0;
virtual void visit(ConditionAtom& rAtom) = 0;
@@ -68,7 +69,7 @@ protected:
sal_Int32 mnCurrIdx;
sal_Int32 mnCurrStep;
sal_Int32 mnCurrCnt;
- enum {LAYOUT_NODE, CONSTRAINT, ALGORITHM} meLookFor;
+ enum {LAYOUT_NODE, CONSTRAINT, ALGORITHM, RULE} meLookFor;
};
class ShallowPresNameVisitor : public LayoutAtomVisitorBase
@@ -81,6 +82,7 @@ public:
using LayoutAtomVisitorBase::visit;
virtual void visit(ConstraintAtom& rAtom) override;
+ virtual void visit(RuleAtom& rAtom) override;
virtual void visit(AlgAtom& rAtom) override;
virtual void visit(ForEachAtom& rAtom) override;
virtual void visit(LayoutNode& rAtom) override;
diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.cxx b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
index c616ca3a9010..53c52a2ed3a5 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitors.cxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
@@ -35,6 +35,11 @@ void ShapeCreationVisitor::visit(ConstraintAtom& /*rAtom*/)
// stop processing
}
+void ShapeCreationVisitor::visit(RuleAtom& /*rAtom*/)
+{
+ // stop processing
+}
+
void ShapeCreationVisitor::visit(AlgAtom& rAtom)
{
if (meLookFor == ALGORITHM)
@@ -143,6 +148,11 @@ void ShapeTemplateVisitor::visit(ConstraintAtom& /*rAtom*/)
// stop processing
}
+void ShapeTemplateVisitor::visit(RuleAtom& /*rAtom*/)
+{
+ // stop processing
+}
+
void ShapeTemplateVisitor::visit(AlgAtom& /*rAtom*/)
{
// stop processing
@@ -182,6 +192,12 @@ void ShapeLayoutingVisitor::visit(ConstraintAtom& rAtom)
rAtom.parseConstraint(maConstraints, /*bRequireForName=*/true);
}
+void ShapeLayoutingVisitor::visit(RuleAtom& rAtom)
+{
+ if (meLookFor == RULE)
+ rAtom.parseRule(maRules);
+}
+
void ShapeLayoutingVisitor::visit(AlgAtom& rAtom)
{
if (meLookFor == ALGORITHM)
@@ -189,7 +205,7 @@ void ShapeLayoutingVisitor::visit(AlgAtom& rAtom)
const PresPointShapeMap aMap = rAtom.getLayoutNode().getDiagram().getLayout()->getPresPointShapeMap();
auto pShape = aMap.find(mpCurrentNode);
if (pShape != aMap.end())
- rAtom.layoutShape(pShape->second, maConstraints);
+ rAtom.layoutShape(pShape->second, maConstraints, maRules);
}
}
@@ -227,6 +243,8 @@ void ShapeLayoutingVisitor::visit(LayoutNode& rAtom)
// process alg atoms first, nested layout nodes afterwards
meLookFor = CONSTRAINT;
defaultVisit(rAtom);
+ meLookFor = RULE;
+ defaultVisit(rAtom);
meLookFor = ALGORITHM;
defaultVisit(rAtom);
meLookFor = LAYOUT_NODE;
diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.hxx b/oox/source/drawingml/diagram/layoutatomvisitors.hxx
index 656f61d79e6a..3ac2fa7e4fb8 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitors.hxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.hxx
@@ -41,6 +41,7 @@ public:
using LayoutAtomVisitorBase::visit;
virtual void visit(ConstraintAtom& rAtom) override;
+ virtual void visit(RuleAtom& rAtom) override;
virtual void visit(AlgAtom& rAtom) override;
virtual void visit(LayoutNode& rAtom) override;
virtual void visit(ShapeAtom& rAtom) override;
@@ -58,6 +59,7 @@ public:
using LayoutAtomVisitorBase::visit;
virtual void visit(ConstraintAtom& rAtom) override;
+ virtual void visit(RuleAtom& rAtom) override;
virtual void visit(AlgAtom& rAtom) override;
virtual void visit(ForEachAtom& rAtom) override;
virtual void visit(LayoutNode& rAtom) override;
@@ -79,12 +81,14 @@ public:
using LayoutAtomVisitorBase::visit;
virtual void visit(ConstraintAtom& rAtom) override;
+ virtual void visit(RuleAtom& rAtom) override;
virtual void visit(AlgAtom& rAtom) override;
virtual void visit(LayoutNode& rAtom) override;
virtual void visit(ShapeAtom& rAtom) override;
private:
std::vector<Constraint> maConstraints;
+ std::vector<Rule> maRules;
};
} }
diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx
index 3547aad28a7a..7157176053d8 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -24,6 +24,7 @@
#include <drawingml/customshapeproperties.hxx>
#include "diagramdefinitioncontext.hxx"
#include "constraintlistcontext.hxx"
+#include "rulelistcontext.hxx"
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
#include <sal/log.hxx>
@@ -262,8 +263,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
}
case DGM_TOKEN( ruleLst ):
// CT_Rules
- // TODO
- break;
+ return new RuleListContext( *this, mpNode );
case DGM_TOKEN( varLst ):
{
LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
diff --git a/oox/source/drawingml/diagram/rulelistcontext.cxx b/oox/source/drawingml/diagram/rulelistcontext.cxx
new file mode 100644
index 000000000000..69e930cdc758
--- /dev/null
+++ b/oox/source/drawingml/diagram/rulelistcontext.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "rulelistcontext.hxx"
+#include <oox/helper/attributelist.hxx>
+#include <oox/token/namespaces.hxx>
+#include <oox/token/tokens.hxx>
+
+namespace oox::drawingml
+{
+RuleListContext::RuleListContext(ContextHandler2Helper const& rParent, const LayoutAtomPtr& pNode)
+ : ContextHandler2(rParent)
+ , mpNode(pNode)
+{
+ assert(pNode);
+}
+
+RuleListContext::~RuleListContext() {}
+
+core::ContextHandlerRef RuleListContext::onCreateContext(sal_Int32 nElement,
+ const AttributeList& rAttribs)
+{
+ switch (nElement)
+ {
+ case DGM_TOKEN(rule):
+ {
+ auto pNode = std::make_shared<RuleAtom>(mpNode->getLayoutNode());
+ LayoutAtom::connect(mpNode, pNode);
+
+ Rule& rRule = pNode->getRule();
+ rRule.msForName = rAttribs.getString(XML_forName, "");
+ break;
+ }
+ default:
+ break;
+ }
+
+ return this;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/diagram/rulelistcontext.hxx b/oox/source/drawingml/diagram/rulelistcontext.hxx
new file mode 100644
index 000000000000..43098ce71833
--- /dev/null
+++ b/oox/source/drawingml/diagram/rulelistcontext.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <oox/core/contexthandler2.hxx>
+#include "diagramlayoutatoms.hxx"
+
+namespace oox::drawingml
+{
+/// Handles one <dgm:ruleLst> element.
+class RuleListContext : public oox::core::ContextHandler2
+{
+public:
+ RuleListContext(ContextHandler2Helper const& rParent, const LayoutAtomPtr& pNode);
+ virtual ~RuleListContext() override;
+
+ virtual oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement,
+ const AttributeList& rAttribs) override;
+
+private:
+ LayoutAtomPtr mpNode;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */