diff nodejs/svg.js @ 810:84853c8559cf

Support opacity on coords
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 02 Sep 2010 10:59:02 +0800
parents 9b6c26cf9102
children 2a73ff24c141
line wrap: on
line diff
--- a/nodejs/svg.js	Wed Sep 01 21:51:13 2010 +0800
+++ b/nodejs/svg.js	Thu Sep 02 10:59:02 2010 +0800
@@ -491,6 +491,29 @@
 // Each element must be responsible to calculate its absolute origin
 // point and update the origin of its parent.
 
+function parseGroupStyle(style,n)
+{
+    var attr;
+    if (n) {
+        attr = n.attr('style');
+    } else {
+        attr = null;
+    }
+    if (attr == null) {
+        return;
+    }
+    var f = attr.value().split(';');
+
+    for(i in f) {
+        var kv = f[i].split(':');
+        if (kv[0] == 'opacity') {
+            style.opacity = parseFloat(kv[1]);
+        } else {
+            sys.puts("Unknown style: "+kv[0]);
+        }
+    }
+}
+
 loadSVG.prototype.parseGroup=function(accu_matrix,root, group_id, n) {
     var k;
     var nodes = n.childNodes();
@@ -498,6 +521,8 @@
     // Parse the transform and style here
     var trans = n.attr('transform');
     var accu=[1,0,0,0,1,0];
+    var style;
+
     coord.center= new Object();
     coord.center.x = 10000;
     coord.center.y = 10000;
@@ -507,6 +532,13 @@
     multiply(accu,accu_matrix);
     multiply(accu,coord);
 
+    style = {};
+    parseGroupStyle(style, n);
+    if(style.opacity) {
+	sys.puts(style.opacity);
+	coord.set_opacity(style.opacity);
+    }
+
     for(k in nodes) {
 	var c = nodes[k].name();
 	var attr = nodes[k].attr('id');