Skip to content

Commit 62b79da

Browse files
authored
Support fill patterns and viewbox clipping (#132)
* Do not mark unstroked paths * Implement clipping and patterns * Address clippy warnings * Fix no movement command on polyline/polygon * Clippy * Fix bad merge
1 parent 69a1bdd commit 62b79da

21 files changed

Lines changed: 2252 additions & 344 deletions

‎Cargo.lock‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ paste = "1"
3535
roxmltree = "0.21"
3636
serde = { version = "1", default-features = false }
3737
serde_json = "1"
38+
smallvec = "1.16"
3839
svgtypes = "0.16"
39-
uom = "0.38"
40+
uom = "0.38"

‎g_code/src/turtle.rs‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{borrow::Cow, fmt::Debug};
22

33
use ::g_code::{command, emit::Token};
4-
use lyon_geom::{Point, SvgArc};
4+
use lyon_geom::{LineSegment, Point, SvgArc};
55
use rust_decimal::{Decimal, prelude::*};
66
use svg2star::turtle::{
77
Turtle,
@@ -140,18 +140,15 @@ impl Turtle for GCodeTurtle<'_> {
140140

141141
fn stroke(&mut self, stroke: Stroke) {
142142
let start = stroke.start_point();
143-
let mut commands = stroke.into_commands().peekable();
144143

145144
self.tool_off();
146145

147146
// Comments should be inline after tool_off but before a rapid move.
148-
while matches!(commands.peek(), Some(DrawCommand::Comment(_))) {
149-
if let Some(DrawCommand::Comment(comment)) = commands.next() {
150-
self.program.push(Token::Comment {
151-
is_inline: false,
152-
inner: Cow::Owned(comment),
153-
});
154-
}
147+
if let Some(comment) = stroke.comment() {
148+
self.program.push(Token::Comment {
149+
is_inline: false,
150+
inner: Cow::Owned(comment.to_owned()),
151+
});
155152
}
156153

157154
self.program.append(
@@ -163,9 +160,9 @@ impl Turtle for GCodeTurtle<'_> {
163160
);
164161
self.tool_on();
165162

166-
for command in commands {
163+
for command in stroke.into_commands() {
167164
match command {
168-
DrawCommand::LineTo { from: _, to } => {
165+
DrawCommand::LineTo(LineSegment { from: _, to }) => {
169166
self.program.append(
170167
&mut command!(LinearInterpolation {
171168
X: self.round(to.x),
@@ -248,12 +245,6 @@ impl Turtle for GCodeTurtle<'_> {
248245
}
249246
}
250247
}
251-
DrawCommand::Comment(comment) => {
252-
self.program.push(Token::Comment {
253-
is_inline: false,
254-
inner: Cow::Owned(comment),
255-
});
256-
}
257248
}
258249
}
259250
}

‎g_code/tests/shapes.gcode‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ G1 X133.707 Y112.443 F300
930930
G1 X133.716 Y112.143 F300
931931
G1 X133.717 Y112.053 F300;svg#svg1 > g#layer1 > polygon#polygon1
932932
G0 X12.575 Y173.877
933-
G1 X12.575 Y173.877 F300
934933
G1 X8.009 Y179.602 F300
935934
G1 X9.639 Y186.741 F300
936935
G1 X16.236 Y189.919 F300
@@ -939,7 +938,6 @@ G1 X24.463 Y179.602 F300
939938
G1 X42.162 Y169.979 F300
940939
G1 X12.575 Y173.877 F300;svg#svg1 > g#layer1 > polyline#polyline1
941940
G0 X76.339 Y112.397
942-
G1 X76.339 Y112.397 F300
943941
G1 X71.773 Y118.122 F300
944942
G1 X73.402 Y125.261 F300
945943
G1 X80 Y128.439 F300

‎g_code/tests/smooth_curves.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎g_code/tests/transform_origin.svg‎

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading

‎g_code/tests/use_defs.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎g_code/tests/use_symbol.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎g_code/tests/use_xlink_href.svg‎

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)