From 2f766641b0317f2bd32be413c808cad7fdb42fcd Mon Sep 17 00:00:00 2001 From: dhrname Date: Mon, 18 Jul 2016 23:41:12 +0900 Subject: [PATCH] Support the rotate attribute --- org/w3c/dom/smil.js | 34 ++++++++++++++++++++++++++++++++-- tool/Spec/spec/SvgDomSpec.js | 20 +++++++++++--------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index d5b4260..50f8a75 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -1687,6 +1687,8 @@ base("$calcMode").up("$attribute").mix( { path: document.createElementNS("http://www.w3.org/2000/svg", "path"), + rotate: "0", + /*tocallメソッドのオーバライド*/ tocall: function(advance) { /*モーションは仕様の関係上、かならず、CTMの一番初めに置かれ、前置積となる @@ -1696,12 +1698,39 @@ base("$calcMode").up("$attribute").mix( { + this.joinList(this.defaultValue || "")).trim(); }, + /*図の現在の角度rを求めて、rotate(rの文字列(最後に括弧はいらない)で返すメソッド*/ + getRotate: function(path, advanceLength) { + /*パスセグメントの数値を求めてから、動いている図形の傾き角度r(ラジアンではなく度数)を算出する*/ + var length = path.getPathSegAtLength(advanceLength), + seg = path.pathSegList.getItem(length), + command = seg.pathSegTypeAsLetter; + if (command === "M") { + /*次のセグメントがどのコマンドによるかで、計算方式が違う*/ + var nextSeg = path.pathSegList.getItem(length+1), + nextCommand = nextSeg.pathSegTypeAsLetter; + if (nextCommand === "M") { + return ""; + } else if (nextCommand === "L") { + return ") rotate(" +Math.atan2(nextSeg.y, nextSeg.x)/Math.Pi*180+ ""; + } else if (nextCommand === "C") { + } + } else if (command === "L") { + return ") rotate(" +Math.atan2(seg.y, seg.x)/Math.Pi*180+ ""; + } else if (command === "C") { + } + }, + /*$animateElement.tocallメソッドを置き換えるためのメソッド * mpath要素が指定されたときか、path属性のときにのみ使われる*/ _tocallForPath: function(advance) { + var path = this.path, + advanceLength = advance * path.getTotalLength(); /*全体の距離から、現在進めている距離を算出して、そこから、現在点を導き出す*/ - var point = this.path.getPointAtLength(advance * this.path.getTotalLength()); - return point.x+ "," +point.y; + var point = path.getPointAtLength(advanceLength); + if (this.rotate === "0") { + return point.x+ "," +point.y; + } + return point.x+ "," +point.y + this.getRotate(path, advanceLength); } } ) .on("init", function (ele) { @@ -1714,6 +1743,7 @@ base("$calcMode").up("$attribute").mix( { * また、$aniamteTransformElementのtocallメソッド参照*/ this.isSum = true; this.mode = this.getAttr("mode", "paced"); + this.rotate = this.getAttr("rotate", "0"); this.path = this.path.cloneNode(true); var mpath = ele.getElementsByTagNameNS(this.path.namespaceURI, "mpath"); var list = this.element.__transformList; diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 2f3491e..629f74e 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -3064,25 +3064,27 @@ describe("SMIL Animation Spec", function() { expect($animate.type).toBe("translate"); expect($animate.mode).toBe("paced"); ele.setAttributeNS(null, "type", "scale"); + expect($animate.rotate).toBe("0"); $animate.init(ele); expect($animate.type).toBe("translate"); expect($animate.mode).toBe("paced"); + expect($animate.rotate).toBe("0"); - ele.setAttributeNS(null, "values", "0;1"); + ele.setAttributeNS(null, "values", "0,0;1,0"); $animate.up("$a").init(ele); - expect($animate.$a.tocall(0)).toBe("translate(0.0)"); - expect($animate.$a.tocall(0.5)).toBe("translate(0.5)"); - expect($animate.$a.tocall(1)).toBe("translate(1.0)"); + expect($animate.$a.tocall(0)).toBe("translate(0.0,0.0)"); + expect($animate.$a.tocall(0.5)).toBe("translate(0.5,0.0)"); + expect($animate.$a.tocall(1)).toBe("translate(1.0,0.0)"); var ec = ele.cloneNode(true); p.appendChild(ec); ec.removeAttributeNS(null, "values"); - ec.setAttributeNS(null, "from", "0"); - ec.setAttributeNS(null, "to", "1"); + ec.setAttributeNS(null, "from", "0,0"); + ec.setAttributeNS(null, "to", "1,0"); $animate.up("$a").init(ec); - expect($animate.$a.tocall(0)).toBe("translate(0.0)"); - expect($animate.$a.tocall(0.5)).toBe("translate(0.5)"); - expect($animate.$a.tocall(1)).toBe("translate(1.0)"); + expect($animate.$a.tocall(0)).toBe("translate(0.0,0.0)"); + expect($animate.$a.tocall(0.5)).toBe("translate(0.5,0.0)"); + expect($animate.$a.tocall(1)).toBe("translate(1.0,0.0)"); } ); /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/ it("should be this for the value (the invalid partion )", function() { -- 2.11.0