This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVGElements.hpp
238 lines (217 loc) · 10.2 KB
/
SVGElements.hpp
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//! @file shape.hpp
#ifndef __svg_SVGElements_hpp__
#define __svg_SVGElements_hpp__
#include "Color.hpp"
#include "Point.hpp"
#include "PNGImage.hpp"
namespace svg
{
class SVGElement
{
public:
SVGElement();
virtual ~SVGElement();
virtual void draw(PNGImage &img) const = 0; // Declaration of the draw virtual pure function for each SVG element.
virtual void translate(const Point &t) = 0; // Declaration of the translate virtual pure function for each SVG element.
virtual void rotate(const Point &origin,
int degrees) = 0; // Declaration of the rotate virtual pure function for each SVG element.
virtual void scale(const Point &origin,
int v) = 0; // Declaration of the scale virtual pure function for each SVG element.
virtual SVGElement* copy() const = 0; // Declaration of the translate virtual pure function for each SVG element.
std::string id;
};
void readSVG(const std::string &svg_file,
Point &dimensions,
std::vector<SVGElement *> &svg_elements); // Declaration of namespace function readSVG.
void convert(const std::string &svg_file,
const std::string &png_file); // Declaration of namespace function convert.
/**
* @class Ellipse
* @brief Represents an ellipse SVG element.
*/
class Ellipse : public SVGElement
{
public:
/**
* @brief Constructs an Ellipse object.
*
* @param fill The fill color of the ellipse.
* @param center The center point of the ellipse.
* @param radius The radius of the ellipse.
* @param id The id of the ellipse.
*/
Ellipse(const Color &fill,
const Point ¢er,
const Point &radius,
const std::string &id = "");
void draw(PNGImage &img) const override; // Declaration of the Ellipse's draw function.
void translate(const Point &t) override; // Declaration of the Ellipse's translate function.
void rotate(const Point &origin,
int degrees) override; // Declaration of the Ellipse's rotate function.
void scale(const Point &origin,
int v) override; // Declaration of the Ellipse's scale function.
SVGElement* copy() const override; // Declaration of the Ellipse's copy function.
protected:
Color fill; // The fill color of the ellipse.
Point center; // The center point of the ellipse.
Point radius; // The radius of the ellipse.
};
/**
* @class Circle
* @brief Represents a circle SVG element.
*/
class Circle : public Ellipse
{
public:
/**
* @brief Constructs a Circle object with the specified fill color, center point, and radius.
*
* @param fill The fill color of the circle.
* @param center The center point of the circle.
* @param radius The radius of the circle.
* @param id The id of the circle.
*/
Circle(const Color &fill,
const Point ¢er,
const int &radius,
const std::string &id = "")
: Ellipse(fill, center, {radius , radius}, id) { };
void draw(PNGImage &img) const override; // Declaration of the Circle's draw function.
SVGElement* copy() const override; // Declaration of the Circle's copy function.
};
/**
* @class Polyline
* @brief Represents a polyline SVG element.
*/
class Polyline : public SVGElement
{
public:
/**
* @brief Constructs a Polyline object with the given points and stroke color.
*
* @param points The vector of points that define the polyline.
* @param stroke The color of the polyline stroke.
* @param id The id for the polyline.
*/
Polyline(const std::vector<Point> &points,
const Color &stroke,
const std::string &id = "");
void draw(PNGImage &img) const override; // Declaration of the Polyline's draw function.
void translate(const Point &t) override; // Declaration of the Polyline's translate function.
void rotate(const Point &origin,
int degrees) override; // Declaration of the Polyline's rotate function.
void scale(const Point &origin,
int v) override; // Declaration of the Polyline's scale function.
SVGElement* copy() const override; // Declaration of the Polyline's copy function.
protected:
std::vector<Point> points; // The vector of points that define the polyline.
Color stroke; // The color of the polyline stroke.
};
/**
* @class Line
* @brief Represents a line SVG element.
*/
class Line : public Polyline
{
public:
/**
* @brief Constructs a Line object with the given start and end points and stroke color.
*
* @param start The starting point of the line.
* @param end The ending point of the line.
* @param stroke The color of the line stroke.
* @param id The id of the line.
*/
Line(const Point &start,
const Point &end,
const Color &stroke,
const std::string &id = "")
: Polyline({start, end}, stroke, id), start(start), end(end) { };
void draw(PNGImage &img) const override; // Declaration of the Line's draw function.
void translate(const Point &t) override; // Declaration of the Line's translate function.
void rotate(const Point &origin,
int degrees) override; // Declaration of the Line's rotate function.
void scale(const Point &origin,
int v) override; // Declaration of the Line's scale function.
SVGElement* copy() const override; // Declaration of the Line's copy function.
private:
Point start; // The starting point of the line.
Point end; // The ending point of the line.
};
/**
* @class Polygon
* @brief Represents a polygon SVG element.
*/
class Polygon : public SVGElement
{
public:
/**
* @brief Constructs a `Polygon` object with the given points and fill color.
*
* @param points The vector of points that define the vertices of the polygon.
* @param fill The fill color of the polygon.
* @param id The id for the polygon.
*/
Polygon(const std::vector<Point> &points,
const Color &fill,
const std::string &id = "");
void draw(PNGImage &img) const override; // Declaration of the Polygon's draw function.
void translate(const Point &t) override; // Declaration of the Polygon's translate function.
void rotate(const Point &origin,
int degrees) override; // Declaration of the Polygon's rotate function.
void scale(const Point &origin,
int v) override; // Declaration of the Polygon's scale function.
SVGElement* copy() const override; // Declaration of the Polygon's copy function.
protected:
std::vector<Point> points; // The vector of points that define the vertices of the polygon.
Color fill; // The fill color of the polygon.
};
/**
* @class Rect
* @brief Represents a rectangle SVG element.
*/
class Rect : public Polygon
{
public:
/**
* @brief Constructs a `Rect` object with the specified corner, width, height, and fill color.
*
* @param corner The top-left corner of the rectangle.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @param fill The fill color of the rectangle.
*/
Rect(const std::vector<Point> &points,
const Color &fill,
const std::string &id = "")
: Polygon(points, fill, id) { };
void draw(PNGImage &img) const override; // Declaration of the Rectangle's draw function.
SVGElement* copy() const override; // Declaration of the Rectangle's copy function.
};
/**
* @class Group
* @brief Represents a group of SVG elements.
*/
class Group:public SVGElement
{
public:
/**
* @brief Constructs a Group object with the given vector of SVGElement pointers.
*
* @param VectorFigs The vector of SVGElement pointers to be stored in the Group.
*/
Group(const std::vector<SVGElement*> &VectorFigs)
: V(VectorFigs) {}
void draw(PNGImage &img) const override; // Declaration of the Groups's draw function.
void translate(const Point &t) override; // Declaration of the Groups's translate function.
void rotate(const Point &origin,
int degrees) override; // Declaration of the Groups's rotate function.
void scale(const Point &origin,
int v) override; // Declaration of the Groups's scale function.
~Group();
SVGElement* copy() const override; // Declaration of the Groups's copy function.
private:
std::vector<SVGElement*> V;
};
}
#endif