Mercurial > MadButterfly
comparison nodejs/svg.js @ 861:e69f551e4a37 abs_n_rel_center
Move initial values of bbox and center to bbox.orig and center.orig
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 21 Sep 2010 00:28:44 +0800 |
parents | ea1e88c40548 |
children | 881efcd8a18f |
comparison
equal
deleted
inserted
replaced
860:9303fb45a958 | 861:e69f551e4a37 |
---|---|
383 /*! \brief Update x, y, width, and height of the bbox. | 383 /*! \brief Update x, y, width, and height of the bbox. |
384 */ | 384 */ |
385 update: function() { | 385 update: function() { |
386 var mtx; | 386 var mtx; |
387 | 387 |
388 this.x = this._svg_saved_x; | 388 this.x = this.orig.x; |
389 this.y = this._svg_saved_y; | 389 this.y = this.orig.y; |
390 this.width = this._svg_saved_width; | 390 this.width = this.orig.width; |
391 this.height = this._svg_saved_height; | 391 this.height = this.orig.height; |
392 | 392 |
393 mtx = this._saved_to_current(); | 393 mtx = this._saved_to_current(); |
394 _transform_bbox(this, mtx); | 394 _transform_bbox(this, mtx); |
395 }, | 395 }, |
396 }; | 396 }; |
457 update: function() { | 457 update: function() { |
458 var mtx; | 458 var mtx; |
459 var xy; | 459 var xy; |
460 | 460 |
461 mtx = this._saved_to_current(); | 461 mtx = this._saved_to_current(); |
462 xy = _pnt_transform(this._svg_saved_x, this._svg_saved_y, mtx); | 462 xy = _pnt_transform(this.orig.x, this.orig.y, mtx); |
463 | 463 |
464 this._x = xy[0]; | 464 this._x = xy[0]; |
465 this._y = xy[1]; | 465 this._y = xy[1]; |
466 }, | 466 }, |
467 | 467 |
505 get rel() { | 505 get rel() { |
506 var rev; | 506 var rev; |
507 var xy; | 507 var xy; |
508 | 508 |
509 rev = this._get_ac_rev(); | 509 rev = this._get_ac_rev(); |
510 xy = _pnt_transform(this._svg_saved_x, this._svg_saved_y, rev); | 510 xy = _pnt_transform(this.orig.x, this.orig.y, rev); |
511 | 511 |
512 return {x: xy[0], y: xy[1]}; | 512 return {x: xy[0], y: xy[1]}; |
513 }, | 513 }, |
514 }; | 514 }; |
515 | 515 |
516 loadSVG.prototype._set_bbox = function(node, tgt) { | 516 loadSVG.prototype._set_bbox = function(node, tgt) { |
517 var a; | 517 var a; |
518 var vstr; | 518 var vstr; |
519 var bbox, center; | 519 var bbox, center; |
520 var orig; | |
520 | 521 |
521 a = node.attr("bbox-x"); | 522 a = node.attr("bbox-x"); |
522 sys.puts("a="+a); | 523 sys.puts("a="+a); |
523 if(!a) | 524 if(!a) |
524 return 0; | 525 return 0; |
525 | 526 |
527 /* bbox.orig is initial values of bbox. The bbox is recomputed | |
528 * according bbox.orig and current matrix. See bbox.update(). | |
529 */ | |
526 tgt.bbox = bbox = new Object(); | 530 tgt.bbox = bbox = new Object(); |
531 bbox.orig = orig = new Object(); | |
527 bbox.owner = tgt; | 532 bbox.owner = tgt; |
528 bbox.__proto__ = _bbox_proto; | 533 bbox.__proto__ = _bbox_proto; |
529 vstr = a.value(); | 534 vstr = a.value(); |
530 bbox._svg_saved_x = parseFloat(vstr); | 535 orig.x = parseFloat(vstr); |
531 | 536 |
532 a = node.attr("bbox-y"); | 537 a = node.attr("bbox-y"); |
533 vstr = a.value(); | 538 vstr = a.value(); |
534 bbox._svg_saved_y = this.height - parseFloat(vstr); | 539 orig.y = this.height - parseFloat(vstr); |
535 | 540 |
536 a = node.attr("bbox-width"); | 541 a = node.attr("bbox-width"); |
537 vstr = a.value(); | 542 vstr = a.value(); |
538 bbox._svg_saved_width = parseFloat(vstr); | 543 orig.width = parseFloat(vstr); |
539 | 544 |
540 a = node.attr("bbox-height"); | 545 a = node.attr("bbox-height"); |
541 vstr = a.value(); | 546 vstr = a.value(); |
542 bbox._svg_saved_height = parseFloat(vstr); | 547 orig.height = parseFloat(vstr); |
543 bbox._svg_saved_y -= bbox._svg_saved_height; | 548 orig.y -= orig.height; |
544 | 549 |
545 bbox.update(); | 550 bbox.update(); |
546 | 551 |
552 /* center.orig is initial values of center. The center is | |
553 * recomputed according center.orig and current matrix. See | |
554 * center.update(). | |
555 */ | |
547 tgt.center = center = new Object(); | 556 tgt.center = center = new Object(); |
548 | 557 center.orig = orig = new Object(); |
549 center._svg_saved_x = bbox._svg_saved_width / 2 + bbox._svg_saved_x; | 558 |
550 center._svg_saved_y = bbox._svg_saved_height / 2 + bbox._svg_saved_y; | 559 orig.x = bbox.orig.width / 2 + bbox.orig.x; |
560 orig.y = bbox.orig.height / 2 + bbox.orig.y; | |
551 a = node.attr("transform-center-x"); | 561 a = node.attr("transform-center-x"); |
552 if(a) { | 562 if(a) { |
553 vstr = a.value(); | 563 vstr = a.value(); |
554 center._svg_saved_x += parseFloat(vstr); | 564 orig.x += parseFloat(vstr); |
555 a = node.attr("transform-center-y"); | 565 a = node.attr("transform-center-y"); |
556 vstr = a.value(); | 566 vstr = a.value(); |
557 center._svg_saved_y -= parseFloat(vstr); | 567 orig.y -= parseFloat(vstr); |
558 } | 568 } |
559 center.__proto__ = _center_proto; | 569 center.__proto__ = _center_proto; |
560 center.owner = tgt; | 570 center.owner = tgt; |
561 center.update(); | 571 center.update(); |
562 | 572 |