-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrvg-facade.cpp
309 lines (241 loc) · 9.98 KB
/
rvg-facade.cpp
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// Stroke-to-fill conversion program and test harness
// Copyright (C) 2020 Diego Nehab
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// Contact information: diego.nehab@gmail.com
//
#include <type_traits>
#include <iterator>
#include <cstdint>
#include "rvg-ptr.h"
#include "rvg-meta.h"
#include "rvg-svg-path-parse.h"
#include "rvg-facade.h"
namespace rvg_facade { namespace driver {
rvg::RGBA8 rgba(float r, float g, float b, float a) {
return rvg::make_rgba(r, g, b, a);
}
rvg::RGBA8 rgba8(int r, int g, int b, int a) {
return rvg::make_rgba8(r, g, b, a);
}
rvg::RGBA8 rgb(float r, float g, float b) {
return rvg::make_rgb(r, g, b);
}
rvg::RGBA8 rgb8(int r, int g, int b) {
return rvg::make_rgb8(r, g, b);
}
rvg::shape path(const char *svg) {
auto p = rvg::make_intrusive<rvg::path_data>();
if (!svg_path_iterate(svg, *p)) {
p->clear();
p->shrink_to_fit();
}
return rvg::shape(p);
}
rvg::shape circle(rvgf x, rvgf y, rvgf r) {
return rvg::shape(rvg::make_intrusive<rvg::circle_data>(x, y, r));
}
rvg::shape triangle(rvgf x1, rvgf y1, rvgf x2, rvgf y2,
rvgf x3, rvgf y3) {
return rvg::shape(rvg::make_intrusive<rvg::triangle_data>(x1, y1, x2, y2, x3, y3));
}
rvg::shape rect(rvgf x, rvgf y, rvgf width, rvgf height) {
return rvg::shape(rvg::make_intrusive<rvg::rect_data>(x, y, width, height));
}
rvg::shape polygon(const std::initializer_list<rvgf> &coordinates) {
return rvg::shape(rvg::make_intrusive<rvg::polygon_data>(coordinates));
}
rvg::shape path(const std::initializer_list<rvg::svg_path_token> &svg) {
auto p = rvg::make_intrusive<rvg::path_data>();
if (!rvg::svg_path_iterate(svg, *p)) {
p->clear();
p->shrink_to_fit();
}
return rvg::shape(p);
}
rvg::patch<16,4> tensor_product_patch(const R2 (&points)[16],
const rvg::RGBA8 (&colors)[4], uint8_t opacity) {
return rvg::patch<16,4>{rvg::make_intrusive<rvg::patch_data<16,4>>(
points, colors), rvg::unorm8{opacity}};
}
rvg::patch<12,4> coons_patch(const R2 (&points)[12],
const rvg::RGBA8 (&colors)[4], uint8_t opacity) {
return rvg::patch<12,4>{rvg::make_intrusive<rvg::patch_data<12,4>>(
points, colors), rvg::unorm8{opacity}};
}
rvg::patch<3,3> gouraud_triangle(const R2 (&points)[3],
const rvg::RGBA8 (&colors)[3], uint8_t opacity) {
return rvg::patch<3,3>{rvg::make_intrusive<rvg::patch_data<3,3>>(
points, colors), rvg::unorm8{opacity}};
}
painted_compound nzfill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::non_zero, s, p);
}
painted_compound zfill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::zero, s, p);
}
painted_compound ofill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::odd, s, p);
}
painted_compound efill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::even, s, p);
}
painted_compound fill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::non_zero, s, p);
}
painted_compound eofill(const rvg::shape &s, const rvg::paint &p) {
return make_painted_compound_painted_shape(rvg::e_winding_rule::odd, s, p);
}
painted_compound nzfill(const rvg::shape &s, const rvg::RGBA8 &c) {
return nzfill(s, solid_color(c));
}
painted_compound zfill(const rvg::shape &s, const rvg::RGBA8 &c) {
return zfill(s, solid_color(c));
}
painted_compound ofill(const rvg::shape &s, const rvg::RGBA8 &c) {
return zfill(s, solid_color(c));
}
painted_compound efill(const rvg::shape &s, const rvg::RGBA8 &c) {
return efill(s, solid_color(c));
}
painted_compound fill(const rvg::shape &s, const rvg::RGBA8 &c) {
return fill(s, solid_color(c));
}
painted_compound eofill(const rvg::shape &s, const rvg::RGBA8 &c) {
return eofill(s, solid_color(c));
}
painted_compound fade(uint8_t opacity, const vec_painted &painted_compound) {
return make_painted_compound_faded(rvg::unorm8{opacity}, painted_compound);
}
painted_compound fade(uint8_t opacity, const il_painted &painted_compound) {
return make_painted_compound_faded(rvg::unorm8{opacity}, painted_compound);
}
painted_compound transform(const rvg::xform &xf, const vec_painted &painted_compound) {
return make_painted_compound_xformed(xf, painted_compound);
}
painted_compound transform(const rvg::xform &xf, const il_painted &painted_compound) {
return make_painted_compound_xformed(xf, painted_compound);
}
painted_compound blur(float radius, const vec_painted &painted_compound) {
return make_painted_compound_blurred(radius, painted_compound);
}
painted_compound blur(float radius, const il_painted &painted_compound) {
return make_painted_compound_blurred(radius, painted_compound);
}
painted_compound blur(float radius, const painted_compound &painted_compound) {
return blur(radius, { painted_compound });
}
stencil_compound nzpunch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::non_zero, s);
}
stencil_compound zpunch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::zero, s);
}
stencil_compound opunch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::odd, s);
}
stencil_compound epunch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::even, s);
}
stencil_compound punch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::non_zero, s);
}
stencil_compound eopunch(const rvg::shape &s) {
return make_stencil_compound_stencil_shape(rvg::e_winding_rule::odd, s);
}
painted_compound clip(const vec_stencil &clipper, const vec_painted &clippee) {
return make_painted_compound_clipped(clipper, clippee);
}
painted_compound clip(const il_stencil &clipper, const il_painted &clippee) {
return make_painted_compound_clipped(clipper, clippee);
}
painted_compound clip(const stencil_compound &clipper, const il_painted &clippee) {
return clip({ clipper }, clippee);
}
painted_compound clip(const il_stencil &clipper, const painted_compound &clippee) {
return clip(clipper, { clippee });
}
painted_compound clip(const stencil_compound &clipper, const painted_compound &clippee) {
return clip({ clipper }, { clippee });
}
stencil_compound clip(const il_stencil &clipper, const il_stencil &clippee) {
return make_stencil_compound_clipped(clipper, clippee);
}
stencil_compound clip(const vec_stencil &clipper, const vec_stencil &clippee) {
return make_stencil_compound_clipped(clipper, clippee);
}
stencil_compound clip(const stencil_compound &clipper, const il_stencil &clippee) {
return clip({ clipper }, clippee);
}
stencil_compound clip(const il_stencil &clipper, const stencil_compound &clippee) {
return clip(clipper, { clippee });
}
stencil_compound clip(const stencil_compound &clipper, const stencil_compound &clippee) {
return clip({ clipper }, { clippee });
}
stencil_compound transform(const rvg::xform &xf, const il_stencil &stencil) {
return make_stencil_compound_xformed(xf, stencil);
}
stencil_compound transform(const rvg::xform &xf, const vec_stencil &stencil) {
return make_stencil_compound_xformed(xf, stencil);
}
rvg::scene scene(rvg::scene_data::const_ptr s) {
return rvg::scene{s};
}
rvg::scene scene(const il_painted &painted_compound) {
return rvg::scene{rvg::make_intrusive<rvg::scene_data>(
make_scene_data(painted_compound))};
}
rvg::scene scene(const std::vector<painted_compound> &painted_compound) {
return rvg::scene{rvg::make_intrusive<rvg::scene_data>(
make_scene_data(painted_compound))};
}
rvg::scene scene(const painted_compound &painted_compound) {
return rvg::scene{rvg::make_intrusive<rvg::scene_data>(
make_scene_data(painted_compound))};
}
rvg::paint solid_color(const rvg::RGBA8 &color, uint8_t opacity) {
return rvg::paint{color, rvg::unorm8{opacity}};
}
rvg::color_ramp::const_ptr color_ramp(rvg::e_spread spread,
const std::initializer_list<rvg::color_stop> &stops) {
return rvg::make_intrusive<rvg::color_ramp>(spread, stops);
}
rvg::color_ramp::const_ptr color_ramp(const std::initializer_list<rvg::color_stop> &stops) {
return rvg::make_intrusive<rvg::color_ramp>(rvg::e_spread::clamp, stops);
}
rvg::paint texture(rvg::e_spread spread, rvg::i_image::const_ptr image_ptr,
uint8_t opacity) {
return rvg::paint(rvg::make_intrusive<rvg::texture_data>(spread, image_ptr),
rvg::unorm8{opacity});
}
rvg::paint texture(rvg::i_image::const_ptr image_ptr, uint8_t opacity) {
return rvg::paint(rvg::make_intrusive<rvg::texture_data>(rvg::e_spread::clamp, image_ptr),
rvg::unorm8{opacity});
}
rvg::paint linear_gradient(rvg::color_ramp::const_ptr ramp_ptr,
float x1, float y1, float x2, float y2, uint8_t opacity) {
return rvg::paint(rvg::make_intrusive<rvg::linear_gradient_data>(ramp_ptr,
x1, y1, x2, y2), rvg::unorm8{opacity});
}
rvg::paint radial_gradient(rvg::color_ramp::const_ptr ramp_ptr,
float cx, float cy, float fx, float fy, float r, uint8_t opacity) {
return rvg::paint(rvg::make_intrusive<rvg::radial_gradient_data>(ramp_ptr,
cx, cy, fx, fy, r), rvg::unorm8{opacity});
}
rvg::window window(rvgf xl, rvgf yb, rvgf xr, rvgf yt) {
return rvg::make_window(xl, yb, xr, yt);
}
rvg::viewport viewport(rvgi xl, rvgi yb, rvgi xr, rvgi yt) {
return rvg::make_viewport(xl, yb, xr, yt);
}
} } // namespace rvg_facade::driver