@@ -5,6 +5,7 @@ _html2canvas.Renderer.Canvas = function(options) {
5
5
safeImages = [ ] ,
6
6
testCanvas = document . createElement ( "canvas" ) ,
7
7
testctx = testCanvas . getContext ( "2d" ) ,
8
+ Util = _html2canvas . Util ,
8
9
canvas = options . canvas || doc . createElement ( 'canvas' ) ;
9
10
10
11
function createShape ( ctx , args ) {
@@ -40,33 +41,36 @@ _html2canvas.Renderer.Canvas = function(options) {
40
41
ctx [ item . name ] = item [ 'arguments' ] ;
41
42
break ;
42
43
case "function" :
43
- if ( item . name === "createPattern" ) {
44
- if ( item [ 'arguments' ] [ 0 ] . width > 0 && item [ 'arguments' ] [ 0 ] . height > 0 ) {
45
- try {
46
- ctx . fillStyle = ctx . createPattern ( item [ 'arguments' ] [ 0 ] , "repeat" ) ;
44
+ switch ( item . name ) {
45
+ case "createPattern" :
46
+ if ( item [ 'arguments' ] [ 0 ] . width > 0 && item [ 'arguments' ] [ 0 ] . height > 0 ) {
47
+ try {
48
+ ctx . fillStyle = ctx . createPattern ( item [ 'arguments' ] [ 0 ] , "repeat" ) ;
49
+ }
50
+ catch ( e ) {
51
+ Util . log ( "html2canvas: Renderer: Error creating pattern" , e . message ) ;
52
+ }
47
53
}
48
- catch ( e ) {
49
- _html2canvas . Util . log ( "html2canvas: Renderer: Error creating pattern" , e . message ) ;
54
+ break ;
55
+ case "drawShape" :
56
+ createShape ( ctx , item [ 'arguments' ] ) ;
57
+ break ;
58
+ case "drawImage" :
59
+ if ( item [ 'arguments' ] [ 8 ] > 0 && item [ 'arguments' ] [ 7 ] > 0 ) {
60
+ if ( ! options . taintTest || ( options . taintTest && safeImage ( item ) ) ) {
61
+ ctx . drawImage . apply ( ctx , item [ 'arguments' ] ) ;
62
+ }
50
63
}
51
- }
52
- } else if ( item . name === "drawShape" ) {
53
- createShape ( ctx , item [ 'arguments' ] ) ;
54
- } else if ( item . name === "drawImage" ) {
55
- if ( item [ 'arguments' ] [ 8 ] > 0 && item [ 'arguments' ] [ 7 ] > 0 ) {
56
- if ( ! options . taintTest || ( options . taintTest && safeImage ( item ) ) ) {
57
- ctx . drawImage . apply ( ctx , item [ 'arguments' ] ) ;
58
- }
59
- }
60
- } else {
61
- ctx [ item . name ] . apply ( ctx , item [ 'arguments' ] ) ;
64
+ break ;
65
+ default :
66
+ ctx [ item . name ] . apply ( ctx , item [ 'arguments' ] ) ;
62
67
}
63
68
break ;
64
69
}
65
70
}
66
71
67
72
return function ( zStack , options , document , queue , _html2canvas ) {
68
73
var ctx = canvas . getContext ( "2d" ) ,
69
- render = renderItem . bind ( null , ctx ) ,
70
74
newCanvas ,
71
75
bounds ,
72
76
fstyle ;
@@ -97,13 +101,15 @@ _html2canvas.Renderer.Canvas = function(options) {
97
101
}
98
102
99
103
if ( storageContext . ctx . storage ) {
100
- storageContext . ctx . storage . forEach ( render ) ;
104
+ storageContext . ctx . storage . forEach ( function ( item ) {
105
+ renderItem ( ctx , item ) ;
106
+ } ) ;
101
107
}
102
108
103
109
ctx . restore ( ) ;
104
110
} ) ;
105
111
106
- _html2canvas . Util . log ( "html2canvas: Renderer: Canvas renderer done - returning canvas obj" ) ;
112
+ Util . log ( "html2canvas: Renderer: Canvas renderer done - returning canvas obj" ) ;
107
113
108
114
if ( options . elements . length === 1 ) {
109
115
if ( typeof options . elements [ 0 ] === "object" && options . elements [ 0 ] . nodeName !== "BODY" ) {
0 commit comments