OSDN Git Service

Support the rotate attribute
authordhrname <dhrname@users.sourceforge.jp>
Mon, 18 Jul 2016 14:41:12 +0000 (23:41 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Mon, 18 Jul 2016 14:41:12 +0000 (23:41 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

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