[Sie-announce] SIEコード [1808] SVGLengthについて、%などに対応

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 4月 29日 (木) 23:43:34 JST


Revision: 1808
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1808
Author:   dhrname
Date:     2010-04-29 23:43:34 +0900 (Thu, 29 Apr 2010)

Log Message:
-----------
SVGLengthについて、%などに対応

Modified Paths:
--------------
    branches/ufltima/dom/svg.js

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-04-29 14:42:39 UTC (rev 1807)
+++ branches/ufltima/dom/svg.js	2010-04-29 14:43:34 UTC (rev 1808)
@@ -226,12 +226,20 @@
       tar.xmlbase = evt.newValue;
     } else {
       if (!!tar[name]) {
-        var tea = tar[name];
-        if (evt.attrChange === MutationEvent.ADDITION) {
+        var tea = tar[name], tod = tar.ownerDocument.documentElement;
+        if (tea instanceof SVGAnimatedLength) {
+          if (evt.attrChange === MutationEvent.ADDITION) {
+            tea.baseVal = tod.createSVGLength();
+          }
           var n = evt.newValue.match(/\D+$/), type = 0;
           if (!n) {
             type = SVGLength.SVG_LENGTHTYPE_NUMBER;
           } else if (n === "%") {
+            if ((name === "x") || (name === "width")) {
+              tea._percent *= tod.viewport.width;
+            } else if ((name === "y") || (name === "height")) {
+              tea._percent *= tod.viewport.height;
+            }
             type = SVGLength.SVG_LENGTHTYPE_PERCENTAGE;
           } else if (n === "em") {
             type = SVGLength.SVG_LENGTHTYPE_EMS;
@@ -250,10 +258,6 @@
           } else if (n === "pc") {
             type = SVGLength.SVG_LENGTHTYPE_PC;
           }
-        } else {
-          var type = tea.unitType;
-        }
-        if (tea instanceof SVGAnimatedLength) {
           var s = _parseFloat(evt.newValue);
           s = isNaN(s) ? 0 : s;
           tea.baseVal.newValueSpecifiedUnits(type, s);
@@ -437,6 +441,7 @@
   /*attribute float*/          this.value = 0;                  //利用単位における値
   /*attribute float*/          this.valueInSpecifiedUnits = SVGLength.SVG_LENGTHTYPE_UNKNOWN;  //unitTypeにおける値
   /*attribute DOMString*/      this.valueAsString;
+  this._percent = 0.01; //単位に%が使われていた場合、このプロパティの数値を1%として使う
 };
     // Length Unit Types
   /*const unsigned short*/ SVGLength.SVG_LENGTHTYPE_UNKNOWN    = 0;
@@ -460,7 +465,7 @@
   if (unitType === SVGLength.SVG_LENGTHTYPE_NUMBER) {
     _s = "";
   } else if (unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) {
-    n = 0.01;
+    n = this._percent;
     _s = "%"
   } else if (unitType === SVGLength.SVG_LENGTHTYPE_EMS) {
     _s = "em";
@@ -500,7 +505,8 @@
 };
 
 function SVGAnimatedLength() {
-  /*readonly SVGLength*/ this.animVal = this.baseVal = new SVGLength();
+  /*readonly SVGLength*/ this.animVal;
+  this.baseVal;
   return this;
 };
 function SVGLengthList() {
@@ -1202,6 +1208,8 @@
             dcp.appendChild(sdt)
             tar.viewport.top = 0;
             tar.viewport.left = 0;
+            tar.width.baseVal = tar.createSVGLength();
+            tar.height.baseVal = tar.createSVGLength();
             tar.width.baseVal.value = tar.viewport.width = 1237;
             tar.height.baseVal.value = tar.viewport.height = 800;
             var fi = doc.documentElement.firstChild, n;
@@ -2282,7 +2290,6 @@
   /*readonly SVGAnimatedLength*/ this.height = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.rx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.ry = new SVGAnimatedLength();
-  this.x.baseVal.value = this.y.baseVal.value = 0;
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
@@ -2352,7 +2359,6 @@
   /*readonly SVGAnimatedLength*/ this.cx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.cy = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.r = new SVGAnimatedLength();
-  this.cx.baseVal.value = this.cy.baseVal.value = 0; //初期値を設定
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
@@ -2405,7 +2411,6 @@
   /*readonly SVGAnimatedLength*/ this.cy = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.rx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.ry = new SVGAnimatedLength();
-  this.cx.baseVal.value = this.cy.baseVal.value = 0; //初期値を設定
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
@@ -2458,7 +2463,6 @@
   /*readonly SVGAnimatedLength*/ this.y1 = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.x2 = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.y2 = new SVGAnimatedLength();
-  this.x1.baseVal.value = this.y1.baseVal.value = this.x2.baseVal.value = this.y2.baseVal.value = 0;
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
@@ -2710,7 +2714,7 @@
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACING           = 1;
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS  = 2;
 /*long*/     SVGTextContentElement.prototype.getNumberOfChars = function() {
-  return (this._list.length/2);
+  return (this._list.length/3);
 };
 /*float*/    SVGTextContentElement.prototype.getComputedTextLength = function() {
   this.getSubStringLength(0, this.getNumberOfChars());




Sie-announce メーリングリストの案内
Back to archive index