function escapeXML(s) {
if ( typeof s === 'number' ) return s.toString();
- var replace = { '&': 'amp', '<': 'lt', '>': 'gt', '"': 'quot', '\'': 'apos' };
+ var replace = {
+ '&': 'amp',
+ '<': 'lt',
+ '>': 'gt',
+ '"': 'quot',
+ '\'': 'apos'
+ };
for ( var entity in replace ) {
s = s.replace(new RegExp(entity, 'g'), '&' + replace[entity] + ';');
}
return '<' + name + ( matrix ? ' transform="matrix(' + matrix.toString().replace(/^matrix\(|\)$/g, '') + ')" ' : ' ' ) + attrs + '>' +
- escapeXML(content) +
- '</' + name + '>';
+ content +
+ '</' + name + '>' + "\n";
}
/**
return {
font: {
family: node.attrs.font.replace(/^.*?"(\w+)".*$/, '$1'),
- size: typeof node.attrs['font-size'] === 'undefined' ? null : node.attrs['font-size']
+ size: typeof node.attrs['font-size'] === 'undefined' ? null : node.attrs['font-size'],
+ anchor : typeof node.attrs['text-anchor'] === 'undefined' ? null : node.attrs['text-anchor'],
}
};
}
*/
function styleToString(style) {
// TODO figure out what is 'normal'
- return 'font: normal normal normal 10px/normal ' + style.font.family + ( style.font.size === null ? '' : '; font-size: ' + style.font.size + 'px' );
+
+ var r = [
+ 'font-family:' + style.font.family,
+ 'font-weight:normal',
+ 'font-style:normal',
+ 'font-stretch:normal',
+ 'font-variant:normal'
+ ];
+ if (style.font.size !== null ) {
+ r.push('font-size: ' + style.font.size + 'px')
+ }
+
+ return r.join(';')
+
}
/**
var serializer = {
'text': function(node) {
style = extractStyle(node);
-
+ Roo.log(style);
var tags = new Array;
map(node.attrs['text'].split('\n'), function(text, iterable, line) {
- line = line || 0;
+ line = line || 0;
tags.push(tag(
'text',
reduce(
return initial;
},
- { style: 'text-anchor: middle; ' + styleToString(style) + ';' }
- ),
+ {
+ style: 'text-anchor: ' + (style.font.anchor ? (style.font.anchor +';' ): 'middle;') +
+ styleToString(style) + ';'
+ }
+ ),
node.matrix,
tag('tspan',
{
dy: computeTSpanDy(style.font.size, line + 1, node.attrs['text'].split('\n').length)
},
null,
- text
+ escapeXML(text)
)
));
});
reduce(
node.attrs,
function(initial, value, name) {
- if ( name === 'path' ) name = 'd';
+ if ( name === 'path' ) {
+ name = 'd';
+ }
- initial[name] = value.toString();
+ initial[name] = (typeof(value) == 'undefined') ? '' : value.toString();
return initial;
},
- {}
+ {
+ style: node.attrs.style
+ }
),
node.matrix
);
for ( i in node.attrs ) {
var name = i;
-
+ var val = node.attrs[i].toString();
switch ( i ) {
case 'src':
name = 'xlink:href';
break;
case 'transform':
name = '';
-
break;
+
+ case 'stroke':
+ case 'fill':
+ val = Raphael.getRGB(val).hex;
+ break;
}
if ( name ) {
- attrs += ' ' + name + '="' + escapeXML(node.attrs[i].toString()) + '"';
+ attrs += ' ' + name + '="' + escapeXML(val) + '"';
}
}