aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas/canvas_paint_task.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-04-14 12:57:48 -0500
committerbors-servo <metajack+bors@gmail.com>2015-04-14 12:57:48 -0500
commitfe81ce942a36b08ece8ef6d58de72624a961eeaa (patch)
tree7112d48bfaccd920db50ac59b7752ec927c9afae /components/canvas/canvas_paint_task.rs
parente597fd0c007372840e256056f8790264096681e3 (diff)
parentccfff159e7b79d4dc9a64d5cbb3b24518578bd43 (diff)
downloadservo-fe81ce942a36b08ece8ef6d58de72624a961eeaa.tar.gz
servo-fe81ce942a36b08ece8ef6d58de72624a961eeaa.zip
Auto merge of #5635 - mmatyas:canvas_linecapjoin, r=jdm
This patch adds support for setting the line cap and join. However, it seems there's a problem on the azure-side, as the line cap setting doesn't work. Changing either the default values or using the new function has no effect. Line join works fine though. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5635) <!-- Reviewable:end -->
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