Mercurial > MadButterfly
comparison nodejs/svg.js @ 703:3457519e3b9c
Add rect and matrix support. The test.svg can be rendered almost correctly now.
author | wycc |
---|---|
date | Fri, 13 Aug 2010 08:16:18 +0800 |
parents | 492da72e6537 |
children | d950487bd9f9 |
comparison
equal
deleted
inserted
replaced
702:78a01b0d3fc9 | 703:3457519e3b9c |
---|---|
67 } else if (kv[0] == "font-style") { | 67 } else if (kv[0] == "font-style") { |
68 } else if (kv[0] == "font-weight") { | 68 } else if (kv[0] == "font-weight") { |
69 } else if (kv[0] == "fill") { | 69 } else if (kv[0] == "fill") { |
70 style.color = parseColor(kv[1]); | 70 style.color = parseColor(kv[1]); |
71 } else if (kv[0] == "fill-opacity") { | 71 } else if (kv[0] == "fill-opacity") { |
72 } else if (kv[0] == "stroke-opacity") { | |
72 } else if (kv[0] == "stroke") { | 73 } else if (kv[0] == "stroke") { |
73 } else if (kv[0] == "stroke-width") { | 74 } else if (kv[0] == "stroke-width") { |
74 } else if (kv[0] == "stroke-linecap") { | 75 } else if (kv[0] == "stroke-linecap") { |
75 } else if (kv[0] == "stroke-linejoin") { | 76 } else if (kv[0] == "stroke-linejoin") { |
76 } else if (kv[0] == "stroke-lineopacity") { | 77 } else if (kv[0] == "stroke-lineopacity") { |
159 coord[5] = y; | 160 coord[5] = y; |
160 } | 161 } |
161 off = s.indexOf('matrix'); | 162 off = s.indexOf('matrix'); |
162 if (off != -1) { | 163 if (off != -1) { |
163 sys.puts("matrix"); | 164 sys.puts("matrix"); |
165 var end = s.indexOf(')'); | |
166 var m = s.substring(7,end); | |
167 var fields = m.split(','); | |
168 coord[0] = parseFloat(fields[0]); | |
169 coord[1] = parseFloat(fields[1]); | |
170 coord[2] = parseFloat(fields[4]); | |
171 coord[3] = parseFloat(fields[2]); | |
172 coord[4] = parseFloat(fields[3]); | |
173 coord[5] = parseFloat(fields[5]); | |
164 } | 174 } |
165 } | 175 } |
166 | 176 |
167 function _MB_parseRect(coord, id, n) | 177 function _MB_parseRect(coord, id, n) |
168 { | 178 { |
169 | 179 var x = getInteger(n,'x'); |
180 var y = getInteger(n,'y'); | |
181 var w = getInteger(n,'width'); | |
182 var h = getInteger(n,'height'); | |
183 var paint; | |
184 | |
185 var style = n.attr('style'); | |
186 | |
187 if (style==null) { | |
188 paint = mb_rt.paint_color_new(0,0,0,0.1); | |
189 } else { | |
190 var items = style.value().split(';'); | |
191 var fill = ''; | |
192 var alpha; | |
193 for(i in items) { | |
194 sys.puts(items[i]); | |
195 var f = items[i].split(':'); | |
196 if (f[0] == 'opacity') { | |
197 alpha = f[1]; | |
198 } else if (f[0] == 'fill') { | |
199 fill = f[1]; | |
200 } else if (f[0] == 'fill-opacity') { | |
201 } else if (f[0] == 'stroke') { | |
202 } else if (f[0] == 'stroken-width') { | |
203 } else if (f[0] == 'stroke-opacity') { | |
204 } | |
205 } | |
206 sys.puts("fill="+fill); | |
207 if (fill[0]=='#') { | |
208 var r,g,b; | |
209 r = parseInt(fill.substring(1,3),16)/256; | |
210 g = parseInt(fill.substring(3,5),16)/256; | |
211 b = parseInt(fill.substring(5,7),16)/256; | |
212 sys.puts("r="+r+" g="+g+" b="+b+" a="+alpha); | |
213 | |
214 paint = mb_rt.paint_color_new(r,g,b,parseFloat(alpha)); | |
215 } else { | |
216 paint = mb_rt.paint_color_new(0,0,0,1); | |
217 } | |
218 } | |
219 var rect = mb_rt.rect_new(x,y,w,h,10, 10); | |
220 sys.puts("rect x="+x+" y="+y+" w="+w+" h="+h); | |
221 paint.fill(rect); | |
222 coord.add_shape(rect); | |
170 } | 223 } |
171 | 224 |
172 function _MB_parseGroup(root, group_id, n) | 225 function _MB_parseGroup(root, group_id, n) |
173 { | 226 { |
174 var k; | 227 var k; |