X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=org%2Fw3c%2Fdom%2Fsvg.js;h=7dc35d744a316e7b9324ae105b5142a2a444a40c;hb=84e6e8c2dadcfd0595dfbd142e4fe1dd6e419035;hp=8e8d3c35a8576079ba7d7678349a4b331e0d4a0a;hpb=c7d1c6a2718ebaa3e5ee430e6ebf7630a8c8df7e;p=sie%2Fsie.git diff --git a/org/w3c/dom/svg.js b/org/w3c/dom/svg.js index 8e8d3c3..7dc35d7 100644 --- a/org/w3c/dom/svg.js +++ b/org/w3c/dom/svg.js @@ -1932,7 +1932,7 @@ function _ca_() { NAIBU._buff = setInterval(function(){ var n = NAIBU._buff_num, dbuf = DOMImplementation._buffer_, - dbufli = dbuf.length, + dbufli = dbuf ? dbuf.length : 0, //極端な負荷がかかると、dbufはnullになる可能性あり s, evt; if (dbufli === 0) { clearInterval(NAIBU._buff); @@ -2535,10 +2535,10 @@ for (var prop in SVGStringList.prototype) { //prototypeのコピーで継承を }; /*documentは引数の変数として登録しておく*/ -(function(_doc, _pInt, _math) { +(function(_doc, _math) { //freeArg関数はunloadで使う解放処理 NAIBU.freeArg = function() { - SVGPathElement = _doc = _pInt = _math = void 0; + SVGPathElement = _doc = _math = void 0; }; //仮のfill属性とstroke属性の処理 NAIBU._setPaint = function(tar, matrix) { @@ -3022,11 +3022,11 @@ _sproto._nodeInsertInto = function(evt){ var tar = evt.target, matrix = tar.getScreenCTM(), tlist = tar.normalizedPathSegList, - _parseInt = _pInt, dat = [], ma = matrix.a, mb = matrix.b, mc = matrix.c, md = matrix.d, me = matrix.e, mf = matrix.f, cname = tar._com._nameCom, - isZ = tar._com._isZ, isC = tar._com._isC; + isZ = tar._com._isZ, isC = tar._com._isC, + mr = _math.round; for (var i=0, tli=tlist.numberOfItems;i j) ? i - j : j - i - var sty = ti._tars[ij].style, - p = tar.getStartPositionOfChar(i); - sty.position = "absolute"; - if (tar._isYokogaki) { - if (anchor === "middle") { - p.x -= tlen / 2; - } else if (anchor === "end") { - p.x -= tlen; - } - } else { - if (anchor === "middle") { - p.y -= tlen / 2; - } else if (anchor === "end") { - p.y -= tlen; - } - } - sty.left = p.x + "px"; - sty.top = p.y + "px"; - sty.width = "0px"; - sty.height = "0px"; - sty.marginTop = tar._isYokogaki ? -n-5+ "px" : "-5px"; - sty.lineHeight = n+10+ "px"; - sty.textDecoration = tedeco; - sty.display = "none" - ttp.appendChild(ti._tars[ij]); - sty = p = void 0; + tar.addEventListener("DOMNodeInsertedIntoDocument", tar._texto, false); + evt = tar = void 0; + },false); + return this; +}; +SVGTextPositioningElement.constructor = SVGTextContentElement; +SVGTextPositioningElement.prototype = new SVGTextContentElement(); +SVGTextPositioningElement.prototype._texto = function(evt) { + var tar = evt.target, + ti = tar.firstChild, + ttp = tar._tar, + style = tar.ownerDocument.defaultView.getComputedStyle(tar, null), + n = parseFloat(style.getPropertyValue("font-size")) * Math.sqrt(Math.abs(tar.getScreenCTM()._determinant())), + tod = tar.ownerDocument.documentElement, + ttpc = ttp, //ttpcはttpのキャッシュ + tlen = tar.getComputedTextLength(), + anchor = style.getPropertyValue("text-anchor"), + tedeco = style.getPropertyValue("text-decoration"), //text-decorationは継承しないので、個々に設定する + ttps = ttp.style, + ae = []; + ttps.fontSize = n + "px"; + ttps.fontFamily = style.getPropertyValue("font-family"); + ttps.fontStyle = style.getPropertyValue("font-style"); + ttps.fontWeight = style.getPropertyValue("font-weight"); + /*ここでの変数jは前回ノードまでの総文字数*/ + for (var i=0, j=0, tli=tar.getNumberOfChars();i j) ? i - j : j - i + var sty = ti._tars[ij].style, + p = tar.getStartPositionOfChar(i); + sty.position = "absolute"; + if (tar._isYokogaki) { + if (anchor === "middle") { + p.x -= tlen / 2; + } else if (anchor === "end") { + p.x -= tlen; } - if (ti.nodeName === "#text") { - if ((ti.data.length+j) <= i+1) { //テキストノード内の文字をすべて処理し終えれば - j = j + ti.data.length; - if (ti.parentNode.localName === "a") { - ti = ti.parentNode; - ttp = ttpc; - } - ti = ti.nextSibling; - } - } else if (!!ti.getNumberOfChars) { - if ((ti.getNumberOfChars()+j) <= i+1) { - j = j + ti.getNumberOfChars(); - ti = ti.nextSibling; - } - } else if ((ti.localName === "a") && (ti.namespaceURI === "http://www.w3.org/2000/svg") && ti.firstChild) { - ttp = ti._tar; - ti = ti.firstChild; - ae[ae.length] = ti; - i-=2; + } else { + if (anchor === "middle") { + p.y -= tlen / 2; + } else if (anchor === "end") { + p.y -= tlen; } } + sty.left = p.x + "px"; + sty.top = p.y + "px"; + sty.width = "0px"; + sty.height = "0px"; + sty.marginTop = tar._isYokogaki ? -n-5+ "px" : "-5px"; + sty.lineHeight = n+10+ "px"; + sty.textDecoration = tedeco; + sty.display = "none" + ttp.appendChild(ti._tars[ij]); + sty = p = void 0; } - var color = style.getPropertyValue("fill"), - cursor = style.getPropertyCSSValue("cursor"), - vis = style.getPropertyCSSValue("visibility"), - disp = style.getPropertyCSSValue("display"), - tts = tar._tar.style, - tft = tar.firstChild._tars, //空白のテキストノードの場合、tftがundefinedになる恐れがある - ttt = tft[0] ? tft[0].innerText.charAt(0) : [""], //あらかじめ初期化しておく - tfti; - if (color === "none"){ - tts.color = "transparent"; - } else if (color.indexOf("url") === -1) { - tts.color = color; - } else { - tts.color = "black"; - } - if (cursor && !cursor._isDefault) { //初期値でないならば - var tc = cursor.cssText; - tts.cursor = tc.split(":")[1]; - tc = void 0; - } - if ((tar.x.baseVal.numberOfItems === 1) && (tar.y.baseVal.numberOfItems === 1) - && tar._isYokogaki && (tar.firstChild.nodeName === "#text")) { - /*xとy属性が一つの値しか取らないとき、字詰めの処理をすべてブラウザに任せておく。 - *以下では、他のdiv要素のテキストをすべて、最初のdiv要素にまとめている - */ - for (var i=1, tli=tft.length;i -1)) { - di = "none"; -  } else if (disp && !disp._isDefault) { - di = "block"; - } - var jt = tar._tar.firstChild, - j = 0; - while (jt) { - jt.style.display = di; - jt = jt.nextSibling; - } - while (ae[j]) { //要素内部にあるa要素の処理 - for (var l=0, tli=ae[j]._tars.length;l -1)) { + di = "none"; +  } else if (disp && !disp._isDefault) { + di = "block"; + } + var jt = tar._tar.firstChild, + j = 0; + while (jt) { + jt.style.display = di; + jt = jt.nextSibling; + } + while (ae[j]) { //要素内部にあるa要素の処理 + for (var l=0, tli=ae[j]._tars.length;l (end - begin)) ? tar._getOffset(td) : (end - begin); + } + } else if (durv && !td && !tc && !endv) { + ac = dur; + } else if (durv && !td && tc && !endv) { + ac = dur * (+tc); + } else if (durv && td && !tc && !endv) { + ac = tar._getOffset(td); + } else if (durv && !td && !tc && endv) { + ac = (dur > (end - begin)) ? dur : (end - begin); + } else if (durv && td && tc && !endv) { + ac = (+tc*dur > tar._getOffset(td)) ? +tc*dur : tar._getOffset(td); + } else if (durv && td && tc && endv) { + ac = (+tc*dur > Math.min(+td, (end-begin))) ? +tc*dur : Math.min(tar._getOffset(td), (end - begin)); + } else if (durv && td && !tc && endv) { + ac = (tar._getOffset(td) > (end - begin)) ? tar._getOffset(td) : (end - begin); + } else if (durv && !td && tc && endv) { + ac = (+tc*dur > (end - begin)) ? +tc*dur : (end - begin) } + } catch (e) { + throw new DOMException(DOMException.INVALID_STATE_ERR); } + tar.endElementAt(active); }, false); this.addEventListener("DOMAttrModified", function(evt){ if (evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) { return; } - var tar = evt.target, name = evt.attrName; + var tar = evt.target, + name = evt.attrName, + evtv = evt.newValue; if (name === "begin") { - tar._beginValue = evt.newValue; + tar._begin = evtv; } else if (name === "end") { - tar._endValue = evt.newValue; + tar._end = evtv; } else if (name === "dur") { - tar._simpleDuration = tar._getOffset(evt.newValue); + tar._dur = evtv; } else if (name === "repeatCount") { - tar._maxCount = parseFloat(evt.newValue); + tar._maxCount = parseFloat(evtv); + tar._repeatCount = evtv; tar._isRepeat = true; } else if (name === "repeatDur") { - tar._maxDur = parseFloat(evt.newValue); + tar._maxDur = parseFloat(evtv); + tar._repeatCount = evtv; tar._isRepeat = true; } else if (name === "from") { - tar._from = evt.newValue; + tar._from = evtv; } else if (name === "to") { - tar._to = evt.newValue; + tar._to = evtv; } else if (name === "values") { - tar._values = evt.newValue.split(";"); + tar._values = evtv.split(";"); } else if (name === "by") { - tar._by = evt.newValue; + tar._by = evtv; } else if (name === "keyTimes") { - var s = evt.newValue.split(";"); + var s = evtv.split(";"); tar._keyTimes = []; //_keyTimesプロパティを初期化 for (var i=0;i 0) && (/[a-z]/i).test(val.charAt(n+1))) { //. (dot)の後がアルファベットならば + return (val.slice(0, n)); + } + n = nn = void 0; + return ""; + }, + id; + /* + *W3CのSMIl AnimationのTimingモデルは7パターンがあるので、場合分けする + */ + if (isFinite(parseFloat(val))) { //1) offset-valueの場合 + that[name](offset); + } else if (val.indexOf("repeat(") > -1) { //2) repeat-valueの場合 + var inte = parseFloat(val.slice(7)), + ds = function (evt) { + if (inte === evt.target._numRepeat) { + that[name](offset); + } + }; + id = searchId(); + if (id) { + that.ownerDocument.getElementById(id).addEventListener("repeatEvent", ds); + } else { + that.addEventListener("repeatEvent", ds); + } + } else if ((/\.(begin|end)/).test(val)) { //3) syncbase-valueの場合 + id = searchId(); + if (id) { + var ds = function (evt) { + that[name](offset); + }, + ev = ""; + if (RegExp.$1 === "begin") { + ev = "beginEvent"; + } else if (RegExp.$1 === "end") { + ev = "endEvent"; + } + that.ownerDocument.getElementById(id).addEventListener(ev, ds); + } + } else if (val.indexOf("wallclock(") === 0) { //4) wallclock-valueの場合 + + } else if (val === "indefinte") { //5) indefinteの場合 + } else if (val.indexOf("accesskey(") > -1) { //6) accesskey-valueの場合 + + } else { //7) event-valueの場合 + id = searchId(); + var ds = function (evt) { + that[name](offset); + }; + if (id && val.match(/\.([a-z]+)/i)) { + that.ownerDocument.getElementById(id).addEventListener(RegExp.$1, ds); + } else if (val){ + that.targetElement.addEventListener(val.match(/^[a-z]+/i)[0], ds) + } + } + val = searchId = id = void 0; + }; + timing((tar._begin || "0ms"), "beginElementAt", _begin); + if (tar._end) { + timing(tar._end, "endElementAt", tar._getOffset(tar._end)); + } + that = void 0; 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; } - 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], - function(){ - te.endElementAt(offse); - }, false ); - }), "endElementAt"); - } evt = tar = void 0; }, false); evt = tar = void 0; }, false); - this.addEventListener("repeatEvent", function(evt) { - var tar = evt.target; - if ((tar._currentCount >= tar._maxCount) || (tar.getCurrentTime() >= (tar._maxDur+tar.getStartTime()))) { - tar._isRepeat = false; - } - }, false); return this; }; SVGAnimationElement.constructor = SVGElement; @@ -5216,14 +5323,14 @@ SVGAnimationElement.prototype = new SVGElement(); }; /*void*/ SVGAnimationElement.prototype.beginElementAt = function(/*float*/ offset) { var ntc = this.ownerDocument.documentElement.getCurrentTime(); - this._begin = offset + ntc; + this._start = offset + ntc; }; /*void*/ SVGAnimationElement.prototype.endElementAt = function(/*float*/ offset) { var ntc = this.ownerDocument.documentElement.getCurrentTime(); - this._end = offset + ntc; + this._finish = offset + ntc; }; SVGAnimationElement.prototype._eventRegExp = /(mouse|activ|clic|begi|en)[a-z]+/; -SVGAnimationElement.prototype._timeRegExp = /[\-\d\.]+(h|min|s|ms)?/; +SVGAnimationElement.prototype._timeRegExp = /[\-\d\.]+(h|min|s|ms)?$/; SVGAnimationElement.prototype._unit = { "h" : 2880000, "min" : 48000, @@ -5239,43 +5346,20 @@ SVGAnimationElement.prototype._unit = { ** Note that when the simple duration is "indefinite", some simple use cases can yield surprising results. See the related example #4 in Appendix B. */ SVGAnimationElement.prototype._getOffset = function(/*string*/ t) { - var n = parseFloat(t.match(this._timeRegExp)); - if (!isNaN(n) && RegExp.$1) { + var n = parseFloat(t.match(this._timeRegExp)), + offset = 0; + if (isFinite(n) && RegExp.$1) { var offset = n * this._unit[RegExp.$1] - } else if (!isNaN(n)) { - var offset = n; - } else { - var offset = 0; + } else if (isFinite(n)) { + offset = n; } n = t = void 0; return offset; }; -/*_eventSyncメソッド - *イベントがある場合とない場合とで、別々の処理に分けるメソッド - */ -SVGAnimationElement.prototype._eventSync = function(/*string*/ t, /*function*/ f, /*string*/ methodName) { - var offset = this._getOffset(t); - this._begin = NAIBU.Time.Max; - if ( /(mouse|activ|click|begin|end)/.test(t) ) { //イベントがある場合 - var tar; - if ( /([^;]+)\.\D/.test(t) ) { - tar = this.ownerDocument.getElementById(RegExp.$1); - } else { - tar = this.targetElement; - } - if (!offset && offset !== 0) { - offset = NAIBU.Time.Max; - } - f(this, offset, tar, t); - } else if (!offset && (t !== "undefined") && (offset !== 0)) { - this._begin = 0; - } else { - this[methodName](offset); - } -}; + /*float*/ SVGAnimationElement.prototype.getStartTime = function(){ - if (!!this._begin || (this._begin === 0)) { - return (this._begin); + if (this._start || (this._start === 0)) { + return (this._start); } else { throw new DOMException(DOMException.INVALID_STATE_ERR); } @@ -5288,14 +5372,11 @@ SVGAnimationElement.prototype._eventSync = function(/*string*/ t, /*function*/ f return (this._currentFrame * 125 * 0.8); }; /*float*/ SVGAnimationElement.prototype.getSimpleDuration = function(){ - if (!!!this._simpleDuration && !!!this._end && (this._simpleDuration !== 0)) { + if (!this._dur && !this._finish && (this._dur === "indefinte")) { throw new DOMException(DOMException.NOT_SUPPORTED_ERR); - } else if (!!this._simpleDuration && !!this._end) { - var s = (this._simpleDuration > this._end - this._begin) ? this._end - this._begin : this._simpleDuration; } else { - var s = !!this._end ? this._end - this._begin : this._simpleDuration; + return (this._getOffset(this._dur)); } - return s; }; //raises( DOMException ); NAIBU.Time = { @@ -5310,34 +5391,40 @@ NAIBU.Time = { } NAIBU.stop = setInterval( (function() { /* try{*/ - var ntc = NAIBU.Time.currentFrame++; - var nc = NAIBU.Clip; - var s = ntc * 100; //フレーム数ntcをミリ秒数sに変換 + var ntc = NAIBU.Time.currentFrame, + nc = NAIBU.Clip, + s = ntc * 100; //フレーム数ntcをミリ秒数sに変換 (100 = 125 * 0.8) if (ntc > NAIBU.Time.Max) { clearInterval(NAIBU.stop); } + nc[0] && nc[0].ownerDocument.documentElement.setCurrentTime(s); for (var i=0,ncli=nc.length;i