Skip to content

Commit

Permalink
render: Extract out common LineScaleMode code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Mar 13, 2023
1 parent 2c537a0 commit 78e1d35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
7 changes: 1 addition & 6 deletions render/canvas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,7 @@ fn swf_shape_strokes_to_canvas_commands(
line_cap: line_cap.to_string(),
line_join: line_join.to_string(),
miter_limit: miter_limit as f64 / 20.0,
scale_mode: match (path.style.allow_scale_x(), path.style.allow_scale_y()) {
(false, false) => LineScaleMode::None,
(true, false) => LineScaleMode::Horizontal,
(false, true) => LineScaleMode::Vertical,
(true, true) => LineScaleMode::Both,
},
scale_mode: path.style.scale_mode(),
});
}
canvas_data
Expand Down
10 changes: 10 additions & 0 deletions render/src/shape_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ impl LineStyle {
self
}

#[inline]
pub fn scale_mode(&self) -> LineScaleMode {
match (self.allow_scale_x(), self.allow_scale_y()) {
(false, false) => LineScaleMode::None,
(true, false) => LineScaleMode::Horizontal,
(false, true) => LineScaleMode::Vertical,
(true, true) => LineScaleMode::Both,
}
}

#[inline]
pub fn is_pixel_hinted(&self) -> bool {
self.flags.contains(LineStyleFlag::PIXEL_HINTING)
Expand Down
38 changes: 17 additions & 21 deletions render/src/tessellator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::bitmap::BitmapHandle;
use crate::matrix::Matrix;
use crate::shape_utils::{DrawCommand, FillPath, FillStyle, LineScaleMode, LineScales, StrokePath};
use crate::shape_utils::{DrawCommand, FillPath, FillStyle, LineScales, StrokePath};
use enum_map::Enum;
use lyon::path::Path;
use lyon::tessellation::{
Expand Down Expand Up @@ -140,26 +140,22 @@ impl ShapeStrokeTessellator {
let mut buffers_builder =
BuffersBuilder::new(&mut self.lyon_mesh, RuffleVertexCtor { color });

let mut stroke_options = StrokeOptions::default()
.with_line_width(scales.transform_width(
path.style.width.to_pixels() as f32,
match (path.style.allow_scale_x(), path.style.allow_scale_y()) {
(false, false) => LineScaleMode::None,
(true, false) => LineScaleMode::Horizontal,
(false, true) => LineScaleMode::Vertical,
(true, true) => LineScaleMode::Both,
},
))
.with_start_cap(match path.style.start_cap() {
swf::LineCapStyle::None => tessellation::LineCap::Butt,
swf::LineCapStyle::Round => tessellation::LineCap::Round,
swf::LineCapStyle::Square => tessellation::LineCap::Square,
})
.with_end_cap(match path.style.end_cap() {
swf::LineCapStyle::None => tessellation::LineCap::Butt,
swf::LineCapStyle::Round => tessellation::LineCap::Round,
swf::LineCapStyle::Square => tessellation::LineCap::Square,
});
let mut stroke_options =
StrokeOptions::default()
.with_line_width(scales.transform_width(
path.style.width.to_pixels() as f32,
path.style.scale_mode(),
))
.with_start_cap(match path.style.start_cap() {
swf::LineCapStyle::None => tessellation::LineCap::Butt,
swf::LineCapStyle::Round => tessellation::LineCap::Round,
swf::LineCapStyle::Square => tessellation::LineCap::Square,
})
.with_end_cap(match path.style.end_cap() {
swf::LineCapStyle::None => tessellation::LineCap::Butt,
swf::LineCapStyle::Round => tessellation::LineCap::Round,
swf::LineCapStyle::Square => tessellation::LineCap::Square,
});

let line_join = match path.style.join_style() {
swf::LineJoinStyle::Round => tessellation::LineJoin::Round,
Expand Down

0 comments on commit 78e1d35

Please sign in to comment.