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

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 4月 14日 (水) 23:17:44 JST


Revision: 1793
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1793
Author:   dhrname
Date:     2010-04-14 23:17:44 +0900 (Wed, 14 Apr 2010)

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


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

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-04-13 12:22:15 UTC (rev 1792)
+++ branches/ufltima/dom/svg.js	2010-04-14 14:17:44 UTC (rev 1793)
@@ -499,7 +499,18 @@
   /*readonly SVGLength*/ this.animVal = this.baseVal = new SVGLength();
   return this;
 };
-
+function SVGLengthList() {
+  /*readonly unsigned long*/ this.numberOfItems = 0;
+  this._list = []; //リストの本体
+  return this;
+};
+for (var prop in SVGStringList.prototype) { //prototypeのコピーで継承を行う
+  SVGLengthList.prototype[prop] = SVGStringList.prototype[prop];
+}
+function SVGAnimatedLengthList() {
+  /*readonly SVGNumberList*/ this.animVal = this.baseVal = new SVGLengthList();
+  return this;
+};
 function SVGColor() {
   CSSValue.call(this, arguments);
   /*readonly unsigned short*/ this.colorType = SVGColor.SVG_COLORTYPE_UNKNOWN;
@@ -2616,7 +2627,32 @@
   return (this._tar.innerText.length);
 };
 /*float*/    SVGTextContentElement.prototype.getComputedTextLength = function() {
-  
+  var s = 0, t = this.firstChild, f = /[fijlt.,:;1]/g;
+  //以下のメソッドに関しては、css.js(org.w3c.dom.css)をご覧下さい
+  var style = this.ownerDocument.defaultView.getComputedStyle(this, null);
+  var isYokogaki = (style.getPropertyValue("writing-mode")) === "lr-tb" true : false;
+  var fontSize = parseFloat(style.getPropertyValue("font-size"));
+  /*以下はCTM処理後の、fontの実際の大きさを算出するための処理。
+   *つまり、CTMの行列式の2乗を掛け合わせることにより、CTMを組み入れる
+   */
+  fontSize = fontSize * Math.sqrt(Math.abs(this.getScreenCTM().determinant()));
+  while (t) {
+    if (t.nodeName === "#text") {
+      var kerning = t.data.match(f).length; //カーニングの対象となる文字の数(SVGFontのときはhkernとvkern要素を考慮する)
+      var n = t.length;
+      n = n * fontSize - kerning;
+      s += n;
+    } else if (t.localName === "tspan") {
+      s += t.getComputedTextLength();
+      //dx(縦書きのときはdy)属性のずらしを考慮に入れて、長さを計算する
+      var td = isYokogaki ? t.dx.baseVal : t.dy.baseVal;
+      for (var i=0;i<td.numberOfItems;++i) {
+        s += td.getItem(i);
+      }
+    }
+    t = t.nextSibling;
+  }
+  return s;
 };
 /*float*/    SVGTextContentElement.prototype.getSubStringLength = function(/*unsigned long*/ charnum, /*unsigned long*/ nchars ) {
   
@@ -2625,9 +2661,6 @@
   if (charnum > this.getNumberOfChars() || charnum < 0) {
     return (new DOMException(DOMException.INDEX_SIZE_ERR));
   } else {
-    //以下のメソッドに関しては、css.js(org.w3c.dom.css)をご覧下さい
-    var fontSize = this.style.getPropertyCSSValue("font-size").getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
-    fontSize = fontSize * Math.sqrt(Math.abs(this.getCTM().determinant()));
   }
 };
 /*SVGPoint*/ SVGTextContentElement.prototype.getEndPositionOfChar = function(/*unsigned long*/ charnum ) {
@@ -2658,11 +2691,13 @@
 
 function SVGTextPositioningElement() { 
   SVGTextContentElement.apply(this, arguments);
-  /*readonly SVGAnimatedLengthList*/ this.x;
-  /*readonly SVGAnimatedLengthList*/ this.y;
-  /*readonly SVGAnimatedLengthList*/ this.dx;
-  /*readonly SVGAnimatedLengthList*/ this.dy;
-  /*readonly SVGAnimatedNumberList*/ this.rotate;
+  /*readonly SVGAnimatedLengthList*/ this.x = new SVGAnimatedLengthList();
+  /*readonly SVGAnimatedLengthList*/ this.y = new SVGAnimatedLengthList();
+  /*readonly SVGAnimatedLengthList*/ this.dx = new SVGAnimatedLengthList();
+  /*readonly SVGAnimatedLengthList*/ this.dy = new SVGAnimatedLengthList();
+  /*readonly SVGAnimatedNumberList*/ this.rotate = new SVGAnimatedNumberList();
+  this.x.baseVal.appendItem(this.ownerDocument.createSVGLength());
+  this.y.baseVal.appendItem(this.ownerDocument.createSVGLength());
   return this;
 };
 SVGTextPositioningElement.constructor = SVGTextContentElement;




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