Skip to content

Commit

Permalink
lib v0.2.2: fix #55
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Apr 8, 2024
1 parent 3b0800e commit 6a1e23f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "svg2gcode-cli"
version = "0.0.10"
version = "0.0.11"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Command line interface for svg2gcode"
repository = "https://github.com/sameer/svg2gcode"
license = "MIT"

[dependencies]
svg2gcode = { version = "0.2.1", features = ["serde"]}
svg2gcode = { version = "0.2.2", features = ["serde"]}
env_logger = { version = "0", default-features = false, features = ["atty", "termcolor", "humantime"] }
log = "0"
g-code = "0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode"
version = "0.2.1"
version = "0.2.2"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Convert paths in SVG files to GCode for a pen plotter, laser engraver, or other machine."
Expand Down
15 changes: 11 additions & 4 deletions lib/src/converter/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ const CIRCLE_TAG_NAME: &str = "circle";
const ELLIPSE_TAG_NAME: &str = "ellipse";
const LINE_TAG_NAME: &str = "line";
const GROUP_TAG_NAME: &str = "g";
const DEFS_TAG_NAME: &str = "defs";
const USE_TAG_NAME: &str = "use";

pub trait XmlVisitor {
fn visit_enter(&mut self, node: Node);
fn visit_exit(&mut self, node: Node);
}

/// Used to skip over SVG elements that are explicitly marked as do not render
fn is_valid_node(node: Node) -> bool {
return node.is_element()
fn should_render_node(node: Node) -> bool {
node.is_element()
&& !node
.attribute("style")
.map_or(false, |style| style.contains("display:none"));
.map_or(false, |style| style.contains("display:none"))
// Defs are not rendered
&& node.tag_name().name() != DEFS_TAG_NAME
}

pub fn depth_first_visit(doc: &Document, visitor: &mut impl XmlVisitor) {
fn visit_node(node: Node, visitor: &mut impl XmlVisitor) {
if !is_valid_node(node) {
if !should_render_node(node) {
return;
}
visitor.visit_enter(node);
Expand Down Expand Up @@ -352,6 +356,9 @@ impl<'a, T: Turtle> XmlVisitor for ConversionVisitor<'a, T> {
}
}
}
USE_TAG_NAME => {
warn!("Unsupported node: {node:?}");
}
// No-op tags
SVG_TAG_NAME | GROUP_TAG_NAME => {}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode-web"
version = "0.0.10"
version = "0.0.11"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
Expand All @@ -10,7 +10,7 @@ license = "MIT"

[dependencies]
wasm-bindgen = "0.2"
svg2gcode = { version = "0.2.1", features = ["serde"] }
svg2gcode = { version = "0.2.2", features = ["serde"] }
roxmltree = "0.19"
g-code = "0.4.2"
codespan-reporting = "0.11"
Expand Down

0 comments on commit 6a1e23f

Please sign in to comment.