1/*
2 * Copyright (C) 2019 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "SVGPathSeg.h"
29
30namespace WebCore {
31
32template<class... Arguments>
33class SVGPathSegValue : public SVGPathSeg {
34public:
35 template<typename PathSegType>
36 static Ref<PathSegType> create(Arguments... arguments)
37 {
38 return adoptRef(*new PathSegType(std::forward<Arguments>(arguments)...));
39 }
40
41 template<typename PathSegType>
42 Ref<PathSegType> clone() const
43 {
44 return adoptRef(*new PathSegType(m_arguments));
45 }
46
47 SVGPathSegValue(Arguments... arguments)
48 : m_arguments(std::forward<Arguments>(arguments)...)
49 {
50 }
51
52 SVGPathSegValue(const std::tuple<Arguments...>& arguments)
53 : m_arguments(arguments)
54 {
55 }
56
57protected:
58 template<size_t I>
59 const auto& argument() const
60 {
61 return std::get<I>(m_arguments);
62 }
63
64 template<size_t I, typename ArgumentValue>
65 void setArgument(ArgumentValue value)
66 {
67 std::get<I>(m_arguments) = value;
68 commitChange();
69 }
70
71 std::tuple<Arguments...> m_arguments;
72};
73
74class SVGPathSegLinetoHorizontal : public SVGPathSegValue<float> {
75public:
76 float x() const { return argument<0>(); }
77 void setX(float x) { setArgument<0>(x); }
78
79private:
80 using SVGPathSegValue::SVGPathSegValue;
81};
82
83class SVGPathSegLinetoVertical : public SVGPathSegValue<float> {
84public:
85 float y() const { return argument<0>(); }
86 void setY(float x) { setArgument<0>(x); }
87
88private:
89 using SVGPathSegValue::SVGPathSegValue;
90};
91
92class SVGPathSegSingleCoordinate : public SVGPathSegValue<float, float> {
93public:
94 float x() const { return argument<0>(); }
95 void setX(float x) { setArgument<0>(x); }
96
97 float y() const { return argument<1>(); }
98 void setY(float y) { setArgument<1>(y); }
99
100private:
101 using SVGPathSegValue::SVGPathSegValue;
102};
103
104class SVGPathSegCurvetoQuadratic : public SVGPathSegValue<float, float, float, float> {
105public:
106 float x() const { return argument<0>(); }
107 void setX(float x) { setArgument<0>(x); }
108
109 float y() const { return argument<1>(); }
110 void setY(float y) { setArgument<1>(y); }
111
112 float x1() const { return argument<2>(); }
113 void setX1(float x) { setArgument<2>(x); }
114
115 float y1() const { return argument<3>(); }
116 void setY1(float y) { setArgument<3>(y); }
117
118private:
119 using SVGPathSegValue::SVGPathSegValue;
120};
121
122class SVGPathSegCurvetoCubicSmooth : public SVGPathSegValue<float, float, float, float> {
123public:
124 float x() const { return argument<0>(); }
125 void setX(float x) { setArgument<0>(x); }
126
127 float y() const { return argument<1>(); }
128 void setY(float y) { setArgument<1>(y); }
129
130 float x2() const { return argument<2>(); }
131 void setX2(float x) { setArgument<2>(x); }
132
133 float y2() const { return argument<3>(); }
134 void setY2(float y) { setArgument<3>(y); }
135
136private:
137 using SVGPathSegValue::SVGPathSegValue;
138};
139
140class SVGPathSegCurvetoCubic : public SVGPathSegValue<float, float, float, float, float, float> {
141public:
142 float x() const { return argument<0>(); }
143 void setX(float x) { setArgument<0>(x); }
144
145 float y() const { return argument<1>(); }
146 void setY(float y) { setArgument<1>(y); }
147
148 float x1() const { return argument<2>(); }
149 void setX1(float x) { setArgument<2>(x); }
150
151 float y1() const { return argument<3>(); }
152 void setY1(float y) { setArgument<3>(y); }
153
154 float x2() const { return argument<4>(); }
155 void setX2(float x) { setArgument<4>(x); }
156
157 float y2() const { return argument<5>(); }
158 void setY2(float y) { setArgument<5>(y); }
159
160private:
161 using SVGPathSegValue::SVGPathSegValue;
162};
163
164class SVGPathSegArc : public SVGPathSegValue<float, float, float, float, float, bool, bool> {
165public:
166 float x() const { return argument<0>(); }
167 void setX(float x) { setArgument<0>(x); }
168
169 float y() const { return argument<1>(); }
170 void setY(float y) { setArgument<1>(y); }
171
172 float r1() const { return argument<2>(); }
173 void setR1(float r1) { setArgument<2>(r1); }
174
175 float r2() const { return argument<3>(); }
176 void setR2(float r2) { setArgument<3>(r2); }
177
178 float angle() const { return argument<4>(); }
179 void setAngle(float angle) { setArgument<4>(angle); }
180
181 bool largeArcFlag() const { return argument<5>(); }
182 void setLargeArcFlag(bool largeArcFlag) { setArgument<5>(largeArcFlag); }
183
184 bool sweepFlag() const { return argument<6>(); }
185 void setSweepFlag(bool sweepFlag) { setArgument<6>(sweepFlag); }
186
187private:
188 using SVGPathSegValue::SVGPathSegValue;
189};
190
191}
192