@@ -59,7 +59,7 @@ function ScratchCanvas(width, height) {
59
59
return canvas ;
60
60
}
61
61
62
- function addCtxCurrentTransform (ctx ) {
62
+ function addContextCurrentTransform (ctx ) {
63
63
// If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
64
64
if (!ctx .mozCurrentTransform ) {
65
65
// Store the original context
@@ -73,29 +73,34 @@ function addCtxCurrentTransform(ctx) {
73
73
ctx ._transformMatrix = [1 , 0 , 0 , 1 , 0 , 0 ];
74
74
ctx ._transformStack = [];
75
75
76
- ctx .__defineGetter__ ('mozCurrentTransform' , function getCurrentTransform () {
77
- return this ._transformMatrix ;
76
+ Object .defineProperty (ctx , 'mozCurrentTransform' , {
77
+ get : function getCurrentTransform () {
78
+ return this ._transformMatrix ;
79
+ }
78
80
});
79
81
80
- ctx . __defineGetter__ ( 'mozCurrentTransformInverse' ,
81
- function getCurrentTransformInverse () {
82
+ Object . defineProperty ( ctx , 'mozCurrentTransformInverse' , {
83
+ get : function getCurrentTransformInverse () {
82
84
// Calculation done using WolframAlpha:
83
85
// http://www.wolframalpha.com/input/?
84
86
// i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
85
87
86
88
var m = this ._transformMatrix ;
87
89
var a = m [0 ], b = m [1 ], c = m [2 ], d = m [3 ], e = m [4 ], f = m [5 ];
88
90
91
+ var ad_bc = a * d - b * c ;
92
+ var bc_ad = b * c - a * d ;
93
+
89
94
return [
90
- d / ( a * d - b * c ) ,
91
- b / ( b * c - a * d ) ,
92
- c / ( b * c - a * d ) ,
93
- a / ( a * d - b * c ) ,
94
- (d * e - c * f ) / ( b * c - a * d ) ,
95
- (b * e - a * f ) / ( a * d - b * c )
95
+ d / ad_bc ,
96
+ b / bc_ad ,
97
+ c / bc_ad ,
98
+ a / ad_bc ,
99
+ (d * e - c * f ) / bc_ad ,
100
+ (b * e - a * f ) / ad_bc
96
101
];
97
102
}
98
- );
103
+ } );
99
104
100
105
ctx .save = function ctxSave () {
101
106
var old = this ._transformMatrix ;
@@ -111,15 +116,15 @@ function addCtxCurrentTransform(ctx) {
111
116
this ._transformMatrix = prev ;
112
117
this ._originalRestore ();
113
118
}
114
- }
119
+ };
115
120
116
121
ctx .translate = function ctxTranslate (x , y ) {
117
122
var m = this ._transformMatrix ;
118
123
m [4 ] = m [0 ] * x + m [2 ] * y + m [4 ];
119
124
m [5 ] = m [1 ] * x + m [3 ] * y + m [5 ];
120
125
121
126
this ._originalTranslate (x , y );
122
- }
127
+ };
123
128
124
129
ctx .scale = function ctxScale (x , y ) {
125
130
var m = this ._transformMatrix ;
@@ -129,7 +134,7 @@ function addCtxCurrentTransform(ctx) {
129
134
m [3 ] = m [3 ] * y ;
130
135
131
136
this ._originalScale (x , y );
132
- }
137
+ };
133
138
134
139
ctx .transform = function ctxTransform (a , b , c , d , e , f ) {
135
140
var m = this ._transformMatrix ;
@@ -143,7 +148,7 @@ function addCtxCurrentTransform(ctx) {
143
148
];
144
149
145
150
ctx ._originalTransform (a , b , c , d , e , f );
146
- }
151
+ };
147
152
148
153
ctx .rotate = function ctxRotate (angle ) {
149
154
var cosValue = Math .cos (angle );
@@ -160,7 +165,7 @@ function addCtxCurrentTransform(ctx) {
160
165
];
161
166
162
167
this ._originalRotate (angle );
163
- }
168
+ };
164
169
}
165
170
}
166
171
@@ -184,7 +189,7 @@ var CanvasGraphics = (function canvasGraphics() {
184
189
this .objs = objs ;
185
190
186
191
if (canvasCtx ) {
187
- addCtxCurrentTransform (canvasCtx );
192
+ addContextCurrentTransform (canvasCtx );
188
193
}
189
194
}
190
195
0 commit comments