diff --git a/Cargo.lock b/Cargo.lock index baf2a03..e1987f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,7 +1242,7 @@ dependencies = [ [[package]] name = "svg2gcode" -version = "0.1.2" +version = "0.1.3" dependencies = [ "cairo-rs", "euclid", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index efa88b3..c40a53c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -20,4 +20,4 @@ serde_json = "1" [[bin]] name = "svg2gcode" -path = "src/main.rs" \ No newline at end of file +path = "src/main.rs" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 6ba0645..481263b 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svg2gcode" -version = "0.1.2" +version = "0.1.3" authors = ["Sameer Puri "] edition = "2021" description = "Convert paths in SVG files to GCode for a pen plotter, laser engraver, or other machine." diff --git a/lib/src/converter/mod.rs b/lib/src/converter/mod.rs index 896c976..86c1b95 100644 --- a/lib/src/converter/mod.rs +++ b/lib/src/converter/mod.rs @@ -11,8 +11,8 @@ use roxmltree::{Document, Node}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use svgtypes::{ - Length, LengthListParser, PathParser, PathSegment, TransformListParser, TransformListToken, - ViewBox, + Length, LengthListParser, PathParser, PathSegment, PointsParser, TransformListParser, + TransformListToken, ViewBox, }; use crate::{turtle::*, Machine}; @@ -24,6 +24,7 @@ mod visit; const SVG_TAG_NAME: &str = "svg"; const CLIP_PATH_TAG_NAME: &str = "clipPath"; const PATH_TAG_NAME: &str = "path"; +const POLYLINE_TAG_NAME: &str = "polyline"; /// High-level output configuration #[derive(Debug, Clone, PartialEq)] @@ -215,6 +216,28 @@ impl<'a, T: Turtle> visit::XmlVisitor for ConversionVisitor<'a, T> { } else { warn!("There is a path node containing no actual path: {:?}", node); } + } else if node.tag_name().name() == POLYLINE_TAG_NAME { + if let Some(points) = node.attribute("points") { + self.terrarium.reset(); + let mut comment = String::new(); + self.name_stack.iter().for_each(|name| { + comment += name; + comment += " > "; + }); + comment += &node_name(&node); + self.terrarium.turtle.comment(comment); + + let mut pp = PointsParser::from(points); + + if let Some((x, y)) = pp.next() { + self.terrarium.move_to(true, x, y); + } + while let Some((x, y)) = pp.next() { + self.terrarium.line(true, x, y); + } + } else { + warn!("There is a polyline node containing no actual path: {:?}", node); + } } self.name_stack.push(node_name(&node));