svnno****@sourc*****
svnno****@sourc*****
2010年 4月 30日 (金) 23:33:45 JST
Revision: 1810 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1810 Author: dhrname Date: 2010-04-30 23:33:45 +0900 (Fri, 30 Apr 2010) Log Message: ----------- text要素の実装 Modified Paths: -------------- branches/ufltima/dom/svg.js Modified: branches/ufltima/dom/svg.js =================================================================== --- branches/ufltima/dom/svg.js 2010-04-30 14:33:16 UTC (rev 1809) +++ branches/ufltima/dom/svg.js 2010-04-30 14:33:45 UTC (rev 1810) @@ -468,6 +468,7 @@ n = this._percent; _s = "%" } else if (unitType === SVGLength.SVG_LENGTHTYPE_EMS) { + n = this._percent * 100; _s = "em"; } else if (unitType === SVGLength.SVG_LENGTHTYPE_EXS) { _s = "ex"; @@ -2691,9 +2692,9 @@ } else { y += fontSize; } - this._list[this._list.length] = x; - this._list[this._list.length] = y; - this._list[this._list.length] = fontSize - alm; + tar._list[tar._list.length] = x; + tar._list[tar._list.length] = y; + tar._list[tar._list.length] = fontSize - alm; ++n; } } else if ((ti.localName === "tspan") && (ti.namespaceURI === "http://www.w3.org/2000/svg") && ti.firtChild) { @@ -2728,7 +2729,7 @@ if (charnum > this.getNumberOfChars() || charnum < 0) { throw (new DOMException(DOMException.INDEX_SIZE_ERR)); } else { - var s = this.ownerDocument.createSVGPoint(); + var s = this.ownerDocument.documentElement.createSVGPoint(); s.x = this._list[charnum*3]; s.y = this._list[charnum*3 + 1]; s.matrixTransform(this.getScreenCTM()); @@ -2740,7 +2741,8 @@ throw (new DOMException(DOMException.INDEX_SIZE_ERR)); } else { var s = this.getStartPositionOfChar(charnum); - var n = this._list[charnum*3 + 2]; + //アドバンス値(すなわちフォントの大きさ)をCTMの行列式を用いて、算出する + var n = this._list[charnum*3 + 2] * Math.sqrt(Math.abs(this.getScreenCTM().determinant())); if (this._isYokogaki) { s.x += n; } else { @@ -2770,8 +2772,47 @@ /*readonly SVGAnimatedLengthList*/ this.dy = new SVGAnimatedLengthList(); /*readonly SVGAnimatedNumberList*/ this.rotate = new SVGAnimatedNumberList(); this.addEventListener("DOMAttrModified", function(evt){ - var tar = evt.target, name = evt.attrName; + var tar = evt.target, name = evt.attrName, tod = tar.ownerDocument.documentElement; + var _parseFloat = parseFloat; if ((name === "x") || (name === "y") || (name === "dx") || (name === "dy")) { + var enr = evt.newValue.replace(/^\s+|\s+$/g, "").split(/[\s,]+/), teas = tar[name].baseVal; + for (var i=0, tli=enr.length;i<tli;++i) { + var tea = tod.createSVGLength(); + var n = enr[i].match(/\D+$/), type = 0; + if (!n) { + type = SVGLength.SVG_LENGTHTYPE_NUMBER; + } else if (n === "%") { + if ((name === "x") || (name === "dx")) { + tea._percent *= tod.viewport.width; + } else if ((name === "y") || (name === "dy")) { + tea._percent *= tod.viewport.height; + } + type = SVGLength.SVG_LENGTHTYPE_PERCENTAGE; + } else if (n === "em") { + var style = tar.ownerDocument.defaultView.getComputedStyle(tar, null); + tea._percent *= _parseFloat(style.getPropertyValue("font-size")); + style = null; + type = SVGLength.SVG_LENGTHTYPE_EMS; + } else if (n === "ex") { + type = SVGLength.SVG_LENGTHTYPE_EXS; + } else if (n === "px") { + type = SVGLength.SVG_LENGTHTYPE_PX; + } else if (n === "cm") { + type = SVGLength.SVG_LENGTHTYPE_CM; + } else if (n === "mm") { + type = SVGLength.SVG_LENGTHTYPE_MM; + } else if (n === "in") { + type = SVGLength.SVG_LENGTHTYPE_IN; + } else if (n === "pt") { + type = SVGLength.SVG_LENGTHTYPE_PT; + } else if (n === "pc") { + type = SVGLength.SVG_LENGTHTYPE_PC; + } + var s = _parseFloat(enr[i]); + s = isNaN(s) ? 0 : s; + tea.newValueSpecifiedUnits(type, s); + teas.appendItem(tea); + } } }, false); return this; @@ -2806,6 +2847,8 @@ } tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) { var tar = evt.target, ti = tar.firstChild; + var style = tar.ownerDocument.defaultView.getComputedStyle(tar, null); + tar._tar.style.fontSize = style.getPropertyValue("font-size") + "px"; for (var i=0, j=0, tli=tar.getNumberOfChars();i<tli;++i) { if (ti) { var p = tar.getStartPositionOfChar(i-j); @@ -2815,7 +2858,7 @@ style.top = p.y; style.width = "0px"; style.height = "0px"; - tar._tar.appnedChild(ti._tar[i]); + tar._tar.appendChild(ti._tar[i]); } if (!!ti.data) { if (ti.data.length <= i+1) {