summaryrefslogtreecommitdiff
path: root/svgio/source/svgreader
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-02-24 18:08:38 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-03-06 16:33:06 +0100
commit7894fd2b442eff45ecf14088ebd17ee9f8678752 (patch)
treecf1525a0c7118b6c84a0abd555a36277f8d8e91b /svgio/source/svgreader
parentde5dc664fc923b9704860f51267c438cad28cbe4 (diff)
svgio visitor, add draw commands and create the from svg
Adds a visitor for svgio for visiting svg nodes and create something useful from them. Basic draw commands - a tree of draw commands (with sub-pixel precision support) just to store a simple definition for drawing. Adds a svg draw visitor and create draw commands from the svg structure and expose the commands through UNO API. Change-Id: I073e891a2cffdd76d4e3b838590e3a19c998e9bf Reviewed-on: https://gerrit.libreoffice.org/68770 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r--svgio/source/svgreader/svgnode.cxx4
-rw-r--r--svgio/source/svgreader/svgvisitor.cxx105
2 files changed, 109 insertions, 0 deletions
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 88b9a72ec196..cb30c3111131 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -673,6 +673,10 @@ namespace svgio
return XmlSpace_default;
}
+ void SvgNode::accept(Visitor & rVisitor)
+ {
+ rVisitor.visit(*this);
+ }
} // end of namespace svgreader
} // end of namespace svgio
diff --git a/svgio/source/svgreader/svgvisitor.cxx b/svgio/source/svgreader/svgvisitor.cxx
new file mode 100644
index 000000000000..841a1cb7022e
--- /dev/null
+++ b/svgio/source/svgreader/svgvisitor.cxx
@@ -0,0 +1,105 @@
+/* -*- 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/.
+ *
+ */
+
+#include <sal/config.h>
+#include <sal/log.hxx>
+
+#include <svgdocumenthandler.hxx>
+#include <svgrectnode.hxx>
+#include <svgsvgnode.hxx>
+#include <svggnode.hxx>
+#include <svgpathnode.hxx>
+
+#include <svgvisitor.hxx>
+
+namespace svgio
+{
+namespace svgreader
+{
+SvgDrawVisitor::SvgDrawVisitor()
+ : mpDrawRoot(std::make_shared<DrawRoot>())
+ , mpCurrent(mpDrawRoot)
+{
+}
+
+void SvgDrawVisitor::visit(svgio::svgreader::SvgNode const& rNode)
+{
+ switch (rNode.getType())
+ {
+ case svgio::svgreader::SVGTokenSvg:
+ {
+ auto const& rSvgNode = static_cast<svgio::svgreader::SvgSvgNode const&>(rNode);
+
+ double x = rSvgNode.getX().getNumber();
+ double y = rSvgNode.getY().getNumber();
+ double w = rSvgNode.getWidth().getNumber();
+ double h = rSvgNode.getHeight().getNumber();
+
+ static_cast<DrawRoot*>(mpCurrent.get())->maRectangle
+ = basegfx::B2DRange(x, y, x + w, y + h);
+ }
+ break;
+ case svgio::svgreader::SVGTokenG:
+ {
+ auto const& rGNode = static_cast<svgio::svgreader::SvgGNode const&>(rNode);
+
+ if (rGNode.getTransform() != nullptr)
+ {
+ basegfx::B2DHomMatrix rMatrix = *rGNode.getTransform();
+
+ printf("G [%f %f %f - %f %f %f - %f %f %f]\n", rMatrix.get(0, 0), rMatrix.get(0, 1),
+ rMatrix.get(0, 2), rMatrix.get(1, 0), rMatrix.get(1, 1), rMatrix.get(1, 2),
+ rMatrix.get(2, 0), rMatrix.get(2, 1), rMatrix.get(2, 2));
+ }
+ }
+ break;
+ case svgio::svgreader::SVGTokenRect:
+ {
+ auto const& rRectNode = static_cast<svgio::svgreader::SvgRectNode const&>(rNode);
+
+ double x = rRectNode.getX().getNumber();
+ double y = rRectNode.getY().getNumber();
+ double w = rRectNode.getWidth().getNumber();
+ double h = rRectNode.getHeight().getNumber();
+
+ auto pRectangle
+ = std::make_shared<DrawRectangle>(basegfx::B2DRange(x, y, x + w, y + h));
+ mpCurrent->maChildren.push_back(pRectangle);
+ }
+ break;
+ case svgio::svgreader::SVGTokenPath:
+ {
+ auto const& rPathNode = static_cast<svgio::svgreader::SvgPathNode const&>(rNode);
+ auto pPath = rPathNode.getPath();
+ if (pPath)
+ {
+ auto pDrawPath = std::make_shared<DrawPath>(*pPath);
+ mpCurrent->maChildren.push_back(pDrawPath);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ goToChildren(rNode);
+}
+
+void SvgDrawVisitor::goToChildren(svgio::svgreader::SvgNode const& rNode)
+{
+ for (auto& rChild : rNode.getChildren())
+ {
+ rChild->accept(*this);
+ }
+}
+}
+} // end of namespace svgio::svgreader
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */