diff options
author | pylbrecht <palbrecht@mailbox.org> | 2019-06-20 10:58:06 +0200 |
---|---|---|
committer | Bastien Orivel <eijebong@bananium.fr> | 2019-08-21 19:08:17 +0200 |
commit | 4179f91f93dbe4f59c6c693dd96315dbc0a734bf (patch) | |
tree | 69557e00bd003dace2b52e7fe48401348893e69d /components/canvas/raqote_backend.rs | |
parent | 4aad4ff858899dfb8d3315ec2b944b4325877cfa (diff) | |
download | servo-4179f91f93dbe4f59c6c693dd96315dbc0a734bf.tar.gz servo-4179f91f93dbe4f59c6c693dd96315dbc0a734bf.zip |
Implement StrokeOptions
Diffstat (limited to 'components/canvas/raqote_backend.rs')
-rw-r--r-- | components/canvas/raqote_backend.rs | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index ada5fbc672d..5540759d5a0 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -76,7 +76,7 @@ impl<'a> CanvasPaintState<'a> { draw_options: DrawOptions::Raqote(raqote::DrawOptions::new()), fill_style: Pattern::Raqote(()), stroke_style: Pattern::Raqote(()), - stroke_opts: StrokeOptions::Raqote(PhantomData), + stroke_opts: StrokeOptions::Raqote(Default::default(), PhantomData), transform: Transform2D::identity(), shadow_offset_x: 0.0, shadow_offset_y: 0.0, @@ -96,16 +96,24 @@ impl Pattern { impl<'a> StrokeOptions<'a> { pub fn set_line_width(&mut self, _val: f32) { - unimplemented!() + match self { + StrokeOptions::Raqote(options, _) => options.width = _val, + } } pub fn set_miter_limit(&mut self, _val: f32) { - unimplemented!() + match self { + StrokeOptions::Raqote(options, _) => options.miter_limit = _val, + } } pub fn set_line_join(&mut self, _val: LineJoinStyle) { - unimplemented!() + match self { + StrokeOptions::Raqote(options, _) => options.join = _val.to_raqote_style(), + } } pub fn set_line_cap(&mut self, _val: LineCapStyle) { - unimplemented!() + match self { + StrokeOptions::Raqote(options, _) => options.cap = _val.to_raqote_style(), + } } } @@ -260,3 +268,33 @@ impl GenericDrawTarget for raqote::DrawTarget { unimplemented!() } } + +pub trait ToRaqoteStyle { + type Target; + + fn to_raqote_style(self) -> Self::Target; +} + +impl ToRaqoteStyle for LineJoinStyle { + type Target = raqote::LineJoin; + + fn to_raqote_style(self) -> raqote::LineJoin { + match self { + LineJoinStyle::Round => raqote::LineJoin::Round, + LineJoinStyle::Bevel => raqote::LineJoin::Bevel, + LineJoinStyle::Miter => raqote::LineJoin::Miter, + } + } +} + +impl ToRaqoteStyle for LineCapStyle { + type Target = raqote::LineCap; + + fn to_raqote_style(self) -> raqote::LineCap { + match self { + LineCapStyle::Butt => raqote::LineCap::Butt, + LineCapStyle::Round => raqote::LineCap::Round, + LineCapStyle::Square => raqote::LineCap::Square, + } + } +} |