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

@ -38,6 +38,7 @@ pub enum CanvasMsg {
ArcTo(Point2D<f32>, Point2D<f32>, f32),
SetFillStyle(FillOrStrokeStyle),
SetStrokeStyle(FillOrStrokeStyle),
SetLineWidth(f32),
SetTransform(Matrix2D<f32>),
Recreate(Size2D<i32>),
SendPixelContents(Sender<Vec<u8>>),
@ -240,6 +241,7 @@ 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::SetTransform(ref matrix) => painter.set_transform(matrix),
CanvasMsg::Recreate(size) => painter.recreate(size),
CanvasMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
@ -419,6 +421,10 @@ impl<'a> CanvasPaintTask<'a> {
self.stroke_style = style.to_azure_pattern(&self.drawtarget)
}
fn set_line_width(&mut self, width: f32) {
self.stroke_opts.line_width = width;
}
fn set_transform(&mut self, transform: &Matrix2D<f32>) {
self.transform = *transform;
self.drawtarget.set_transform(transform)

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;

View file

@ -1,5 +0,0 @@
[2d.strokeRect.basic.html]
type: testharness
[strokeRect works]
expected: FAIL

View file

@ -0,0 +1,5 @@
[2d.strokeRect.globalalpha.html]
type: testharness
[strokeRect is affected by globalAlpha]
expected: FAIL

View file

@ -0,0 +1,5 @@
[2d.strokeRect.globalcomposite.html]
type: testharness
[strokeRect is not affected by globalCompositeOperation]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.line.join.bevel.html]
type: testharness
[lineJoin \'bevel\' is rendered correctly]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.line.union.html]
type: testharness
[Canvas test: 2d.line.union]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.line.width.basic.html]
type: testharness
[lineWidth determines the width of line strokes]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.line.width.invalid.html]
type: testharness
[Setting lineWidth to invalid values is ignored]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.line.width.valid.html]
type: testharness
[Setting lineWidth to valid values works]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.scale.2.html]
type: testharness
[Highly scaled arcs are the right shape]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.selfintersect.2.html]
type: testharness
[arc() with lineWidth > 2*radius is drawn sensibly]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.shape.2.html]
type: testharness
[arc() from 0 to pi draws stuff in the right half]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.shape.4.html]
type: testharness
[arc() from 0 to -pi/2 draws stuff in the right quadrant]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.twopie.2.html]
type: testharness
[arc() draws a full circle when end = start + 2pi-e and clockwise]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.twopie.3.html]
type: testharness
[arc() draws a full circle when end = start + 2pi+e and anticlockwise]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arc.twopie.4.html]
type: testharness
[arc() draws nothing when end = start + 2pi+e and clockwise]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arcTo.coincide.1.html]
type: testharness
[arcTo() has no effect if P0 = P1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.arcTo.shape.start.html]
type: testharness
[arcTo() draws a straight line from P0 to P1]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.bezierCurveTo.ensuresubpath.2.html]
type: testharness
[If there is no subpath, the first control point is added]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.bezierCurveTo.shape.html]
type: testharness
[Canvas test: 2d.path.bezierCurveTo.shape]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.quadraticCurveTo.ensuresubpath.2.html]
type: testharness
[If there is no subpath, the first control point is added]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.quadraticCurveTo.shape.html]
type: testharness
[Canvas test: 2d.path.quadraticCurveTo.shape]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.stroke.overlap.html]
type: testharness
[Stroked subpaths are combined before being drawn]
expected: FAIL

View file

@ -1,5 +0,0 @@
[2d.path.stroke.union.html]
type: testharness
[Strokes in opposite directions are unioned, not subtracted]
expected: FAIL

View file

@ -7026,9 +7026,6 @@
[CanvasRenderingContext2D interface: operation putImageData(ImageData,double,double)]
expected: FAIL
[CanvasRenderingContext2D interface: attribute lineWidth]
expected: FAIL
[CanvasRenderingContext2D interface: attribute lineCap]
expected: FAIL
@ -7242,9 +7239,6 @@
[CanvasRenderingContext2D interface: calling removeHitRegion(DOMString) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "lineWidth" with the proper type (59)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "lineCap" with the proper type (60)]
expected: FAIL