aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas/canvas_paint_task.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/canvas/canvas_paint_task.rs')
-rw-r--r--components/canvas/canvas_paint_task.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs
index 150240bc722..8a1fc0679c4 100644
--- a/components/canvas/canvas_paint_task.rs
+++ b/components/canvas/canvas_paint_task.rs
@@ -39,6 +39,8 @@ pub enum CanvasMsg {
SetFillStyle(FillOrStrokeStyle),
SetStrokeStyle(FillOrStrokeStyle),
SetLineWidth(f32),
+ SetLineCap(LineCapStyle),
+ SetLineJoin(LineJoinStyle),
SetMiterLimit(f32),
SetTransform(Matrix2D<f32>),
SetGlobalAlpha(f32),
@@ -246,6 +248,8 @@ impl<'a> CanvasPaintTask<'a> {
CanvasMsg::SetFillStyle(style) => painter.set_fill_style(style),
CanvasMsg::SetStrokeStyle(style) => painter.set_stroke_style(style),
CanvasMsg::SetLineWidth(width) => painter.set_line_width(width),
+ CanvasMsg::SetLineCap(cap) => painter.set_line_cap(cap),
+ CanvasMsg::SetLineJoin(join) => painter.set_line_join(join),
CanvasMsg::SetMiterLimit(limit) => painter.set_miter_limit(limit),
CanvasMsg::SetTransform(ref matrix) => painter.set_transform(matrix),
CanvasMsg::SetGlobalAlpha(alpha) => painter.set_global_alpha(alpha),
@@ -427,6 +431,14 @@ impl<'a> CanvasPaintTask<'a> {
self.stroke_opts.line_width = width;
}
+ fn set_line_cap(&mut self, cap: LineCapStyle) {
+ self.stroke_opts.line_cap = cap.to_azure_style();
+ }
+
+ fn set_line_join(&mut self, join: LineJoinStyle) {
+ self.stroke_opts.line_join = join.to_azure_style();
+ }
+
fn set_miter_limit(&mut self, limit: f32) {
self.stroke_opts.miter_limit = limit;
}
@@ -626,6 +638,58 @@ impl FillOrStrokeStyle {
}
}
+#[derive(Copy, Clone, PartialEq)]
+pub enum LineCapStyle {
+ Butt = 0,
+ Round = 1,
+ Square = 2,
+}
+
+impl LineCapStyle {
+ fn to_azure_style(&self) -> CapStyle {
+ match *self {
+ LineCapStyle::Butt => CapStyle::Butt,
+ LineCapStyle::Round => CapStyle::Round,
+ LineCapStyle::Square => CapStyle::Square,
+ }
+ }
+
+ pub fn from_str(string: &str) -> Option<LineCapStyle> {
+ match string {
+ "butt" => Some(LineCapStyle::Butt),
+ "round" => Some(LineCapStyle::Round),
+ "square" => Some(LineCapStyle::Square),
+ _ => None
+ }
+ }
+}
+
+#[derive(Copy, Clone, PartialEq)]
+pub enum LineJoinStyle {
+ Round = 0,
+ Bevel = 1,
+ Miter = 2,
+}
+
+impl LineJoinStyle {
+ fn to_azure_style(&self) -> JoinStyle {
+ match *self {
+ LineJoinStyle::Round => JoinStyle::Round,
+ LineJoinStyle::Bevel => JoinStyle::Bevel,
+ LineJoinStyle::Miter => JoinStyle::Miter,
+ }
+ }
+
+ pub fn from_str(string: &str) -> Option<LineJoinStyle> {
+ match string {
+ "round" => Some(LineJoinStyle::Round),
+ "bevel" => Some(LineJoinStyle::Bevel),
+ "miter" => Some(LineJoinStyle::Miter),
+ _ => None
+ }
+ }
+}
+
/// Used by drawImage to get rid of the extra pixels of the image data that
/// won't be copied to the canvas
/// image_data: Color pixel data of the image