svnno****@sourc*****
svnno****@sourc*****
2010年 9月 27日 (月) 22:29:53 JST
Revision: 2024
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2024
Author: dhrname
Date: 2010-09-27 22:29:53 +0900 (Mon, 27 Sep 2010)
Log Message:
-----------
text-anchorプロパティを実装
Modified Paths:
--------------
branches/06x/061/org/w3c/dom/svg.js
Modified: branches/06x/061/org/w3c/dom/svg.js
===================================================================
--- branches/06x/061/org/w3c/dom/svg.js 2010-09-27 12:29:36 UTC (rev 2023)
+++ branches/06x/061/org/w3c/dom/svg.js 2010-09-27 13:29:53 UTC (rev 2024)
@@ -3249,6 +3249,7 @@
SVGElement.apply(this);
/*readonly SVGAnimatedLength*/ this.textLength = new SVGAnimatedLength();
/*readonly SVGAnimatedEnumeration*/ this.lengthAdjust = new SVGAnimatedEnumeration(SVGTextContentElement.LENGTHADJUST_UNKNOWN);
+ this._isYokogaki = true;
this.addEventListener("DOMNodeInserted", function(evt){
var tar = evt.target;
if ((evt.eventPhase === Event.CAPTURING_PHASE) && (tar.nodeType === Node.TEXT_NODE) && !!!tar._tar) {
@@ -3400,12 +3401,24 @@
return (this._list.length/3);
};
/*float*/ SVGTextContentElement.prototype.getComputedTextLength = function() {
- this.getSubStringLength(0, this.getNumberOfChars());
+ var l = this.textLength.baseVal;
+ if (l.unitType === SVGLength.SVG_LENGTHTYPE_UNKNOWN) {
+ l.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER, this.getSubStringLength(0, this.getNumberOfChars()));
+ }
+ l = null;
+ return (this.textLength.baseVal.value);
};
/*getSubStringLengthメソッド
*charnum番目の文字からnchars+charnum-1番目までの文字列の長さを求めて返す
*/
/*float*/ SVGTextContentElement.prototype.getSubStringLength = function(/*unsigned long*/ charnum, /*unsigned long*/ nchars ) {
+ var end = this.getEndPositionOfChar(nchars+charnum-1), st = this.getStartPositionOfChar(charnum);
+ if (this._isYokogaki) {
+ var s = end.x - st.x;
+ } else {
+ var s = end.y - st.y;
+ }
+ return s;
}
/*SVGPoint*/ SVGTextContentElement.prototype.getStartPositionOfChar = function (/*unsigned long*/ charnum ) {
if (charnum > this.getNumberOfChars() || charnum < 0) {
@@ -3549,12 +3562,26 @@
ttp.style.fontSize = n + "px";
ttp.style.fontFamily = style.getPropertyValue("font-family");
var tod = tar.ownerDocument.documentElement;
+ var tlen = tar.getComputedTextLength(), anchor = style.getPropertyValue("text-anchor");
for (var i=0, j=0, tli=tar.getNumberOfChars();i<tli;++i) {
if (ti) {
var p = tar.getStartPositionOfChar(i-j);
if (!!ti._tar) {
var sty = ti._tar[i].style;
sty.position = "absolute";
+ if (tar._isYokogaki) {
+ if (anchor === "middle") {
+ p.x -= tlen / 2;
+ } else if (anchor === "end") {
+ p.x -= tlen;
+ }
+ } else {
+ if (anchor === "middle") {
+ p.y -= tlen / 2;
+ } else if (anchor === "end") {
+ p.y -= tlen;
+ }
+ }
sty.left = p.x + "px";
sty.top = p.y + "px";
sty.width = "0px";
@@ -3574,6 +3601,7 @@
ti = ti.nextSibling;
}
}
+ p = null;
}
}
var color = style.getPropertyValue("fill");