@@ -12,49 +12,27 @@ var Lib = require('../lib');
1212var EventEmitter = require ( 'events' ) . EventEmitter ;
1313
1414function svgToImg ( opts ) {
15-
1615 var ev = opts . emitter || new EventEmitter ( ) ;
1716
1817 var promise = new Promise ( function ( resolve , reject ) {
19-
2018 var Image = window . Image ;
21-
2219 var svg = opts . svg ;
2320 var format = opts . format || 'png' ;
2421
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 ;
5332 }
5433 }
5534
5635 var canvas = opts . canvas ;
57-
5836 var ctx = canvas . getContext ( '2d' ) ;
5937 var img = new Image ( ) ;
6038
0 commit comments