svnno****@sourc*****
svnno****@sourc*****
2010年 5月 7日 (金) 22:25:02 JST
Revision: 1814 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1814 Author: dhrname Date: 2010-05-07 22:25:00 +0900 (Fri, 07 May 2010) Log Message: ----------- 日本語やアルファベットの調整 Modified Paths: -------------- branches/ufltima/dom/svg.js Modified: branches/ufltima/dom/svg.js =================================================================== --- branches/ufltima/dom/svg.js 2010-05-04 13:33:14 UTC (rev 1813) +++ branches/ufltima/dom/svg.js 2010-05-07 13:25:00 UTC (rev 1814) @@ -2622,7 +2622,6 @@ function SVGTextContentElement() { SVGElement.apply(this, arguments); - this._list = []; //文字の位置を格納しておくリスト /*readonly SVGAnimatedLength*/ this.textLength = new SVGAnimatedLength(); /*readonly SVGAnimatedEnumeration*/ this.lengthAdjust = new SVGAnimatedEnumeration(SVGTextContentElement.LENGTHADJUST_UNKNOWN); this.addEventListener("DOMNodeInserted", function(evt){ @@ -2652,6 +2651,7 @@ var tar = evt.target; tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt) { var tar = evt.target, ti = tar.firstChild, tp = tar.parentNode; + tar._list = []; //文字の位置を格納しておくリスト var x = y = n = 0; //現在のテキスト位置と順番 var style = tar.ownerDocument.defaultView.getComputedStyle(tar, null); var isYokogaki = ((style.getPropertyValue("writing-mode")) === "lr-tb") ? true : false; @@ -2663,8 +2663,12 @@ } else { var ptx = pty = ptdx = ptdy = {numberOfItems : 0}; } - var kern = "fijlt.,IJ:;1'-", akern = "a bcdeghknopqsuvxyz"; -; + var kern = "fijlt.,I:;1'-", akern = "a bcdeghknopqsuvxyz"; + if (isYokogaki) { + y += fontSize * 0.25; + } else { + x += fontSize * 0.5; + } while (ti) { if (ti.nodeType === Node.TEXT_NODE) { var tt = ti._tar; @@ -2691,18 +2695,27 @@ } var alm = 0; if (isYokogaki) { + //カーニングを求めて、字の幅を文字ごとに調整する var tdc = ti.data.charAt(i); - if (kern.indexOf(tdc) > -1) { //カーニングを求める - alm = fontSize * 0.75; + if (kern.indexOf(tdc) > -1) { + alm = fontSize * 0.7; } else if ((tdc === "r") || (tdc === "s")){ alm = fontSize * 0.65; - } else if ((tdc === "m") || (tdc === "w")){ - alm = fontSize * 0.3; + } else if ((tdc === "C") || (tdc === "D") || (tdc === "M") || (tdc === "W") || (tdc === "G")){ + alm = fontSize * 0.2; } else if (akern.indexOf(tdc) > -1){ alm = fontSize * 0.55; } else { - alm = fontSize * 0.17; + alm = fontSize * 0.35; } + var tcca = tdc.charCodeAt(0); + if ((12288 <= tcca) && (tcca <= 65533)) { + alm = -fontSize * 0.01; + if ((tdc === "う") || (tdc === "く") || (tdc === "し") || (tdc === "ち")) { + alm += fontSize * 0.2; + } + } + tcca = null; } tar._list[tar._list.length] = x; tar._list[tar._list.length] = y; @@ -2873,8 +2886,8 @@ var p = tar.getStartPositionOfChar(i-j); if (!!ti._tar) { var style = ti._tar[i].style; - style.left = p.x; - style.top = p.y; + style.left = parseInt(p.x, 10); + style.top = parseInt(p.y, 10); style.width = "0px"; style.height = "0px"; tar._tar.appendChild(ti._tar[i]);