Fixed base64 decoder

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@980 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2009-11-30 14:05:20 +00:00
parent ac19a9fe15
commit 474690f2a2
2 changed files with 26 additions and 21 deletions

View File

@ -2092,12 +2092,6 @@ function svg_edit_setup() {
// var revnums = "svg-editor.js ($Rev$) ";
// revnums += svgCanvas.getVersion();
// $('#copyright')[0].setAttribute("title", revnums);
var loc = document.location.href;
if(loc.indexOf('?source=') != -1) {
var pre = '?source=data:image/svg+xml;base64,';
var src = loc.substring(loc.indexOf(pre) + pre.length);
svgCanvas.setSvgString(Utils.decode64(src));
}
return svgCanvas;
};
@ -2236,6 +2230,14 @@ function setSVGIcons() {
// Make smaller
svgCanvas.setIconSize('s');
}
// Load source if given
var loc = document.location.href;
if(loc.indexOf('?source=') != -1) {
var pre = '?source=data:image/svg+xml;base64,';
var src = loc.substring(loc.indexOf(pre) + pre.length);
svgCanvas.setSvgString(Utils.decode64(src));
}
}
});
}

View File

@ -5996,35 +5996,38 @@ var Utils = {
"decode64" : function(input) {
if(window.atob) return window.atob(input);
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
do {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output.append(String.fromCharCode(chr1));
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output.append(String.fromCharCode(chr2));
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output.append(String.fromCharCode(chr3));
output = output + String.fromCharCode(chr3);
}
}
return output.toString();
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return unescape(output);
},
// based on http://phpjs.org/functions/utf8_encode:577