Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Canvas: implement rectangle drawing.
  • Loading branch information
mmatyas committed Apr 21, 2015
1 parent e4b620e commit 5287cb7
Show file tree
Hide file tree
Showing 34 changed files with 21 additions and 155 deletions.
1 change: 1 addition & 0 deletions components/canvas/canvas_msg.rs
Expand Up @@ -33,6 +33,7 @@ pub enum Canvas2dMsg {
MoveTo(Point2D<f32>),
PutImageData(Vec<u8>, Rect<f64>, Option<Rect<f64>>),
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
Rect(Rect<f32>),
RestoreContext,
SaveContext,
StrokeRect(Rect<f32>),
Expand Down
10 changes: 10 additions & 0 deletions components/canvas/canvas_paint_task.rs
Expand Up @@ -220,6 +220,7 @@ impl<'a> CanvasPaintTask<'a> {
}
Canvas2dMsg::MoveTo(ref point) => painter.move_to(point),
Canvas2dMsg::LineTo(ref point) => painter.line_to(point),
Canvas2dMsg::Rect(ref rect) => painter.rect(rect),
Canvas2dMsg::QuadraticCurveTo(ref cp, ref pt) => {
painter.quadratic_curve_to(cp, pt)
}
Expand Down Expand Up @@ -351,6 +352,15 @@ impl<'a> CanvasPaintTask<'a> {
self.path_builder.line_to(*point)
}

fn rect(&self, rect: &Rect<f32>) {
self.path_builder.move_to(Point2D(rect.origin.x, rect.origin.y));
self.path_builder.line_to(Point2D(rect.origin.x + rect.size.width, rect.origin.y));
self.path_builder.line_to(Point2D(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height));
self.path_builder.line_to(Point2D(rect.origin.x, rect.origin.y + rect.size.height));
self.path_builder.close();
}

fn quadratic_curve_to(&self,
cp: &Point2D<AzFloat>,
endpoint: &Point2D<AzFloat>) {
Expand Down
9 changes: 9 additions & 0 deletions components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -640,6 +640,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::LineTo(Point2D(x as f32, y as f32)))).unwrap();
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
fn Rect(self, x: f64, y: f64, width: f64, height: f64) {
if [x, y, width, height].iter().all(|val| val.is_finite()) {
let rect = Rect(Point2D(x as f32, y as f32),
Size2D(width as f32, height as f32));
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Rect(rect))).unwrap();
}
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto
fn QuadraticCurveTo(self, cpx: f64, cpy: f64, x: f64, y: f64) {
if !(cpx.is_finite() && cpy.is_finite() &&
Expand Down
Expand Up @@ -171,7 +171,7 @@ interface CanvasPathMethods {
unrestricted double radius);
// NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);

//void rect(double x, double y, double w, double h);
void rect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);

[Throws]
void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -6993,9 +6993,6 @@
[CanvasRenderingContext2D interface: operation arcTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
expected: FAIL
[CanvasRenderingContext2D interface: operation rect(unrestricted double,unrestricted double,unrestricted double,unrestricted double)]
expected: FAIL
[CanvasRenderingContext2D interface: operation arc(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,boolean)]
expected: FAIL
Expand Down Expand Up @@ -7191,12 +7188,6 @@
[CanvasRenderingContext2D interface: calling arcTo(unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double,unrestricted double) 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 "rect" with the proper type (77)]
expected: FAIL
[CanvasRenderingContext2D interface: calling rect(unrestricted double,unrestricted double,unrestricted double,unrestricted double) 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 "ellipse" with the proper type (79)]
expected: FAIL
Expand Down

0 comments on commit 5287cb7

Please sign in to comment.