comparison nodejs/svg.js @ 842:76fe4afce640

The inkscape:bbox is defined as the global coordinate system. However, the center.x and center.y must be the coordiante system of the parent group of the SVG entity. Therefore, we need to do coordinate transformation from the global coordination system to the local coordination system.
author wycc
date Sat, 18 Sep 2010 21:23:51 +0800
parents 2a73ff24c141
children f348a41e1aae
comparison
equal deleted inserted replaced
841:ce6cd06adccf 842:76fe4afce640
252 var vstr; 252 var vstr;
253 var bbox, center; 253 var bbox, center;
254 254
255 a = node.attr("bbox-x"); 255 a = node.attr("bbox-x");
256 if(!a) 256 if(!a)
257 return; 257 return 0;
258 258
259 tgt.bbox = bbox = new Object(); 259 tgt.bbox = bbox = new Object();
260 vstr = a.value(); 260 vstr = a.value();
261 bbox.x = parseFloat(vstr); 261 bbox.x = parseFloat(vstr);
262 262
273 bbox.height = parseFloat(vstr); 273 bbox.height = parseFloat(vstr);
274 bbox.y -= bbox.height; 274 bbox.y -= bbox.height;
275 275
276 tgt.center = center = new Object(); 276 tgt.center = center = new Object();
277 277
278 center.x = bbox.width / 2 + bbox.x; 278 //center.x = bbox.width / 2 + bbox.x;
279 center.y = bbox.height / 2 + bbox.y; 279 //center.y = bbox.height / 2 + bbox.y;
280 center.x = bbox.x;
281 center.y = bbox.y;
280 a = node.attr("transform-center-x"); 282 a = node.attr("transform-center-x");
281 if(!a) 283 if(!a)
282 return; 284 return 1;
283 285
284 vstr = a.value(); 286 vstr = a.value();
285 center.x += parseFloat(vstr); 287 center.x += parseFloat(vstr);
286 a = node.attr("transform-center-y"); 288 a = node.attr("transform-center-y");
287 vstr = a.value(); 289 vstr = a.value();
288 center.y -= parseFloat(vstr); 290 center.y -= parseFloat(vstr);
291 return 1;
289 } 292 }
290 293
291 loadSVG.prototype._set_paint = function(node, tgt) { 294 loadSVG.prototype._set_paint = function(node, tgt) {
292 var style = node.attr('style'); 295 var style = node.attr('style');
293 var paint; 296 var paint;
458 var paint; 461 var paint;
459 var tcoord = this.mb_rt.coord_new(coord); 462 var tcoord = this.mb_rt.coord_new(coord);
460 463
461 var style = n.attr('style'); 464 var style = n.attr('style');
462 465
463 if (trans) { 466 if (trans)
464 parseTransform(tcoord,trans.value()); 467 parseTransform(tcoord,trans.value());
465 //var m = [1,0,0,0,1,0];
466 //multiply(m,tcoord);
467 rx = tcoord[0]*x+tcoord[1]*y+tcoord[2];
468 ry = tcoord[3]*x+tcoord[4]*y+tcoord[5];
469 }
470
471 if (coord.center.x > rx)
472 coord.center.x = rx;
473 if (coord.center.y > ry)
474 coord.center.y = ry;
475 468
476 var rect = this.mb_rt.rect_new(x,y,w,h,10, 10); 469 var rect = this.mb_rt.rect_new(x,y,w,h,10, 10);
477 this._set_paint(n, rect); 470 this._set_paint(n, rect);
478 this._set_bbox(n, tcoord); 471 if (this._set_bbox(n, tcoord)) {
472 rx = accu_matrix[0]*tcoord.center.x+accu_matrix[1]*tcoord.center.y+accu_matrix[2];
473 ry = accu_matrix[3]*tcoord.center.x+accu_matrix[4]*tcoord.center.y+accu_matrix[5];
474 tcoord.center.x -= accu_matrix[2]+tcoord[2];
475 tcoord.center.y -= accu_matrix[2]+tcoord[2];
476 } else {
477 if (trans) {
478 rx = tcoord[0]*x+tcoord[1]*y+tcoord[2];
479 ry = tcoord[3]*x+tcoord[4]*y+tcoord[5];
480 if (tcoord.center.x > rx)
481 tcoord.center.x = rx;
482 if (tcoord.center.y > ry)
483 tcoord.center.y = ry;
484 }
485 }
479 tcoord.add_shape(rect); 486 tcoord.add_shape(rect);
480 487
481 make_mbnames(this.mb_rt, n, tcoord); 488 make_mbnames(this.mb_rt, n, tcoord);
482 }; 489 };
483 490
561 if (root.center.x > coord.center.x) 568 if (root.center.x > coord.center.x)
562 root.center.x = coord.center.x; 569 root.center.x = coord.center.x;
563 if (root.center.y > coord.center.y) 570 if (root.center.y > coord.center.y)
564 root.center.y = coord.center.y; 571 root.center.y = coord.center.y;
565 572
566 this._set_bbox(n, coord); 573 if (this._set_bbox(n, coord)) {
574 coord.center.x -= accu[2];
575 coord.center.y -= accu[5];
576 }
577 sys.puts("coord.center.x="+coord.center.x+",coord.center.y="+coord.center.y);
567 578
568 make_mbnames(this.mb_rt, n, coord); 579 make_mbnames(this.mb_rt, n, coord);
569 }; 580 };
570 581
571 loadSVG.prototype.parseImage=function(accu,coord,id, n) 582 loadSVG.prototype.parseImage=function(accu,coord,id, n)
613 var img_data = ldr.load(ref); 624 var img_data = ldr.load(ref);
614 var paint = this.mb_rt.paint_image_new(img_data); 625 var paint = this.mb_rt.paint_image_new(img_data);
615 paint.fill(img); 626 paint.fill(img);
616 tcoord.add_shape(img); 627 tcoord.add_shape(img);
617 628
618 this._set_bbox(n, img); 629 if (this._set_bbox(n, img)) {
630 img.center.x -= accu[2]+coord[2];
631 img.center.y -= accu[5]+coord[5];
632 }
619 633
620 make_mbnames(this.mb_rt, n, img); 634 make_mbnames(this.mb_rt, n, img);
621 }; 635 };
622 636
623 loadSVG.prototype._MB_parseLinearGradient=function(root,n) 637 loadSVG.prototype._MB_parseLinearGradient=function(root,n)