Auto merge of #5562 - mmatyas:canvas_linewidth, r=jdm

Rebase of #5488
This commit is contained in:
bors-servo 2015-04-08 00:56:37 -05:00
commit f57b487e4d
27 changed files with 52 additions and 111 deletions

View file

@ -51,6 +51,7 @@ pub struct CanvasRenderingContext2D {
canvas: JS<HTMLCanvasElement>,
image_smoothing_enabled: Cell<bool>,
stroke_color: Cell<RGBA>,
line_width: Cell<f64>,
fill_color: Cell<RGBA>,
transform: Cell<Matrix2D<f32>>,
}
@ -71,6 +72,7 @@ impl CanvasRenderingContext2D {
canvas: JS::from_rooted(canvas),
image_smoothing_enabled: Cell::new(true),
stroke_color: Cell::new(black),
line_width: Cell::new(1.0),
fill_color: Cell::new(black),
transform: Cell::new(Matrix2D::identity()),
}
@ -786,6 +788,19 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
Ok(CanvasGradient::new(self.global.root().r(),
CanvasGradientStyle::Radial(RadialGradientStyle::new(x0, y0, r0, x1, y1, r1, Vec::new()))))
}
fn LineWidth(self) -> f64 {
self.line_width.get()
}
fn SetLineWidth(self, width: f64) {
if !width.is_finite() || width <= 0.0 {
return;
}
self.line_width.set(width);
self.renderer.send(CanvasMsg::SetLineWidth(width as f32)).unwrap()
}
}
#[unsafe_destructor]

View file

@ -130,6 +130,26 @@ interface CanvasRenderingContext2D {
void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
};
[NoInterfaceObject]
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 unrestricted double miterLimit; // (default 10)
// dashed lines
//void setLineDash(sequence<unrestricted double> segments); // default empty
//sequence<unrestricted double> getLineDash();
//attribute unrestricted double lineDashOffset;
// text
//attribute DOMString font; // (default 10px sans-serif)
//attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
//attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
//attribute DOMString direction; // "ltr", "rtl", "inherit" (default: "inherit")
};
[NoInterfaceObject]
interface CanvasPathMethods {
// shared path API methods
@ -159,5 +179,6 @@ interface CanvasPathMethods {
};
CanvasRenderingContext2D implements CanvasDrawingStyles;
CanvasRenderingContext2D implements CanvasPathMethods;