svnno****@sourc*****
svnno****@sourc*****
2010年 5月 18日 (火) 21:00:10 JST
Revision: 1826
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1826
Author: dhrname
Date: 2010-05-18 21:00:09 +0900 (Tue, 18 May 2010)
Log Message:
-----------
1, HTMLのobject要素に対応
2, svg要素のviewBox属性のバグを修正
3, %を使う値に対する修正
Modified Paths:
--------------
branches/ufltima/dom/svg.js
Modified: branches/ufltima/dom/svg.js
===================================================================
--- branches/ufltima/dom/svg.js 2010-05-18 11:56:40 UTC (rev 1825)
+++ branches/ufltima/dom/svg.js 2010-05-18 12:00:09 UTC (rev 1826)
@@ -236,11 +236,14 @@
var n = evt.newValue.match(/\D+$/), type = 0;
if (!n) {
type = SVGLength.SVG_LENGTHTYPE_NUMBER;
- } else if (n === "%") {
+ } else {
+ n = n[0];
+ }
+ if (n === "%") {
if ((name === "x") || (name === "width")) {
- tea._percent *= tod.viewport.width;
+ tea.baseVal._percent *= tod.viewport.width;
} else if ((name === "y") || (name === "height")) {
- tea._percent *= tod.viewport.height;
+ tea.baseVal._percent *= tod.viewport.height;
}
type = SVGLength.SVG_LENGTHTYPE_PERCENTAGE;
} else if (n === "em") {
@@ -952,14 +955,16 @@
this.addEventListener("DOMAttrModified", function(evt){
var tar = evt.target, name = evt.attrName;
if (name === "viewBox") {
- var tv = tar.vewBox.baseVal;
- var ovb = vb.replace(/^\s+|\s+$/g, "").split(/[\s,]+/);
+ tar._cacheScreenCTM = null;
+ var tv = tar.viewBox.baseVal;
+ var ovb = evt.newValue.replace(/^\s+|\s+$/g, "").split(/[\s,]+/);
tv.x = parseFloat(ovb[0]);
tv.y = parseFloat(ovb[1]);
tv.width = parseFloat(ovb[2]);
tv.height = parseFloat(ovb[3]);
tar.viewBox.baseVal._isUsed = 1;
} else if (name === "preserveAspectRatio") {
+ tar._cacheScreenCTM = null;
var par = evt.newValue, tp = tar.preserveAspectRatio.baseVal;
var sa = 1, mos = SVGPreserveAspectRatio.SVG_MEETORSLICE_UNKNOWN;
if (!!par.match(/x(Min|Mid|Max)Y(Min|Mid|Max)(?:\s+(meet|slice))?/)) {
@@ -1049,7 +1054,7 @@
*/
/*SVGMatrix*/ SVGSVGElement.prototype.getScreenCTM = function(){
if (!!this._cacheScreenCTM) { //キャッシュがあれば
- return this._cacheScreenCTM;
+ return (this._cacheScreenCTM);
}
var vw = this.viewport.width, vh = this.viewport.height;
if (!this.useCurrentView) {
@@ -1289,8 +1294,8 @@
//HTML内のobject要素を探し出して、メソッドを結びつける
var obje = document.getElementsByTagName("object");
for (var i=0, objli=1;i<objli;++i) {
- var objei = {style:{}};//obje[i];
- xmlhttp.open("GET", "zeimusu_sakura_.svg", true);//objei.getAttribute("data"), true);
+ 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) {
@@ -1304,25 +1309,32 @@
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 = "1237px";
- dcp.style.height = "800px";
- dcp.coordsize = "1237 800";
+ 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);
document.body.insertBefore(sp, document.body.lastChild);
dcp.appendChild(sdt)
- tar.viewport.top = 0;
- tar.viewport.left = 0;
- tar.width.baseVal = tar.createSVGLength();
- tar.height.baseVal = tar.createSVGLength();
- tar.width.baseVal.value = tar.viewport.width = 1237;
- tar.height.baseVal.value = tar.viewport.height = 800;
- var fi = doc.documentElement.firstChild, n;
- var attr = tar.attributes, att;
- for (var i=0,atli=attr.length;i<atli;++i) { //NamedNodeMapを検索する
- att = this.importNode(attr[i], false);
- s.setAttributeNodeNS(att);
- }
while (fi) { //子ノードを検索して、子供がいれば、importNodeメソッドを再帰的に実行する
n = s.importNode(fi, true);
tar.appendChild(n);