pub fn add_svg(&mut self, svg: &str, pinout: Pinout) -> Result<()> {
        let mut elements = svg::to_elements(svg)?;
        let mut sx = 1.0;
        let mut sy = 1.0;
        let mut dx = 0.0;
        let mut dy = 0.0;
        if let Some(SvgElement::HLine(ch)) = elements.remove("ch") {
            sx = 1.0 / ch.len();
            dx = -ch.cx();
        }
        if let Some(SvgElement::VLine(cv)) = elements.remove("cv") {
            sy = 1.0 / cv.len();
            dy = -cv.cy();
        }
        self.canvas_transform.translate(dx, dy);
        // SVG has y axis directed downwards. We need to turn it upwards
        self.canvas_transform.scale(sx, -sy);

        debug!("SVG elements: {:?}", &elements);
        for (id, element) in elements {
            match element {
                SvgElement::HLine(hline) => {
                    let line = Line::new(hline.x0, hline.y, hline.x1, hline.y);
                    if id.starts_with("pin") {
                        self.add_symbol_pin(&id, &pinout, line)?;
                    } else {
                        self.add_line(line.width(hline.width));
                    }
                }
                SvgElement::VLine(vline) => {
                    let line = Line::new(vline.x, vline.y0, vline.x, vline.y1);
                    if id.starts_with("pin") {
                        self.add_symbol_pin(&id, &pinout, line)?;
                    } else {
                        self.add_line(line.width(vline.width));
                    }
                }
                SvgElement::Line(line) => self.add_line(
                    Line::new(line.p.0.x, line.p.0.y, line.p.1.x, line.p.1.y).width(line.width),
                ),
                SvgElement::Text(text) => {
                    let attr = Attribute::new(&id, &text.text)
                        .origin(text.x, text.y)
                        .font_size(text.height)
                        .align(text.halign, text.valign);
                    self.add_attribute(attr);
                }
                _ => (),
            }
        }
        debug!("Elements: {:?}", &self.elements);
        Ok(())
    }
/// Adds drawing elements from the SVG string.
Adds drawing elements from the SVG string.
Adds drawing elements from the SVG string .
pub fn add_svg(&mut self, svg: &str, pinout: Pinout) -> Result<()> {
        let mut elements = svg::to_elements(svg)?;
        let mut sx = 1.0;
        let mut sy = 1.0;
        let mut dx = 0.0;
        let mut dy = 0.0;
        if let Some(SvgElement::HLine(ch)) = elements.remove("ch") {
            sx = 1.0 / ch.len();
            dx = -ch.cx();
        }
        if let Some(SvgElement::VLine(cv)) = elements.remove("cv") {
            sy = 1.0 / cv.len();
            dy = -cv.cy();
        }
        self.canvas_transform.translate(dx, dy);
        // SVG has y axis directed downwards. We need to turn it upwards
        self.canvas_transform.scale(sx, -sy);
        debug!("SVG elements: {:?}", &elements);
        for (id, element) in elements {
            match element {
                SvgElement::HLine(hline) => {
                    let line = Line::new(hline.x0, hline.y, hline.x1, hline.y);
                    if id.starts_with("pin") {
                        self.add_symbol_pin(&id, &pinout, line)?;
                    } else {
                        self.add_line(line.width(hline.width));
                    }
                }
                SvgElement::VLine(vline) => {
                    let line = Line::new(vline.x, vline.y0, vline.x, vline.y1);
                    if id.starts_with("pin") {
                        self.add_symbol_pin(&id, &pinout, line)?;
                    } else {
                        self.add_line(line.width(vline.width));
                    }
                }
                SvgElement::Line(line) => self.add_line(
                    Line::new(line.p.0.x, line.p.0.y, line.p.1.x, line.p.1.y).width(line.width),
                ),
                SvgElement::Text(text) => {
                    let attr = Attribute::new(&id, &text.text)
                        .origin(text.x, text.y)
                        .font_size(text.height)
                        .align(text.halign, text.valign);
                    self.add_attribute(attr);
                }
                _ => (),
            }
        }
        debug!("Elements: {:?}", &self.elements);
        Ok(())
    }
pub fn add_svg ( & mut self , svg : & str , pinout : Pinout ) -> Result < ( ) > { let mut elements = svg :: to_elements ( svg ) ? ; let mut sx = 1.0 ; let mut sy = 1.0 ; let mut dx = 0.0 ; let mut dy = 0.0 ; if let Some ( SvgElement :: HLine ( ch ) ) = elements . remove ( " " ) { sx = 1.0 / ch . len ( ) ; dx = - ch . cx ( ) ; } if let Some ( SvgElement :: VLine ( cv ) ) = elements . remove ( " " ) { sy = 1.0 / cv . len ( ) ; dy = - cv . cy ( ) ; } self . canvas_transform . translate ( dx , dy ) ; // SVG has y axis directed downwards. We need to turn it upwards self . canvas_transform . scale ( sx , - sy ) ; debug ! ( " " elements ) ; for ( id , element ) in elements { match element { SvgElement :: HLine ( hline ) => { let line = Line :: new ( hline . x0 , hline . y , hline . x1 , hline . y ) ; if id . starts_with ( " " ) { self . add_symbol_pin ( & id , & pinout , line ) ? ; } else { self . add_line ( line . width ( hline . width ) ) ; } } SvgElement :: VLine ( vline ) => { let line = Line :: new ( vline . x , vline . y0 , vline . x , vline . y1 ) ; if id . starts_with ( " " ) { self . add_symbol_pin ( & id , & pinout , line ) ? ; } else { self . add_line ( line . width ( vline . width ) ) ; } } SvgElement :: Line ( line ) => self . add_line ( Line :: new ( line . p . 0 . x , line . p . 0 . y , line . p . 1 . x , line . p . 1 . y ) . width ( line . width ) , ) , SvgElement :: Text ( text ) => { let attr = Attribute :: new ( & id , & text . text ) . origin ( text . x , text . y ) . font_size ( text . height ) . align ( text . halign , text . valign ) ; self . add_attribute ( attr ) ; } _ => ( ) , } } debug ! ( " " self elements ) ; Ok ( ( ) ) }
Adds drawing elements from the SVG string.
Adds drawing elements from the SVG string .
&mut self
svg
&str
pinout
Pinout
&mut self
svg
&str
pinout
Pinout