svnno****@sourc*****
svnno****@sourc*****
2010年 5月 18日 (火) 22:48:12 JST
Revision: 1829 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1829 Author: dhrname Date: 2010-05-18 22:48:12 +0900 (Tue, 18 May 2010) Log Message: ----------- text要素の位置調整 Modified Paths: -------------- branches/ufltima/dom/svg.js Modified: branches/ufltima/dom/svg.js =================================================================== --- branches/ufltima/dom/svg.js 2010-05-18 12:26:09 UTC (rev 1828) +++ branches/ufltima/dom/svg.js 2010-05-18 13:48:12 UTC (rev 1829) @@ -1131,6 +1131,7 @@ } } } + //text要素の位置調整に使うため、ここで、viewの移動量を記録しておく this._tx = tx; this._ty = ty; var m = this.createSVGMatrix(); @@ -2796,7 +2797,7 @@ tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) { var tar = evt.target, ti = tar.firstChild, tp = tar.parentNode; tar._list = []; //文字の位置を格納しておくリスト - var x = y = n = 0; //現在のテキスト位置と順番 + var x = 0, y = 0, 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")); @@ -2878,8 +2879,8 @@ } ti = ti.nextSibling; } - this._isYokogaki = isYokogaki //getEndPositionOfCharメソッドで使う - }, false); + tar._isYokogaki = isYokogaki //getEndPositionOfCharメソッドなどで使う + }, true); },false); return this; }; @@ -3005,19 +3006,25 @@ var tar = evt.target; var ttp = tar._tar; if (ttp) { + var isRect = true; 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); + isRect = false; } + } else { + isRect = false; } + if (!isRect) { + 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) { @@ -3025,16 +3032,21 @@ var style = tar.ownerDocument.defaultView.getComputedStyle(tar, null); var n = parseFloat(style.getPropertyValue("font-size")) * Math.sqrt(Math.abs(tar.getScreenCTM()._determinant())); tar._tar.style.fontSize = n + "px"; + var tod = tar.ownerDocument.documentElement; + var tx = tod._tx, ty = tod._ty; 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 = parseInt(p.x, 10); - style.top = parseInt(p.y, 10); + style.left = parseInt(p.x, 10) - tx + "px"; + style.top = parseInt(p.y, 10) - ty + "px"; style.width = "0px"; style.height = "0px"; - tar._tar.appendChild(ti._tar[i]); + style.marginTop = tar._isYokogaki ? -n+ "px" : "0px"; + style.textIndent = "0px"; + style.lineHeight = n+ "px"; + tar._tar.insertBefore(ti._tar[i], tar._tar.firstChild); } if (!!ti.data) { if (ti.data.length <= i+1) {