svnno****@sourc*****
svnno****@sourc*****
2009年 9月 30日 (水) 21:45:12 JST
Revision: 1303
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1303
Author: dhrname
Date: 2009-09-30 21:45:12 +0900 (Wed, 30 Sep 2009)
Log Message:
-----------
SVGPathElementオブジェクトの実装
Modified Paths:
--------------
branches/DOM/org/w3c/dom/svg.js
Modified: branches/DOM/org/w3c/dom/svg.js
===================================================================
--- branches/DOM/org/w3c/dom/svg.js 2009-09-30 12:23:23 UTC (rev 1302)
+++ branches/DOM/org/w3c/dom/svg.js 2009-09-30 12:45:12 UTC (rev 1303)
@@ -375,120 +375,6 @@
}
//path要素の処理
-function STPath( /*element*/ ele) {
- SVGElement.call(this, arguments);
- this.tar = ele;
- this.d = ele.getAttribute("d");
- this.paint = new NAIBU.PaintColor(ele);
- this.transformable = new TransformList(ele);
- return this;
-}
-STPath.prototype.set = function shapeset( /*float*/ w, /*float*/ h, /*Matrix*/ matrix) {
- var dat;
- var minx = 0, miny = 0;
- try {
- var dd = this.d
- .replace(/\s*([A-DF-Z])/gi, '],["$1" ') //convert to JSON array
- .replace(/^\],/, "[")
- .replace(/\s*$/, "]]")
- .replace(/[\s,]{2,}|\s/g, ",")
- .replace(/([\d.])-/g, "$1,-");
- var D = eval('('+dd+')'); //ここまでd属性のパーサ
- var ttm = matrix.multiply(this.transformable.tr.matrix);
- var G = new Array();
- var preCom;
- var x = 0, y = 0; //現在の点の絶対座標
- var x0 = 0, y0 = 0; //subpath の始点の絶対座標
- var dx = 0, dy = 0;
- for (var i = 0, Dli = D.length; i < Dli; i++) {
- var F = D[i];
- var com = F[0].toLowerCase(); //F[0]の値はコマンド文字
- var rel = (com == F[0]); //相対座標のコマンドならtrue
- if (com == "z") {
- F = ["x"];
- x = x0; y = y0;
- } else if (com == "a") { //ArcTo
- F[0] = "c";
- preCom = com;
- var relx = 0, rely = 0;
- if (rel) {
- relx = x; rely = y;
- }
- var ar = new STArc();
- ar.sset(x, y, F, relx, rely);
- x = F[F.length-2] + relx;
- y = F[F.length-1] + rely;
- var pl = new PList(ar.D);
- var plm = pl.matrixTransform(ttm);
- F = ["c"].concat(plm.list);
- if (F.length == 8) {
- F[7] = "";
- }
- } else {
- var rx = x, ry = y;
- if (rel) {
- rx = ry = 0;
- }
- switch (com) {
- case "h": F = ["l", F[F.length-1], ry];
- break;
- case "v": F = ["l", rx, F[F.length-1]];
- break;
- case "s": F[0] = "c"; if (preCom != "c") {dx = dy = 0;} F = NAIBU.nst(6, F, rx + dx, ry + dy);
- break;
- case "t": F[0] = "q"; if (preCom != "q") {dx = dy = 0;} F = NAIBU.nst(4, F, rx + dx, ry + dy);
- break;
- default: F[0] = com; //"M", "L", "C", "Q" は小文字に変換
- }
- if (rel) {
- F = NAIBU.reltoabs(x, y, F); //絶対座標に変換
- }
- preCom = com = F[0];
- if (com == "c" || com == "q") {
- dx = F[F.length-2] - F[F.length-4];
- dy = F[F.length-1] - F[F.length-3];
- }
- if (com == "q") {
- F = NAIBU.qtoc(x, y, F); //二次ベジェは三次ベジェに変換
- }
- if (com == "m") {
- x0 = F[1]; y0 = F[2]; //subpath の始点を記憶
- }
- var Fli = F.length;
- x = F[Fli-2];
- y = F[Fli-1];
- for (var j = 1; j < Fli; j += 2) { //CTMで座標変換
- var p = new Point(F[j], F[j+1]);
- var pmt = p.matrixTransform(ttm);
- F[j] = pmt.x;
- F[j+1] = pmt.y;
- minx = Math.min(minx, F[j]); //負の値があれば、minx,yに入れる
- miny = Math.min(miny, F[j+1]);
- }
- if (com == "m" && Fli > 3) { //MoveToが複数の座標ならば、2番目以降の座標ペアをLineToとして処理
- F.splice(3, 0, "l");
- }
- }
- D[i] = F;
- G[i] = F.join(" ");
- F = null;
- }
- if (minx != 0 || miny != 0) {
- G = D._minm(minx, miny);
- }
- dat = G.join(" ");
- } catch(e) {if(this.d == ""){/*d属性が空*/}else{stlog.add(e,355);}}
- try {
- var ele = this.tar;
- ele.setAttribute("path", dat + " e");
- ele.setAttribute("coordsize", w + " " + h);
- this.paint.set(ele, w, h, ttm);
- if (minx != 0 || miny != 0) {
- ele.style.posLeft = minx;
- ele.style.posTop = miny;
- }
- } catch(e) {stlog.add(e,372);}
-}
//QからCに変換
NAIBU.qtoc = function (/*float*/ x, /*float*/ y, /*Array*/ F) {
@@ -1068,11 +954,6 @@
return matri;
}
-//SVGPreserveAspectRatioを参照
-function STPreserveAspectRatio( /*int*/ a, /*int*/ mos) {this.align=a;this.meetOrSlice=mos;
- return this;
-}
-
//path要素のd属性で使われるA(rcTo)コマンドを処理
function STArc() {
return this;
@@ -1388,7 +1269,9 @@
} else {
return null;
}
-}
+};
+SVGElement.prototype.read = function(){};
+SVGElement.prototype.set = function(){};
/*interface SVGLocatable*/
/*SVGRect*/ SVGElement.prototype.getBBox = function(){
var s = new SVGRect();
@@ -2167,6 +2050,7 @@
function SVGDefsElement() {
SVGElement.apply(this, arguments);
+ this.style.display = "none";
return this;
};
SVGDefsElement.constructor = SVGElement;
@@ -2741,6 +2625,7 @@
return this;
};
+
function SVGPathElement() {
SVGElement.apply(this, arguments);
//interface SVGAnimatedPathData
@@ -2751,6 +2636,108 @@
};
SVGPathElement.constructor = SVGElement;
SVGPathElement.prototype = new SVGElement();
+SVGPathElement.prototype.read = function(){
+ this.d = this.getNamedItemNS(null, "d").nodeValue;
+};
+SVGPathElement.prototype.set = function( /*float*/ w, /*float*/ h) {
+ var dat = "";
+ try {
+ var dd = this.d
+ .replace(/\s*([A-DF-Z])/gi, '],["$1" ') //convert to JSON array
+ .replace(/^\],/, "[")
+ .replace(/\s*$/, "]]")
+ .replace(/[\s,]{2,}|\s/g, ",")
+ .replace(/([\d.])-/g, "$1,-");
+ var D = eval('('+dd+')'); //ここまでd属性のパーサ
+ var ttm = this.transformable;
+ var preCom;
+ var x = 0, y = 0; //現在の点の絶対座標
+ var x0 = 0, y0 = 0; //subpath の始点の絶対座標
+ var dx = 0, dy = 0;
+ var tma = ttm.a, tmb = ttm.b, tmc = ttm.c, tmd = ttm.d, tme = ttm.e, tmf = ttm.f;
+ for (var i = 0, Dli = D.length; i < Dli; ++i) {
+ var F = D[i];
+ var com = F[0].toLowerCase(); //F[0]の値はコマンド文字
+ var rel = (com === F[0]); //相対座標のコマンドならtrue
+ if (com === "z") {
+ F = ["x"];
+ x = x0; y = y0;
+ } else if (com === "a") { //ArcTo
+ F[0] = "c";
+ preCom = com;
+ var relx = 0, rely = 0;
+ if (rel) {
+ relx = x; rely = y;
+ }
+ var ar = new STArc();
+ ar.sset(x, y, F, relx, rely);
+ x = F[F.length-2] + relx;
+ y = F[F.length-1] + rely;
+ var pl = new PList(ar.D);
+ var plm = pl.matrixTransform(ttm);
+ F = ["c"].concat(plm.list);
+ if (F.length === 8) {
+ F[7] = "";
+ }
+ } else {
+ var rx = x, ry = y;
+ if (rel) {
+ rx = ry = 0;
+ }
+ switch (com) { //ここはif文ではなくて、switch文で処理する必要がある。
+ case "h": F = ["l", F[F.length-1], ry];
+ break;
+ case "v": F = ["l", rx, F[F.length-1]];
+ break;
+ case "s": F[0] = "c"; if (preCom !== "c") {dx = dy = 0;} F = NAIBU.nst(6, F, rx + dx, ry + dy);
+ break;
+ case "t": F[0] = "q"; if (preCom !== "q") {dx = dy = 0;} F = NAIBU.nst(4, F, rx + dx, ry + dy);
+ break;
+ default: F[0] = com; //"M", "L", "C", "Q" は小文字に変換
+ }
+ if (rel) {
+ F = NAIBU.reltoabs(x, y, F); //絶対座標に変換
+ }
+ preCom = com = F[0];
+ if (com === "c" || com === "q") {
+ var Fli = F.length;
+ dx = F[Fli-2] - F[Fli-4];
+ dy = F[Fli-1] - F[Fli-3];
+ }
+ if (com === "q") {
+ F = NAIBU.qtoc(x, y, F); //二次ベジェは三次ベジェに変換
+ }
+ if (com === "m") {
+ x0 = F[1]; y0 = F[2]; //subpath の始点を記憶
+ }
+ var Fli = F.length;
+ x = F[Fli-2];
+ y = F[Fli-1];
+ var _x, _y; //この変数は初期化されないために必要
+ for (var j = 1; j < Fli; j += 2) { //CTMで座標変換
+ _x = parseInt(tma * F[j] + tmc * F[j+1] + tme, 10);
+ _y = parseInt(tmb * F[j] + tmd * F[j+1] + tmf, 10);
+ F[j] = _x;
+ F[j+1] = _y;
+ }
+ if (com === "m" && Fli > 3) { //MoveToが複数の座標ならば、2番目以降の座標ペアをLineToとして処理
+ F.splice(3, 0, "l");
+ }
+ }
+ dat += F.join(" ");
+ F = null;
+ }
+ D = dd = Fli = null; //解放
+ } catch(e) {if(this.d == ""){/*d属性が空*/}else{stlog.add(e,355);}}
+ try {
+ var ele = this.tar;
+ ele.path = dat + " e";
+ ele.coordsize = w + " " + h;
+ this.paint.set(w, h, this.transformable);
+ ttm = this.transformable = this.paint = this.d = preCom = x = y = x0 = y0 = dx = dy = tma = tmb = tmc = tmd = tme = tmf = w = h = null;
+ } catch(e) {stlog.add(e,372);}
+
+};
with(SVGPathElement.prototype) {
/*float*/ getTotalLength = function() {
return (this.pathLength.baseVal.value);