1use crate::display::PixelFormat;
8use crate::element::{Element, IntoElement};
9use crate::pod::FrameScope;
10use crate::solver::Region;
11use crate::style::Color;
12use crate::svg::math::{atan2_f32, floor_f32, sqrt_f32};
13
14#[derive(Copy, Clone, Debug, Default)]
16pub struct VecPoint {
17 pub x: f32,
18 pub y: f32,
19}
20
21impl VecPoint {
22 #[inline(always)]
23 pub const fn new(x: f32, y: f32) -> Self {
24 Self { x, y }
25 }
26}
27
28#[inline(always)]
29fn canon_f32(v: f32) -> u32 {
30 if v == 0.0 { 0 } else { v.to_bits() }
31}
32
33impl PartialEq for VecPoint {
34 #[inline(always)]
35 fn eq(&self, other: &Self) -> bool {
36 canon_f32(self.x) == canon_f32(other.x) && canon_f32(self.y) == canon_f32(other.y)
37 }
38}
39
40impl Eq for VecPoint {}
41
42#[derive(Copy, Clone, Debug)]
44pub enum VectorPrimitive<'a> {
45 Polyline {
47 points: &'a [VecPoint],
48 color: Color,
49 width: f32,
50 dash_len: f32,
51 gap_len: f32,
52 closed: bool,
53 },
54 Polygon {
56 points: &'a [VecPoint],
57 fill: Color,
58 stroke: Color,
59 stroke_width: f32,
60 },
61 Circle {
63 cx: f32,
64 cy: f32,
65 radius: f32,
66 fill: Color,
67 stroke: Color,
68 stroke_width: f32,
69 },
70 Sector {
72 cx: f32,
73 cy: f32,
74 inner_r: f32,
75 outer_r: f32,
76 start_deg: f32,
77 sweep_deg: f32,
78 fill: Color,
79 },
80 CubicBezier {
82 p0: VecPoint,
83 p1: VecPoint,
84 p2: VecPoint,
85 p3: VecPoint,
86 color: Color,
87 width: f32,
88 dash_len: f32,
89 gap_len: f32,
90 },
91 SvgPath {
93 d: &'a str,
94 fill: Color,
95 fill_rule: crate::svg::SvgFillRule,
96 stroke: Color,
97 stroke_width: f32,
98 line_cap: crate::svg::SvgLineCap,
99 line_join: crate::svg::SvgLineJoin,
100 },
101}
102
103impl<'a> PartialEq for VectorPrimitive<'a> {
104 fn eq(&self, other: &Self) -> bool {
105 match (*self, *other) {
106 (
107 Self::Polyline {
108 points: p1,
109 color: c1,
110 width: w1,
111 dash_len: d1,
112 gap_len: g1,
113 closed: cl1,
114 },
115 Self::Polyline {
116 points: p2,
117 color: c2,
118 width: w2,
119 dash_len: d2,
120 gap_len: g2,
121 closed: cl2,
122 },
123 ) => {
124 p1 == p2
125 && c1 == c2
126 && canon_f32(w1) == canon_f32(w2)
127 && canon_f32(d1) == canon_f32(d2)
128 && canon_f32(g1) == canon_f32(g2)
129 && cl1 == cl2
130 }
131 (
132 Self::Polygon {
133 points: p1,
134 fill: f1,
135 stroke: s1,
136 stroke_width: sw1,
137 },
138 Self::Polygon {
139 points: p2,
140 fill: f2,
141 stroke: s2,
142 stroke_width: sw2,
143 },
144 ) => p1 == p2 && f1 == f2 && s1 == s2 && canon_f32(sw1) == canon_f32(sw2),
145 (
146 Self::Circle {
147 cx: x1,
148 cy: y1,
149 radius: r1,
150 fill: f1,
151 stroke: s1,
152 stroke_width: sw1,
153 },
154 Self::Circle {
155 cx: x2,
156 cy: y2,
157 radius: r2,
158 fill: f2,
159 stroke: s2,
160 stroke_width: sw2,
161 },
162 ) => {
163 canon_f32(x1) == canon_f32(x2)
164 && canon_f32(y1) == canon_f32(y2)
165 && canon_f32(r1) == canon_f32(r2)
166 && f1 == f2
167 && s1 == s2
168 && canon_f32(sw1) == canon_f32(sw2)
169 }
170 (
171 Self::Sector {
172 cx: x1,
173 cy: y1,
174 inner_r: ir1,
175 outer_r: or1,
176 start_deg: sd1,
177 sweep_deg: sw1,
178 fill: f1,
179 },
180 Self::Sector {
181 cx: x2,
182 cy: y2,
183 inner_r: ir2,
184 outer_r: or2,
185 start_deg: sd2,
186 sweep_deg: sw2,
187 fill: f2,
188 },
189 ) => {
190 canon_f32(x1) == canon_f32(x2)
191 && canon_f32(y1) == canon_f32(y2)
192 && canon_f32(ir1) == canon_f32(ir2)
193 && canon_f32(or1) == canon_f32(or2)
194 && canon_f32(sd1) == canon_f32(sd2)
195 && canon_f32(sw1) == canon_f32(sw2)
196 && f1 == f2
197 }
198 (
199 Self::CubicBezier {
200 p0: a0,
201 p1: a1,
202 p2: a2,
203 p3: a3,
204 color: c1,
205 width: w1,
206 dash_len: d1,
207 gap_len: g1,
208 },
209 Self::CubicBezier {
210 p0: b0,
211 p1: b1,
212 p2: b2,
213 p3: b3,
214 color: c2,
215 width: w2,
216 dash_len: d2,
217 gap_len: g2,
218 },
219 ) => {
220 a0 == b0
221 && a1 == b1
222 && a2 == b2
223 && a3 == b3
224 && c1 == c2
225 && canon_f32(w1) == canon_f32(w2)
226 && canon_f32(d1) == canon_f32(d2)
227 && canon_f32(g1) == canon_f32(g2)
228 }
229 (
230 Self::SvgPath {
231 d: d1,
232 fill: f1,
233 fill_rule: r1,
234 stroke: s1,
235 stroke_width: sw1,
236 line_cap: lc1,
237 line_join: lj1,
238 },
239 Self::SvgPath {
240 d: d2,
241 fill: f2,
242 fill_rule: r2,
243 stroke: s2,
244 stroke_width: sw2,
245 line_cap: lc2,
246 line_join: lj2,
247 },
248 ) => {
249 d1 == d2
250 && f1 == f2
251 && r1 == r2
252 && s1 == s2
253 && canon_f32(sw1) == canon_f32(sw2)
254 && lc1 == lc2
255 && lj1 == lj2
256 }
257 _ => false,
258 }
259 }
260}
261
262impl<'a> Eq for VectorPrimitive<'a> {}
263
264#[derive(Copy, Clone, PartialEq, Eq, Debug)]
266pub struct VectorDrawSpec<'a> {
267 pub primitives: &'a [VectorPrimitive<'a>],
268 pub width: i16,
269 pub height: i16,
270 pub opacity: u8,
271}
272
273impl<'a> VectorDrawSpec<'a> {
274 pub fn mix_hash(&self, h: &mut u32) {
275 #[inline(always)]
276 fn mix_u8(h: &mut u32, b: u8) {
277 *h ^= b as u32;
278 *h = h.wrapping_mul(0x0100_0193);
279 }
280 #[inline(always)]
281 fn mix_u32(h: &mut u32, v: u32) {
282 for b in v.to_le_bytes() {
283 mix_u8(h, b);
284 }
285 }
286 mix_u32(
287 h,
288 ((self.width as u16 as u32) << 16) | (self.height as u16 as u32),
289 );
290 mix_u8(h, self.opacity);
291 for p in self.primitives {
292 match *p {
293 VectorPrimitive::Polyline {
294 points,
295 color,
296 width,
297 dash_len,
298 gap_len,
299 closed,
300 } => {
301 mix_u8(h, 1);
302 mix_u32(h, color.0);
303 mix_u32(h, canon_f32(width));
304 mix_u32(h, canon_f32(dash_len));
305 mix_u32(h, canon_f32(gap_len));
306 mix_u8(h, if closed { 1 } else { 0 });
307 for pt in points {
308 mix_u32(h, canon_f32(pt.x));
309 mix_u32(h, canon_f32(pt.y));
310 }
311 }
312 VectorPrimitive::Polygon {
313 points,
314 fill,
315 stroke,
316 stroke_width,
317 } => {
318 mix_u8(h, 2);
319 mix_u32(h, fill.0);
320 mix_u32(h, stroke.0);
321 mix_u32(h, canon_f32(stroke_width));
322 for pt in points {
323 mix_u32(h, canon_f32(pt.x));
324 mix_u32(h, canon_f32(pt.y));
325 }
326 }
327 VectorPrimitive::Circle {
328 cx,
329 cy,
330 radius,
331 fill,
332 stroke,
333 stroke_width,
334 } => {
335 mix_u8(h, 3);
336 mix_u32(h, canon_f32(cx));
337 mix_u32(h, canon_f32(cy));
338 mix_u32(h, canon_f32(radius));
339 mix_u32(h, fill.0);
340 mix_u32(h, stroke.0);
341 mix_u32(h, canon_f32(stroke_width));
342 }
343 VectorPrimitive::Sector {
344 cx,
345 cy,
346 inner_r,
347 outer_r,
348 start_deg,
349 sweep_deg,
350 fill,
351 } => {
352 mix_u8(h, 4);
353 mix_u32(h, canon_f32(cx));
354 mix_u32(h, canon_f32(cy));
355 mix_u32(h, canon_f32(inner_r));
356 mix_u32(h, canon_f32(outer_r));
357 mix_u32(h, canon_f32(start_deg));
358 mix_u32(h, canon_f32(sweep_deg));
359 mix_u32(h, fill.0);
360 }
361 VectorPrimitive::CubicBezier {
362 p0,
363 p1,
364 p2,
365 p3,
366 color,
367 width,
368 dash_len,
369 gap_len,
370 } => {
371 mix_u8(h, 5);
372 for pt in [p0, p1, p2, p3] {
373 mix_u32(h, canon_f32(pt.x));
374 mix_u32(h, canon_f32(pt.y));
375 }
376 mix_u32(h, color.0);
377 mix_u32(h, canon_f32(width));
378 mix_u32(h, canon_f32(dash_len));
379 mix_u32(h, canon_f32(gap_len));
380 }
381 VectorPrimitive::SvgPath {
382 d,
383 fill,
384 fill_rule,
385 stroke,
386 stroke_width,
387 line_cap,
388 line_join,
389 } => {
390 mix_u8(h, 6);
391 mix_u32(h, fill.0);
392 mix_u8(h, fill_rule as u8);
393 mix_u32(h, stroke.0);
394 mix_u32(h, canon_f32(stroke_width));
395 mix_u8(h, line_cap as u8);
396 mix_u8(h, line_join as u8);
397 for &b in d.as_bytes() {
398 mix_u8(h, b);
399 }
400 }
401 }
402 }
403 }
404}
405
406#[derive(Copy, Clone, Debug)]
408pub struct VectorCanvas<'a> {
409 pub spec: VectorDrawSpec<'a>,
410}
411
412#[inline]
414pub fn vector_canvas<'a>(
415 cx: &'a FrameScope,
416 width: i16,
417 height: i16,
418 primitives: &[VectorPrimitive<'a>],
419) -> VectorCanvas<'a> {
420 let alloc = cx.arena().alloc_iter(primitives.iter().copied());
421 VectorCanvas {
422 spec: VectorDrawSpec {
423 primitives: alloc,
424 width,
425 height,
426 opacity: 255,
427 },
428 }
429}
430
431impl<'a> VectorCanvas<'a> {
432 #[inline(always)]
433 pub const fn opacity(mut self, opacity: u8) -> Self {
434 self.spec.opacity = opacity;
435 self
436 }
437}
438
439impl<'a> IntoElement<'a> for VectorCanvas<'a> {
440 #[inline]
441 fn into_element(self, cx: &'a FrameScope) -> Element<'a> {
442 let spec_ref = cx.arena().alloc_temp(self.spec);
443 Element::Vector(spec_ref)
444 }
445}
446
447#[inline]
452fn blend_cov_pixel<P: PixelFormat>(target: &mut [P], idx: usize, color: Color, cov: f32) {
453 let a = ((color.a() as f32) * cov.clamp(0.0, 1.0) + 0.5) as u8;
454 if a == 0 {
455 return;
456 }
457 if let Some(dst) = target.get_mut(idx) {
458 let blended = crate::sdf::blend_color(dst.to_color(), color, a);
459 *dst = P::from_color(blended);
460 }
461}
462
463#[inline]
464fn dist_point_to_segment(px: f32, py: f32, ax: f32, ay: f32, bx: f32, by: f32) -> (f32, f32) {
465 let vx = bx - ax;
466 let vy = by - ay;
467 let len2 = vx * vx + vy * vy;
468 if len2 <= 1e-6 {
469 let dx = px - ax;
470 let dy = py - ay;
471 return (sqrt_f32(dx * dx + dy * dy), 0.0);
472 }
473 let t = (((px - ax) * vx + (py - ay) * vy) / len2).clamp(0.0, 1.0);
474 let dx = px - (ax + vx * t);
475 let dy = py - (ay + vy * t);
476 (sqrt_f32(dx * dx + dy * dy), t * sqrt_f32(len2))
477}
478
479#[allow(clippy::too_many_arguments)]
480fn rasterize_polyline<P: PixelFormat>(
481 points: &[VecPoint],
482 color: Color,
483 width: f32,
484 dash_len: f32,
485 gap_len: f32,
486 closed: bool,
487 bounds: Region,
488 vis: Region,
489 sf: f32,
490 origin_x: i16,
491 origin_y: i16,
492 stride: usize,
493 target: &mut [P],
494) {
495 if points.len() < 2 || color.a() == 0 || width <= 0.0 {
496 return;
497 }
498 let half_w = (width * sf * 0.5).max(0.5);
499 let bx0 = bounds.x as f32;
500 let by0 = bounds.y as f32;
501 let seg_count = if closed { points.len() } else { points.len() - 1 };
502 let dash_period = if dash_len > 0.0 && gap_len > 0.0 {
503 (dash_len + gap_len) * sf
504 } else {
505 0.0
506 };
507 let dash_on = dash_len * sf;
508 let mut accum_len = 0.0f32;
509
510 for s in 0..seg_count {
511 let p0 = points[s];
512 let p1 = points[(s + 1) % points.len()];
513 let ax = bx0 + p0.x * sf;
514 let ay = by0 + p0.y * sf;
515 let bx = bx0 + p1.x * sf;
516 let by = by0 + p1.y * sf;
517 let seg_len = sqrt_f32((bx - ax) * (bx - ax) + (by - ay) * (by - ay));
518
519 let pad = half_w + 1.5;
520 let min_x = (floor_f32(ax.min(bx) - pad) as i16).max(vis.x);
521 let max_x = ((ax.max(bx) + pad) as i16 + 1).min(vis.right());
522 let min_y = (floor_f32(ay.min(by) - pad) as i16).max(vis.y);
523 let max_y = ((ay.max(by) + pad) as i16 + 1).min(vis.bottom());
524
525 for py in min_y..max_y {
526 let row_off = ((py - origin_y) as usize) * stride;
527 let cy = py as f32 + 0.5;
528 for px in min_x..max_x {
529 let cx = px as f32 + 0.5;
530 let (d, along) = dist_point_to_segment(cx, cy, ax, ay, bx, by);
531 let cov = (half_w + 0.5 - d).clamp(0.0, 1.0);
532 if cov <= 0.0 {
533 continue;
534 }
535 if dash_period > 0.0 {
536 let phase = (accum_len + along) % dash_period;
537 if phase > dash_on {
538 continue;
539 }
540 }
541 blend_cov_pixel(target, row_off + ((px - origin_x) as usize), color, cov);
542 }
543 }
544 accum_len += seg_len;
545 }
546}
547
548#[allow(clippy::too_many_arguments)]
549fn rasterize_polygon<P: PixelFormat>(
550 points: &[VecPoint],
551 fill: Color,
552 stroke: Color,
553 stroke_width: f32,
554 bounds: Region,
555 vis: Region,
556 sf: f32,
557 origin_x: i16,
558 origin_y: i16,
559 stride: usize,
560 target: &mut [P],
561) {
562 if points.len() < 3 {
563 return;
564 }
565 let bx0 = bounds.x as f32;
566 let by0 = bounds.y as f32;
567 if fill.a() > 0 {
568 let mut min_x = f32::INFINITY;
569 let mut max_x = f32::NEG_INFINITY;
570 let mut min_y = f32::INFINITY;
571 let mut max_y = f32::NEG_INFINITY;
572 for pt in points {
573 let x = bx0 + pt.x * sf;
574 let y = by0 + pt.y * sf;
575 min_x = min_x.min(x);
576 max_x = max_x.max(x);
577 min_y = min_y.min(y);
578 max_y = max_y.max(y);
579 }
580 let x0 = (floor_f32(min_x) as i16).max(vis.x);
581 let x1 = (max_x as i16 + 1).min(vis.right());
582 let y0 = (floor_f32(min_y) as i16).max(vis.y);
583 let y1 = (max_y as i16 + 1).min(vis.bottom());
584
585 for py in y0..y1 {
586 let row_off = ((py - origin_y) as usize) * stride;
587 let cy = py as f32 + 0.5;
588 for px in x0..x1 {
589 let cx = px as f32 + 0.5;
590 let mut inside = false;
592 let mut j = points.len() - 1;
593 for i in 0..points.len() {
594 let xi = bx0 + points[i].x * sf;
595 let yi = by0 + points[i].y * sf;
596 let xj = bx0 + points[j].x * sf;
597 let yj = by0 + points[j].y * sf;
598 let cond = ((yi > cy) != (yj > cy))
599 && (cx < (xj - xi) * (cy - yi) / ((yj - yi) + 1e-7) + xi);
600 if cond {
601 inside = !inside;
602 }
603 j = i;
604 }
605 if inside {
606 blend_cov_pixel(target, row_off + ((px - origin_x) as usize), fill, 1.0);
607 }
608 }
609 }
610 }
611 if stroke.a() > 0 && stroke_width > 0.0 {
612 rasterize_polyline(
613 points,
614 stroke,
615 stroke_width,
616 0.0,
617 0.0,
618 true,
619 bounds,
620 vis,
621 sf,
622 origin_x,
623 origin_y,
624 stride,
625 target,
626 );
627 }
628}
629
630#[allow(clippy::too_many_arguments)]
632pub fn rasterize_vector_spec<P: PixelFormat>(
633 spec: &VectorDrawSpec<'_>,
634 bounds: Region,
635 clip: Region,
636 sf: f32,
637 origin_x: i16,
638 origin_y: i16,
639 stride: usize,
640 target: &mut [P],
641) {
642 let vis = bounds.intersect(clip);
643 if vis.is_empty() || spec.opacity == 0 {
644 return;
645 }
646 let scale_c = |c: Color| c.scale_alpha(spec.opacity);
647 let bx0 = bounds.x as f32;
648 let by0 = bounds.y as f32;
649
650 for prim in spec.primitives {
651 match *prim {
652 VectorPrimitive::Polyline {
653 points,
654 color,
655 width,
656 dash_len,
657 gap_len,
658 closed,
659 } => rasterize_polyline(
660 points,
661 scale_c(color),
662 width,
663 dash_len,
664 gap_len,
665 closed,
666 bounds,
667 vis,
668 sf,
669 origin_x,
670 origin_y,
671 stride,
672 target,
673 ),
674 VectorPrimitive::Polygon {
675 points,
676 fill,
677 stroke,
678 stroke_width,
679 } => rasterize_polygon(
680 points,
681 scale_c(fill),
682 scale_c(stroke),
683 stroke_width,
684 bounds,
685 vis,
686 sf,
687 origin_x,
688 origin_y,
689 stride,
690 target,
691 ),
692 VectorPrimitive::Circle {
693 cx,
694 cy,
695 radius,
696 fill,
697 stroke,
698 stroke_width,
699 } => {
700 let ccx = bx0 + cx * sf;
701 let ccy = by0 + cy * sf;
702 let r = radius * sf;
703 let sw = stroke_width * sf;
704 let outer = r + sw * 0.5 + 1.5;
705 let x0 = (floor_f32(ccx - outer) as i16).max(vis.x);
706 let x1 = ((ccx + outer) as i16 + 1).min(vis.right());
707 let y0 = (floor_f32(ccy - outer) as i16).max(vis.y);
708 let y1 = ((ccy + outer) as i16 + 1).min(vis.bottom());
709 let fcol = scale_c(fill);
710 let scol = scale_c(stroke);
711
712 for py in y0..y1 {
713 let row_off = ((py - origin_y) as usize) * stride;
714 let dy = py as f32 + 0.5 - ccy;
715 for px in x0..x1 {
716 let dx = px as f32 + 0.5 - ccx;
717 let dist = sqrt_f32(dx * dx + dy * dy);
718 let idx = row_off + ((px - origin_x) as usize);
719 if fcol.a() > 0 {
720 let cov = (r + 0.5 - dist).clamp(0.0, 1.0);
721 if cov > 0.0 {
722 blend_cov_pixel(target, idx, fcol, cov);
723 }
724 }
725 if scol.a() > 0 && sw > 0.0 {
726 let sd = crate::svg::math::abs_f32(dist - r);
727 let cov = (sw * 0.5 + 0.5 - sd).clamp(0.0, 1.0);
728 if cov > 0.0 {
729 blend_cov_pixel(target, idx, scol, cov);
730 }
731 }
732 }
733 }
734 }
735 VectorPrimitive::Sector {
736 cx,
737 cy,
738 inner_r,
739 outer_r,
740 start_deg,
741 sweep_deg,
742 fill,
743 } => {
744 let fcol = scale_c(fill);
745 if fcol.a() == 0 || outer_r <= inner_r || sweep_deg <= 0.0 {
746 continue;
747 }
748 let ccx = bx0 + cx * sf;
749 let ccy = by0 + cy * sf;
750 let ir = inner_r.max(0.0) * sf;
751 let or = outer_r * sf;
752 let pad = or + 1.5;
753 let x0 = (floor_f32(ccx - pad) as i16).max(vis.x);
754 let x1 = ((ccx + pad) as i16 + 1).min(vis.right());
755 let y0 = (floor_f32(ccy - pad) as i16).max(vis.y);
756 let y1 = ((ccy + pad) as i16 + 1).min(vis.bottom());
757 let start_n = ((start_deg % 360.0) + 360.0) % 360.0;
758 let sweep_c = sweep_deg.clamp(0.0, 360.0);
759
760 for py in y0..y1 {
761 let row_off = ((py - origin_y) as usize) * stride;
762 let dy = py as f32 + 0.5 - ccy;
763 for px in x0..x1 {
764 let dx = px as f32 + 0.5 - ccx;
765 let dist = sqrt_f32(dx * dx + dy * dy);
766 let cov_r = (or + 0.5 - dist).min(dist - ir + 0.5).clamp(0.0, 1.0);
767 if cov_r <= 0.0 {
768 continue;
769 }
770 if sweep_c < 359.9 {
771 let mut ang = atan2_f32(dx, -dy) * (180.0 / core::f32::consts::PI);
773 if ang < 0.0 {
774 ang += 360.0;
775 }
776 let rel = ((ang - start_n) + 360.0) % 360.0;
777 if rel > sweep_c {
778 continue;
779 }
780 }
781 blend_cov_pixel(
782 target,
783 row_off + ((px - origin_x) as usize),
784 fcol,
785 cov_r,
786 );
787 }
788 }
789 }
790 VectorPrimitive::CubicBezier {
791 p0,
792 p1,
793 p2,
794 p3,
795 color,
796 width,
797 dash_len,
798 gap_len,
799 } => {
800 let col = scale_c(color);
801 if col.a() == 0 || width <= 0.0 {
802 continue;
803 }
804 let mut pts = [VecPoint::default(); 25];
805 for i in 0..=24 {
806 let t = i as f32 / 24.0;
807 let u = 1.0 - t;
808 let uu = u * u;
809 let tt = t * t;
810 let uuu = uu * u;
811 let ttt = tt * t;
812 pts[i] = VecPoint::new(
813 uuu * p0.x + 3.0 * uu * t * p1.x + 3.0 * u * tt * p2.x + ttt * p3.x,
814 uuu * p0.y + 3.0 * uu * t * p1.y + 3.0 * u * tt * p2.y + ttt * p3.y,
815 );
816 }
817 rasterize_polyline(
818 &pts,
819 col,
820 width,
821 dash_len,
822 gap_len,
823 false,
824 bounds,
825 vis,
826 sf,
827 origin_x,
828 origin_y,
829 stride,
830 target,
831 );
832 }
833 VectorPrimitive::SvgPath {
834 d,
835 fill,
836 fill_rule,
837 stroke,
838 stroke_width,
839 line_cap,
840 line_join,
841 } => {
842 if d.is_empty() {
843 continue;
844 }
845 let xf = crate::svg::Transform2D::new(sf, 0.0, 0.0, sf, bx0, by0);
846 let mut path = crate::svg::FlattenedPath::new();
847 path.parse_svg_path_d(d, xf);
848 if path.is_empty() {
849 continue;
850 }
851 let fcol = scale_c(fill);
852 if fcol.a() > 0 {
853 crate::svg::fill_path(
854 &path, fcol, fill_rule, vis, origin_x, origin_y, stride, target,
855 );
856 }
857 let scol = scale_c(stroke);
858 if scol.a() > 0 && stroke_width > 0.0 {
859 crate::svg::stroke_path(
860 &path,
861 scol,
862 stroke_width * sf,
863 line_cap,
864 line_join,
865 4.0,
866 vis,
867 origin_x,
868 origin_y,
869 stride,
870 target,
871 );
872 }
873 }
874 }
875 }
876}