mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Canvas: implement transformation matrix rotation.
This commit is contained in:
parent
7b87085c18
commit
e3e2119c4c
10 changed files with 15 additions and 45 deletions
|
@ -355,6 +355,20 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
|||
self.update_transform()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate
|
||||
fn Rotate(self, angle: f64) {
|
||||
if angle == 0.0 || !angle.is_finite() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (sin, cos) = (angle.sin(), angle.cos());
|
||||
let transform = self.state.borrow().transform;
|
||||
self.state.borrow_mut().transform = transform.mul(&Matrix2D::new(cos as f32, sin as f32,
|
||||
-sin as f32, cos as f32,
|
||||
0.0, 0.0));
|
||||
self.update_transform()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-translate
|
||||
fn Translate(self, x: f64, y: f64) {
|
||||
if !(x.is_finite() && y.is_finite()) {
|
||||
|
|
|
@ -32,7 +32,7 @@ interface CanvasRenderingContext2D {
|
|||
// transformations (default transform is the identity matrix)
|
||||
// attribute SVGMatrix currentTransform;
|
||||
void scale(unrestricted double x, unrestricted double y);
|
||||
//void rotate(unrestricted double angle);
|
||||
void rotate(unrestricted double angle);
|
||||
void translate(unrestricted double x, unrestricted double y);
|
||||
void transform(unrestricted double a,
|
||||
unrestricted double b,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue