plugins/raphael.export.js
[raphael] / plugins / raphael.export.js
index a645817..bdd3b91 100644 (file)
@@ -90,7 +90,7 @@
 
                return '<' + name + ( matrix ? ' transform="matrix(' + matrix.toString().replace(/^matrix\(|\)$/g, '') + ')" ' : ' ' ) + attrs + '>' +
              content +
-            '</' + name + '>';
+            '</' + 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',
                             {
                                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) + '"';
                                }
                        }