fn render_path(&self, p: &usvg::Path, ctx: &mut PaintCtx) {
        if matches!(
            p.visibility,
            usvg::Visibility::Hidden | usvg::Visibility::Collapse
        ) {
            // skip rendering
            return;
        }

        let mut path = BezPath::new();
        for segment in p.data.iter() {
            match *segment {
                usvg::PathSegment::MoveTo { x, y } => {
                    path.move_to((x, y));
                }
                usvg::PathSegment::LineTo { x, y } => {
                    path.line_to((x, y));
                }
                usvg::PathSegment::CurveTo {
                    x1,
                    y1,
                    x2,
                    y2,
                    x,
                    y,
                } => {
                    path.curve_to((x1, y1), (x2, y2), (x, y));
                }
                usvg::PathSegment::ClosePath => {
                    path.close_path();
                }
            }
        }

        path.apply_affine(self.offset_matrix * transform_to_affine(p.transform));

        match &p.fill {
            Some(fill) => {
                let brush = self.brush_from_usvg(&fill.paint, fill.opacity);
                if let usvg::FillRule::EvenOdd = fill.rule {
                    ctx.fill_even_odd(path.clone(), &*brush);
                } else {
                    ctx.fill(path.clone(), &*brush);
                }
            }
            None => {}
        }

        match &p.stroke {
            Some(stroke) => {
                let brush = self.brush_from_usvg(&stroke.paint, stroke.opacity);
                let mut stroke_style = StrokeStyle::new()
                    .line_join(match stroke.linejoin {
                        usvg::LineJoin::Miter => LineJoin::Miter {
                            limit: stroke.miterlimit.value(),
                        },
                        usvg::LineJoin::Round => LineJoin::Round,
                        usvg::LineJoin::Bevel => LineJoin::Bevel,
                    })
                    .line_cap(match stroke.linecap {
                        usvg::LineCap::Butt => LineCap::Butt,
                        usvg::LineCap::Round => LineCap::Round,
                        usvg::LineCap::Square => LineCap::Square,
                    });
                if let Some(dash_array) = &stroke.dasharray {
                    stroke_style.set_dash_pattern(dash_array.as_slice());
                    stroke_style.set_dash_offset(stroke.dashoffset as f64);
                }
                ctx.stroke_styled(path, &*brush, stroke.width.value(), &stroke_style);
            }
            None => {}
        }
    }
/// Take a usvg path and render it to the given context.
Take a usvg path and render it to the given context.
Take a usvg path and render it to the given context .
fn render_path(&self, p: &usvg::Path, ctx: &mut PaintCtx) {
        if matches!(
            p.visibility,
            usvg::Visibility::Hidden | usvg::Visibility::Collapse
        ) {
            // skip rendering
            return;
        }
        let mut path = BezPath::new();
        for segment in p.data.iter() {
            match *segment {
                usvg::PathSegment::MoveTo { x, y } => {
                    path.move_to((x, y));
                }
                usvg::PathSegment::LineTo { x, y } => {
                    path.line_to((x, y));
                }
                usvg::PathSegment::CurveTo {
                    x1,
                    y1,
                    x2,
                    y2,
                    x,
                    y,
                } => {
                    path.curve_to((x1, y1), (x2, y2), (x, y));
                }
                usvg::PathSegment::ClosePath => {
                    path.close_path();
                }
            }
        }
        path.apply_affine(self.offset_matrix * transform_to_affine(p.transform));
        match &p.fill {
            Some(fill) => {
                let brush = self.brush_from_usvg(&fill.paint, fill.opacity);
                if let usvg::FillRule::EvenOdd = fill.rule {
                    ctx.fill_even_odd(path.clone(), &*brush);
                } else {
                    ctx.fill(path.clone(), &*brush);
                }
            }
            None => {}
        }
        match &p.stroke {
            Some(stroke) => {
                let brush = self.brush_from_usvg(&stroke.paint, stroke.opacity);
                let mut stroke_style = StrokeStyle::new()
                    .line_join(match stroke.linejoin {
                        usvg::LineJoin::Miter => LineJoin::Miter {
                            limit: stroke.miterlimit.value(),
                        },
                        usvg::LineJoin::Round => LineJoin::Round,
                        usvg::LineJoin::Bevel => LineJoin::Bevel,
                    })
                    .line_cap(match stroke.linecap {
                        usvg::LineCap::Butt => LineCap::Butt,
                        usvg::LineCap::Round => LineCap::Round,
                        usvg::LineCap::Square => LineCap::Square,
                    });
                if let Some(dash_array) = &stroke.dasharray {
                    stroke_style.set_dash_pattern(dash_array.as_slice());
                    stroke_style.set_dash_offset(stroke.dashoffset as f64);
                }
                ctx.stroke_styled(path, &*brush, stroke.width.value(), &stroke_style);
            }
            None => {}
        }
    }
fn render_path ( & self , p : & usvg :: Path , ctx : & mut PaintCtx ) { if matches ! ( p visibility usvg Visibility Hidden usvg Visibility Collapse ) { // skip rendering return ; } let mut path = BezPath :: new ( ) ; for segment in p . data . iter ( ) { match * segment { usvg :: PathSegment :: MoveTo { x , y } => { path . move_to ( ( x , y ) ) ; } usvg :: PathSegment :: LineTo { x , y } => { path . line_to ( ( x , y ) ) ; } usvg :: PathSegment :: CurveTo { x1 , y1 , x2 , y2 , x , y , } => { path . curve_to ( ( x1 , y1 ) , ( x2 , y2 ) , ( x , y ) ) ; } usvg :: PathSegment :: ClosePath => { path . close_path ( ) ; } } } path . apply_affine ( self . offset_matrix * transform_to_affine ( p . transform ) ) ; match & p . fill { Some ( fill ) => { let brush = self . brush_from_usvg ( & fill . paint , fill . opacity ) ; if let usvg :: FillRule :: EvenOdd = fill . rule { ctx . fill_even_odd ( path . clone ( ) , & * brush ) ; } else { ctx . fill ( path . clone ( ) , & * brush ) ; } } None => { } } match & p . stroke { Some ( stroke ) => { let brush = self . brush_from_usvg ( & stroke . paint , stroke . opacity ) ; let mut stroke_style = StrokeStyle :: new ( ) . line_join ( match stroke . linejoin { usvg :: LineJoin :: Miter => LineJoin :: Miter { limit : stroke . miterlimit . value ( ) , } , usvg :: LineJoin :: Round => LineJoin :: Round , usvg :: LineJoin :: Bevel => LineJoin :: Bevel , } ) . line_cap ( match stroke . linecap { usvg :: LineCap :: Butt => LineCap :: Butt , usvg :: LineCap :: Round => LineCap :: Round , usvg :: LineCap :: Square => LineCap :: Square , } ) ; if let Some ( dash_array ) = & stroke . dasharray { stroke_style . set_dash_pattern ( dash_array . as_slice ( ) ) ; stroke_style . set_dash_offset ( stroke . dashoffset as f64 ) ; } ctx . stroke_styled ( path , & * brush , stroke . width . value ( ) , & stroke_style ) ; } None => { } } }
Take a usvg path and render it to the given context.
Take a usvg path and render it to the given context .
&self
p
&usvg::Path
ctx
&mut PaintCtx
&self
p
&usvg::Path
ctx
&mut PaintCtx