[Sie-announce] SIEコード [1802] SVGTextContentElementの修正

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2010年 4月 26日 (月) 23:45:26 JST


Revision: 1802
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1802
Author:   dhrname
Date:     2010-04-26 23:45:26 +0900 (Mon, 26 Apr 2010)

Log Message:
-----------
SVGTextContentElementの修正

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

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-04-23 14:18:01 UTC (rev 1801)
+++ branches/ufltima/dom/svg.js	2010-04-26 14:45:26 UTC (rev 1802)
@@ -2617,8 +2617,91 @@
 
 function SVGTextContentElement() { 
   SVGElement.apply(this, arguments);
+  this._tar = [];     //div要素を格納しておくリスト
   /*readonly SVGAnimatedLength*/      this.textLength = new SVGAnimatedLength();
   /*readonly SVGAnimatedEnumeration*/ this.lengthAdjust = new SVGAnimatedEnumeration(SVGTextContentElement.LENGTHADJUST_UNKNOWN);
+  this.addEventListener("DOMNodeInserted", function(evt){
+    if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      return; //強制終了させる
+    }
+    var tar = evt.target;
+    for (var i=0, tli=tar.getNumberOfChars();i<tli;++i) {
+      tar.parentNode._tar.appendChild(tar._tar[i]);
+    }
+    tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) {
+      var tar = evt.target, ti = tar.firstChild;
+      var x = y = n = 0; //現在のテキスト位置と順番
+      this._list = [];   //文字の位置を格納しておくリスト
+      var style = tar.ownerDocument.defaultView.getComputedStyle(tar, null);
+      var isYokogaki = ((style.getPropertyValue("writing-mode")) === "lr-tb") ? true : false;
+      var fontSize = parseFloat(style.getPropertyValue("font-size"));
+      var tx = tar.x.baseVal, ty = tar.y.baseVal, tdx = tar.dx.baseVal, tdy = tar.dy.baseVal;
+      while (ti) {
+        if (ti.nodeType === Node.TEXT_NODE) {
+          var tt = ti._tar;
+          for (var i=0, tli=tt.length;i<tli;++i) {
+            if (n < tx.numberOfItems) {
+              x = tx.getItem(n).value;
+            }
+            if (n < ty.numberOfItems) {
+              y = ty.getItem(n).value;
+            }
+            if (n < tdx.numberOfItems) {
+              x += tdx.getItem(n).value;
+            }
+            if (n < tdy.numberOfItems) {
+              y += tdy.getItem(n).value;
+            }
+            if (isYokogaki) {
+              x += fontSize;
+            } else {
+              y += fontSize;
+            }
+            this._list[this._list.length] = x;
+            this._list[this._list.length] = y;
+            ++n;
+          }
+        } else if (ti.localName === "tspan" && ti.namespaceURI === "http://www.w3.org/2000/svg"){
+          var tstyle = this.ownerDocument.defaultView.getComputedStyle(ti, null);
+          var tisYokogaki = ((tstyle.getPropertyValue("writing-mode")) === "lr-tb") ? true : false;
+          var tfontSize = parseFloat(tstyle.getPropertyValue("font-size"));
+          var tt = ti._tar, ttx = tt.x.baseVal, tty = tt.y.baseVal, ttdx = tt.dx.baseVal, ttdy = tt.dy.baseVal;
+          for (var i=0, tli=tt.length;i<tli;++i) {
+            if (n < ttx.numberOfItems) {
+              x = ttx.getItem(n).value;
+            } else if (n < tx.numberOfItems) {
+              x = tx.getItem(n).value;
+            }
+            if (n < tty.numberOfItems) {
+              y = ttx.getItem(n).value;
+            } else if (n < ty.numberOfItems) {
+              y = ty.getItem(n).value;
+            }
+            if (n < ttdx.numberOfItems) {
+              x += ttdx.getItem(n).value;
+            } else if (n < tdx.numberOfItems) {
+              x += tdx.getItem(n).value;
+            }
+            if (n < ttdy.numberOfItems) {
+              y += ttdx.getItem(n).value;
+            } else if (n < tdy.numberOfItems) {
+              y += tdy.getItem(n).value;
+            }
+            if (tisYokogaki) {
+              x += tfontSize;
+            } else {
+              y += tfontSize;
+            }
+            this._list[this._list.length] = x;
+            this._list[this._list.length] = y;
+            ++n;
+          }
+        }
+        ti = ti.nextSibling;
+      }
+    }, false);
+    evt = tar = null;
+  }, false);
   return this;
 };
 SVGTextContentElement.constructor = SVGElement;
@@ -2628,7 +2711,7 @@
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACING           = 1;
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS  = 2;
 /*long*/     SVGTextContentElement.prototype.getNumberOfChars = function() {
-  return (this._tar.innerText.length);
+  return (this._tar.length);
 };
 /*float*/    SVGTextContentElement.prototype.getComputedTextLength = function() {
   this.getSubStringLength(0, this.getNumberOfChars());
@@ -2799,12 +2882,9 @@
   /*readonly SVGAnimatedLengthList*/ this.dy = new SVGAnimatedLengthList();
   /*readonly SVGAnimatedNumberList*/ this.rotate = new SVGAnimatedNumberList();
   this.addEventListener("DOMAttrModified", function(evt){
-    var tar = evt.target;
-    if (evt.eventPhase === Event.BUBBLING_PHASE) {
-      return; //強制終了させる
-    }
-    tar.x.baseVal.appendItem(tar.ownerDocument.documentElement.createSVGLength());
-    tar.y.baseVal.appendItem(tar.ownerDocument.documentElement.createSVGLength());
+    var tar = evt.target, name = evt.attrName;
+    if ((name === "x") || (name === "y") || (name === "dx") || (name === "dy")) {
+     }
   }, false);
   return this;
 };
@@ -2815,52 +2895,12 @@
   SVGTextPositioningElement.apply(this, arguments);
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      if (evt.target.nodeType === Node.TEXT_NODE) {
+      }
       return; //強制終了させる
     }
     var tar = evt.target;
-    tar.parentNode._tar.appendChild(tar._tar);
-    tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) {
-      var tar = evt.target, ti = tar.firstChild;
-      var x = y = n = 0; //現在のテキスト位置と順番
-      var tx = tar.x.baseVal, ty = tar.y.baseVal;
-      while (ti) {
-        if (ti.nodeType === Node.TEXT_NODE) {
-          var tt = ti._tar;
-          for (var i=0, tli=tt.length;i<tli;++i) {
-            if (n < tx.numberOfItems) {
-              x = tx.getItem(n).value;
-            }
-            if (n < ty.numberOfItems) {
-              y = ty.getItem(n).value;
-            }
-            var ts = tt[i].style;
-            ts.left = x+"px";
-            ts.top = y+"px";
-            ++n;
-          }
-        } else if (ti.localName === "tspan" && ti.namespaceURI === "http://www.w3.org/2000/svg"){
-          var tt = ti._tar, ttx = tt.x.baseVal, tty = tt.y.baseVal;
-          for (var i=0, tli=tt.length;i<tli;++i) {
-            if (n < ttx.numberOfItems) {
-              x = ttx.getItem(n).value;
-            } else if (n < tx.numberOfItems) {
-              x = tx.getItem(n).value;
-            }
-            if (n < tty.numberOfItems) {
-              y = ttx.getItem(n).value;
-            } else if (n < ty.numberOfItems) {
-              y = ty.getItem(n).value;
-            }
-            var ts = tt[i].style;
-            ts.left = x+"px";
-            ts.top = y+"px";
-            ++n;
-          }
-        }
-      }
-    }, false);
-    evt = tar = null;
-  }, false);
+  },false);
   return this;
 };
 SVGTextElement.constructor = SVGTextPositioningElement;




Sie-announce メーリングリストの案内
Zurück zum Archiv-Index