[Libreoffice-commits] core.git: oox/Library_oox.mk oox/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 24 15:45:15 UTC 2020
oox/Library_oox.mk | 1
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 16 ++++
oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 24 ++++++-
oox/source/drawingml/diagram/layoutatomvisitorbase.cxx | 5 +
oox/source/drawingml/diagram/layoutatomvisitorbase.hxx | 4 -
oox/source/drawingml/diagram/layoutatomvisitors.cxx | 20 +++++
oox/source/drawingml/diagram/layoutatomvisitors.hxx | 4 +
oox/source/drawingml/diagram/layoutnodecontext.cxx | 4 -
oox/source/drawingml/diagram/rulelistcontext.cxx | 58 +++++++++++++++++
oox/source/drawingml/diagram/rulelistcontext.hxx | 42 ++++++++++++
10 files changed, 172 insertions(+), 6 deletions(-)
New commits:
commit 6ca5412bac9e3da5cd20f315fc853c7733f10858
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jul 24 15:52:10 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jul 24 17:44:37 2020 +0200
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.
Change-Id: I5f0f9ffcaff75a804796851e48a9ce10583ec362
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99377
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index 3d8b46b2a24b..287a4bb70003 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -149,6 +149,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
oox/source/drawingml/diagram/layoutatomvisitorbase \
oox/source/drawingml/diagram/layoutatomvisitors \
oox/source/drawingml/diagram/layoutnodecontext \
+ oox/source/drawingml/diagram/rulelistcontext \
oox/source/drawingml/drawingmltypes \
oox/source/drawingml/effectproperties \
oox/source/drawingml/effectpropertiescontext \
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index babc65ac88c7..2aebfc85bcdc 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -337,6 +337,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
{
@@ -366,6 +371,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);
@@ -466,7 +479,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 65bfe5975a67..cb34f7a005f1 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -62,6 +62,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;
@@ -77,6 +78,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;
@@ -145,6 +152,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
{
@@ -161,7 +182,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 22ba236033fa..9b7ddaf8c0c7 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 ec937fd3559d..0f97c578cfc2 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitorbase.hxx
@@ -29,6 +29,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;
@@ -65,7 +66,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
@@ -78,6 +79,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 52ae12b2a592..6b064e28b39b 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 ebb83a28ae27..b8c060b0dc36 100644
--- a/oox/source/drawingml/diagram/layoutatomvisitors.hxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.hxx
@@ -39,6 +39,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;
@@ -56,6 +57,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;
@@ -77,12 +79,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 944f8dc6e390..80ae1d5bb6a9 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -23,6 +23,7 @@
#include <oox/drawingml/shapecontext.hxx>
#include <drawingml/customshapeproperties.hxx>
#include "constraintlistcontext.hxx"
+#include "rulelistcontext.hxx"
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
#include <sal/log.hxx>
@@ -265,8 +266,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: */
More information about the Libreoffice-commits
mailing list