Mercurial > MadButterfly
comparison nodejs/svg.js @ 808:9b6c26cf9102
Move bounding box and center back to an object
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Sep 2010 20:04:35 +0800 |
parents | 5723e5446b7c |
children | 84853c8559cf |
comparison
equal
deleted
inserted
replaced
807:5723e5446b7c | 808:9b6c26cf9102 |
---|---|
248 | 248 |
249 | 249 |
250 loadSVG.prototype._set_bbox = function(node, tgt) { | 250 loadSVG.prototype._set_bbox = function(node, tgt) { |
251 var a; | 251 var a; |
252 var vstr; | 252 var vstr; |
253 var bbox, center; | |
253 | 254 |
254 a = node.attr("bbox-x"); | 255 a = node.attr("bbox-x"); |
255 if(!a) | 256 if(!a) |
256 return; | 257 return; |
257 | 258 |
259 tgt.bbox = bbox = new Object(); | |
258 vstr = a.value(); | 260 vstr = a.value(); |
259 tgt.bbox_x = parseFloat(vstr); | 261 bbox.x = parseFloat(vstr); |
260 | 262 |
261 a = node.attr("bbox-y"); | 263 a = node.attr("bbox-y"); |
262 vstr = a.value(); | 264 vstr = a.value(); |
263 tgt.bbox_y = this.height - parseFloat(vstr); | 265 bbox.y = this.height - parseFloat(vstr); |
264 | 266 |
265 a = node.attr("bbox-width"); | 267 a = node.attr("bbox-width"); |
266 vstr = a.value(); | 268 vstr = a.value(); |
267 tgt.bbox_width = parseFloat(vstr); | 269 bbox.width = parseFloat(vstr); |
268 | 270 |
269 a = node.attr("bbox-height"); | 271 a = node.attr("bbox-height"); |
270 vstr = a.value(); | 272 vstr = a.value(); |
271 tgt.bbox_height = parseFloat(vstr); | 273 bbox.height = parseFloat(vstr); |
272 tgt.bbox_y -= tgt.bbox_height; | 274 bbox.y -= bbox.height; |
273 | 275 |
274 tgt.center_x = tgt.bbox_width / 2 + tgt.bbox_x; | 276 tgt.center = center = new Object(); |
277 | |
278 center.x = bbox.width / 2 + bbox.x; | |
279 center.y = bbox.height / 2 + bbox.y; | |
275 a = node.attr("transform-center-x"); | 280 a = node.attr("transform-center-x"); |
276 if(a) { | 281 if(!a) |
277 vstr = a.value(); | 282 return; |
278 tgt.center_x += parseFloat(vstr); | 283 |
279 } | 284 vstr = a.value(); |
280 | 285 center.x += parseFloat(vstr); |
281 tgt.center_y = tgt.bbox_height / 2 + tgt.bbox_y; | |
282 a = node.attr("transform-center-y"); | 286 a = node.attr("transform-center-y"); |
283 if(a) { | 287 vstr = a.value(); |
284 vstr = a.value(); | 288 center.y -= parseFloat(vstr); |
285 tgt.center_y -= parseFloat(vstr); | |
286 } | |
287 } | 289 } |
288 | 290 |
289 loadSVG.prototype._set_paint = function(node, tgt) { | 291 loadSVG.prototype._set_paint = function(node, tgt) { |
290 var style = node.attr('style'); | 292 var style = node.attr('style'); |
291 var paint; | 293 var paint; |