@@ -12,49 +12,27 @@ var Lib = require('../lib');
12
12
var EventEmitter = require ( 'events' ) . EventEmitter ;
13
13
14
14
function svgToImg ( opts ) {
15
-
16
15
var ev = opts . emitter || new EventEmitter ( ) ;
17
16
18
17
var promise = new Promise ( function ( resolve , reject ) {
19
-
20
18
var Image = window . Image ;
21
-
22
19
var svg = opts . svg ;
23
20
var format = opts . format || 'png' ;
24
21
25
- // IE is very strict, so we will need to clean
26
- // svg with the following regex
27
- // yes this is messy, but do not know a better way
28
- // Even with this IE will not work due to tainted canvas
29
- // see https://github.com/kangax/fabric.js/issues/1957
30
- // http://stackoverflow.com/questions/18112047/canvas-todataurl-working-in-all-browsers-except-ie10
31
- // Leave here just in case the CORS/tainted IE issue gets resolved
32
- if ( Lib . isIE ( ) ) {
33
- // replace double quote with single quote
34
- svg = svg . replace ( / " / gi, '\'' ) ;
35
- // url in svg are single quoted
36
- // since we changed double to single
37
- // we'll need to change these to double-quoted
38
- svg = svg . replace ( / ( \( ' # ) ( [ ^ ' ] * ) ( ' \) ) / gi, '(\"$2\")' ) ;
39
- // font names with spaces will be escaped single-quoted
40
- // we'll need to change these to double-quoted
41
- svg = svg . replace ( / ( \\ ' ) / gi, '\"' ) ;
42
- // IE only support svg
43
- if ( format !== 'svg' ) {
44
- var ieSvgError = new Error ( 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.' ) ;
45
- reject ( ieSvgError ) ;
46
- // eventually remove the ev
47
- // in favor of promises
48
- if ( ! opts . promise ) {
49
- return ev . emit ( 'error' , ieSvgError ) ;
50
- } else {
51
- return promise ;
52
- }
22
+ // IE only support svg
23
+ if ( Lib . isIE ( ) && format !== 'svg' ) {
24
+ var ieSvgError = new Error ( 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.' ) ;
25
+ reject ( ieSvgError ) ;
26
+ // eventually remove the ev
27
+ // in favor of promises
28
+ if ( ! opts . promise ) {
29
+ return ev . emit ( 'error' , ieSvgError ) ;
30
+ } else {
31
+ return promise ;
53
32
}
54
33
}
55
34
56
35
var canvas = opts . canvas ;
57
-
58
36
var ctx = canvas . getContext ( '2d' ) ;
59
37
var img = new Image ( ) ;
60
38
0 commit comments