[Sie-announce] SIEコード [1806]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 4月 28日 (水) 23:47:31 JST


Revision: 1806
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1806
Author:   dhrname
Date:     2010-04-28 23:47:31 +0900 (Wed, 28 Apr 2010)

Log Message:
-----------


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

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-04-27 14:46:35 UTC (rev 1805)
+++ branches/ufltima/dom/svg.js	2010-04-28 14:47:31 UTC (rev 1806)
@@ -1179,7 +1179,7 @@
     var obje = document.getElementsByTagName("object");
     for (var i=0, objli=1;i<objli;++i) {
       var objei = {style:{}};//obje[i];
-      xmlhttp.open("GET", "../svggen/shapes-rect-01-t.svg", true);//objei.getAttribute("data"), true);
+      xmlhttp.open("GET", "../svggen/text-text-01-b.svg", true);//objei.getAttribute("data"), true);
       xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
       xmlhttp.onreadystatechange = function() {
         if (xmlhttp.readyState === 4  &&  xmlhttp.status === 200) {
@@ -2622,21 +2622,86 @@
   /*readonly SVGAnimatedEnumeration*/ this.lengthAdjust = new SVGAnimatedEnumeration(SVGTextContentElement.LENGTHADJUST_UNKNOWN);
   this.addEventListener("DOMNodeInserted", function(evt){
     var tar = evt.target;
-    if (evt.eventPhase === Event.BUBBLING_PHASE) {
-      if (tar.nodeType === Node.TEXT_NODE) {
+    if ((evt.eventPhase === Event.CAPTURING_PHASE) && (tar.nodeType === Node.TEXT_NODE) && !!!tar._tar) {
         //Textノードにdiv要素を格納したリストをプロパティとして蓄えておく
         tar._tar = [];
         for (var i=0, tdli=tar.data.length;i<tdli;++i) {
           var d = document.createElement("div");
+          d.style.position = "absolute";
           d.appendChild(document.createTextNode(tar.data.charAt(i)));
           tar._tar[tar._tar.length] = d;
         }
-      }
-      return;
     }
     evt = tar = null;
-  }, false);
-  return this;
+  }, true);
+  this.addEventListener("DOMNodeInserted", function(evt){
+    if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      return; //強制終了させる
+    }
+    var tar = evt.target;
+    tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) {
+      var tar = evt.target, ti = tar.firstChild, tp = tar.parentNode;
+      var x = y = n = 0; //現在のテキスト位置と順番
+      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;
+      //親要素の属性も参照しておく
+      if ((tp.localName === "text") || (tp.localName === "tspan")) {
+        var ptx = tp.x.baseVal, pty = tp.y.baseVal, ptdx = tp.dx.baseVal, ptdy = tp.dy.baseVal;
+      } else {
+        var ptx = pty = ptdx = ptdy = {numberOfItems : 0};
+      }
+      var kern = "fijlt.,:;1";
+      while (ti) {
+        if (ti.nodeType === Node.TEXT_NODE) {
+          var tt = ti._tar;
+          for (var i=0, tli=tt.length;i<tli;++i) {
+            if (n < ptx.numberOfItems) {
+              x = ptx.getItem(n).value;
+            } else if (n < tx.numberOfItems) {
+              x = tx.getItem(n).value;
+            }
+            if (n < pty.numberOfItems) {
+              y = ptx.getItem(n).value;
+            } else if (n < ty.numberOfItems) {
+              y = ty.getItem(n).value;
+            }
+            if (n < ptdx.numberOfItems) {
+              x += ptdx.getItem(n).value;
+            } else if (n < tdx.numberOfItems) {
+              x += tdx.getItem(n).value;
+            }
+            if (n < ptdy.numberOfItems) {
+              y += ptdy.getItem(n).value;
+            } else if (n < tdy.numberOfItems) {
+              y += tdy.getItem(n).value;
+            }
+            var alm = 0;
+            if (isYokogaki) {
+              if (kern.indexOf(ti.data.charAt(i))) { //カーニングを求める
+                alm = fontSize/2;
+              }
+              x += fontSize;
+              x -= alm;
+            } else {
+              y += fontSize;
+            }
+            this._list[this._list.length] = x;
+            this._list[this._list.length] = y;
+            this._list[this._list.length] = fontSize - alm;
+            ++n;
+          }
+        } else if ((ti.localName === "tspan") && (ti.namespaceURI === "http://www.w3.org/2000/svg") && ti.firtChild) {
+          this._list.concat(ti._list);
+          n += ti.getNumberOfChars();
+        }
+        ti = ti.nextSibling;
+      }
+      this._isYokogaki = isYokogaki //getEndPositionOfCharメソッドで使う
+    }, false);
+  },false);
+ return this;
 };
 SVGTextContentElement.constructor = SVGElement;
 SVGTextContentElement.prototype = new SVGElement();
@@ -2645,15 +2710,7 @@
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACING           = 1;
   /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS  = 2;
 /*long*/     SVGTextContentElement.prototype.getNumberOfChars = function() {
-  var s = 0;
-  while (ti) {
-    if (ti.nodeType === Node.TEXT_NODE) {
-      s += ti._tar.length;
-    } else if ((ti.localName === "tspan") && (ti.namespaceURI === "http://www.w3.org/2000/svg") && ti.firtChild){
-      s += ti.firstChild._tar.length;
-    }
-  }
-  return s;
+  return (this._list.length/2);
 };
 /*float*/    SVGTextContentElement.prototype.getComputedTextLength = function() {
   this.getSubStringLength(0, this.getNumberOfChars());
@@ -2667,7 +2724,10 @@
   if (charnum > this.getNumberOfChars() || charnum < 0) {
     throw (new DOMException(DOMException.INDEX_SIZE_ERR));
   } else {
-    var s = this.ownerDocument.createSVGPoint(), t = this.firstChild;
+    var s = this.ownerDocument.createSVGPoint();
+    s.x = this._list[charnum*3];
+    s.y = this._list[charnum*3 + 1];
+    s.matrixTransform(this.getScreenCTM());
     return s;
   }
 };
@@ -2675,8 +2735,14 @@
   if (charnum > this.getNumberOfChars() || charnum < 0) {
     throw (new DOMException(DOMException.INDEX_SIZE_ERR));
   } else {
-    var s = this.ownerDocument.createSVGPoint(), t = this.firstChild;
-   return s;
+    var s = this.getStartPositionOfChar(charnum);
+    var n = this._list[charnum*3 + 2];
+    if (this._isYokogaki) {
+      s.x += n;
+    } else {
+      s.y += n;
+    }
+    return s;
   }
 };
 /*SVGRect*/  SVGTextContentElement.prototype.getExtentOfChar = function(/*unsigned long*/ charnum ) {
@@ -2711,80 +2777,54 @@
 
 function SVGTextElement() {
   SVGTextPositioningElement.apply(this, arguments);
+  this._tar = document.createElement("v:group");
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
     }
     var tar = evt.target;
+    var ttp = tar._tar;
+    if (ttp) {
+      if (ttp.lastChild) {
+        if (ttp.lastChild.nodeName !== "rect") {
+          var backr = document.createElement("v:rect");
+          var backrs = backr.style; //ずれを修正するためのもの
+          backrs.width = "1px";
+          backrs.height = "1px";
+          backrs.left = "0px";
+          backrs.top = "0px";
+          backr.stroked = "false";
+          backr.filled = "false";
+          ttp.appendChild(backr);
+        }
+      }
+      tar.parentNode._tar.appendChild(ttp);
+    }
     tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) {
       var tar = evt.target, ti = tar.firstChild;
-      var x = y = n = 0; //現在のテキスト位置と順番
-      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;
+      for (var i=0, j=0, tli=tar.getNumberOfChars();i<tli;++i) {
+        if (ti) {
+          var p = tar.getStartPositionOfChar(i-j);
+          if (!!ti._tar) {
+            var style = ti._tar[i].style;
+            style.left = p.x;
+            style.top = p.y;
+            style.width = "0px";
+            style.height = "0px";
+            tar._tar.appnedChild(ti._tar[i]);
           }
-        } else if ((ti.localName === "tspan") && (ti.namespaceURI === "http://www.w3.org/2000/svg") && ti.firtChild){
-          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.firstChild._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 (!!ti.data) {
+            if (ti.data.length <= i+1) {
+              j = j + i + 1;
+              ti = ti.nextSibling;
             }
-            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;
+          } else if (!!ti.getNumberOfChars) {
+              if (ti.getNumberOfChars() <= i+1) {
+                j = j + i + 1;
+                ti = ti.nextSibling;
+              }
           }
         }
-        ti = ti.nextSibling;
       }
     }, false);
   },false);




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