@c9up/orbit 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +139 -0
- package/Cargo.toml +20 -0
- package/LICENSE +21 -0
- package/README.md +320 -2
- package/android/orbit.cmake +31 -0
- package/android/src/main/cpp/NativeOrbit.cpp +309 -0
- package/android/src/main/cpp/NativeOrbit.h +35 -0
- package/android/src/main/cpp/orbit_host.h +34 -0
- package/android/src/main/java/com/c9up/orbit/OrbitEffects.kt +286 -0
- package/android/src/main/java/com/c9up/orbit/OrbitHost.kt +258 -0
- package/android/src/main/java/com/c9up/orbit/OrbitImage.kt +346 -0
- package/android/src/main/java/com/c9up/orbit/OrbitInput.kt +161 -0
- package/android/src/main/java/com/c9up/orbit/OrbitPress.kt +110 -0
- package/android/src/main/java/com/c9up/orbit/OrbitVector.kt +115 -0
- package/android/src/main/java/com/c9up/orbit/OrbitViews.kt +362 -0
- package/crates/orbit-host/Cargo.toml +14 -0
- package/crates/orbit-host/src/gesture.rs +561 -0
- package/crates/orbit-host/src/lib.rs +2042 -0
- package/crates/orbit-host/src/motion.rs +328 -0
- package/crates/orbit-host/src/vector.rs +1173 -0
- package/dist/color.d.ts +10 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +62 -0
- package/dist/color.js.map +1 -0
- package/dist/commit.d.ts +77 -0
- package/dist/commit.d.ts.map +1 -0
- package/dist/commit.js +302 -0
- package/dist/commit.js.map +1 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +89 -0
- package/dist/errors.js.map +1 -0
- package/dist/host.d.ts +49 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/motion.d.ts +18 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +67 -0
- package/dist/motion.js.map +1 -0
- package/dist/node.d.ts +46 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +110 -0
- package/dist/node.js.map +1 -0
- package/dist/pages.d.ts +56 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +157 -0
- package/dist/pages.js.map +1 -0
- package/dist/react-native/index.d.ts +33 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +71 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/report.d.ts +13 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +22 -0
- package/dist/report.js.map +1 -0
- package/dist/server.d.ts +109 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +290 -0
- package/dist/server.js.map +1 -0
- package/dist/stack.d.ts +117 -0
- package/dist/stack.d.ts.map +1 -0
- package/dist/stack.js +299 -0
- package/dist/stack.js.map +1 -0
- package/dist/styles.d.ts +138 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +920 -0
- package/dist/styles.js.map +1 -0
- package/dist/template.d.ts +27 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +1436 -0
- package/dist/template.js.map +1 -0
- package/dist/textDecoder.d.ts +29 -0
- package/dist/textDecoder.d.ts.map +1 -0
- package/dist/textDecoder.js +149 -0
- package/dist/textDecoder.js.map +1 -0
- package/dist/url.d.ts +45 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +303 -0
- package/dist/url.js.map +1 -0
- package/package.json +96 -3
- package/scripts/build-android.sh +27 -0
- package/scripts/test-styles.mjs +31 -0
- package/specs/NativeOrbit.ts +34 -0
- package/src/color.ts +68 -0
- package/src/commit.ts +373 -0
- package/src/errors.ts +178 -0
- package/src/host.ts +91 -0
- package/src/index.ts +64 -0
- package/src/motion.ts +88 -0
- package/src/node.ts +133 -0
- package/src/pages.ts +207 -0
- package/src/react-native/index.ts +115 -0
- package/src/react-native/react-native.d.ts +39 -0
- package/src/report.ts +25 -0
- package/src/server.ts +395 -0
- package/src/stack.ts +428 -0
- package/src/styles.ts +1021 -0
- package/src/template.ts +1681 -0
- package/src/textDecoder.ts +162 -0
- package/src/url.ts +333 -0
|
@@ -0,0 +1,1173 @@
|
|
|
1
|
+
//! Vector drawings: an `<svg>` subtree, reduced to filled and stroked paths.
|
|
2
|
+
//!
|
|
3
|
+
//! JS hands over the subtree as it was written — tags, attributes, colours
|
|
4
|
+
//! already read into ARGB — and this resolves everything a platform canvas
|
|
5
|
+
//! should not have to know: path data (relative commands, smooth curves,
|
|
6
|
+
//! arcs), the basic shapes, `g` inheritance, transforms, opacity and
|
|
7
|
+
//! `currentColor`. What comes out is a short list of shapes, each a path of
|
|
8
|
+
//! move / line / cubic / quad / close in viewBox units with its paint, which
|
|
9
|
+
//! the platform view replays scaled to its box.
|
|
10
|
+
//!
|
|
11
|
+
//! Encoding (little endian), what follows OP_VECTOR's tag and length:
|
|
12
|
+
//!
|
|
13
|
+
//! f32 x4 viewBox (min x, min y, width, height)
|
|
14
|
+
//! u8 0 xMidYMid meet, 1 none (stretch)
|
|
15
|
+
//! i32 shape count, then per shape:
|
|
16
|
+
//! i32 fill ARGB (0: none) u8 fill rule (0 nonzero, 1 evenodd)
|
|
17
|
+
//! i32 stroke ARGB (0: none) f32 stroke width u8 cap u8 join f32 miter
|
|
18
|
+
//! u8 crisp (no antialiasing)
|
|
19
|
+
//! i32 verb count, then per verb: u8 verb, its f32 points
|
|
20
|
+
//! (0 move x y, 1 line x y, 2 cubic x1 y1 x2 y2 x y, 3 quad x1 y1 x y, 4 close)
|
|
21
|
+
//!
|
|
22
|
+
//! A value the host cannot read never fails the commit, as a browser draws
|
|
23
|
+
//! the rest of a page: a non-finite number counts as absent, path data and
|
|
24
|
+
//! `points` are drawn up to their first error (SVG 2, "Path data error
|
|
25
|
+
//! handling"), and an element whose paint or `transform` cannot be read is
|
|
26
|
+
//! left out with what it holds. Each such value is reported once in the
|
|
27
|
+
//! commit's `warnings`, coded `E_ORBIT_SVG_VALUE`.
|
|
28
|
+
|
|
29
|
+
use serde_json::{Map, Value};
|
|
30
|
+
|
|
31
|
+
pub const VERB_MOVE: u8 = 0;
|
|
32
|
+
pub const VERB_LINE: u8 = 1;
|
|
33
|
+
pub const VERB_CUBIC: u8 = 2;
|
|
34
|
+
pub const VERB_QUAD: u8 = 3;
|
|
35
|
+
pub const VERB_CLOSE: u8 = 4;
|
|
36
|
+
|
|
37
|
+
/// An affine transform `[a b c d e f]`: x' = a x + c y + e, y' = b x + d y + f.
|
|
38
|
+
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
39
|
+
struct Matrix([f64; 6]);
|
|
40
|
+
|
|
41
|
+
impl Matrix {
|
|
42
|
+
const IDENTITY: Matrix = Matrix([1.0, 0.0, 0.0, 1.0, 0.0, 0.0]);
|
|
43
|
+
|
|
44
|
+
/// `self` applied after `inner` (`self × inner`).
|
|
45
|
+
fn then(self, inner: Matrix) -> Matrix {
|
|
46
|
+
let [a, b, c, d, e, f] = self.0;
|
|
47
|
+
let [p, q, r, s, t, u] = inner.0;
|
|
48
|
+
Matrix([
|
|
49
|
+
a * p + c * q,
|
|
50
|
+
b * p + d * q,
|
|
51
|
+
a * r + c * s,
|
|
52
|
+
b * r + d * s,
|
|
53
|
+
a * t + c * u + e,
|
|
54
|
+
b * t + d * u + f,
|
|
55
|
+
])
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn apply(&self, x: f64, y: f64) -> (f64, f64) {
|
|
59
|
+
let [a, b, c, d, e, f] = self.0;
|
|
60
|
+
(a * x + c * y + e, b * x + d * y + f)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// How much the transform scales a length, on average (for stroke widths).
|
|
64
|
+
fn scale(&self) -> f64 {
|
|
65
|
+
let [a, b, c, d, ..] = self.0;
|
|
66
|
+
(a * d - b * c).abs().sqrt()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
71
|
+
enum PaintValue {
|
|
72
|
+
None,
|
|
73
|
+
Current,
|
|
74
|
+
Color(u32),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// What a `g` hands down to what it holds.
|
|
78
|
+
#[derive(Clone, Copy, Debug)]
|
|
79
|
+
struct Inherited {
|
|
80
|
+
fill: PaintValue,
|
|
81
|
+
stroke: PaintValue,
|
|
82
|
+
stroke_width: f64,
|
|
83
|
+
cap: u8,
|
|
84
|
+
join: u8,
|
|
85
|
+
miter: f64,
|
|
86
|
+
fill_rule: u8,
|
|
87
|
+
fill_opacity: f64,
|
|
88
|
+
stroke_opacity: f64,
|
|
89
|
+
crisp: bool,
|
|
90
|
+
/// `opacity` is not inherited but multiplies down the groups.
|
|
91
|
+
opacity: f64,
|
|
92
|
+
matrix: Matrix,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
impl Default for Inherited {
|
|
96
|
+
fn default() -> Self {
|
|
97
|
+
Inherited {
|
|
98
|
+
fill: PaintValue::Color(0xFF00_0000),
|
|
99
|
+
stroke: PaintValue::None,
|
|
100
|
+
stroke_width: 1.0,
|
|
101
|
+
cap: 0,
|
|
102
|
+
join: 0,
|
|
103
|
+
miter: 4.0,
|
|
104
|
+
fill_rule: 0,
|
|
105
|
+
fill_opacity: 1.0,
|
|
106
|
+
stroke_opacity: 1.0,
|
|
107
|
+
crisp: false,
|
|
108
|
+
opacity: 1.0,
|
|
109
|
+
matrix: Matrix::IDENTITY,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// A path being built, in final (transformed) coordinates.
|
|
115
|
+
#[derive(Default)]
|
|
116
|
+
struct PathOut {
|
|
117
|
+
verbs: Vec<u8>,
|
|
118
|
+
points: Vec<f32>,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
impl PathOut {
|
|
122
|
+
fn push(&mut self, verb: u8, m: &Matrix, pts: &[(f64, f64)]) {
|
|
123
|
+
self.verbs.push(verb);
|
|
124
|
+
for &(x, y) in pts {
|
|
125
|
+
let (x, y) = m.apply(x, y);
|
|
126
|
+
self.points.push(x as f32);
|
|
127
|
+
self.points.push(y as f32);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// At most this many values are reported per commit: the report stays small
|
|
133
|
+
/// whatever a drawing holds.
|
|
134
|
+
pub const MAX_WARNINGS: usize = 16;
|
|
135
|
+
|
|
136
|
+
/// The longest excerpt of an attribute a warning quotes.
|
|
137
|
+
const EXCERPT: usize = 40;
|
|
138
|
+
|
|
139
|
+
/// Record a value left out (coded, bounded in count and length).
|
|
140
|
+
fn warn(warnings: &mut Vec<String>, message: String) {
|
|
141
|
+
if warnings.len() < MAX_WARNINGS {
|
|
142
|
+
warnings.push(format!("E_ORBIT_SVG_VALUE: {message}"));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// The start of an attribute, quoted, for a warning.
|
|
147
|
+
fn excerpt(text: &str) -> String {
|
|
148
|
+
match text.char_indices().nth(EXCERPT) {
|
|
149
|
+
Some((end, _)) => format!("{:?}…", &text[..end]),
|
|
150
|
+
None => format!("{text:?}"),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// Read an `<svg>` description (`{ color, root }`) into the encoding above.
|
|
155
|
+
/// What cannot be read is left out and reported in `warnings`.
|
|
156
|
+
pub fn encode(vector: &Value, warnings: &mut Vec<String>) -> Vec<u8> {
|
|
157
|
+
let current = vector
|
|
158
|
+
.get("color")
|
|
159
|
+
.and_then(Value::as_i64)
|
|
160
|
+
.unwrap_or(0xFF00_0000) as u32;
|
|
161
|
+
let root = vector.get("root").unwrap_or(&Value::Null);
|
|
162
|
+
let attrs = attrs_of(root);
|
|
163
|
+
let sized = || {
|
|
164
|
+
let w = attr_num(attrs, "width").unwrap_or(300.0);
|
|
165
|
+
let h = attr_num(attrs, "height").unwrap_or(150.0);
|
|
166
|
+
[0.0, 0.0, w, h]
|
|
167
|
+
};
|
|
168
|
+
let view_box = match attr_str(attrs, "viewBox") {
|
|
169
|
+
Some(text) => match numbers(text) {
|
|
170
|
+
Ok(n) if n.len() == 4 && n[2] > 0.0 && n[3] > 0.0 => [n[0], n[1], n[2], n[3]],
|
|
171
|
+
_ => {
|
|
172
|
+
warn(
|
|
173
|
+
warnings,
|
|
174
|
+
format!(
|
|
175
|
+
"svg: viewBox {} is not four numbers with a positive size",
|
|
176
|
+
excerpt(text)
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
sized()
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
None => sized(),
|
|
183
|
+
};
|
|
184
|
+
let stretch = attr_str(attrs, "preserveAspectRatio").map(str::trim) == Some("none");
|
|
185
|
+
let mut shapes: Vec<u8> = Vec::new();
|
|
186
|
+
let mut count = 0i32;
|
|
187
|
+
match inherit(Inherited::default(), attrs) {
|
|
188
|
+
Ok(inherited) => {
|
|
189
|
+
for child in children_of(root) {
|
|
190
|
+
walk(child, inherited, current, &mut shapes, &mut count, warnings);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
Err(e) => warn(warnings, format!("{e}: the drawing is left out")),
|
|
194
|
+
}
|
|
195
|
+
let mut out = Vec::with_capacity(21 + shapes.len());
|
|
196
|
+
for v in view_box {
|
|
197
|
+
out.extend_from_slice(&(v as f32).to_le_bytes());
|
|
198
|
+
}
|
|
199
|
+
out.push(u8::from(stretch));
|
|
200
|
+
out.extend_from_slice(&count.to_le_bytes());
|
|
201
|
+
out.extend_from_slice(&shapes);
|
|
202
|
+
out
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
fn attrs_of(node: &Value) -> &Map<String, Value> {
|
|
206
|
+
static EMPTY: std::sync::OnceLock<Map<String, Value>> = std::sync::OnceLock::new();
|
|
207
|
+
node.get("a")
|
|
208
|
+
.and_then(Value::as_object)
|
|
209
|
+
.unwrap_or_else(|| EMPTY.get_or_init(Map::new))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
fn children_of(node: &Value) -> &[Value] {
|
|
213
|
+
node.get("c")
|
|
214
|
+
.and_then(Value::as_array)
|
|
215
|
+
.map_or(&[], Vec::as_slice)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fn attr_str<'a>(attrs: &'a Map<String, Value>, key: &str) -> Option<&'a str> {
|
|
219
|
+
attrs.get(key).and_then(Value::as_str)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// A number attribute; a value that is not a finite number (`NaN`,
|
|
223
|
+
/// `Infinity`, `undefined`) counts as absent, as an attribute in error does.
|
|
224
|
+
fn attr_num(attrs: &Map<String, Value>, key: &str) -> Option<f64> {
|
|
225
|
+
match attrs.get(key)? {
|
|
226
|
+
Value::Number(n) => n.as_f64().filter(|v| v.is_finite()),
|
|
227
|
+
Value::String(s) => length(s),
|
|
228
|
+
_ => None,
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// A length attribute: a finite number, optionally in px.
|
|
233
|
+
fn length(text: &str) -> Option<f64> {
|
|
234
|
+
let text = text.trim();
|
|
235
|
+
let text = text.strip_suffix("px").unwrap_or(text);
|
|
236
|
+
text.parse::<f64>().ok().filter(|v| v.is_finite())
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fn paint(value: &Value) -> Result<PaintValue, String> {
|
|
240
|
+
match value {
|
|
241
|
+
Value::Number(n) => Ok(PaintValue::Color(n.as_i64().unwrap_or(0) as u32)),
|
|
242
|
+
Value::String(s) if s == "none" || s == "transparent" => Ok(PaintValue::None),
|
|
243
|
+
Value::String(s) if s == "currentColor" => Ok(PaintValue::Current),
|
|
244
|
+
Value::String(s) => Err(format!("svg: paint {} is not a colour", excerpt(s))),
|
|
245
|
+
other => Err(format!(
|
|
246
|
+
"svg: paint {} is not a colour",
|
|
247
|
+
excerpt(&other.to_string())
|
|
248
|
+
)),
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/// The inherited properties after `attrs` (a `g`, a shape or the svg itself).
|
|
253
|
+
fn inherit(mut st: Inherited, attrs: &Map<String, Value>) -> Result<Inherited, String> {
|
|
254
|
+
if let Some(v) = attrs.get("fill") {
|
|
255
|
+
st.fill = paint(v)?;
|
|
256
|
+
}
|
|
257
|
+
if let Some(v) = attrs.get("stroke") {
|
|
258
|
+
st.stroke = paint(v)?;
|
|
259
|
+
}
|
|
260
|
+
if let Some(w) = attr_num(attrs, "stroke-width") {
|
|
261
|
+
st.stroke_width = w.max(0.0);
|
|
262
|
+
}
|
|
263
|
+
if let Some(cap) = attr_str(attrs, "stroke-linecap") {
|
|
264
|
+
st.cap = match cap {
|
|
265
|
+
"round" => 1,
|
|
266
|
+
"square" => 2,
|
|
267
|
+
_ => 0,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if let Some(join) = attr_str(attrs, "stroke-linejoin") {
|
|
271
|
+
st.join = match join {
|
|
272
|
+
"round" => 1,
|
|
273
|
+
"bevel" => 2,
|
|
274
|
+
_ => 0,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if let Some(m) = attr_num(attrs, "stroke-miterlimit") {
|
|
278
|
+
st.miter = m.max(1.0);
|
|
279
|
+
}
|
|
280
|
+
if let Some(rule) = attr_str(attrs, "fill-rule") {
|
|
281
|
+
st.fill_rule = u8::from(rule == "evenodd");
|
|
282
|
+
}
|
|
283
|
+
if let Some(o) = attr_num(attrs, "fill-opacity") {
|
|
284
|
+
st.fill_opacity = o.clamp(0.0, 1.0);
|
|
285
|
+
}
|
|
286
|
+
if let Some(o) = attr_num(attrs, "stroke-opacity") {
|
|
287
|
+
st.stroke_opacity = o.clamp(0.0, 1.0);
|
|
288
|
+
}
|
|
289
|
+
if let Some(o) = attr_num(attrs, "opacity") {
|
|
290
|
+
st.opacity *= o.clamp(0.0, 1.0);
|
|
291
|
+
}
|
|
292
|
+
if let Some(r) = attr_str(attrs, "shape-rendering") {
|
|
293
|
+
st.crisp = r == "crispEdges" || r == "optimizeSpeed";
|
|
294
|
+
}
|
|
295
|
+
if let Some(t) = attr_str(attrs, "transform") {
|
|
296
|
+
st.matrix = st.matrix.then(transform(t)?);
|
|
297
|
+
}
|
|
298
|
+
Ok(st)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
fn walk(
|
|
302
|
+
node: &Value,
|
|
303
|
+
parent: Inherited,
|
|
304
|
+
current: u32,
|
|
305
|
+
out: &mut Vec<u8>,
|
|
306
|
+
count: &mut i32,
|
|
307
|
+
warnings: &mut Vec<String>,
|
|
308
|
+
) {
|
|
309
|
+
let tag = node.get("t").and_then(Value::as_str).unwrap_or("");
|
|
310
|
+
let attrs = attrs_of(node);
|
|
311
|
+
let st = match inherit(parent, attrs) {
|
|
312
|
+
Ok(st) => st,
|
|
313
|
+
Err(e) => {
|
|
314
|
+
warn(warnings, format!("{e}: <{}> is left out", excerpt(tag)));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
let mut path = PathOut::default();
|
|
319
|
+
let m = st.matrix;
|
|
320
|
+
let num = |key: &str| attr_num(attrs, key).unwrap_or(0.0);
|
|
321
|
+
match tag {
|
|
322
|
+
"g" => {
|
|
323
|
+
for child in children_of(node) {
|
|
324
|
+
walk(child, st, current, out, count, warnings);
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
"path" => {
|
|
329
|
+
if let Some(d) = attr_str(attrs, "d") {
|
|
330
|
+
// Drawn up to the first error, as SVG 2 says.
|
|
331
|
+
if let Err(e) = path_data(d, &m, &mut path) {
|
|
332
|
+
warn(warnings, format!("{e} in d={}", excerpt(d)));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
"rect" => {
|
|
337
|
+
let (x, y, w, h) = (num("x"), num("y"), num("width"), num("height"));
|
|
338
|
+
if w <= 0.0 || h <= 0.0 {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
let rx = attr_num(attrs, "rx");
|
|
342
|
+
let ry = attr_num(attrs, "ry");
|
|
343
|
+
let (rx, ry) = match (rx, ry) {
|
|
344
|
+
(Some(a), Some(b)) => (a, b),
|
|
345
|
+
(Some(a), None) | (None, Some(a)) => (a, a),
|
|
346
|
+
(None, None) => (0.0, 0.0),
|
|
347
|
+
};
|
|
348
|
+
rect(
|
|
349
|
+
x,
|
|
350
|
+
y,
|
|
351
|
+
w,
|
|
352
|
+
h,
|
|
353
|
+
rx.clamp(0.0, w / 2.0),
|
|
354
|
+
ry.clamp(0.0, h / 2.0),
|
|
355
|
+
&m,
|
|
356
|
+
&mut path,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
"circle" => {
|
|
360
|
+
let r = num("r");
|
|
361
|
+
if r > 0.0 {
|
|
362
|
+
ellipse(num("cx"), num("cy"), r, r, &m, &mut path);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
"ellipse" => {
|
|
366
|
+
let (rx, ry) = (num("rx"), num("ry"));
|
|
367
|
+
if rx > 0.0 && ry > 0.0 {
|
|
368
|
+
ellipse(num("cx"), num("cy"), rx, ry, &m, &mut path);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
"line" => {
|
|
372
|
+
path.push(VERB_MOVE, &m, &[(num("x1"), num("y1"))]);
|
|
373
|
+
path.push(VERB_LINE, &m, &[(num("x2"), num("y2"))]);
|
|
374
|
+
}
|
|
375
|
+
"polyline" | "polygon" => {
|
|
376
|
+
let text = attr_str(attrs, "points").unwrap_or("");
|
|
377
|
+
// Drawn up to the first error, as SVG 2 says (an odd count
|
|
378
|
+
// leaves the last number out).
|
|
379
|
+
let (pts, error) = numbers_until_error(text);
|
|
380
|
+
if let Some(e) = error {
|
|
381
|
+
warn(warnings, format!("{e} in points={}", excerpt(text)));
|
|
382
|
+
}
|
|
383
|
+
for (i, [x, y]) in pts.as_chunks::<2>().0.iter().enumerate() {
|
|
384
|
+
let verb = if i == 0 { VERB_MOVE } else { VERB_LINE };
|
|
385
|
+
path.push(verb, &m, &[(*x, *y)]);
|
|
386
|
+
}
|
|
387
|
+
if tag == "polygon" && !path.verbs.is_empty() {
|
|
388
|
+
path.verbs.push(VERB_CLOSE);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
"title" | "desc" | "metadata" => return,
|
|
392
|
+
other => {
|
|
393
|
+
warn(
|
|
394
|
+
warnings,
|
|
395
|
+
format!("svg: <{}> is not drawn by orbit", excerpt(other)),
|
|
396
|
+
);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if path.verbs.is_empty() {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
// Finite numbers can still add up past what an f32 holds.
|
|
404
|
+
let width = (st.stroke_width * m.scale()) as f32;
|
|
405
|
+
if !width.is_finite() || path.points.iter().any(|v| !v.is_finite()) {
|
|
406
|
+
warn(
|
|
407
|
+
warnings,
|
|
408
|
+
format!(
|
|
409
|
+
"svg: <{}> lies outside the numbers a drawing holds",
|
|
410
|
+
excerpt(tag)
|
|
411
|
+
),
|
|
412
|
+
);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
// A line has no inside: only its stroke shows.
|
|
416
|
+
let fill = if tag == "line" {
|
|
417
|
+
0
|
|
418
|
+
} else {
|
|
419
|
+
argb(st.fill, current, st.fill_opacity * st.opacity)
|
|
420
|
+
};
|
|
421
|
+
let stroke = argb(st.stroke, current, st.stroke_opacity * st.opacity);
|
|
422
|
+
if fill == 0 && (stroke == 0 || st.stroke_width == 0.0) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
out.extend_from_slice(&fill.to_le_bytes());
|
|
426
|
+
out.push(st.fill_rule);
|
|
427
|
+
out.extend_from_slice(&stroke.to_le_bytes());
|
|
428
|
+
out.extend_from_slice(&width.to_le_bytes());
|
|
429
|
+
out.push(st.cap);
|
|
430
|
+
out.push(st.join);
|
|
431
|
+
out.extend_from_slice(&(st.miter as f32).to_le_bytes());
|
|
432
|
+
out.push(u8::from(st.crisp));
|
|
433
|
+
out.extend_from_slice(&(path.verbs.len() as i32).to_le_bytes());
|
|
434
|
+
let mut p = 0;
|
|
435
|
+
for verb in path.verbs {
|
|
436
|
+
out.push(verb);
|
|
437
|
+
let n = match verb {
|
|
438
|
+
VERB_MOVE | VERB_LINE => 2,
|
|
439
|
+
VERB_CUBIC => 6,
|
|
440
|
+
VERB_QUAD => 4,
|
|
441
|
+
_ => 0,
|
|
442
|
+
};
|
|
443
|
+
for v in &path.points[p..p + n] {
|
|
444
|
+
out.extend_from_slice(&v.to_le_bytes());
|
|
445
|
+
}
|
|
446
|
+
p += n;
|
|
447
|
+
}
|
|
448
|
+
*count += 1;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/// A paint as ARGB with `opacity` folded into its alpha; 0 for none.
|
|
452
|
+
fn argb(paint: PaintValue, current: u32, opacity: f64) -> i32 {
|
|
453
|
+
let color = match paint {
|
|
454
|
+
PaintValue::None => return 0,
|
|
455
|
+
PaintValue::Current => current,
|
|
456
|
+
PaintValue::Color(c) => c,
|
|
457
|
+
};
|
|
458
|
+
let alpha = (f64::from(color >> 24) * opacity).round() as u32;
|
|
459
|
+
if alpha == 0 {
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
462
|
+
((alpha << 24) | (color & 0x00FF_FFFF)) as i32
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ------------------------------------------------------------------ shapes
|
|
466
|
+
|
|
467
|
+
/// The cubic Bezier that best follows a quarter circle, as a fraction of r.
|
|
468
|
+
const KAPPA: f64 = 0.552_284_749_830_793_6;
|
|
469
|
+
|
|
470
|
+
fn ellipse(cx: f64, cy: f64, rx: f64, ry: f64, m: &Matrix, out: &mut PathOut) {
|
|
471
|
+
let (kx, ky) = (rx * KAPPA, ry * KAPPA);
|
|
472
|
+
out.push(VERB_MOVE, m, &[(cx + rx, cy)]);
|
|
473
|
+
out.push(
|
|
474
|
+
VERB_CUBIC,
|
|
475
|
+
m,
|
|
476
|
+
&[(cx + rx, cy + ky), (cx + kx, cy + ry), (cx, cy + ry)],
|
|
477
|
+
);
|
|
478
|
+
out.push(
|
|
479
|
+
VERB_CUBIC,
|
|
480
|
+
m,
|
|
481
|
+
&[(cx - kx, cy + ry), (cx - rx, cy + ky), (cx - rx, cy)],
|
|
482
|
+
);
|
|
483
|
+
out.push(
|
|
484
|
+
VERB_CUBIC,
|
|
485
|
+
m,
|
|
486
|
+
&[(cx - rx, cy - ky), (cx - kx, cy - ry), (cx, cy - ry)],
|
|
487
|
+
);
|
|
488
|
+
out.push(
|
|
489
|
+
VERB_CUBIC,
|
|
490
|
+
m,
|
|
491
|
+
&[(cx + kx, cy - ry), (cx + rx, cy - ky), (cx + rx, cy)],
|
|
492
|
+
);
|
|
493
|
+
out.verbs.push(VERB_CLOSE);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
#[allow(clippy::too_many_arguments)]
|
|
497
|
+
fn rect(x: f64, y: f64, w: f64, h: f64, rx: f64, ry: f64, m: &Matrix, out: &mut PathOut) {
|
|
498
|
+
if rx <= 0.0 || ry <= 0.0 {
|
|
499
|
+
out.push(VERB_MOVE, m, &[(x, y)]);
|
|
500
|
+
out.push(VERB_LINE, m, &[(x + w, y)]);
|
|
501
|
+
out.push(VERB_LINE, m, &[(x + w, y + h)]);
|
|
502
|
+
out.push(VERB_LINE, m, &[(x, y + h)]);
|
|
503
|
+
out.verbs.push(VERB_CLOSE);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
let (kx, ky) = (rx * KAPPA, ry * KAPPA);
|
|
507
|
+
let (r, b) = (x + w, y + h);
|
|
508
|
+
out.push(VERB_MOVE, m, &[(x + rx, y)]);
|
|
509
|
+
out.push(VERB_LINE, m, &[(r - rx, y)]);
|
|
510
|
+
out.push(
|
|
511
|
+
VERB_CUBIC,
|
|
512
|
+
m,
|
|
513
|
+
&[(r - rx + kx, y), (r, y + ry - ky), (r, y + ry)],
|
|
514
|
+
);
|
|
515
|
+
out.push(VERB_LINE, m, &[(r, b - ry)]);
|
|
516
|
+
out.push(
|
|
517
|
+
VERB_CUBIC,
|
|
518
|
+
m,
|
|
519
|
+
&[(r, b - ry + ky), (r - rx + kx, b), (r - rx, b)],
|
|
520
|
+
);
|
|
521
|
+
out.push(VERB_LINE, m, &[(x + rx, b)]);
|
|
522
|
+
out.push(
|
|
523
|
+
VERB_CUBIC,
|
|
524
|
+
m,
|
|
525
|
+
&[(x + rx - kx, b), (x, b - ry + ky), (x, b - ry)],
|
|
526
|
+
);
|
|
527
|
+
out.push(VERB_LINE, m, &[(x, y + ry)]);
|
|
528
|
+
out.push(
|
|
529
|
+
VERB_CUBIC,
|
|
530
|
+
m,
|
|
531
|
+
&[(x, y + ry - ky), (x + rx - kx, y), (x + rx, y)],
|
|
532
|
+
);
|
|
533
|
+
out.verbs.push(VERB_CLOSE);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// ------------------------------------------------------------------ numbers
|
|
537
|
+
|
|
538
|
+
/// A reader over SVG's number lists: `4.3-4.3`, `.5.5`, `1e-3`, commas or spaces.
|
|
539
|
+
struct Scanner<'a> {
|
|
540
|
+
s: &'a [u8],
|
|
541
|
+
i: usize,
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
impl<'a> Scanner<'a> {
|
|
545
|
+
fn new(s: &'a str) -> Self {
|
|
546
|
+
Scanner {
|
|
547
|
+
s: s.as_bytes(),
|
|
548
|
+
i: 0,
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
fn skip_separators(&mut self) {
|
|
553
|
+
while self.i < self.s.len() && matches!(self.s[self.i], b' ' | b'\t' | b'\n' | b'\r' | b',')
|
|
554
|
+
{
|
|
555
|
+
self.i += 1;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
fn peek(&mut self) -> Option<u8> {
|
|
560
|
+
self.skip_separators();
|
|
561
|
+
self.s.get(self.i).copied()
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
fn at_number(&mut self) -> bool {
|
|
565
|
+
matches!(self.peek(), Some(b'0'..=b'9' | b'.' | b'-' | b'+'))
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
fn number(&mut self) -> Result<f64, String> {
|
|
569
|
+
self.skip_separators();
|
|
570
|
+
let start = self.i;
|
|
571
|
+
let s = self.s;
|
|
572
|
+
if matches!(s.get(self.i), Some(b'-' | b'+')) {
|
|
573
|
+
self.i += 1;
|
|
574
|
+
}
|
|
575
|
+
let mut digits = 0;
|
|
576
|
+
while matches!(s.get(self.i), Some(b'0'..=b'9')) {
|
|
577
|
+
self.i += 1;
|
|
578
|
+
digits += 1;
|
|
579
|
+
}
|
|
580
|
+
if s.get(self.i) == Some(&b'.') {
|
|
581
|
+
self.i += 1;
|
|
582
|
+
while matches!(s.get(self.i), Some(b'0'..=b'9')) {
|
|
583
|
+
self.i += 1;
|
|
584
|
+
digits += 1;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if digits > 0 && matches!(s.get(self.i), Some(b'e' | b'E')) {
|
|
588
|
+
let save = self.i;
|
|
589
|
+
self.i += 1;
|
|
590
|
+
if matches!(s.get(self.i), Some(b'-' | b'+')) {
|
|
591
|
+
self.i += 1;
|
|
592
|
+
}
|
|
593
|
+
if matches!(s.get(self.i), Some(b'0'..=b'9')) {
|
|
594
|
+
while matches!(s.get(self.i), Some(b'0'..=b'9')) {
|
|
595
|
+
self.i += 1;
|
|
596
|
+
}
|
|
597
|
+
} else {
|
|
598
|
+
self.i = save;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if digits == 0 {
|
|
602
|
+
return Err(format!("svg: a number was expected at {start}"));
|
|
603
|
+
}
|
|
604
|
+
std::str::from_utf8(&s[start..self.i])
|
|
605
|
+
.ok()
|
|
606
|
+
.and_then(|t| t.parse::<f64>().ok())
|
|
607
|
+
.filter(|v| v.is_finite())
|
|
608
|
+
.ok_or_else(|| format!("svg: unreadable number at {start}"))
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/// An arc flag: one `0` or `1`, which may touch what follows (`a1 1 0 011 1`).
|
|
612
|
+
fn flag(&mut self) -> Result<bool, String> {
|
|
613
|
+
match self.peek() {
|
|
614
|
+
Some(b'0') => {
|
|
615
|
+
self.i += 1;
|
|
616
|
+
Ok(false)
|
|
617
|
+
}
|
|
618
|
+
Some(b'1') => {
|
|
619
|
+
self.i += 1;
|
|
620
|
+
Ok(true)
|
|
621
|
+
}
|
|
622
|
+
_ => Err(format!("svg: an arc flag was expected at {}", self.i)),
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
fn numbers(text: &str) -> Result<Vec<f64>, String> {
|
|
628
|
+
match numbers_until_error(text) {
|
|
629
|
+
(out, None) => Ok(out),
|
|
630
|
+
(_, Some(e)) => Err(e),
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/// The numbers read before the first error, and that error.
|
|
635
|
+
fn numbers_until_error(text: &str) -> (Vec<f64>, Option<String>) {
|
|
636
|
+
let mut sc = Scanner::new(text);
|
|
637
|
+
let mut out = Vec::new();
|
|
638
|
+
while sc.peek().is_some() {
|
|
639
|
+
match sc.number() {
|
|
640
|
+
Ok(n) => out.push(n),
|
|
641
|
+
Err(e) => return (out, Some(e)),
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
(out, None)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/// A `transform` attribute: a list of matrix / translate / scale / rotate / skewX / skewY.
|
|
648
|
+
fn transform(text: &str) -> Result<Matrix, String> {
|
|
649
|
+
let mut m = Matrix::IDENTITY;
|
|
650
|
+
let mut rest = text.trim();
|
|
651
|
+
while !rest.is_empty() {
|
|
652
|
+
let unreadable = || format!("svg: transform {} is not read", excerpt(text));
|
|
653
|
+
let open = rest.find('(').ok_or_else(unreadable)?;
|
|
654
|
+
// The `)` that closes this `(`, not one written before it.
|
|
655
|
+
let close = rest[open..].find(')').ok_or_else(unreadable)? + open;
|
|
656
|
+
let name = rest[..open].trim().trim_start_matches(',').trim();
|
|
657
|
+
let a = numbers(&rest[open + 1..close])?;
|
|
658
|
+
let get = |i: usize| a.get(i).copied();
|
|
659
|
+
let t = match (name, a.len()) {
|
|
660
|
+
("matrix", 6) => Matrix([a[0], a[1], a[2], a[3], a[4], a[5]]),
|
|
661
|
+
("translate", 1 | 2) => Matrix([1.0, 0.0, 0.0, 1.0, a[0], get(1).unwrap_or(0.0)]),
|
|
662
|
+
("scale", 1 | 2) => Matrix([a[0], 0.0, 0.0, get(1).unwrap_or(a[0]), 0.0, 0.0]),
|
|
663
|
+
("rotate", 1 | 3) => {
|
|
664
|
+
let (s, c) = a[0].to_radians().sin_cos();
|
|
665
|
+
let r = Matrix([c, s, -s, c, 0.0, 0.0]);
|
|
666
|
+
match (get(1), get(2)) {
|
|
667
|
+
(Some(cx), Some(cy)) => Matrix([1.0, 0.0, 0.0, 1.0, cx, cy])
|
|
668
|
+
.then(r)
|
|
669
|
+
.then(Matrix([1.0, 0.0, 0.0, 1.0, -cx, -cy])),
|
|
670
|
+
_ => r,
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
("skewX", 1) => Matrix([1.0, 0.0, a[0].to_radians().tan(), 1.0, 0.0, 0.0]),
|
|
674
|
+
("skewY", 1) => Matrix([1.0, a[0].to_radians().tan(), 0.0, 1.0, 0.0, 0.0]),
|
|
675
|
+
_ => return Err(format!("svg: transform {name}({}) is not read", a.len())),
|
|
676
|
+
};
|
|
677
|
+
m = m.then(t);
|
|
678
|
+
rest = rest[close + 1..].trim();
|
|
679
|
+
}
|
|
680
|
+
Ok(m)
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// ------------------------------------------------------------------ path data
|
|
684
|
+
|
|
685
|
+
/// Path data (`d`), every command made absolute and reduced to move, line,
|
|
686
|
+
/// cubic, quad and close.
|
|
687
|
+
fn path_data(d: &str, m: &Matrix, out: &mut PathOut) -> Result<(), String> {
|
|
688
|
+
let mut sc = Scanner::new(d);
|
|
689
|
+
let (mut x, mut y) = (0.0f64, 0.0f64);
|
|
690
|
+
let (mut sx, mut sy) = (0.0f64, 0.0f64);
|
|
691
|
+
// The last control point, for S and T, and which kind it came from.
|
|
692
|
+
let mut last_cubic: Option<(f64, f64)> = None;
|
|
693
|
+
let mut last_quad: Option<(f64, f64)> = None;
|
|
694
|
+
let mut cmd: Option<u8> = None;
|
|
695
|
+
while let Some(c) = sc.peek() {
|
|
696
|
+
let command = if c.is_ascii_alphabetic() {
|
|
697
|
+
sc.i += 1;
|
|
698
|
+
c
|
|
699
|
+
} else {
|
|
700
|
+
match cmd {
|
|
701
|
+
// Coordinates after a moveto are implicit linetos.
|
|
702
|
+
Some(b'M') => b'L',
|
|
703
|
+
Some(b'm') => b'l',
|
|
704
|
+
Some(prev) if prev != b'Z' && prev != b'z' => prev,
|
|
705
|
+
_ => return Err("svg: path data does not start with a command".to_owned()),
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
let rel = command.is_ascii_lowercase();
|
|
709
|
+
let (ox, oy) = if rel { (x, y) } else { (0.0, 0.0) };
|
|
710
|
+
let mut cubic_ctrl = None;
|
|
711
|
+
let mut quad_ctrl = None;
|
|
712
|
+
match command.to_ascii_uppercase() {
|
|
713
|
+
b'M' => {
|
|
714
|
+
x = ox + sc.number()?;
|
|
715
|
+
y = oy + sc.number()?;
|
|
716
|
+
(sx, sy) = (x, y);
|
|
717
|
+
out.push(VERB_MOVE, m, &[(x, y)]);
|
|
718
|
+
}
|
|
719
|
+
b'L' => {
|
|
720
|
+
x = ox + sc.number()?;
|
|
721
|
+
y = oy + sc.number()?;
|
|
722
|
+
out.push(VERB_LINE, m, &[(x, y)]);
|
|
723
|
+
}
|
|
724
|
+
b'H' => {
|
|
725
|
+
x = ox + sc.number()?;
|
|
726
|
+
out.push(VERB_LINE, m, &[(x, y)]);
|
|
727
|
+
}
|
|
728
|
+
b'V' => {
|
|
729
|
+
y = (if rel { y } else { 0.0 }) + sc.number()?;
|
|
730
|
+
out.push(VERB_LINE, m, &[(x, y)]);
|
|
731
|
+
}
|
|
732
|
+
b'C' => {
|
|
733
|
+
let p1 = (ox + sc.number()?, oy + sc.number()?);
|
|
734
|
+
let p2 = (ox + sc.number()?, oy + sc.number()?);
|
|
735
|
+
(x, y) = (ox + sc.number()?, oy + sc.number()?);
|
|
736
|
+
out.push(VERB_CUBIC, m, &[p1, p2, (x, y)]);
|
|
737
|
+
cubic_ctrl = Some(p2);
|
|
738
|
+
}
|
|
739
|
+
b'S' => {
|
|
740
|
+
let p1 = match last_cubic {
|
|
741
|
+
Some((cx, cy)) => (2.0 * x - cx, 2.0 * y - cy),
|
|
742
|
+
None => (x, y),
|
|
743
|
+
};
|
|
744
|
+
let p2 = (ox + sc.number()?, oy + sc.number()?);
|
|
745
|
+
(x, y) = (ox + sc.number()?, oy + sc.number()?);
|
|
746
|
+
out.push(VERB_CUBIC, m, &[p1, p2, (x, y)]);
|
|
747
|
+
cubic_ctrl = Some(p2);
|
|
748
|
+
}
|
|
749
|
+
b'Q' => {
|
|
750
|
+
let p1 = (ox + sc.number()?, oy + sc.number()?);
|
|
751
|
+
(x, y) = (ox + sc.number()?, oy + sc.number()?);
|
|
752
|
+
out.push(VERB_QUAD, m, &[p1, (x, y)]);
|
|
753
|
+
quad_ctrl = Some(p1);
|
|
754
|
+
}
|
|
755
|
+
b'T' => {
|
|
756
|
+
let p1 = match last_quad {
|
|
757
|
+
Some((cx, cy)) => (2.0 * x - cx, 2.0 * y - cy),
|
|
758
|
+
None => (x, y),
|
|
759
|
+
};
|
|
760
|
+
(x, y) = (ox + sc.number()?, oy + sc.number()?);
|
|
761
|
+
out.push(VERB_QUAD, m, &[p1, (x, y)]);
|
|
762
|
+
quad_ctrl = Some(p1);
|
|
763
|
+
}
|
|
764
|
+
b'A' => {
|
|
765
|
+
let rx = sc.number()?.abs();
|
|
766
|
+
let ry = sc.number()?.abs();
|
|
767
|
+
let rotation = sc.number()?;
|
|
768
|
+
let large = sc.flag()?;
|
|
769
|
+
let sweep = sc.flag()?;
|
|
770
|
+
let (ex, ey) = (ox + sc.number()?, oy + sc.number()?);
|
|
771
|
+
arc((x, y), rx, ry, rotation, large, sweep, (ex, ey), m, out);
|
|
772
|
+
(x, y) = (ex, ey);
|
|
773
|
+
}
|
|
774
|
+
b'Z' => {
|
|
775
|
+
out.verbs.push(VERB_CLOSE);
|
|
776
|
+
(x, y) = (sx, sy);
|
|
777
|
+
}
|
|
778
|
+
other => return Err(format!("svg: path command {:?} is not read", other as char)),
|
|
779
|
+
}
|
|
780
|
+
last_cubic = cubic_ctrl;
|
|
781
|
+
last_quad = quad_ctrl;
|
|
782
|
+
cmd = Some(command);
|
|
783
|
+
// A command letter must come next unless more coordinates follow.
|
|
784
|
+
if !sc.at_number() && !matches!(sc.peek(), None | Some(b'A'..=b'Z' | b'a'..=b'z')) {
|
|
785
|
+
return Err(format!("svg: unreadable path data at {}", sc.i));
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
Ok(())
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/// An elliptical arc as cubics (SVG 1.1 F.6: endpoint to center
|
|
792
|
+
/// parameterization, then at most a quarter turn per cubic).
|
|
793
|
+
#[allow(clippy::too_many_arguments)]
|
|
794
|
+
fn arc(
|
|
795
|
+
from: (f64, f64),
|
|
796
|
+
mut rx: f64,
|
|
797
|
+
mut ry: f64,
|
|
798
|
+
rotation: f64,
|
|
799
|
+
large: bool,
|
|
800
|
+
sweep: bool,
|
|
801
|
+
to: (f64, f64),
|
|
802
|
+
m: &Matrix,
|
|
803
|
+
out: &mut PathOut,
|
|
804
|
+
) {
|
|
805
|
+
if from == to {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if rx == 0.0 || ry == 0.0 {
|
|
809
|
+
out.push(VERB_LINE, m, &[to]);
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
let (sin, cos) = rotation.to_radians().sin_cos();
|
|
813
|
+
let dx = (from.0 - to.0) / 2.0;
|
|
814
|
+
let dy = (from.1 - to.1) / 2.0;
|
|
815
|
+
let x1 = cos * dx + sin * dy;
|
|
816
|
+
let y1 = -sin * dx + cos * dy;
|
|
817
|
+
let lambda = (x1 * x1) / (rx * rx) + (y1 * y1) / (ry * ry);
|
|
818
|
+
if lambda > 1.0 {
|
|
819
|
+
let s = lambda.sqrt();
|
|
820
|
+
rx *= s;
|
|
821
|
+
ry *= s;
|
|
822
|
+
}
|
|
823
|
+
let num = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1;
|
|
824
|
+
let den = rx * rx * y1 * y1 + ry * ry * x1 * x1;
|
|
825
|
+
let mut coef = (num / den).max(0.0).sqrt();
|
|
826
|
+
if large == sweep {
|
|
827
|
+
coef = -coef;
|
|
828
|
+
}
|
|
829
|
+
let cx1 = coef * rx * y1 / ry;
|
|
830
|
+
let cy1 = -coef * ry * x1 / rx;
|
|
831
|
+
let cx = cos * cx1 - sin * cy1 + (from.0 + to.0) / 2.0;
|
|
832
|
+
let cy = sin * cx1 + cos * cy1 + (from.1 + to.1) / 2.0;
|
|
833
|
+
let angle = |ux: f64, uy: f64, vx: f64, vy: f64| (ux * vy - uy * vx).atan2(ux * vx + uy * vy);
|
|
834
|
+
let theta = angle(1.0, 0.0, (x1 - cx1) / rx, (y1 - cy1) / ry);
|
|
835
|
+
let mut delta = angle(
|
|
836
|
+
(x1 - cx1) / rx,
|
|
837
|
+
(y1 - cy1) / ry,
|
|
838
|
+
(-x1 - cx1) / rx,
|
|
839
|
+
(-y1 - cy1) / ry,
|
|
840
|
+
);
|
|
841
|
+
if !sweep && delta > 0.0 {
|
|
842
|
+
delta -= std::f64::consts::TAU;
|
|
843
|
+
} else if sweep && delta < 0.0 {
|
|
844
|
+
delta += std::f64::consts::TAU;
|
|
845
|
+
}
|
|
846
|
+
let segments = (delta.abs() / std::f64::consts::FRAC_PI_2).ceil().max(1.0) as usize;
|
|
847
|
+
let step = delta / segments as f64;
|
|
848
|
+
let k = 4.0 / 3.0 * (step / 4.0).tan();
|
|
849
|
+
let point = |t: f64| {
|
|
850
|
+
let (s, c) = t.sin_cos();
|
|
851
|
+
(
|
|
852
|
+
cx + rx * c * cos - ry * s * sin,
|
|
853
|
+
cy + rx * c * sin + ry * s * cos,
|
|
854
|
+
)
|
|
855
|
+
};
|
|
856
|
+
let derivative = |t: f64| {
|
|
857
|
+
let (s, c) = t.sin_cos();
|
|
858
|
+
(-rx * s * cos - ry * c * sin, -rx * s * sin + ry * c * cos)
|
|
859
|
+
};
|
|
860
|
+
let mut t = theta;
|
|
861
|
+
for i in 0..segments {
|
|
862
|
+
let t2 = t + step;
|
|
863
|
+
let p0 = point(t);
|
|
864
|
+
let p3 = if i + 1 == segments { to } else { point(t2) };
|
|
865
|
+
let d0 = derivative(t);
|
|
866
|
+
let d3 = derivative(t2);
|
|
867
|
+
let p1 = (p0.0 + k * d0.0, p0.1 + k * d0.1);
|
|
868
|
+
let p2 = (p3.0 - k * d3.0, p3.1 - k * d3.1);
|
|
869
|
+
out.push(VERB_CUBIC, m, &[p1, p2, p3]);
|
|
870
|
+
t = t2;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
#[cfg(test)]
|
|
875
|
+
mod tests {
|
|
876
|
+
use super::*;
|
|
877
|
+
use serde_json::json;
|
|
878
|
+
|
|
879
|
+
fn path_of(d: &str) -> (Vec<u8>, Vec<f32>) {
|
|
880
|
+
let mut out = PathOut::default();
|
|
881
|
+
path_data(d, &Matrix::IDENTITY, &mut out).unwrap();
|
|
882
|
+
(out.verbs, out.points)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
#[test]
|
|
886
|
+
fn reads_compact_numbers_and_relative_commands() {
|
|
887
|
+
// Lucide's search handle: `m21 21-4.3-4.3`.
|
|
888
|
+
let (verbs, points) = path_of("m21 21-4.3-4.3");
|
|
889
|
+
assert_eq!(verbs, vec![VERB_MOVE, VERB_LINE]);
|
|
890
|
+
assert!((points[2] - 16.7).abs() < 1e-5 && (points[3] - 16.7).abs() < 1e-5);
|
|
891
|
+
let (_, points) = path_of("M12 8h.01");
|
|
892
|
+
assert!((points[2] - 12.01).abs() < 1e-5);
|
|
893
|
+
assert_eq!(numbers(".5.5-1e2,3").unwrap(), vec![0.5, 0.5, -100.0, 3.0]);
|
|
894
|
+
// Implicit lineto after a moveto, and V relative to the current point.
|
|
895
|
+
let (verbs, points) = path_of("M0 0 10 0v5z");
|
|
896
|
+
assert_eq!(verbs, vec![VERB_MOVE, VERB_LINE, VERB_LINE, VERB_CLOSE]);
|
|
897
|
+
assert_eq!(&points[4..6], &[10.0, 5.0]);
|
|
898
|
+
assert!(path_data("X1", &Matrix::IDENTITY, &mut PathOut::default()).is_err());
|
|
899
|
+
assert!(path_data("10 10", &Matrix::IDENTITY, &mut PathOut::default()).is_err());
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
#[test]
|
|
903
|
+
fn turns_an_arc_into_cubics_that_end_on_its_endpoint() {
|
|
904
|
+
// Lucide's loader: three quarters of a circle of radius 9.
|
|
905
|
+
let (verbs, points) = path_of("M21 12a9 9 0 1 1-6.219-8.56");
|
|
906
|
+
assert_eq!(verbs[0], VERB_MOVE);
|
|
907
|
+
assert!(verbs[1..].iter().all(|&v| v == VERB_CUBIC));
|
|
908
|
+
assert_eq!(verbs.len() - 1, 4);
|
|
909
|
+
let end = &points[points.len() - 2..];
|
|
910
|
+
assert!((end[0] - 14.781).abs() < 1e-3 && (end[1] - 3.44).abs() < 1e-3);
|
|
911
|
+
// Every on-curve point sits on the circle around (12, 12).
|
|
912
|
+
for seg in 0..4 {
|
|
913
|
+
let base = 2 + seg * 6 + 4;
|
|
914
|
+
let (x, y) = (points[base] - 12.0, points[base + 1] - 12.0);
|
|
915
|
+
assert!(((x * x + y * y).sqrt() - 9.0).abs() < 1e-3);
|
|
916
|
+
}
|
|
917
|
+
// Flags that touch the numbers after them.
|
|
918
|
+
let (verbs, _) = path_of("M0 0a5 5 0 015 5");
|
|
919
|
+
assert_eq!(verbs, vec![VERB_MOVE, VERB_CUBIC]);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
#[test]
|
|
923
|
+
fn smooth_curves_reflect_the_previous_control_point() {
|
|
924
|
+
let (verbs, points) = path_of("M0 0C0 10 10 10 10 0S20 -10 20 0");
|
|
925
|
+
assert_eq!(verbs, vec![VERB_MOVE, VERB_CUBIC, VERB_CUBIC]);
|
|
926
|
+
assert_eq!(&points[8..10], &[10.0, -10.0]);
|
|
927
|
+
let (_, points) = path_of("M0 0Q5 10 10 0T20 0");
|
|
928
|
+
assert_eq!(&points[6..8], &[15.0, -10.0]);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
#[test]
|
|
932
|
+
fn applies_transforms() {
|
|
933
|
+
let m = transform("translate(10 20) scale(2)").unwrap();
|
|
934
|
+
assert_eq!(m.apply(1.0, 1.0), (12.0, 22.0));
|
|
935
|
+
let r = transform("rotate(90 5 5)").unwrap();
|
|
936
|
+
let (x, y) = r.apply(10.0, 5.0);
|
|
937
|
+
assert!((x - 5.0).abs() < 1e-9 && (y - 10.0).abs() < 1e-9);
|
|
938
|
+
assert!(transform("perspective(3)").is_err());
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
fn shapes(v: Value) -> Vec<(i32, i32, f32, usize)> {
|
|
942
|
+
let mut warnings = Vec::new();
|
|
943
|
+
let buf = encode(&v, &mut warnings);
|
|
944
|
+
assert_eq!(warnings, Vec::<String>::new());
|
|
945
|
+
let i32_at = |i: usize| i32::from_le_bytes([buf[i], buf[i + 1], buf[i + 2], buf[i + 3]]);
|
|
946
|
+
let f32_at = |i: usize| f32::from_le_bytes([buf[i], buf[i + 1], buf[i + 2], buf[i + 3]]);
|
|
947
|
+
let count = i32_at(17);
|
|
948
|
+
let mut i = 21;
|
|
949
|
+
let mut out = Vec::new();
|
|
950
|
+
for _ in 0..count {
|
|
951
|
+
let fill = i32_at(i);
|
|
952
|
+
let stroke = i32_at(i + 5);
|
|
953
|
+
let width = f32_at(i + 9);
|
|
954
|
+
let verbs = i32_at(i + 20) as usize;
|
|
955
|
+
i += 24;
|
|
956
|
+
for _ in 0..verbs {
|
|
957
|
+
let n = match buf[i] {
|
|
958
|
+
VERB_MOVE | VERB_LINE => 2,
|
|
959
|
+
VERB_CUBIC => 6,
|
|
960
|
+
VERB_QUAD => 4,
|
|
961
|
+
_ => 0,
|
|
962
|
+
};
|
|
963
|
+
i += 1 + 4 * n;
|
|
964
|
+
}
|
|
965
|
+
out.push((fill, stroke, width, verbs));
|
|
966
|
+
}
|
|
967
|
+
assert_eq!(i, buf.len());
|
|
968
|
+
out
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
#[test]
|
|
972
|
+
fn resolves_inheritance_current_color_and_opacity() {
|
|
973
|
+
let red = 0xFFFF_0000u32 as i64;
|
|
974
|
+
let v = json!({
|
|
975
|
+
"color": red,
|
|
976
|
+
"root": { "t": "svg", "a": { "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" },
|
|
977
|
+
"c": [
|
|
978
|
+
{ "t": "path", "a": { "d": "M20 6 9 17l-5-5" } },
|
|
979
|
+
{ "t": "g", "a": { "transform": "scale(2)", "opacity": "0.5" }, "c": [
|
|
980
|
+
{ "t": "circle", "a": { "cx": "12", "cy": "12", "r": "4", "fill": "currentColor", "stroke": "none" } }
|
|
981
|
+
]},
|
|
982
|
+
{ "t": "rect", "a": { "width": "18", "height": "18", "x": "3", "y": "4", "rx": "2" } },
|
|
983
|
+
{ "t": "title" }
|
|
984
|
+
]}
|
|
985
|
+
});
|
|
986
|
+
let s = shapes(v);
|
|
987
|
+
assert_eq!(s.len(), 3);
|
|
988
|
+
assert_eq!(s[0], (0, red as i32, 2.0, 3));
|
|
989
|
+
// currentColor fill at half opacity, no stroke.
|
|
990
|
+
assert_eq!(s[1].0 as u32, 0x80FF_0000);
|
|
991
|
+
assert_eq!(s[1].1, 0);
|
|
992
|
+
// A rounded rect: four sides and four corners.
|
|
993
|
+
assert_eq!(s[2].3, 10);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/// The shapes a drawing holds and what was reported while reading it.
|
|
997
|
+
fn read(root: Value) -> (i32, Vec<String>) {
|
|
998
|
+
let mut warnings = Vec::new();
|
|
999
|
+
let buf = encode(&json!({ "root": root }), &mut warnings);
|
|
1000
|
+
(
|
|
1001
|
+
i32::from_le_bytes([buf[17], buf[18], buf[19], buf[20]]),
|
|
1002
|
+
warnings,
|
|
1003
|
+
)
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
fn one(shape: Value) -> (i32, Vec<String>) {
|
|
1007
|
+
read(json!({ "t": "svg", "a": { "viewBox": "0 0 100 50" }, "c": [
|
|
1008
|
+
shape,
|
|
1009
|
+
{ "t": "rect", "a": { "width": "10", "height": "10" } }
|
|
1010
|
+
]}))
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
#[test]
|
|
1014
|
+
fn leaves_out_what_it_does_not_draw_and_says_so() {
|
|
1015
|
+
let (count, warnings) = one(json!({ "t": "text" }));
|
|
1016
|
+
assert_eq!(count, 1);
|
|
1017
|
+
assert_eq!(warnings.len(), 1);
|
|
1018
|
+
assert!(warnings[0].starts_with("E_ORBIT_SVG_VALUE: "));
|
|
1019
|
+
assert!(warnings[0].contains("<\"text\">"));
|
|
1020
|
+
// A viewBox in error counts as absent: the width and height size it.
|
|
1021
|
+
let (count, warnings) = read(json!({ "t": "svg", "a": { "viewBox": "0 0 0 1" }, "c": [
|
|
1022
|
+
{ "t": "rect", "a": { "width": "1", "height": "1" } }
|
|
1023
|
+
]}));
|
|
1024
|
+
assert_eq!((count, warnings.len()), (1, 1));
|
|
1025
|
+
// No root at all: an empty drawing.
|
|
1026
|
+
let mut warnings = Vec::new();
|
|
1027
|
+
assert_eq!(encode(&json!({}), &mut warnings).len(), 21);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
#[test]
|
|
1031
|
+
fn a_number_that_is_not_finite_counts_as_absent() {
|
|
1032
|
+
// `(0 / 0) * 50`: a rect with no height is not drawn, and nothing panics.
|
|
1033
|
+
for height in ["NaN", "Infinity", "-Infinity", "undefined", "1e999"] {
|
|
1034
|
+
let (count, warnings) =
|
|
1035
|
+
one(json!({ "t": "rect", "a": { "width": "40", "height": height, "rx": "2" } }));
|
|
1036
|
+
assert_eq!(count, 1, "{height}");
|
|
1037
|
+
assert!(warnings.is_empty(), "{height}");
|
|
1038
|
+
}
|
|
1039
|
+
let (count, _) = one(
|
|
1040
|
+
json!({ "t": "rect", "a": { "width": 40, "height": 20, "rx": "NaN", "ry": "NaN" } }),
|
|
1041
|
+
);
|
|
1042
|
+
assert_eq!(count, 2);
|
|
1043
|
+
let (count, _) = one(json!({ "t": "circle", "a": { "r": "NaN" } }));
|
|
1044
|
+
assert_eq!(count, 1);
|
|
1045
|
+
// An opacity in error is ignored: the shape is drawn as if it had none.
|
|
1046
|
+
let (count, _) =
|
|
1047
|
+
one(json!({ "t": "rect", "a": { "width": "4", "height": "4", "opacity": "NaN" } }));
|
|
1048
|
+
assert_eq!(count, 2);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
#[test]
|
|
1052
|
+
fn path_data_and_points_are_drawn_up_to_their_first_error() {
|
|
1053
|
+
let mut out = PathOut::default();
|
|
1054
|
+
assert!(path_data("M0 0 L10 10 L10 NaN L20 20", &Matrix::IDENTITY, &mut out).is_err());
|
|
1055
|
+
assert_eq!(out.verbs, vec![VERB_MOVE, VERB_LINE]);
|
|
1056
|
+
let (count, warnings) =
|
|
1057
|
+
one(json!({ "t": "path", "a": { "d": "M0 0 L10 NaN", "stroke": -1 } }));
|
|
1058
|
+
assert_eq!(count, 2);
|
|
1059
|
+
assert_eq!(warnings.len(), 1);
|
|
1060
|
+
assert!(warnings[0].contains("d=\"M0 0 L10 NaN\""));
|
|
1061
|
+
let (count, warnings) = one(
|
|
1062
|
+
json!({ "t": "polyline", "a": { "points": "0,0 10,10 20,undefined", "stroke": -1 } }),
|
|
1063
|
+
);
|
|
1064
|
+
assert_eq!((count, warnings.len()), (2, 1));
|
|
1065
|
+
// Nothing readable: nothing drawn, still reported.
|
|
1066
|
+
let (count, warnings) = one(json!({ "t": "polygon", "a": { "points": "undefined" } }));
|
|
1067
|
+
assert_eq!((count, warnings.len()), (1, 1));
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
#[test]
|
|
1071
|
+
fn an_unreadable_transform_or_paint_leaves_out_its_element() {
|
|
1072
|
+
for t in [
|
|
1073
|
+
")(",
|
|
1074
|
+
"translate(",
|
|
1075
|
+
"scale)(2",
|
|
1076
|
+
"rotate(NaN)",
|
|
1077
|
+
"matrix(1 2)",
|
|
1078
|
+
")",
|
|
1079
|
+
] {
|
|
1080
|
+
assert!(transform(t).is_err(), "{t}");
|
|
1081
|
+
let (count, warnings) = one(json!({ "t": "g", "a": { "transform": t }, "c": [
|
|
1082
|
+
{ "t": "rect", "a": { "width": "4", "height": "4" } }
|
|
1083
|
+
]}));
|
|
1084
|
+
assert_eq!(count, 1, "{t}");
|
|
1085
|
+
assert_eq!(warnings.len(), 1, "{t}");
|
|
1086
|
+
}
|
|
1087
|
+
let (count, warnings) =
|
|
1088
|
+
one(json!({ "t": "rect", "a": { "width": "4", "height": "4", "fill": "chartreuse" } }));
|
|
1089
|
+
assert_eq!((count, warnings.len()), (1, 1));
|
|
1090
|
+
// On the svg itself: the whole drawing is left out.
|
|
1091
|
+
let (count, warnings) = read(json!({ "t": "svg", "a": { "transform": ")(" }, "c": [
|
|
1092
|
+
{ "t": "rect", "a": { "width": "4", "height": "4" } }
|
|
1093
|
+
]}));
|
|
1094
|
+
assert_eq!((count, warnings.len()), (0, 1));
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
#[test]
|
|
1098
|
+
fn numbers_past_what_a_drawing_holds_leave_out_the_shape() {
|
|
1099
|
+
let (count, warnings) =
|
|
1100
|
+
one(json!({ "t": "rect", "a": { "x": "1e308", "width": "1e308", "height": "1e308" } }));
|
|
1101
|
+
assert_eq!((count, warnings.len()), (1, 1));
|
|
1102
|
+
let (count, warnings) = one(json!({ "t": "line", "a": { "x2": "1e300", "stroke": -1 } }));
|
|
1103
|
+
assert_eq!((count, warnings.len()), (1, 1));
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
#[test]
|
|
1107
|
+
fn warnings_are_bounded_in_count_and_length() {
|
|
1108
|
+
let long = format!("M0 0 L{}", "9".repeat(10_000));
|
|
1109
|
+
let shapes: Vec<Value> = (0..100)
|
|
1110
|
+
.map(|_| json!({ "t": "path", "a": { "d": format!("{long} x") } }))
|
|
1111
|
+
.collect();
|
|
1112
|
+
let (_, warnings) = read(json!({ "t": "svg", "a": {}, "c": shapes }));
|
|
1113
|
+
assert_eq!(warnings.len(), MAX_WARNINGS);
|
|
1114
|
+
assert!(warnings.iter().all(|w| w.len() < 200));
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
#[test]
|
|
1118
|
+
fn no_attribute_text_panics() {
|
|
1119
|
+
let texts = [
|
|
1120
|
+
"",
|
|
1121
|
+
")",
|
|
1122
|
+
"(",
|
|
1123
|
+
")(",
|
|
1124
|
+
"((",
|
|
1125
|
+
"))",
|
|
1126
|
+
"a(",
|
|
1127
|
+
"(1)",
|
|
1128
|
+
"1e",
|
|
1129
|
+
"-",
|
|
1130
|
+
".",
|
|
1131
|
+
"+.e",
|
|
1132
|
+
"e1",
|
|
1133
|
+
"1e-",
|
|
1134
|
+
"NaN",
|
|
1135
|
+
"inf",
|
|
1136
|
+
"\u{fffd}",
|
|
1137
|
+
"é(1)",
|
|
1138
|
+
"rotate(1 2)",
|
|
1139
|
+
"M",
|
|
1140
|
+
"M1",
|
|
1141
|
+
"M1 1 A",
|
|
1142
|
+
"A1 1 0 2 1 1 1",
|
|
1143
|
+
"M0 0 a1 1 0 1 1 0 0",
|
|
1144
|
+
"M0 0 a0 0 0 1 1 5 5",
|
|
1145
|
+
"Z1",
|
|
1146
|
+
"m1e308 1e308 l1e308 1e308",
|
|
1147
|
+
"M0 0 A1e-300 1e-300 0 1 1 1e300 1e300",
|
|
1148
|
+
];
|
|
1149
|
+
for t in texts {
|
|
1150
|
+
let _ = transform(t);
|
|
1151
|
+
let _ = path_data(t, &Matrix::IDENTITY, &mut PathOut::default());
|
|
1152
|
+
let _ = numbers_until_error(t);
|
|
1153
|
+
for key in [
|
|
1154
|
+
"d",
|
|
1155
|
+
"points",
|
|
1156
|
+
"transform",
|
|
1157
|
+
"viewBox",
|
|
1158
|
+
"width",
|
|
1159
|
+
"height",
|
|
1160
|
+
"rx",
|
|
1161
|
+
"r",
|
|
1162
|
+
] {
|
|
1163
|
+
for tag in [
|
|
1164
|
+
"path", "polyline", "polygon", "rect", "circle", "ellipse", "line", "g",
|
|
1165
|
+
] {
|
|
1166
|
+
let _ = read(json!({ "t": "svg", "a": { key: t }, "c": [
|
|
1167
|
+
{ "t": tag, "a": { key: t, "width": "1", "height": "1" }, "c": [] }
|
|
1168
|
+
]}));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|