doc: linguistic changes in C++ API docs
[platform/core/graphics/tizenvg.git] / src / loaders / svg / tvgSvgLoaderCommon.h
1 /*
2  * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
3
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 #ifndef _TVG_SVG_LOADER_COMMON_H_
23 #define _TVG_SVG_LOADER_COMMON_H_
24
25 #include "tvgCommon.h"
26 #include "tvgArray.h"
27
28 enum class SvgNodeType
29 {
30     Doc,
31     G,
32     Defs,
33     //Switch,  //Not support
34     Animation,
35     Arc,
36     Circle,
37     Ellipse,
38     Image,
39     Line,
40     Path,
41     Polygon,
42     Polyline,
43     Rect,
44     Text,
45     TextArea,
46     Tspan,
47     Use,
48     Video,
49     ClipPath,
50     //Custome_command,   //Not support
51     Unknown
52 };
53
54 enum class SvgLengthType
55 {
56     Percent,
57     Px,
58     Pc,
59     Pt,
60     Mm,
61     Cm,
62     In,
63 };
64
65
66 enum class SvgFillFlags
67 {
68     Paint = 0x01,
69     Opacity = 0x02,
70     Gradient = 0x04,
71     FillRule = 0x08,
72     ClipPath = 0x16
73 };
74
75 enum class SvgStrokeFlags
76 {
77     Paint = 0x1,
78     Opacity = 0x2,
79     Gradient = 0x4,
80     Scale = 0x8,
81     Width = 0x10,
82     Cap = 0x20,
83     Join = 0x40,
84     Dash = 0x80,
85 };
86
87 enum class SvgGradientType
88 {
89     Linear,
90     Radial
91 };
92
93 enum class SvgStyleType
94 {
95     Quality,
96     Fill,
97     ViewportFill,
98     Font,
99     Stroke,
100     SolidColor,
101     Gradient,
102     Transform,
103     Opacity,
104     CompOp
105 };
106
107 enum class SvgFillRule
108 {
109     Winding = 0,
110     OddEven = 1
111 };
112
113 //Length type to recalculate %, pt, pc, mm, cm etc
114 enum class SvgParserLengthType
115 {
116     Vertical,
117     Horizontal,
118     //In case of, for example, radius of radial gradient
119     Other
120 };
121
122 struct SvgNode;
123 struct SvgStyleGradient;
124
125
126 struct SvgDocNode
127 {
128     float w;
129     float h;
130     float vx;
131     float vy;
132     float vw;
133     float vh;
134     SvgNode* defs;
135     bool preserveAspect;
136 };
137
138 struct SvgGNode
139 {
140 };
141
142 struct SvgDefsNode
143 {
144     Array<SvgStyleGradient*> gradients;
145 };
146
147 struct SvgArcNode
148 {
149 };
150
151 struct SvgEllipseNode
152 {
153     float cx;
154     float cy;
155     float rx;
156     float ry;
157 };
158
159 struct SvgCircleNode
160 {
161     float cx;
162     float cy;
163     float r;
164 };
165
166 struct SvgRectNode
167 {
168     float x;
169     float y;
170     float w;
171     float h;
172     float rx;
173     float ry;
174     bool hasRx;
175     bool hasRy;
176 };
177
178 struct SvgLineNode
179 {
180     float x1;
181     float y1;
182     float x2;
183     float y2;
184 };
185
186 struct SvgPathNode
187 {
188     string* path;
189 };
190
191 struct SvgPolygonNode
192 {
193     int pointsCount;
194     float* points;
195 };
196
197 struct SvgLinearGradient
198 {
199     float x1;
200     float y1;
201     float x2;
202     float y2;
203 };
204
205 struct SvgRadialGradient
206 {
207     float cx;
208     float cy;
209     float fx;
210     float fy;
211     float r;
212 };
213
214 struct SvgGradientStop
215 {
216     float offset;
217     uint8_t r;
218     uint8_t g;
219     uint8_t b;
220     uint8_t a;
221 };
222
223 struct SvgComposite
224 {
225     CompositeMethod method;     //TODO: Currently support either one method
226     string *url;
227     SvgNode* node;
228 };
229
230 struct SvgPaint
231 {
232     SvgStyleGradient* gradient;
233     string *url;
234     uint8_t r;
235     uint8_t g;
236     uint8_t b;
237     bool none;
238     bool curColor;
239 };
240
241 struct SvgDash
242 {
243     Array<float> array;
244 };
245
246 struct SvgStyleGradient
247 {
248     SvgGradientType type;
249     string *id;
250     string *ref;
251     FillSpread spread;
252     SvgRadialGradient* radial;
253     SvgLinearGradient* linear;
254     Matrix* transform;
255     Array<Fill::ColorStop *> stops;
256     bool userSpace;
257     bool usePercentage;
258 };
259
260 struct SvgStyleFill
261 {
262     SvgFillFlags flags;
263     SvgPaint paint;
264     int opacity;
265     SvgFillRule fillRule;
266 };
267
268 struct SvgStyleStroke
269 {
270     SvgStrokeFlags flags;
271     SvgPaint paint;
272     int opacity;
273     float scale;
274     float width;
275     float centered;
276     StrokeCap cap;
277     StrokeJoin join;
278     SvgDash dash;
279     int dashCount;
280 };
281
282 struct SvgStyleProperty
283 {
284     SvgStyleFill fill;
285     SvgStyleStroke stroke;
286     SvgComposite comp;
287     int opacity;
288     uint8_t r;
289     uint8_t g;
290     uint8_t b;
291 };
292
293 struct SvgNode
294 {
295     SvgNodeType type;
296     SvgNode* parent;
297     Array<SvgNode*> child;
298     string *id;
299     SvgStyleProperty *style;
300     Matrix* transform;
301     union {
302         SvgGNode g;
303         SvgDocNode doc;
304         SvgDefsNode defs;
305         SvgArcNode arc;
306         SvgCircleNode circle;
307         SvgEllipseNode ellipse;
308         SvgPolygonNode polygon;
309         SvgPolygonNode polyline;
310         SvgRectNode rect;
311         SvgPathNode path;
312         SvgLineNode line;
313     } node;
314     bool display;
315 };
316
317 struct SvgParser
318 {
319     SvgNode* node;
320     SvgStyleGradient* styleGrad;
321     Fill::ColorStop* gradStop;
322     struct
323     {
324         int x, y;
325         uint32_t w, h;
326     } global;
327     struct
328     {
329         bool parsedFx;
330         bool parsedFy;
331     } gradient;
332 };
333
334 struct SvgLoaderData
335 {
336     Array<SvgNode *> stack = {nullptr, 0, 0};
337     SvgNode* doc = nullptr;
338     SvgNode* def = nullptr;
339     Array<SvgStyleGradient*> gradients;
340     SvgStyleGradient* latestGradient = nullptr; //For stops
341     SvgParser* svgParse = nullptr;
342     int level = 0;
343     bool result = false;
344 };
345
346 /*
347  * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strtof-strtod-l-wcstod-wcstod-l?view=vs-2017
348  *
349  * src should be one of the following form :
350  *
351  * [whitespace] [sign] {digits [radix digits] | radix digits} [{e | E} [sign] digits]
352  * [whitespace] [sign] {INF | INFINITY}
353  * [whitespace] [sign] NAN [sequence]
354  *
355  * No hexadecimal form supported
356  * no sequence supported after NAN
357  */
358 float customStrtof(const char *nptr, char **endptr);
359
360 #endif