svnno****@sourc*****
svnno****@sourc*****
2010年 6月 21日 (月) 23:21:30 JST
Revision: 1909 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1909 Author: dhrname Date: 2010-06-21 23:21:30 +0900 (Mon, 21 Jun 2010) Log Message: ----------- Zコマンドとmコマンドと、T,tコマンドについて修正を施した 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-06-20 14:38:30 UTC (rev 1908) +++ branches/06x/061/org/w3c/dom/svg.js 2010-06-21 14:21:30 UTC (rev 1909) @@ -2088,11 +2088,11 @@ *変換をする処理。相対座標を絶対座標に変換して、M、L、Cコマンドに正規化していく */ var cx = 0, cy = 0; //現在セグメントの終了点の絶対座標を示す (相対座標を絶対座標に変換するときに使用) + var xn = 0, yn = 0; //T,tコマンドで仮想的な座標を算出するのに用いる + var startx = 0, starty = 0; //M,mコマンドにおける始点座標(Z,zコマンドで用いる) for (var j=0, tli=tlist.numberOfItems;j<tli;++j) { var ti = tlist.getItem(j), ts = ti.pathSegType, dii = ti.pathSegTypeAsLetter; if (ts === SVGPathSeg.PATHSEG_UNKNOWN) { - } else if (ts === SVGPathSeg.PATHSEG_CLOSEPATH) { - tnl.appendItem(ti); } else { var rx = cx, ry = cy; //rx, ryは前のセグメントの終了点 if (ts % 2 === 1) { //相対座標ならば @@ -2114,6 +2114,8 @@ continue; } } + startx = cx; + starty = cy; tnl.appendItem(ti); } else if (dii === "m") { if (j !== 0) { @@ -2123,6 +2125,8 @@ continue; } } + startx = cx; + starty = cy; tnl.appendItem(tar.createSVGPathSegMovetoAbs(cx, cy)); } else if (dii === "L") { tnl.appendItem(ti); @@ -2132,16 +2136,19 @@ tnl.appendItem(ti); } else if (dii === "c") { tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, ti.x1+rx, ti.y1+ry, ti.x2+rx, ti.y2+ry)); - } else if (dii === "Z" || dii === "z") { - var tg = tlist.getItem(j+1); - if (tg.pathSegTypeAsLetter !== "M" && tg.pathSegTypeAsLetter !== "m") { - cx = cy = 0; - } + } else if (dii === "z") { + cx = startx; + cy = starty; + tnl.appendItem(ti); } else if (dii === "Q") { + xn = 2*cx - ti.x1; + yn = 2*cy - ti.y1; //2次スプライン曲線は近似的な3次ベジェ曲線に変換している tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*ti.x1) / 3, (ry + 2*ti.y1) / 3, (2*ti.x1 + cx) / 3, (2*ti.y1 + cy) / 3)); } else if (dii === "q") { var x1 = ti.x1 + rx, y1 = ti.y1 + ry; + xn = 2*cx - x1; + yn = 2*cy - y1; tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*x1) / 3, (ry + 2*y1) / 3, (2*x1 + cx) / 3, (2*y1 + cy) / 3)); x1 = y1 = null; } else if (dii === "A" || dii === "a") { @@ -2227,9 +2234,7 @@ if (j !== 0) { var tg = tlist.getItem(j-1); if (tg.pathSegTypeAsLetter === "Q" || tg.pathSegTypeAsLetter === "q") { - var x1 = 2*tg.x - tg.x1; - var y1 = 2*tg.y - tg.y1; - tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*x1) / 3, (ry + 2*y1) / 3, (2*x1 + cx) / 3, (2*y1 + cy) / 3)); + tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*xn) / 3, (ry + 2*yn) / 3, (2*xn + cx) / 3, (2*yn + cy) / 3)); } } } else if (dii === "H" || dii === "h") { @@ -2238,7 +2243,9 @@ tnl.appendItem(tar.createSVGPathSegLinetoAbs(rx, cy)); } } + ti = dii = ts = null; } + cx = cy = xn = yn = startx = starty = null; } evt = null; }, false);