[Sie-announce] SIEコード [2008] keyTimes属性の実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 9月 22日 (水) 20:33:43 JST


Revision: 2008
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2008
Author:   dhrname
Date:     2010-09-22 20:33:43 +0900 (Wed, 22 Sep 2010)

Log Message:
-----------
keyTimes属性の実装

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-09-21 09:50:56 UTC (rev 2007)
+++ branches/06x/061/org/w3c/dom/svg.js	2010-09-22 11:33:43 UTC (rev 2008)
@@ -4176,6 +4176,8 @@
   this.endElement = s.endElement;
   this.beginElementAt = s.beginElementAt;
   this.endElementAt = s.endElementAt;
+  this._from = this._to = this._values = this._by = null;
+  this._keyTimes = null;
   this.addEventListener("beginEvent", function(evt) {
     var tar = evt.target;
     if (!tar.isRepeat) {
@@ -4191,6 +4193,9 @@
     }
   }, false);
   this.addEventListener("DOMAttrModified", function(evt){
+    if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      return;
+    }
     var tar = evt.target, name = evt.attrName;
     if (name === "begin") {
       tar._beginValue = evt.newValue;
@@ -4204,40 +4209,73 @@
     } else if (name === "repeatDur") {
       tar._maxDur = parseFloat(evt.newValue);
       tar._isRepeat = true;
+    } else if (name === "from") {
+      tar._from = evt.newValue;
+    } else if (name === "to") {
+      tar._to = evt.newValue;
+    } else if (name === "values") {
+      tar._values = evt.newValue.split(";");
+    } else if (name === "by") {
+      tar._by = evt.newValue;
+    } else if (name === "keyTimes") {
+      tar._keyTimes = evt.newValue.split(";");
     }
     evt = null;
   }, false);
-  this.addEventListener("DOMNodeInsertedIntoDocument", function(evt){
+  this.addEventListener("DOMNodeInserted", function(evt){
+    if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      return; //強制終了させる
+    }
     var tar = evt.target;
-    if (tar.hasAttributeNS("http://www.w3.org/1999/xlink", "xlink:href")) {
-      tar.targetElement = tar.ownerDocument.getElementById(tar.getAttributeNS("http://www.w3.org/1999/xlink", "xlink:href").substring(1))
-    } else {
-      tar.targetElement = tar.parentNode;
-    }
-    if (tar._beginValue) {
-      tar._eventSync(tar._beginValue,
-          (function(te, offse, ta, t) {
-            ta.addEventListener( t.match(te._eventRegExp)[0],
-              function(){
-                if (offse !== 0) {
-                  te.beginElementAt(offse);
-                } else {
-                  te._begin = NAIBU.Time.currentFrame;
-                  te.beginElement();
-                  te._currentFrame++;
-                }
-              }, false);
-            }), "beginElementAt");
-    }
-    if (tar._endValue) {
-      tar._eventSync(tar._endValue,
-          (function(te, offse, ta, t) {
-            ta.addEventListener( t.match(te._eventRegExp)[0],
+    tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt){
+      var tar = evt.target;
+      /*以降の場合分けルールに関しては、下記の仕様を参照
+       *http://www.jsa.or.jp/stdz/instac/syoukai/H13/H13annual_report/12/ngc-wg3/offline/smil_20_20020131/animation.html#AnimationNS-FromToBy
+       */
+      if (tar._values) {
+      } else if (tar._from && tar._to) {
+        tar._values = [tar._from, tar._to];
+      } else if (tar._from && tar._by) {
+        var n = parseFloat(tar._from) + parseFloat(tar._by), tanni = tar._from.match(/\D+/) || [""];
+        tar._values = [tar._from, n+tanni[0]];
+      } else if (tar._to) {
+        tar._values = [null, tar._to];
+      } else if (tar._by) {
+        tar._values = ["0", tar._by];
+      } else {
+        throw (new Error("アニメーション属性の設定を忘れていませんか"));
+      }
+      if (tar.hasAttributeNS("http://www.w3.org/1999/xlink", "xlink:href")) {
+        tar.targetElement = tar.ownerDocument.getElementById(tar.getAttributeNS("http://www.w3.org/1999/xlink", "xlink:href").substring(1))
+      } else {
+        tar.targetElement = tar.parentNode;
+      }
+      if (tar._beginValue) {
+        tar._eventSync(tar._beginValue,
+            (function(te, offse, ta, t) {
+              ta.addEventListener( t.match(te._eventRegExp)[0],
                 function(){
-                  te.endElementAt(offse);
-                }, false );
-            }), "endElementAt");
-    }
+                  if (offse !== 0) {
+                    te.beginElementAt(offse);
+                  } else {
+                    te._begin = NAIBU.Time.currentFrame;
+                    te.beginElement();
+                    te._currentFrame++;
+                  }
+                }, false);
+              }), "beginElementAt");
+      }
+      if (tar._endValue) {
+        tar._eventSync(tar._endValue,
+            (function(te, offse, ta, t) {
+              ta.addEventListener( t.match(te._eventRegExp)[0],
+                  function(){
+                    te.endElementAt(offse);
+                  }, false );
+              }), "endElementAt");
+      }
+      evt = tar = null;
+    }, false);
     evt = tar = null;
   }, false);
   this.addEventListener("repeatEvent", function(evt) {
@@ -4398,10 +4436,18 @@
       var tta = tar.targetElement[attrName];
       if (!!tta) {
         var base = tta.baseVal;
-        tta.baseVal = tar.ownerDocument.documentElement.createSVGLength();
+        if (base instanceof SVGLength) {
+          tta.baseVal = tar.ownerDocument.documentElement.createSVGLength();
+        } else if (base instanceof SVGRect) {
+          tta.baseVal = tar.ownerDocument.documentElement.createSVGRect();
+        } else if (base instanceof SVGTransformList) {
+          tta.baseVal = new SVGTransformList();
+          tta.baseVal.initialize(tar.ownerDocument.documentElement.createSVGTransform());
+        }
         /*setAttrbute(NS)メソッドはDOM属性を書き換えるため利用しない。
+         *
          * 参照:アニメーションサンドイッチモデル
-         *>アニメーションが起動している時,それは実際,DOMの中の属性値は変化しない。
+         * >アニメーションが起動している時,それは実際,DOMの中の属性値は変化しない。
          *http://www.jsa.or.jp/stdz/instac/syoukai/H13/H13annual_report/12/ngc-wg3/offline/smil_20_20020131/animation.html#animationNS-AnimationSandwichModel
          */
         var evt = tar.ownerDocument.createEvent("MutationEvents");
@@ -4512,46 +4558,6 @@
 function SVGAnimateColorElement() {
   SVGAnimationElement.apply(this);
   NAIBU.Clip[NAIBU.Clip.length] = this;
-  this._from = this._to = this._values = this._by = null;
-  this.addEventListener("DOMAttrModified", function(evt){
-    if (evt.eventPhase === Event.BUBBLING_PHASE) {
-      return;
-    }
-    var tar = evt.target, name = evt.attrName;
-    if (name === "from") {
-      tar._from = evt.newValue;
-    } else if (name === "to") {
-      tar._to = evt.newValue;
-    } else if (name === "values") {
-      tar._values = evt.newValue.split(";");
-    } else if (name === "by") {
-      tar._by = evt.newValue;
-    }
-  }, false);
-  this.addEventListener("DOMNodeInserted", function(evt){
-    var tar = evt.target;
-    if (evt.eventPhase === Event.BUBBLING_PHASE) {
-      return; //強制終了させる
-    }
-    tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt){
-      var tar = evt.target;
-      /*以降の場合分けルールに関しては、下記の仕様を参照
-       *http://www.jsa.or.jp/stdz/instac/syoukai/H13/H13annual_report/12/ngc-wg3/offline/smil_20_20020131/animation.html#AnimationNS-FromToBy
-       */
-      if (tar._values) {
-      } else if (tar._from && tar._to) {
-        tar._values = [tar._from, tar._to];
-      } else if (tar._from && tar._by) {
-        var n = parseFloat(tar._from) + parseFloat(tar._by), tanni = tar._from.match(/\D+/) || [""];
-        tar._values = [tar._from, n+tanni[0]];
-      } else if (tar._to) {
-        tar._values = [null, tar._to];
-      } else if (tar._by) {
-        tar._values = ["0", tar._by];
-      }
-    }, false);
-    tar = null;
-  }, false);
   this.addEventListener("beginEvent", function(evt) {
     var tar = evt.target, attrName = tar.getAttributeNS(null, "attributeName");
     var style = tar.ownerDocument.getOverrideStyle(tar.targetElement, "");
@@ -4560,14 +4566,25 @@
       style.setProperty(attrName, tar._values[0], null);
     }
     tar._frame = function() {
-      var _tar = tar, t = new SVGColor(), fill = style.getPropertyCSSValue(attrName);
-      t.setRGBColor(tar._valuse[1]);
-      var fc = fill.rgbColor, tc = t.rgbColor, num = CSSPrimitiveValue.CSS_NUMBER, di = _tar.getSimpleDuration();
-      var r = (fc.red.getFloatValue(num) - tc.red.getFloatValue(num)) / di;
-      var g = (fc.green.getFloatValue(num) - tc.blue.getFloatValue(num)) / di;
-      var b = (fc.blue.getFloatValue(num) - tc.blue.getFloatValue(num)) / di;
-      style.setProperty(attrName, "rgb(" +r+ "," +g+ "," +"b"+ ")", null);
-      _tar = t = fc = tc = num = r = g = b = null;
+      var _tar = tar, to = new SVGColor(), from = new SVGColor();
+      var n = _tar._values.length - 1, t = _tar.getCurrentTime(), d = _tar.getSimpleDuration(), i = Math.floor((t*n) / d);
+      to.setRGBColor(_tar._valuse[i+1]);
+      from.setRGBColor(_tar._values[i]);
+      if (!!!_tar._keyTimes) {
+        var ti = d / n, ki =ti;
+        if (n === 1) {
+          ti = 0;
+        }
+      } else {
+        var ti = parseFloat(_tar._keyTimes[i]) * d;
+        var ki = parseFloat(_tar._keyTimes[i+1])*d - ti;
+      }
+      var tc = to.rgbColor, fc = from.rgbColor, num = CSSPrimitiveValue.CSS_NUMBER, di = (t - ti) / ki;
+      var r = fc.red.getFloatValue(num) + (tc.red.getFloatValue(num) - fc.red.getFloatValue(num)) * di;
+      var g = fc.green.getFloatValue(num) + (tc.green.getFloatValue(num) - fc.blue.getFloatValue(num)) * di;
+      var b = fc.blue.getFloatValue(num) + (tc.blue.getFloatValue(num) - fc.blue.getFloatValue(num)) * di;
+      style.setProperty(attrName, "rgb(" +Math.ceil(r)+ "," +Math.ceil(g)+ "," +Math.ceil(b)+ ")", null);
+      _tar = t = to = from = fc = tc = num = r = g = b = null;
     }
   }, false);
   this.addEventListener("endEvent", function(evt) {




Sie-announce メーリングリストの案内
Back to archive index