Canvas: implement transformation matrix reset.

This commit is contained in:
Mátyás Mustoha 2015-05-05 15:39:35 +02:00
parent ccf1e6b9a7
commit 9302aaab96
6 changed files with 72 additions and 7 deletions

View file

@ -413,6 +413,12 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
self.update_transform()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform
fn ResetTransform(self) {
self.state.borrow_mut().transform = Matrix2D::identity();
self.update_transform()
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
fn GlobalAlpha(self) -> f64 {
let state = self.state.borrow();

View file

@ -46,7 +46,7 @@ interface CanvasRenderingContext2D {
unrestricted double d,
unrestricted double e,
unrestricted double f);
//void resetTransform();
void resetTransform();
// compositing
attribute unrestricted double globalAlpha; // (default 1.0)

View file

@ -1157,6 +1157,16 @@
],
"url": "/2dcontext/transformations/canvas_transformations_scale_001.htm"
},
{
"path": "2dcontext/transformations/canvas_transformations_reset_001.htm",
"references": [
[
"/2dcontext/transformations/canvas_transformations_reset_001-ref.htm",
"=="
]
],
"url": "/2dcontext/transformations/canvas_transformations_reset_001.htm"
},
{
"path": "FileAPI/url/url_xmlhttprequest_img.html",
"references": [
@ -20882,6 +20892,18 @@
"url": "/2dcontext/transformations/canvas_transformations_scale_001.htm"
}
],
"2dcontext/transformations/canvas_transformations_reset_001.htm": [
{
"path": "2dcontext/transformations/canvas_transformations_reset_001.htm",
"references": [
[
"/2dcontext/transformations/canvas_transformations_reset_001-ref.htm",
"=="
]
],
"url": "/2dcontext/transformations/canvas_transformations_reset_001.htm"
}
],
"FileAPI/url/url_xmlhttprequest_img.html": [
{
"path": "FileAPI/url/url_xmlhttprequest_img.html",

View file

@ -6828,9 +6828,6 @@
[CanvasRenderingContext2D interface: attribute currentTransform]
expected: FAIL
[CanvasRenderingContext2D interface: operation resetTransform()]
expected: FAIL
[CanvasRenderingContext2D interface: operation createPattern(CanvasImageSource,DOMString)]
expected: FAIL
@ -6957,9 +6954,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "currentTransform" with the proper type (6)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "resetTransform" with the proper type (12)]
expected: FAIL
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "strokeStyle" with the proper type (16)]
expected: FAIL

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<body>
<style>
html, body, div {
margin: 0;
padding: 0;
}
div {
width: 75px;
height: 75px;
float: left;
}
</style>
<div style="background-color:red"></div>
<div style="clear:left"></div>
<div style="background-color:blue"></div>
</body>
</html>

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="match" href="canvas_transformations_reset_001-ref.htm">
<style>
html, body {
margin: 0;
padding: 0;
}
</style>
<canvas id="c" width="150" height="150"></canvas>
<script>
var c = document.getElementById("c");
var ctx = c.getContext("2d");
ctx.translate(75, 75);
ctx.fillStyle = 'blue';
ctx.fillRect(0, 0, 75, 75);
ctx.resetTransform();
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 75, 75);
</script>