diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-04-14 12:57:48 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-04-14 12:57:48 -0500 |
commit | fe81ce942a36b08ece8ef6d58de72624a961eeaa (patch) | |
tree | 7112d48bfaccd920db50ac59b7752ec927c9afae /components/script | |
parent | e597fd0c007372840e256056f8790264096681e3 (diff) | |
parent | ccfff159e7b79d4dc9a64d5cbb3b24518578bd43 (diff) | |
download | servo-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/script')
-rw-r--r-- | components/script/dom/bindings/trace.rs | 2 | ||||
-rw-r--r-- | components/script/dom/canvasrenderingcontext2d.rs | 36 | ||||
-rw-r--r-- | components/script/dom/webidls/CanvasRenderingContext2D.webidl | 4 |
3 files changed, 40 insertions, 2 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 9d4e548e161..1695f16ead7 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -35,6 +35,7 @@ use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler}; use script_task::ScriptChan; use canvas::canvas_paint_task::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle}; +use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle}; use cssparser::RGBA; use encoding::types::EncodingRef; use geom::matrix2d::Matrix2D; @@ -259,6 +260,7 @@ no_jsmanaged_fields!(RGBA); no_jsmanaged_fields!(Matrix2D<T>); no_jsmanaged_fields!(StorageType); no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle); +no_jsmanaged_fields!(LineCapStyle, LineJoinStyle); impl JSTraceable for Box<ScriptChan+Send> { #[inline] diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 32db448af01..891c2d49b87 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -29,6 +29,7 @@ use geom::size::Size2D; use canvas::canvas_paint_task::{CanvasMsg, CanvasPaintTask, FillOrStrokeStyle}; use canvas::canvas_paint_task::{LinearGradientStyle, RadialGradientStyle}; +use canvas::canvas_paint_task::{LineCapStyle, LineJoinStyle}; use net_traits::image::base::Image; use net_traits::image_cache_task::{ImageResponseMsg, Msg}; @@ -40,6 +41,7 @@ use std::num::{Float, ToPrimitive}; use std::sync::{Arc}; use std::sync::mpsc::{channel, Sender}; +use util::str::DOMString; use url::Url; use util::vec::byte_swap; @@ -53,6 +55,8 @@ pub struct CanvasRenderingContext2D { image_smoothing_enabled: Cell<bool>, stroke_color: Cell<RGBA>, line_width: Cell<f64>, + line_cap: Cell<LineCapStyle>, + line_join: Cell<LineJoinStyle>, miter_limit: Cell<f64>, fill_color: Cell<RGBA>, transform: Cell<Matrix2D<f32>>, @@ -76,6 +80,8 @@ impl CanvasRenderingContext2D { image_smoothing_enabled: Cell::new(true), stroke_color: Cell::new(black), line_width: Cell::new(1.0), + line_cap: Cell::new(LineCapStyle::Butt), + line_join: Cell::new(LineJoinStyle::Miter), miter_limit: Cell::new(10.0), fill_color: Cell::new(black), transform: Cell::new(Matrix2D::identity()), @@ -819,6 +825,36 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> self.renderer.send(CanvasMsg::SetLineWidth(width as f32)).unwrap() } + fn LineCap(self) -> DOMString { + match self.line_cap.get() { + LineCapStyle::Butt => "butt".to_owned(), + LineCapStyle::Round => "round".to_owned(), + LineCapStyle::Square => "square".to_owned(), + } + } + + fn SetLineCap(self, cap_str: DOMString) { + if let Some(cap) = LineCapStyle::from_str(&cap_str) { + self.line_cap.set(cap); + self.renderer.send(CanvasMsg::SetLineCap(cap)).unwrap() + } + } + + fn LineJoin(self) -> DOMString { + match self.line_join.get() { + LineJoinStyle::Round => "round".to_owned(), + LineJoinStyle::Bevel => "bevel".to_owned(), + LineJoinStyle::Miter => "miter".to_owned(), + } + } + + fn SetLineJoin(self, join_str: DOMString) { + if let Some(join) = LineJoinStyle::from_str(&join_str) { + self.line_join.set(join); + self.renderer.send(CanvasMsg::SetLineJoin(join)).unwrap() + } + } + fn MiterLimit(self) -> f64 { self.miter_limit.get() } diff --git a/components/script/dom/webidls/CanvasRenderingContext2D.webidl b/components/script/dom/webidls/CanvasRenderingContext2D.webidl index 8b3070c6f64..2805a273550 100644 --- a/components/script/dom/webidls/CanvasRenderingContext2D.webidl +++ b/components/script/dom/webidls/CanvasRenderingContext2D.webidl @@ -134,8 +134,8 @@ interface CanvasRenderingContext2D { interface CanvasDrawingStyles { // line caps/joins attribute unrestricted double lineWidth; // (default 1) - //attribute DOMString lineCap; // "butt", "round", "square" (default "butt") - //attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") + attribute DOMString lineCap; // "butt", "round", "square" (default "butt") + attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") attribute unrestricted double miterLimit; // (default 10) // dashed lines |