summaryrefslogtreecommitdiffstats
path: root/src/livarot/path-description.cpp
blob: ecf50cac72d01e3a2a7789faef43c8fbad949c83 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2011 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#include "livarot/path-description.h"
#include <2geom/affine.h>

PathDescr *PathDescrMoveTo::clone() const
{
    return new PathDescrMoveTo(*this);
}

void PathDescrMoveTo::dumpSVG(Inkscape::SVGOStringStream& s, Geom::Point const &/*last*/) const
{
    s << "M " << p[Geom::X] << " " << p[Geom::Y] << " ";
}

void PathDescrMoveTo::transform(Geom::Affine const& t)
{
    p = p * t;
}

void PathDescrMoveTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  m " << p[Geom::X] << " " << p[Geom::Y];
}

void PathDescrLineTo::dumpSVG(Inkscape::SVGOStringStream& s, Geom::Point const &/*last*/) const
{
    s << "L " << p[Geom::X] << " " << p[Geom::Y] << " ";
}

PathDescr *PathDescrLineTo::clone() const
{
    return new PathDescrLineTo(*this);
}

void PathDescrLineTo::transform(Geom::Affine const& t)
{
    p = p * t;
}

void PathDescrLineTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  l " << p[Geom::X] << " " << p[Geom::Y];
}

PathDescr *PathDescrBezierTo::clone() const
{
    return new PathDescrBezierTo(*this);
}

void PathDescrBezierTo::transform(Geom::Affine const& t)
{
    p = p * t;
}

void PathDescrBezierTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  b " << p[Geom::X] << " " << p[Geom::Y] << " " << nb;
}

PathDescr *PathDescrIntermBezierTo::clone() const
{
    return new PathDescrIntermBezierTo(*this);
}

void PathDescrIntermBezierTo::transform(Geom::Affine const& t)
{
    p = p * t;
}

void PathDescrIntermBezierTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  i " << p[Geom::X] << " " << p[Geom::Y];
}

void PathDescrCubicTo::dumpSVG(Inkscape::SVGOStringStream& s, Geom::Point const &last) const
{
    s << "C "
      << last[Geom::X] + start[0] / 3 << " "
      << last[Geom::Y] + start[1] / 3 << " "
      << p[Geom::X] - end[0] / 3 << " "
      << p[Geom::Y] - end[1] / 3 << " "
      << p[Geom::X] << " "
      << p[Geom::Y] << " ";
}

PathDescr *PathDescrCubicTo::clone() const
{
    return new PathDescrCubicTo(*this);
}

void PathDescrCubicTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  c "
      << p[Geom::X] << " " << p[Geom::Y] << " "
      << start[Geom::X] << " " << start[Geom::Y] << " "
      << end[Geom::X] << " " << end[Geom::Y] << " ";
}

void PathDescrCubicTo::transform(Geom::Affine const& t)
{
    Geom::Affine tr = t;
    tr[4] = tr[5] = 0;
    start = start * tr;
    end = end * tr;
    
    p = p * t;
}

void PathDescrArcTo::dumpSVG(Inkscape::SVGOStringStream& s, Geom::Point const &/*last*/) const
{
    s << "A "
      << rx << " "
      << ry << " "
      << angle << " "
      << (large ? "1" : "0") << " "
      << (clockwise ? "0" : "1") << " "
      << p[Geom::X] << " "
      << p[Geom::Y] << " ";
}

PathDescr *PathDescrArcTo::clone() const
{
    return new PathDescrArcTo(*this);
}

void PathDescrArcTo::transform(Geom::Affine const& t)
{
    p = p * t;
}

void PathDescrArcTo::dump(std::ostream &s) const
{
    /* localizing ok */
    s << "  a "
      << p[Geom::X] << " " << p[Geom::Y] << " "
      << rx << " " << ry << " "
      << angle << " "
      << (clockwise ? 1 : 0) << " "
      << (large ? 1 : 0);
}

PathDescr *PathDescrForced::clone() const
{
    return new PathDescrForced(*this);
}

void PathDescrClose::dumpSVG(Inkscape::SVGOStringStream& s, Geom::Point const &/*last*/) const
{
    s << "z ";
}

PathDescr *PathDescrClose::clone() const
{
    return new PathDescrClose(*this);
}


/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :