@@ -138,6 +138,11 @@ if (!document.createElement('canvas').getContext) {
138
138
139
139
el . getContext = getContext ;
140
140
141
+ // Remove fallback content. There is no way to hide text nodes so we
142
+ // just remove all childNodes. We could hide all elements and remove
143
+ // text nodes but who really cares about the fallback content.
144
+ el . innerHTML = '' ;
145
+
141
146
// do not use inline function because that will leak memory
142
147
el . attachEvent ( 'onpropertychange' , onPropertyChange ) ;
143
148
el . attachEvent ( 'onresize' , onResize ) ;
@@ -314,7 +319,6 @@ if (!document.createElement('canvas').getContext) {
314
319
var contextPrototype = CanvasRenderingContext2D_ . prototype ;
315
320
contextPrototype . clearRect = function ( ) {
316
321
this . element_ . innerHTML = '' ;
317
- this . currentPath_ = [ ] ;
318
322
} ;
319
323
320
324
contextPrototype . beginPath = function ( ) {
@@ -422,27 +426,31 @@ if (!document.createElement('canvas').getContext) {
422
426
} ;
423
427
424
428
contextPrototype . strokeRect = function ( aX , aY , aWidth , aHeight ) {
425
- // Will destroy any existing path (same as FF behaviour)
429
+ var oldPath = this . currentPath_ ;
426
430
this . beginPath ( ) ;
431
+
427
432
this . moveTo ( aX , aY ) ;
428
433
this . lineTo ( aX + aWidth , aY ) ;
429
434
this . lineTo ( aX + aWidth , aY + aHeight ) ;
430
435
this . lineTo ( aX , aY + aHeight ) ;
431
436
this . closePath ( ) ;
432
437
this . stroke ( ) ;
433
- this . currentPath_ = [ ] ;
438
+
439
+ this . currentPath_ = oldPath ;
434
440
} ;
435
441
436
442
contextPrototype . fillRect = function ( aX , aY , aWidth , aHeight ) {
437
- // Will destroy any existing path (same as FF behaviour)
443
+ var oldPath = this . currentPath_ ;
438
444
this . beginPath ( ) ;
445
+
439
446
this . moveTo ( aX , aY ) ;
440
447
this . lineTo ( aX + aWidth , aY ) ;
441
448
this . lineTo ( aX + aWidth , aY + aHeight ) ;
442
449
this . lineTo ( aX , aY + aHeight ) ;
443
450
this . closePath ( ) ;
444
451
this . fill ( ) ;
445
- this . currentPath_ = [ ] ;
452
+
453
+ this . currentPath_ = oldPath ;
446
454
} ;
447
455
448
456
contextPrototype . createLinearGradient = function ( aX0 , aY0 , aX1 , aY1 ) {
@@ -789,14 +797,41 @@ if (!document.createElement('canvas').getContext) {
789
797
this . m_ = this . mStack_ . pop ( ) ;
790
798
} ;
791
799
800
+ function matrixIsFinite ( m ) {
801
+ for ( var j = 0 ; j < 3 ; j ++ ) {
802
+ for ( var k = 0 ; k < 2 ; k ++ ) {
803
+ if ( ! isFinite ( m [ j ] [ k ] ) || isNaN ( m [ j ] [ k ] ) ) {
804
+ return false ;
805
+ }
806
+ }
807
+ }
808
+ return true ;
809
+ }
810
+
811
+ function setM ( ctx , m , updateLineScale ) {
812
+ if ( ! matrixIsFinite ( m ) ) {
813
+ return ;
814
+ }
815
+ ctx . m_ = m ;
816
+
817
+ if ( updateLineScale ) {
818
+ // Get the line scale.
819
+ // Determinant of this.m_ means how much the area is enlarged by the
820
+ // transformation. So its square root can be used as a scale factor
821
+ // for width.
822
+ var det = m [ 0 ] [ 0 ] * m [ 1 ] [ 1 ] - m [ 0 ] [ 1 ] * m [ 1 ] [ 0 ] ;
823
+ ctx . lineScale_ = sqrt ( abs ( det ) ) ;
824
+ }
825
+ }
826
+
792
827
contextPrototype . translate = function ( aX , aY ) {
793
828
var m1 = [
794
829
[ 1 , 0 , 0 ] ,
795
830
[ 0 , 1 , 0 ] ,
796
831
[ aX , aY , 1 ]
797
832
] ;
798
833
799
- this . m_ = matrixMultiply ( m1 , this . m_ ) ;
834
+ setM ( this , matrixMultiply ( m1 , this . m_ ) , false ) ;
800
835
} ;
801
836
802
837
contextPrototype . rotate = function ( aRot ) {
@@ -809,7 +844,7 @@ if (!document.createElement('canvas').getContext) {
809
844
[ 0 , 0 , 1 ]
810
845
] ;
811
846
812
- this . m_ = matrixMultiply ( m1 , this . m_ ) ;
847
+ setM ( this , matrixMultiply ( m1 , this . m_ ) , false ) ;
813
848
} ;
814
849
815
850
contextPrototype . scale = function ( aX , aY ) {
@@ -821,14 +856,27 @@ if (!document.createElement('canvas').getContext) {
821
856
[ 0 , 0 , 1 ]
822
857
] ;
823
858
824
- var m = this . m_ = matrixMultiply ( m1 , this . m_ ) ;
859
+ setM ( this , matrixMultiply ( m1 , this . m_ ) , true ) ;
860
+ } ;
861
+
862
+ contextPrototype . transform = function ( m11 , m12 , m21 , m22 , dx , dy ) {
863
+ var m1 = [
864
+ [ m11 , m12 , 0 ] ,
865
+ [ m21 , m22 , 0 ] ,
866
+ [ dx , dy , 1 ]
867
+ ] ;
868
+
869
+ setM ( this , matrixMultiply ( m1 , this . m_ ) , true ) ;
870
+ } ;
871
+
872
+ contextPrototype . setTransform = function ( m11 , m12 , m21 , m22 , dx , dy ) {
873
+ var m = [
874
+ [ m11 , m12 , 0 ] ,
875
+ [ m21 , m22 , 0 ] ,
876
+ [ dx , dy , 1 ]
877
+ ] ;
825
878
826
- // Get the line scale.
827
- // Determinant of this.m_ means how much the area is enlarged by the
828
- // transformation. So its square root can be used as a scale factor
829
- // for width.
830
- var det = m [ 0 ] [ 0 ] * m [ 1 ] [ 1 ] - m [ 0 ] [ 1 ] * m [ 1 ] [ 0 ] ;
831
- this . lineScale_ = sqrt ( abs ( det ) ) ;
879
+ setM ( this , m , true ) ;
832
880
} ;
833
881
834
882
/******** STUBS ********/
0 commit comments