1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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: */
|