[Sie-announce] SIEコード [1706] GetSVGDocumentインターフェースの実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 3月 7日 (日) 23:37:17 JST


Revision: 1706
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1706
Author:   dhrname
Date:     2010-03-07 23:37:17 +0900 (Sun, 07 Mar 2010)

Log Message:
-----------
GetSVGDocumentインターフェースの実装

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

Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js	2010-03-07 14:36:53 UTC (rev 1705)
+++ branches/ufltima/dom/svg.js	2010-03-07 14:37:17 UTC (rev 1706)
@@ -1197,14 +1197,48 @@
 SVGSwitchElement.prototype = new SVGElement();
 
 function GetSVGDocument() {
-  var obje = document.getElementsByTagName("object"); //HTML内のobject要素を探し出して、メソッドを結びつける
-  for (var i=0;i<obje.length;++i) {
-    /*SVGDocument*/ obje.getSVGDocument = (function(){
-      var s = DOMImplementation.createDocument("http://www.w3.org/svg/2000", "svg");
-      return s;
-    });
+  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;
+    }
+  }
+  if (xmlhttp) {
+    //HTML内のobject要素を探し出して、メソッドを結びつける
+    var obje = document.getElementsByTagName("object");
+    for (var i=0, objli=1;i<objli;++i) {
+      var objei = {};//obje[i];
+      xmlhttp.open("GET", "tiger.svg", true);//objei.getAttribute("data"), true);
+      xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+      xmlhttp.onreadystatechange = function() {
+        if (xmlhttp.readyState === 4  &&  xmlhttp.status === 200) {
+          //responsXMLはDTD処理を行う可能性があるため、ここでは使わない
+          /*SVGDocument*/ objei.getSVGDocument = function(){
+            var doc = new ActiveXObject("MSXML2.DomDocument");
+            str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->");
+            doc.loadXML(str);
+            var s = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg");
+            return s;
+          };
+        }
+      };
+      xmlhttp.send(null);
+      alert(objei.getSVGDocument());
+    }
+  }
 };
+
 /*SVGStyleElement
  *style要素をあらわすオブジェクト
  */
@@ -1678,9 +1712,13 @@
    *描画が開始されることを示す。つまり、appendChildで挿入されない限り、描画をしない。
    */
   this.addEventListener("DOMNodeInserted", function(evt){
+    var tar = evt.target;
     if (evt.eventPhase === Event.BUBBLING_PHASE) {
       return; //強制終了させる
     }
+    if (tar.hasAttributeNS(null, "d")) {
+      tar.setAttributeNS(null, "d", tar.getAttributeNS(null, "d"));
+    }
     evt.target.addEventListener("DOMNodeInsertedIntoDocument", function(evt){
       /*以下の処理は、normalizedpathSegListとCTMに基づいて、
        *SVGのd属性をVMLに変換していく処理である。
@@ -1727,8 +1765,8 @@
       tar._tar.path = dat + " e";
       tar._tar.coordsize = w + " " + h;
       matrix = dat = x = y = null;
-    });
-  });
+    }, false);
+  }, false);
   return this;
 };
 SVGPathElement.constructor = SVGElement;
@@ -1888,6 +1926,57 @@
   /*readonly SVGAnimatedLength*/ this.height = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.rx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.ry = new SVGAnimatedLength();
+  this.addEventListener("DOMNodeInserted", function(evt){
+    if (evt.eventPhase === Event.BUBBLING_PHASE) {
+      return; //強制終了させる
+    }
+    this.addEventListener("DOMNodeInsertedIntoDocument", function(evt) {
+      var tar = evt.target;
+      var rx = tar.hasAttributeNS(null, "rx"), ry = tar.hasAttributeNS(null, "ry");
+      var x = this.x.baseVal.value, y = this.y.baseVal.value, xw = x + this.width.baseVal.value, yh = y + this.height.baseVal.value;
+      var list;
+      if (rx || ry) {
+        var thrx = this.rx.baseVal, thry = thry.baseVal;
+        thrx.value = rx ? thrx.value : thry.value;
+        thry.value = ry ? thry.value : thrx.value;
+        //rx属性が幅より大きければ、幅の半分を属性に設定(ry属性は高さと比較する)
+        var twidth = this.width.baseVal.value, theight = this.height.baseVal.value;
+        if (thrx.value > twidth / 2) {
+          thrx.value = twidth / 2;
+        }
+        if (thry.value > theight / 2) {
+          thry.value = theight / 2;
+        }
+        var rxv = thrx.value, ryv = thry.value;
+        var rrx = rxv * 0.55228, rry = ryv * 0.55228;
+        var a = xw - rxv, b = x + rxv, c = y + ryv, d = yh - ryv;
+        list = ["m",b,y, "l",a,y, "c",a+rrx,y,xw,c-rry,xw,c, "l",xw,d, "c",xw,d+rry,a+rrx,yh,a,yh, "l",b,yh, "c",b-rrx,yh,x,d+rry,x,d, "l",x,c, "c",x,c-rry,b-rrx,y,b,y];
+      } else {
+        list = ["m",x,y, "l",x,yh, xw,yh, xw,y, "x e"];
+      }
+      //以下は、配列listそのものをCTMで座標変換していく処理
+      var par = tar.ownerSVGElement, ctm = tar.getScreenCTM();
+      for (var i=0, lili=list.length;i<lili;) {
+        if (isNaN(list[i])) { //コマンド文字は読み飛ばす
+          ++i;
+          continue;
+        }
+        var p = par.createSVGPoint(list[i], list[i+1]);
+        var pmt = p.matrixTransform(ctm);
+        ++i;
+        list[i] = pmt.x;
+        ++i;
+        list[i] = pmt.y;
+        p = pmt = null;
+      }
+      var dat = list.join(" ");
+      //VMLに結び付けていく
+      var ele = tar._tar;
+      ele.path = dat;
+      ele.coordsize = w + " " + h;
+      list = dat = ele = null;
+    }, false);
+  }, false);
   return this;
 };
 SVGRectElement.constructor = SVGElement;
@@ -1952,9 +2041,9 @@
 SVGTextContentElement.constructor = SVGElement;
 SVGTextContentElement.prototype = new SVGElement();
     // lengthAdjust Types
-  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_UNKNOWN   = 0;
-  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACING     = 1;
-  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS     = 2;
+  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_UNKNOWN           = 0;
+  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACING           = 1;
+  /*unsigned short*/ SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS  = 2;
 /*long*/     SVGTextContentElement.prototype.getNumberOfChars = function() {
   return (this._tar.innerText.length);
 };
@@ -2564,7 +2653,7 @@
  *本来であれば、SVGDocumentのcreateElementNSメソッドを上書きすることが望ましいが、
  *SIEでは軽量化のために、マッピングを用いた
  */
-DOMImplementation["http://www.w3.org/svg/2000"] = {
+DOMImplementation["http://www.w3.org/2000/svg"] = {
   Document:        SVGDocument,
   svg:             SVGSVGElement,
   g:               SVGGElement,
@@ -2623,4 +2712,5 @@
   use:             SVGUseElement,
   view:            SVGViewElement,
   vkern:           SVGVKernElement
-}
\ No newline at end of file
+};
+GetSVGDocument();
\ No newline at end of file




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