prevent bad encoding with only move-tos

This commit is contained in:
Chad Brokaw 2022-11-07 23:26:51 -05:00
parent 373b027780
commit a9170c4330
2 changed files with 18 additions and 13 deletions

View file

@ -13,6 +13,10 @@ pub fn render_funky_paths(sb: &mut SceneBuilder) {
LineTo((0.0, 400.0).into()),
LineTo((100.0, 400.0).into()),
];
let only_movetos = [
PathElement::MoveTo((0.0, 0.0).into()),
PathElement::MoveTo((100.0, 100.0).into()),
];
let empty: [PathElement; 0] = [];
sb.fill(
Fill::NonZero,
@ -28,6 +32,13 @@ pub fn render_funky_paths(sb: &mut SceneBuilder) {
None,
empty,
);
sb.fill(
Fill::NonZero,
Affine::IDENTITY,
&Color::rgb8(0, 0, 255).into(),
None,
only_movetos,
);
sb.stroke(
&simple_stroke(8.0),
Affine::translate(100.0, 100.0),

View file

@ -160,8 +160,8 @@ impl<'a> SceneBuilder<'a> {
PathElement::Close => b.close_path(),
}
}
b.finish();
if b.n_pathseg != 0 {
b.path();
self.scene.n_path += 1;
self.scene.n_pathseg += b.n_pathseg;
true
@ -434,7 +434,7 @@ impl<'a> PathBuilder<'a> {
self.state = PathState::Start;
}
fn finish(&mut self) {
pub fn finish(&mut self) {
if self.is_fill {
self.close_path();
}
@ -442,17 +442,11 @@ impl<'a> PathBuilder<'a> {
let new_len = self.pathseg_stream.len() - 8;
self.pathseg_stream.truncate(new_len);
}
if self.n_pathseg != 0 {
if let Some(tag) = self.tag_stream.last_mut() {
*tag |= 4;
}
}
/// Finish encoding a path.
///
/// Encode this after encoding path segments.
pub fn path(&mut self) {
self.finish();
// maybe don't encode if path is empty? might throw off sync though
self.tag_stream.push(0x10);
}
}
}