Fix Issue 155: non-ASCII characters now work in text elements via XML numeric references

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@832 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-10-14 18:49:35 +00:00
parent f82f098daa
commit 644310d412
1 changed files with 39 additions and 0 deletions

View File

@ -4813,6 +4813,8 @@ var Utils = {
"encode64" : function(input) {
// base64 strings are 4/3 larger than the original string
// input = Utils.encodeUTF8(input); // convert non-ASCII characters
input = Utils.convertToXMLReferences(input);
var output = new Array( Math.floor( (input.length + 2) / 3 ) * 4 );
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
@ -4842,6 +4844,43 @@ var Utils = {
return output.join('');
},
// based on http://phpjs.org/functions/utf8_encode:577
// codedread:does not seem to work with webkit-based browsers on OSX
"encodeUTF8": function(input) {
//return unescape(encodeURIComponent(input)); //may or may not work
var output = '';
for (var n = 0; n < input.length; n++){
var c = input.charCodeAt(n);
if (c < 128) {
output += input[n];
}
else if (c > 127) {
if (c < 2048){
output += String.fromCharCode((c >> 6) | 192);
}
else {
output += String.fromCharCode((c >> 12) | 224) + String.fromCharCode((c >> 6) & 63 | 128);
}
output += String.fromCharCode((c & 63) | 128);
}
}
return output;
},
"convertToXMLReferences": function(input) {
var output = '';
for (var n = 0; n < input.length; n++){
var c = input.charCodeAt(n);
if (c < 128) {
output += input[n];
}
else if(c > 127) {
output += ("&#" + c + ";");
}
}
return output;
},
"rectsIntersect": function(r1, r2) {
return r2.x < (r1.x+r1.width) &&