[Sie-announce] SIEコード [1297] SVGDocumentの内部実装

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 9月 28日 (月) 23:27:48 JST


Revision: 1297
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1297
Author:   dhrname
Date:     2009-09-28 23:27:48 +0900 (Mon, 28 Sep 2009)

Log Message:
-----------
SVGDocumentの内部実装

Modified Paths:
--------------
    branches/DOM/org/w3c/dom/svg.js

Modified: branches/DOM/org/w3c/dom/svg.js
===================================================================
--- branches/DOM/org/w3c/dom/svg.js	2009-09-28 13:06:55 UTC (rev 1296)
+++ branches/DOM/org/w3c/dom/svg.js	2009-09-28 14:27:48 UTC (rev 1297)
@@ -132,136 +132,6 @@
 }
 }
 
-//SVGtoVML 本体。SVGDocumentの代わりを担う
-function SVGtoVML() {
-  return this;
-}
-SVGtoVML.prototype.read = function stvread( /*element*/ obc, /*document*/ doc) {
-  this.rootElement = obc;
-  this.rootElement.style.visibility = "hidden";
-  this.vi = new STViewSpec(this.rootElement);
-  var sh = obc.getElementsByTagName("shape");
-  this.shape = sh;
-  var slen = 0, rlen = 0, clen = 0, elen = 0, pllen = 0, plen = 0, llen = 0;
-  var s = new Array(slen), r = new Array(rlen), c = new Array(clen), e = new Array(elen), pl = new Array(pllen), p = new Array(plen), li = new Array(llen);
-  try {
-  for (var i=0,sli=this.shape.length;i<sli;i++) {
-    var tss = this.shape[i].style;
-    tss.width = "100%";
-    tss.height = "100%";
-    tss.posLeft = 0;
-    tss.posTop = 0;
-  }
-  for (var i=0,shli=sh.length;i<shli;i++) {
-    switch (sh[i].getAttribute("tag")) {
-    case "path":
-      s[slen] = new STPath(sh[i]); slen++;
-    break;
-    case "rect":
-      r[rlen] = new STRectElement(sh[i]); rlen++;
-    break;
-    case "circle":
-      c[clen] = new STCircle(sh[i]); clen++;
-    break;
-    case "ellipse":
-      e[elen] = new STEllipse(sh[i]); elen++;
-    break;
-    case "polyline":
-      pl[pllen] = new STPolyline(sh[i]); pllen++;
-    break;
-    case "polygon":
-      p[plen] = new STPolygon(sh[i]); plen++;
-    break;
-    case "line":
-      li[llen] = new STLine(sh[i]); llen++;
-    break;
-    default:  break;
-    }
-  }
-  var l = null,t = null,a = null;
-  this.getObject("div",STText,"text");
-  this.getObject("a",STAElement,"a");
-  this.getObject("image",STImage,"image");
-  this.getObject("USE", STUseElement, "use");
-  } catch(n) {stlog.add(n,109);}
-  this.path = s;
-  this.rect = r;
-  this.circle = c;
-  this.ellipse = e;
-  this.polygon = p;
-  this.polyline = pl;
-  this.line = li;
-}
-SVGtoVML.prototype.getObject = function stvgetob( /*string*/ tag, /*object*/ st, /*string*/nodes) {
-  try {
-  var li = this.rootElement.getElementsByTagName(tag);
-  var la = new Array();
-  for (var i=0,lli=li ? li.length : 0;i<lli;i++) {
-    la[i] = new st(li[i]);
-  }
-  this[nodes] = la;
-  } catch(e) {stlog.add(e,129);
-    this[nodes] = new Array();
-  }
-}
-//object要素の幅と高さがwとh。 wとhの単位を統一し、px単位に変換したものがswi、shi
-SVGtoVML.prototype.set = function stvset( /*float*/ w, /*float*/ h, /*STLength*/ swi, /*STLength*/ shi) {
-  var c = this.circle,  r = this.rect,  s = this.path,  l = this.line,  text = this.text,  el = this.ellipse,  pg = this.polygon,  pl = this.polyline,  a = this.a,  lin = this.line, imag = this.image;
-  var sw = swi.value,  sh = shi.value;
-  try {
-  var mat = this.vi.set(sw,sh); //返り値はMatrix型
-  } catch(e) {stlog.add(e,1109);}
-  try {
-  this.setObject(s,sw,sh,mat);
-  this.setObject(c,sw,sh,mat);
-  this.setObject(r,sw,sh,mat);
-  this.setObject(el,sw,sh,mat);
-  this.setObject(pg,sw,sh,mat);
-  this.setObject(pl,sw,sh,mat);
-  this.setObject(a,sw,sh,mat);
-  this.setObject(lin,sw,sh,mat);
-  this.setObject(imag,sw,sh,mat);
-  this.setObject(text,sw,sh,mat);
-  this.setObject(this.use,sw,sh,mat);
-  var nods = this.rootElement;
-  chset(nods);
-  var backr = document.createElement("v:rect"); //背景の作成
-  backr.style.width = w;
-  backr.style.height = h;
-  backr.style.zIndex = -1;
-  backr.setAttribute("stroked","false");
-  backr.setAttribute("filled","false");
-  this.rootElement.parentNode.appendChild(backr);
-  this.rootElement.style.visibility = "visible";
-  } catch(e) {stlog.add(e,138);}
-}
-SVGtoVML.prototype.setObject = function stvsetob( /*SVGElement*/ arr, /*float*/ sw, /*float*/ sh, /*Matrix*/ mat) {
-  try {
-  for (var i=0,arri=arr.length;i<arri;i++) {
-    try {
-      arr[i].set(sw,sh,mat);
-    } catch(ee){}
-  }
-  } catch(e) {stlog.add(e,170);}
-}
-
-//chset childNodesで取捨選択
-function chset( /*element*/ ele){
-  var nods = ele.childNodes;
-  var name = new RegExp("^(group|shape|fill|stroke|DIV|SPAN|A|image|rect|USE)$");
-  for (var i=0,nodesli=nods.length;i<nodesli;i++) {
-    var te = nods[i];
-    if (!te.nodeName.match(name)) {
-      ele.removeChild(te);
-      i--; nodesli--;
-    } else {
-      if(te.nodeType == 1 && !te.nodeName.match(/^(DIV|SPAN)$/)) {
-        chset(te);
-      }
-    }
-  }
-}
-
 //DOMツリーを参照して新たなドキュメントを作成していく
 //ele 参照DOMツリー
 //paren 実際のHTMLツリー
@@ -2077,6 +1947,7 @@
  */
 function SVGSVGElement() {
   SVGElement.apply(this, arguments);
+  this.tar = document.createEleemnt("v:group");
 /*                SVGElement,
                 SVGTests,
                 SVGLangSpace,
@@ -2120,83 +1991,126 @@
 };
 SVGSVGElement.constructor = SVGElement;
 SVGSVGElement.prototype = new SVGElement();
-with(SVGSVGElement.prototype) {
-  /*unsigned long*/ suspendRedraw = function(/*unsigned long*/ max_wait_milliseconds ){
-    
+SVGSVGElement.prototype.read = function(/*float*/ w, /*float*/ h){
+  this.tar.style.visibility = "hidden";
+  this.w = w;
+  this.h = h;
+  try{
+  this.children = [];                                                 //子要素
+  var sw = this.width.baseVal.value,  sh = this.height.baseVal.value;
+  this.currentView.set(w, h, this.transform._matrix);                 //this.transform._matrixを加工する
+  this.chset(this,tar, this.transform._matirx, sw, sh);
+  var backr = document.createElement("v:rect");                       //背景の作成
+  backr.style.position = "absolute";
+  backr.style.width = w+ "px";
+  backr.style.height = h+ "px";
+  backr.style.zIndex = -1;
+  backr.stroked = "false";
+  backr.filled = "false";
+  this.tar.appendChild(backr);
+  this.backr = backr;
+  } catch(n) {stlog.add(n,109);}
+};
+/*void*/          SVGSVGElement.prototype.forceRedraw = function(/*element*/ ob) {
+  var w = this.w, h = this.h, c = this.children;
+  var sw = this.width.baseVal.value,  sh = this.height.baseVal.value;
+  this.setObject(this.use,sw,sh);
+  this.setObject(c,sw,sh);
+  try {
+  var trstyle = this.rootElement.style;
+  var tpstyle = ob.style;
+  trstyle.visibility = "visible";
+  //以下、画像を切り取り
+  trstyle.overflow = "hidden";
+  var backrs = this.backr.currentStyle;
+  var viewWidth = w > sw ? sw : w, viewHeight = h > sh ? sh : h; //ウィンドウ枠の長さを決定する
+  var bfl = parseFloat(backrs.left), bft = parseFloat(backrs.top);
+  var bl = -this.vi._tx, bt = -this.vi._ty;
+  if (bfl !== 0 && !isNaN(bfl)) { //内部の図形にずれが生じたとき(isNaNはIE8でautoがデフォルト値のため)
+    bl = bfl;
+    tpstyle.left = -bl+ "px";
   }
-  /*void*/          unsuspendRedraw = function(/*unsigned long*/ suspend_handle_id ){
-    
+  if (bft !== 0 && !isNaN(bfl)) {
+    bt = bft;
+    tpstyle.top = -bt+ "px";
   }
-                    //raises( DOMException );
-  /*void*/          unsuspendRedrawAll = function(){
-    
+  var backright = bl + viewWidth + 1;
+  var backdown = bt + viewHeight + 1;
+  trstyle.clip = "rect(" +bt+ "px " +backright+ "px " +backdown+ "px " +bl+ "px)";
+  //以下、テキストの位置を修正
+  var text = this.tar.getElementsByTagName("div");
+  for (var i=0,textli=text.length;i<textli;++i) {
+    var texti = text[i];
+    if (texti.firstChild.nodeName !== "shape") { //radialGradient用のdiv要素でないならば
+      var tis = texti.style;
+      tis.left = parseFloat(tis.left) + bl + "px";
+      tis.top = parseFloat(tis.top) + bt + "px";
+      //以下はdiv要素がa要素のスタイルを継承しないので必要
+      var tp = texti.parentNode;
+      while (tp.nodeName === "group") { //group要素である限り、さかのぼる
+        tp = tp.parentNode;
+      }
+      if (tp.nodeName === "A") { //先祖要素がa要素ならば
+        tis.cursor = "hand";
+      }
+    }
   }
-  /*void*/          forceRedraw = function(){
-    
+  } catch(e) {stlog.add(e,138);}
+};
+SVGSVGElement.prototype.setObject = function stvsetob( /*SVGElement*/ arr, /*float*/ sw, /*float*/ sh) {
+  try {
+  for (var i=0,arri=arr.length;i<arri;++i) {
+      arr[i].set(sw,sh);
   }
-  /*void*/          pauseAnimations = function(){
-    
-  }
-  /*void*/          unpauseAnimations = function(){
-    
-  }
-  /*boolean*/       animationsPaused = function(){
-    
-  }
-  /*float*/         getCurrentTime = function(){
-    
-  }
-  /*void*/          setCurrentTime = function( in float seconds ){
-    
-  }
-  /*StaticNodeList*/ getIntersectionList = function( in SVGRect rect, in SVGElement referenceElement ){
-    
-  }
-  /*StaticNodeList*/ getEnclosureList = function( in SVGRect rect, in SVGElement referenceElement ){
-    
-  }
-  /*boolean*/       checkIntersection = function( in SVGElement element, in SVGRect rect ){
-    
-  }
-  /*boolean*/       checkEnclosure = function( in SVGElement element, in SVGRect rect ){
-    
-  }
-  /*void*/          deselectAll = function(){
-    
-  }
-  /*SVGNumber*/     createSVGNumber = function(){
-    var s = new SVGNumber();
-    s.value = 0;
-    return s;
-  }
-  /*SVGLength*/     createSVGLength = function(){
-    var s = new SVGLength(0);
-    return s;
-  }
-  /*SVGAngle*/      createSVGAngle = function(){
-    //SVGAngleは軽量化のため、作成していない
-  }
-  /*SVGPoint*/      createSVGPoint = function(){
-    var s = new SVGPoint();
-    return s;
-  }
-  /*SVGMatrix*/     createSVGMatrix = function(){
-    var s = new SVGMatrix(1,0,0,1,0,0); //単位行列を作成
-    return s;
-  }
-  /*SVGRect*/       createSVGRect = function(){
-    var s = new SVGRect();
-    return s;
-  }
-  /*SVGTransform*/  createSVGTransform = function(){
-    var s = this.createSVGTransformFromMatrix(this.createSVGMatrix());
-    return s;
-  }
-  /*SVGTransform*/  createSVGTransformFromMatrix = function(/*SVGMatrix*/ matrix )){
-    var s = new SVGTransform();
-    s.setMatrix(matrix);
-    return s;
+  } catch(e) {stlog.add(e,170);}
+}
+
+/*void*/          SVGSVGElement.prototype.pauseAnimations = function(){
+  
+}
+/*void*/          SVGSVGElement.prototype.unpauseAnimations = function(){
+  
+}
+/*float*/         SVGSVGElement.prototype.getCurrentTime = function(){
+  
+}
+/*void*/          SVGSVGElement.prototype.setCurrentTime = function(/*float*/ seconds ){
+  
+}
+/*SVGNumber*/     createSVGNumber = function(){
+  var s = new SVGNumber();
+  s.value = 0;
+  return s;
+}
+/*SVGLength*/     createSVGLength = function(){
+  var s = new SVGLength(0);
+  return s;
+}
+/*SVGAngle*/      createSVGAngle = function(){
+  //SVGAngleは軽量化のため、作成していない
+}
+/*SVGPoint*/      createSVGPoint = function(){
+  var s = new SVGPoint();
+  return s;
+}
+/*SVGMatrix*/     createSVGMatrix = function(){
+  var s = new SVGMatrix(1,0,0,1,0,0); //単位行列を作成
+  return s;
+}
+/*SVGRect*/       createSVGRect = function(){
+  var s = new SVGRect();
+  return s;
+}
+/*SVGTransform*/  createSVGTransform = function(){
+  var s = this.createSVGTransformFromMatrix(this.createSVGMatrix());
+  return s;
+}
+/*SVGTransform*/  createSVGTransformFromMatrix = function(/*SVGMatrix*/ matrix )){
+  var s = new SVGTransform();
+  s.setMatrix(matrix);
+  return s;
 };
+
   /*interface SVGZoomAndPan*/
   // Zoom and Pan Types
 SVGZoomAndPan = {
@@ -2204,6 +2118,7 @@
   /*const unsigned short*/ SVG_ZOOMANDPAN_DISABLE : 1,
   /*const unsigned short*/ SVG_ZOOMANDPAN_MAGNIFY : 2
 };
+
 function SVGFitToViewBox() {
   /*readonly SVGAnimatedRect*/ this.viewBox = new SVGAnimatedRect();
   /*readonly SVGAnimatedPreserveAspectRatio*/ this.preserveAspectRatio = new SVGAnimatedPreserveAspectRatio();




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