[Sie-announce] SIEコード [1835] 1, 複数のobject要素とembed要素に対応させた

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2010年 5月 22日 (土) 23:50:46 JST


Revision: 1835
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1835
Author:   dhrname
Date:     2010-05-22 23:50:46 +0900 (Sat, 22 May 2010)

Log Message:
-----------
1, 複数のobject要素とembed要素に対応させた
2, SVGElementにおいて、SVGLengthに関する修正

Modified Paths:
--------------
    branches/ufltima/dom/svg.js

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-05-19 14:25:06 UTC (rev 1834)
+++ branches/ufltima/dom/svg.js	2010-05-22 14:50:46 UTC (rev 1835)
@@ -255,10 +255,8 @@
           if (evt.attrChange === MutationEvent.ADDITION) {
             tea.baseVal = tod.createSVGLength();
           }
-          var n = evt.newValue.match(/\D+$/), type = 0;
-          if (!n) {
-            type = SVGLength.SVG_LENGTHTYPE_NUMBER;
-          } else {
+          var n = evt.newValue.match(/\D+$/), type = SVGLength.SVG_LENGTHTYPE_NUMBER;
+          if (!!n) {
             n = n[0];
           }
           if (n === "%") {
@@ -488,7 +486,7 @@
  *例:2pxならば、x.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 2);となる
  */
 SVGLength.prototype.newValueSpecifiedUnits = function (/*unsigned short*/ unitType, /*float*/ valueInSpecifiedUnits) {
-  var n =1, _s = ""; //nは各単位から利用単位への変換数値。_sは単位の文字列を表す
+  var n = 1, _s = ""; //nは各単位から利用単位への変換数値。_sは単位の文字列を表す
   if (unitType === SVGLength.SVG_LENGTHTYPE_NUMBER) {
     _s = "";
   } else if (unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) {
@@ -1281,123 +1279,95 @@
 SVGSwitchElement.constructor = SVGElement;
 SVGSwitchElement.prototype = new SVGElement();
 
-function GetSVGDocument() {
-  var xmlhttp; //XMLHttpオブジェクトを生成
-  try {
-    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
-  } catch (e) {
-    try {
-      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
-    } catch (E) {
-      xmlhttp = false;
+function GetSVGDocument(ele) {
+  this._tar = ele;
+  this._next = null;
+  return this;
+}
+ GetSVGDocument.prototype = {
+  _init : function() {
+  var xmlhttp = NAIBU.xmlhttp, objei = this._tar, thistar = this;   //objeiはobject要素かembed要素
+  xmlhttp.open("GET", objei.getAttribute("data"), true);
+  xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+  xmlhttp.onreadystatechange = function() {
+    if (xmlhttp.readyState === 4  &&  xmlhttp.status === 200) {
+      /*responseXMLを使うと、時々、空のデータを返すことがあるため(原因は不明)、
+       *ここでは、responseTextを用いる
+       */
+      var doc = new ActiveXObject("MSXML2.DomDocument");
+      var dew = new Date();
+      str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->");
+      doc.loadXML(str);
+      var s = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg");
+      var tar = s.documentElement;
+      tar.viewport.top = 0;
+      tar.viewport.left = 0;
+      tar.viewport.width = objei.clientWidth;
+      tar.viewport.height = objei.clientHeight;
+      var objw = objei.getAttribute("width"), objh = objei.getAttribute("height");
+      if (objw) {
+        tar.setAttributeNS(null, "width", objw);
+        tar.viewport.width = tar.width.baseVal.value;
+      }
+      if (objh) {
+        tar.setAttributeNS(null, "height", objh);
+        tar.viewport.height = tar.height.baseVal.value;
+      }
+      var fi = doc.documentElement.firstChild, n;
+      var attr = doc.documentElement.attributes, att;
+      for (var i=0,atli=attr.length;i<atli;++i) { //ルート要素のNamedNodeMapを検索する
+        att = s.importNode(attr[i], false);
+        tar.setAttributeNodeNS(att);
+      }
+      var sdt = tar._tar, sp = document.createElement("div"), dcp = document.createElement("v:group");
+      dcp.style.width = tar.width.baseVal.value+ "px";
+      dcp.style.height = tar.height.baseVal.value+ "px";
+      dcp.coordsize = tar.width.baseVal.value+ " " +tar.height.baseVal.value;
+      sp.appendChild(dcp);
+      objei.parentNode.insertBefore(sp, objei);
+      dcp.appendChild(sdt)
+      while (fi) { //子ノードを検索して、子供がいれば、importNodeメソッドを再帰的に実行する
+        n = s.importNode(fi, true);
+        tar.appendChild(n);
+        fi = fi.nextSibling;
+      }
+      /*以下では、VMLの要素とHTMLのCSSのプロパティを用いて、背景を
+       *作り出す作業を行う。これは必須
+       */
+      var backr = document.createElement("v:rect");
+      var w = tar.viewport.width, h = tar.viewport.height, sw = tar.width.baseVal.value, sh = tar.height.baseVal.value;
+      backr.style.position = "absolute";
+      backr.style.width = w+ "px";
+      backr.style.height = h+ "px";
+      backr.style.zIndex = -1;
+      backr.stroked = "false";
+      backr.filled = "false";
+      tar._tar.appendChild(backr);
+      var trstyle = tar._tar.style;
+      var tpstyle = objei.style;
+      trstyle.visibility = "visible";
+      trstyle.position = "absolute";
+      //以下、画像を切り取り
+      trstyle.overflow = "hidden";
+      var backrs = backr.currentStyle;
+      var viewWidth = w > sw ? sw : w, viewHeight = h > sh ? sh : h; //ウィンドウ枠の長さを決定する
+      var bfl = parseFloat(backrs.left), bft = parseFloat(backrs.top);
+      var bl = -tar._tx, bt = -tar._ty;
+      var backright = bl + viewWidth + 1;
+      var backdown = bt + viewHeight + 1;
+      trstyle.clip = "rect(" +bt+ "px " +backright+ "px " +backdown+ "px " +bl+ "px)";
+      alert((new Date()).getTime() - dew.getTime());
+      doc = str = fi = attr = null;
+      if (thistar._next) {
+        thistar._next._init();
+      } else {
+      }
     }
-  }
-  if (!xmlhttp) {
-    try {
-      xmlhttp = new XMLHttpRequest();
-    } catch (e) {
-      xmlhttp = false;
-    }
-  }
-  NAIBU.xmlhttp = xmlhttp;
-  if (!document.namespaces["v"]) {
-    document.namespaces.add("v","urn:schemas-microsoft-com:vml");
-    document.namespaces.add("o","urn:schemas-microsoft-com:office:office");
-    var st = document.createStyleSheet();
-    var vmlUrl = "behavior: url(#default#VML);display: inline-block;} "; //inline-blockはIEのバグ対策
-    st.cssText = "v\\:rect{" +vmlUrl+ "v\\:image{" +vmlUrl+ "v\\:fill{" +vmlUrl+ "v\\:stroke{" +vmlUrl+ "o\\:opacity2{" +vmlUrl
-      + "dn\\:defs{display:none}"
-      + "v\\:group{text-indent:0px;position:relative;width:100%;height:100%;" +vmlUrl
-      + "v\\:shape{width:100%;height:100%;" +vmlUrl;
-  }
-  if (xmlhttp) {
-    var oba = document.createElement("div");
-    oba.setAttribute("id","_NAIBU_outline");
-    document.body.appendChild(oba);
-    //HTML内のobject要素を探し出して、メソッドを結びつける
-    var obje = document.getElementsByTagName("object");
-    for (var i=0, objli=obje.length;i<objli;++i) {
-      var objei = obje[i];
-      xmlhttp.open("GET", objei.getAttribute("data"), true);
-      xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
-      xmlhttp.onreadystatechange = function() {
-        if (xmlhttp.readyState === 4  &&  xmlhttp.status === 200) {
-          /*SVGDocument*/ objei.getSVGDocument = function(){
-            /*responseXMLを使うと、時々、空のデータを返すことがあるため(原因は不明)、
-             *ここでは、responseTextを用いる
-             */
-            var doc = new ActiveXObject("MSXML2.DomDocument");
-            var dew = new Date();
-            str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->");
-            doc.loadXML(str);
-            var s = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg");
-            var tar = s.documentElement;
-            tar.viewport.top = 0;
-            tar.viewport.left = 0;
-            tar.viewport.width = objei.clientWidth;
-            tar.viewport.height = objei.clientHeight;
-            var objw = objei.getAttribute("width"), objh = objei.getAttribute("height");
-            if (objw) {
-              tar.setAttributeNS(null, "width", objw);
-              tar.viewport.width = tar.width.baseVal.value;
-            }
-            if (objh) {
-              tar.setAttributeNS(null, "height", objh);
-              tar.viewport.height = tar.height.baseVal.value;
-            }
-            var fi = doc.documentElement.firstChild, n;
-            var attr = doc.documentElement.attributes, att;
-            for (var i=0,atli=attr.length;i<atli;++i) { //ルート要素のNamedNodeMapを検索する
-              att = s.importNode(attr[i], false);
-              tar.setAttributeNodeNS(att);
-            }
-            var sdt = tar._tar, sp = document.createElement("div"), dcp = document.createElement("v:group");
-            dcp.style.width = tar.width.baseVal.value+ "px";
-            dcp.style.height = tar.height.baseVal.value+ "px";
-            dcp.coordsize = tar.width.baseVal.value+ " " +tar.height.baseVal.value;
-            sp.appendChild(dcp);
-            objei.parentNode.insertBefore(sp, objei);
-            dcp.appendChild(sdt)
-            while (fi) { //子ノードを検索して、子供がいれば、importNodeメソッドを再帰的に実行する
-              n = s.importNode(fi, true);
-              tar.appendChild(n);
-              fi = fi.nextSibling;
-            }
-            /*以下では、VMLの要素とHTMLのCSSのプロパティを用いて、背景を
-             *作り出す作業を行う。これは必須
-             */
-            var backr = document.createElement("v:rect");
-            var w = tar.viewport.width, h = tar.viewport.height, sw = tar.width.baseVal.value, sh = tar.height.baseVal.value;
-            backr.style.position = "absolute";
-            backr.style.width = w+ "px";
-            backr.style.height = h+ "px";
-            backr.style.zIndex = -1;
-            backr.stroked = "false";
-            backr.filled = "false";
-            tar._tar.appendChild(backr);
-            var trstyle = tar._tar.style;
-            var tpstyle = objei.style;
-            trstyle.visibility = "visible";
-            trstyle.position = "absolute";
-            //以下、画像を切り取り
-            trstyle.overflow = "hidden";
-            var backrs = backr.currentStyle;
-            var viewWidth = w > sw ? sw : w, viewHeight = h > sh ? sh : h; //ウィンドウ枠の長さを決定する
-            var bfl = parseFloat(backrs.left), bft = parseFloat(backrs.top);
-            var bl = -tar._tx, bt = -tar._ty;
-            var backright = bl + viewWidth + 1;
-            var backdown = bt + viewHeight + 1;
-            trstyle.clip = "rect(" +bt+ "px " +backright+ "px " +backdown+ "px " +bl+ "px)";
-            alert((new Date()).getTime() - dew.getTime());
-            doc = str = fi = attr = null;
-            return s;
-          };
-          objei.getSVGDocument();
-        }
-      };
-      xmlhttp.send(null);
-    }
-  }
+  };
+  xmlhttp.send(null);
+  },
+  /*SVGDocument*/  getSVGDocument : function() {
+}
 };
 
 /*SVGStyleElement
@@ -3856,5 +3826,53 @@
     NAIBU = stlog = STLog = document = null;
   } catch(e) {}
 }
-NAIBU.addEvent("load", GetSVGDocument);
+NAIBU.addEvent("load", (function() {
+  var xmlhttp; //XMLHttpオブジェクトを生成
+  try {
+    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+  } catch (e) {
+    try {
+      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+    } catch (E) {
+      xmlhttp = false;
+    }
+  }
+  if (!xmlhttp) {
+    try {
+      xmlhttp = new XMLHttpRequest();
+    } catch (e) {
+      xmlhttp = false;
+    }
+  }
+  NAIBU.xmlhttp = xmlhttp;
+  if (!document.namespaces["v"]) {
+    document.namespaces.add("v","urn:schemas-microsoft-com:vml");
+    document.namespaces.add("o","urn:schemas-microsoft-com:office:office");
+    var st = document.createStyleSheet();
+    var vmlUrl = "behavior: url(#default#VML);display: inline-block;} "; //inline-blockはIEのバグ対策
+    st.cssText = "v\\:rect{" +vmlUrl+ "v\\:image{" +vmlUrl+ "v\\:fill{" +vmlUrl+ "v\\:stroke{" +vmlUrl+ "o\\:opacity2{" +vmlUrl
+      + "dn\\:defs{display:none}"
+      + "v\\:group{text-indent:0px;position:relative;width:100%;height:100%;" +vmlUrl
+      + "v\\:shape{width:100%;height:100%;" +vmlUrl;
+  }
+  if (xmlhttp) {
+    var oba = document.createElement("div");
+    oba.setAttribute("id","_NAIBU_outline");
+    document.body.appendChild(oba);
+    var ob = document.getElementsByTagName("object"), em = document.getElementsByTagName("embed");
+    for (var i=0,s=[];i<ob.length;++i) {
+      s[s.length] = new GetSVGDocument(ob[i]);
+    }
+    for (var i=0;i<em.length;++i) {
+      s[s.length] = new GetSVGDocument(em[i]);
+    }
+    for (var i=0;i<s.length;++i) {
+      if (i < s.length-1) {
+        s[i]._next = s[i+1]
+      }
+    }
+    s[0]._init(); //初期化作業を開始
+    s = null;
+  }
+}) )
 NAIBU.addEvent("unload", unsvgtovml);
\ No newline at end of file




Sie-announce メーリングリストの案内
アーカイブの一覧に戻る