svg/node/element/path/command.rs
1use super::Parameters;
2use super::Position;
3
4/// A command of a data attribute.
5#[derive(Clone, Debug)]
6pub enum Command {
7 /// [Establish][1] a new current point.
8 ///
9 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands
10 Move(Position, Parameters),
11
12 /// [Draw][1] straight lines.
13 ///
14 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands
15 Line(Position, Parameters),
16
17 /// [Draw][1] horizontal lines.
18 ///
19 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands
20 HorizontalLine(Position, Parameters),
21
22 /// [Draw][1] vertical lines.
23 ///
24 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands
25 VerticalLine(Position, Parameters),
26
27 /// [Draw][1] a quadratic Bézier curve.
28 ///
29 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands
30 QuadraticCurve(Position, Parameters),
31
32 /// [Draw][1] a quadratic Bézier curve assuming the control point to be the
33 /// reflection of the control point on the previous command relative to the
34 /// current point.
35 ///
36 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands
37 SmoothQuadraticCurve(Position, Parameters),
38
39 /// [Draw][1] a cubic Bézier curve.
40 ///
41 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands
42 CubicCurve(Position, Parameters),
43
44 /// [Draw][1] a cubic Bézier curve assuming the first control point to be
45 /// the reflection of the second control point on the previous command
46 /// relative to the current point.
47 ///
48 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands
49 SmoothCubicCurve(Position, Parameters),
50
51 /// [Draw][1] an elliptical arc.
52 ///
53 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
54 EllipticalArc(Position, Parameters),
55
56 /// [End][1] the current subpath.
57 ///
58 /// [1]: https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand
59 Close,
60}
61
62macro_rules! implement {
63 ($($command:ident($position:ident) => $letter:expr,)*) => (
64 impl From<Command> for String {
65 fn from(command: Command) -> Self {
66 use self::Command::*;
67 use super::Position::*;
68 match command {
69 $($command($position, parameters) => {
70 format!(concat!($letter, "{}"), String::from(parameters))
71 })*
72 Close => String::from("z"),
73 }
74 }
75 }
76 );
77}
78
79implement! {
80 Move(Absolute) => "M",
81 Move(Relative) => "m",
82 Line(Absolute) => "L",
83 Line(Relative) => "l",
84 HorizontalLine(Absolute) => "H",
85 HorizontalLine(Relative) => "h",
86 VerticalLine(Absolute) => "V",
87 VerticalLine(Relative) => "v",
88 QuadraticCurve(Absolute) => "Q",
89 QuadraticCurve(Relative) => "q",
90 SmoothQuadraticCurve(Absolute) => "T",
91 SmoothQuadraticCurve(Relative) => "t",
92 CubicCurve(Absolute) => "C",
93 CubicCurve(Relative) => "c",
94 SmoothCubicCurve(Absolute) => "S",
95 SmoothCubicCurve(Relative) => "s",
96 EllipticalArc(Absolute) => "A",
97 EllipticalArc(Relative) => "a",
98}