X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=plugins%2Fraphael.export.js;h=24e14cc4028132e1d1869a9ab97eec84d27a5538;hb=265ff3ab60fc67f052f7447edc3e56f0a72e5bad;hp=1fe0317bdd2df118e775b451b4a49890b0042eb8;hpb=671e2f643599d14492f6bfc5888b05176bac60ec;p=raphael diff --git a/plugins/raphael.export.js b/plugins/raphael.export.js index 1fe0317..24e14cc 100644 --- a/plugins/raphael.export.js +++ b/plugins/raphael.export.js @@ -90,7 +90,7 @@ return '<' + name + ( matrix ? ' transform="matrix(' + matrix.toString().replace(/^matrix\(|\)$/g, '') + ')" ' : ' ' ) + attrs + '>' + content + - '' + \n; + '' + "\n"; } /** @@ -100,7 +100,8 @@ 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'], } }; } @@ -111,7 +112,20 @@ */ 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(';') + } /** @@ -130,11 +144,11 @@ 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( @@ -148,8 +162,11 @@ return initial; }, - { style: 'text-anchor: middle; ' + styleToString(style) + ';' } - ), + { + style: 'text-anchor: ' + (style.font.anchor ? (style.font.anchor +';' ): 'middle;') + + styleToString(style) + ';' + } + ), node.matrix, tag('tspan', { @@ -171,9 +188,11 @@ 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; }, @@ -215,7 +234,7 @@ for ( i in node.attrs ) { var name = i; - + var val = node.attrs[i].toString(); switch ( i ) { case 'src': name = 'xlink:href'; @@ -223,12 +242,16 @@ 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) + '"'; } }