74632// SVGTOBITMAP  

zim.svgToBitmap = function(svg, callback, width, height, params) {
	
	if (!zot(svg.draggable)) {
		// CreateJS seems to wrap up an SVG with loadAssets as an SVG object
		var parser = new DOMParser();
		svg = !svg.innerHTML?svg:parser.parseFromString(svg.innerHTML,"text/xml");
		var list = svg.getElementsByTagName("svg");
		var tag = list?svg.getElementsByTagName("svg")[0]:null;
		svg = tag;
	}

        if (!XMLSerializer) {if (zon) {zogy("ZIM svgToBitmap() - sorry, not supported in Browser"); return;}}
	var svgString = (typeof svg == "string") ? svg : new XMLSerializer().serializeToString(svg);		
	if (svgString) {
		// https does not work
		svgString = svgString.replace(/https:\/\/www.w3/i, "http://www.w3");
		// seem to need width and height parameters in svg tag
		var first = svgString.split(">")[0];
		if (first.length>1) {
			var wid = first.split(/width/i);
			if (wid.length==1) { // no width and assume no height
				var w=100;
				var h=100;
				var box = first.split(/viewBox/i);
				if (box.length>1) {
					var dim = box[1].split("\"")[1];
					if (dim) {
						var d = dim.split(" ");
						if (d.length>1) {
							w = d[d.length-2];
							h = d[d.length-1];
						}
					}
				}
				// remember it is xml - need quotes
				svgString = svgString.replace(/svg /i, "svg  width=\""+w+"\" height=\""+h+"\" ");
			}
		}
		if (!svgString.match(/xmlns/i)) svgString = svgString.replace(/svg /i, "svg  xmlns='http://www.w3.org/2000/svg' ");
	}
	var DOMURL = self.URL || self.webkitURL || self;
	var inte = setTimeout(function() {
		zogy("ZIM SVG() could not be made");
		callback(new zim.Bitmap(), params);
		DOMURL.revokeObjectURL(obu);
	}, 100);
        var img = new Image();
        img.onload = function() {
		clearTimeout(inte);
            var bitmap = new zim.Bitmap(img, width, height);
            callback(bitmap, params);
		DOMURL.revokeObjectURL(obu);
        };		
	var obu;
	if (document && document.Blob) {
		obu = DOMURL.createObjectURL(new document.Blob([svgString], {type: "image/svg+xml"}));
	} else obu = DOMURL.createObjectURL(new Blob([svgString], {type: "image/svg+xml"}));
        img.src = obu;
	
    };