svnno****@sourc*****
svnno****@sourc*****
2010年 12月 24日 (金) 23:09:16 JST
Revision: 2242 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2242 Author: dhrname Date: 2010-12-24 23:09:16 +0900 (Fri, 24 Dec 2010) Log Message: ----------- 0.66のモジュール結合 Modified Paths: -------------- branches/06x/sie.js Modified: branches/06x/sie.js =================================================================== --- branches/06x/sie.js 2010-12-24 11:23:38 UTC (rev 2241) +++ branches/06x/sie.js 2010-12-24 14:09:16 UTC (rev 2242) @@ -28,7 +28,7 @@ * respective copyright-holders): * layout/svg/renderer/src/libart/nsSVGLibartBPathBuilder.cpp * - * Contributor(s):DHRNAME revulo + * Contributor(s):DHRNAME revulo bellbind * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -82,17 +82,17 @@ this.code = n; var s = [ "", //数合わせのため - "Index Size Error (入力値が大きすぎるか、マイナスの値ではありませんか)", - "DOMString Size Error (テキストの指定範囲が文字数を超えていませんか)", - "Hierarchy Request Error (先祖ノードを子ノードとして付け加えることができないようです)", - "Wrong Document Error (ノードがどこのドキュメントノードに属しているかお確かめください)", - "Invalid Character Error (入力された文字列に認識できない記号を使っているか、文字列が空ではないでしょうか)", + "Index Size Error", + "DOMString Size Error", + "Hierarchy Request Error", + "Wrong Document Error", + "Invalid Character Error", "No Data Allowed Error", "No Modification Allowed Error", - "Not Found Error (お探しになっているノードが見つかりませんでした)", + "Not Found Error", "Not Supported Error", - "Inuse Attribute Error (その属性ノードはすでに他の要素へ属していないでしょうか)", - "Invalid State Error (仕様や注意事項をよくお読みの上、正しくお使いください)", + "Inuse Attribute Error", + "Invalid State Error", "Syntax Error", "Invalid Modification Error", "Namespace Error", @@ -2488,11 +2488,11 @@ function SVGException(code) { /*unsigned short*/ this.code = code; if (this.code === SVGException.SVG_WRONG_TYPE_ERR) { - this.message = "SVG Wrong Type Error (SVGの型が一致しないのではないでしょうか)"; + this.message = "SVG Wrong Type Error"; } else if (this.code === SVGException.SVG_INVALID_VALUE_ERR) { - this.message = "SVG Invalid Value Error (SVGに認識できない数値が使われていませんか)"; + this.message = "SVG Invalid Value Error"; } else if (this.code === SVGException.SVG_MATRIX_NOT_INVERTABLE) { - this.message = "SVG Matrix Not Invertable (SVGで指定された逆行列ができるかどうかお確かめください)"; + this.message = "SVG Matrix Not Invertable"; } return this; }; @@ -2528,7 +2528,6 @@ var name = evt.attrName, tar = evt.target; if (!!CSS2Properties[name] || name.indexOf("-") > -1) { //スタイルシートのプロパティならば tar._attributeStyle.setProperty(name, evt.newValue, ""); - tar._currentStyle = null; //キャッシュは消しておく } if (evt.relatedNode.localName === "id") { //xml:idあるいはid属性ならば tar.id = evt.newValue; @@ -2592,7 +2591,6 @@ } a = sc = null; } - tar._currentStyle = null; } else if (name === "class") { tar.className = evt.newValue; } else if (name.indexOf("on") === 0) { //event属性ならば @@ -2821,11 +2819,12 @@ throw (new DOMException(DOMException.INDEX_SIZE_ERR)); } else { this._list.splice(index, 1); + --this.numberOfItems; } return newItem; }, /*DOMString*/ appendItem : function(/*DOMString*/ newItem ){ - this._list[this._list.length] = newItem; + this._list[this.numberOfItems] = newItem; ++this.numberOfItems; } }; @@ -3349,12 +3348,11 @@ var doc = new ActiveXObject("MSXML2.DomDocument"); str = xmlhttp.responseText.replace(/!DOCTYPE/,"!--").replace(/(dtd">|\]>)/,"-->"); doc.loadXML(str); + var ele = doc.documentElement; + tar._instance = tar.ownerDocument.importNode(ele, true); if (id) { - var ele = doc.getElementById(id); - } else { - var ele = doc.documentElement; + tar._instance = tar._instance.ownerDocument.getElementById(id); } - tar._instance = tar.ownerDocument.importNode(ele); } else { tar._text = xmlhttp.responseText; } @@ -3368,7 +3366,8 @@ /*IEのメモリリーク対策として、空関数を入力*/ xmlhttp.onreadystatechange = NAIBU.emptyFunction; } - } + }; + xmlhttp.send(null); } } } @@ -3973,7 +3972,7 @@ dcp.coordsize = tview.width+ " " +tview.height; sp.appendChild(dcp); objei.parentNode.insertBefore(sp, objei); - dcp.appendChild(sdt) + dcp.appendChild(sdt); while (fi) { //子ノードを検索して、子供がいれば、importNodeメソッドを再帰的に実行する n = s.importNode(fi, true); tar.appendChild(n); @@ -5048,6 +5047,7 @@ tar._tar.path = dat.join(" "); tar._tar.coordsize = w + " " + h; NAIBU._setPaint(tar, matrix); + delete tar._cacheMatrix, tar._currentStyle; evt = tar = dat = w = h = matrix = tlist = x = y = _parseInt = ma = mb = mc = md = me = mf = vi = isZ = isM = isL = isC = null; }, false); evt = tar = null; @@ -5409,6 +5409,7 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); + delete tar._cacheMatrix, tar._currentStyle; evt = tar = list = dat = ele = vi = null; }, false); evt = tar = null; @@ -5484,6 +5485,7 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); + delete tar._cacheMatrix, tar._currentStyle; evt = tar = list = dat = ele = null; }, false); evt = tar = null; @@ -5560,6 +5562,7 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); + delete tar._cacheMatrix, tar._currentStyle; evt = ele = tar = dat = list = ctm = w = h = null; }, false); evt = tar = null; @@ -5633,7 +5636,8 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); - evt = ele = tar = dat = list = ctm = w = h = null; + delete tar._cacheMatrix, tar._currentStyle; + evt = ele = tar = dat = list = ctm = w = h = null; }, false); evt = tar = null; }, false); @@ -5714,6 +5718,7 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); + delete tar._cacheMatrix, tar._currentStyle; evt = ele = tar = dat = list = ctm = w = h = null; }, false); evt = tar = null; @@ -5795,6 +5800,7 @@ ele.path = dat; ele.coordsize = w + " " + h; NAIBU._setPaint(tar, ctm); + delete tar._cacheMatrix, tar._currentStyle; evt = ele = tar = dat = list = ctm = w = h = null; }, false); evt = tar = null; @@ -5823,6 +5829,7 @@ tar._tars = []; var data = tar.data.replace(/^\s+/, "").replace(/\s+$/, ""); tar.data = data; + data = data.split(''); for (var i=0, tdli=data.length;i<tdli;++i) { var d = document.createElement("div"), dstyle = d.style; dstyle.position = "absolute"; @@ -5830,7 +5837,7 @@ dstyle.paddingTop = dstyle.paddingLeft = "0px"; dstyle.whiteSpace = "nowrap"; dstyle.textIndent = "0px"; - d.appendChild(document.createTextNode(data.charAt(i))); + d.appendChild(document.createTextNode(data[i])); tar._tars[tar._tars.length] = d; } data = null; @@ -6243,6 +6250,7 @@ backr.filled = "false"; ttp.appendChild(backr); } + delete tar._cacheMatrix, tar._currentStyle; isRect = evt = tar = style = null; }, false); evt = tar = null; @@ -7552,11 +7560,34 @@ SVGExternalResourcesRequired, SVGStylable*/ { SVGElement.apply(this); - this.addEventListener("SVGLoad", function(evt){ - var tar = evt.target, ctar = evt.currentTarget; - ctar._instance = tar._instance; - evt = tar = ctar = null; - }, true); + /*_isExternalは外部から呼び出されたfont要素ならば、真(1)となる*/ + /*boolean or number*/ this._isExternal = 0; + this.addEventListener("DOMNodeInserted", function(evt){ + var tar = evt.target; + if (evt.eventPhase === Event.BUBBLING_PHASE) { + return; + } + tar.addEventListener("DOMNodeInsertedIntoDocument", function(evt){ + var tar = evt.target, svgns = "http://www.w3.org/2000/svg", fontFace = tar.getElementsByTagNameNS(svgns, "font-face").item(0); + var nefunc = function(evt){ + var svg = evt.target; + /*以下のtarはfont要素*/ + var familyName = fontFace.getAttributeNS(null, "font-family"); + var textElements = tar.ownerDocument.getElementsByTagNameNS(svgns, "text"); + for (var i=0,_tar=tar,tli=textElements.length;i<tli;++i) { + var ti = textElements[i], style = _tar.ownerDocument.defaultView.getComputedStyle(ti, ''); + if (style.getPropertyValue("font-family", null).indexOf(familyName) > -1) { + NAIBU._noie_createFont(ti, _tar, true); + } + } + evt = tar = svg = curt = textElments = svgns = _tar = null; + }; + if (!fontFace.__isLinked || tar._isExternal) { + tar.ownerDocument.documentElement._svgload_limited = 0; + tar.ownerDocument.documentElement.addEventListener("SVGLoad", nefunc, false); + } + }, false); + }, false); return this; }; SVGFontElement.constructor = SVGElement; @@ -7596,6 +7627,15 @@ function SVGFontFaceElement() { SVGElement.apply(this); + /*boolean(or number)*/ this._isLinked = 0; + this.addEventListener("DOMNodeInserted", function(evt){ + if (evt.eventPhase === Event.BUBBLING_PHASE) { + if (evt.target.localName === "font-face-uri") { //外部リンクがあれば + evt.currentTarget._isLinked = 1; + } + return; //強制終了させる + } + }, false); return this; }; SVGFontFaceElement.constructor = SVGElement; @@ -7616,6 +7656,15 @@ } evt.target.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:show", "embed"); }, false); + this.addEventListener("SVGLoad", function(evt){ + var tar = evt.target, tpp = tar.parentNode.parentNode.parentNode; + if (tpp.localName === "defs") { + tpp = tar.parentNode.parentNode; //tppをfont-face要素としておく + } + tar._instance._isExternal = 1; + tpp.parentNode.appendChild(tar._instance); + evt = tar = tpp = null; + }, false); SVGURIReference.apply(this); return this; }; @@ -7735,6 +7784,147 @@ pattern: SVGPatternElement }; +NAIBU._fontSearchURI = function(evt){ + var doc = evt.target.ownerDocument; + var tsrc = doc.getElementsByTagNameNS("http://www.w3.org/2000/svg", "font-face-uri"); + for (var i=0;i<tsrc.length;++i) { + var src = tsrc[i].getAttributeNS("http://www.w3.org/1999/xlink", "href"); + var ids = src.substring(src.indexOf("#")+1, src.length); + var xmlhttp = NAIBU.xmlhttp; + xmlhttp.open("GET", src.replace(/#.+$/, ""), true); + xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xmlhttp.onreadystatechange = function() { + if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) { + var doce = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml"); + NAIBU._font({document:doce, docu:doc, id:ids}); + xmlhttp = doc = doce = null; + } + }; + xmlhttp.send(null); + } +}; +/*_font関数は、SVGFontで使う*/ +NAIBU._font = function (data) { + var doc = data.document, svgns = "http://www.w3.org/2000/svg"; + //getElementByIdは使えないので注意(DOMParserを使った場合、DTDでの指定が必要) + var font = doc.getElementsByTagNameNS(svgns, "font").item(0); + var familyName = font.getElementsByTagNameNS(svgns, "font-face").item(0).getAttributeNS(null, "font-family"); + if (familyName && (font.getAttributeNS(null, "id") === data.id)) { + var textElements = data.docu.getElementsByTagNameNS(svgns, "text"); + for (var i=0,tli=textElements.length;i<tli;++i) { + var ti = textElements[i], style = data.docu.defaultView.getComputedStyle(ti, ''); + if (style.getPropertyValue("font-family", null).indexOf(familyName) > -1) { + NAIBU._noie_createFont(ti, font, false); + } + } + } + doc = data = null; +}; +NAIBU._noie_createFont = function(/*Element*/ ti, /*Element*/ font, /*boolean*/ isMSIE) { + var style = ti.ownerDocument.defaultView.getComputedStyle(ti, ''), svgns = "http://www.w3.org/2000/svg"; + //isTategakiは縦書きならば真 + var isTategaki = ti.getAttributeNS(null, "writing-mode") || ti.parentNode.getAttributeNS(null, "writing-mode"), horizOrVert = isTategaki ? "vert-adv-y" : "horiz-adv-x"; + var node = ti.firstChild, data, glyphs = font.getElementsByTagNameNS(svgns, "glyph"); + var em = parseFloat(font.getElementsByTagNameNS(svgns, "font-face").item(0).getAttribute("units-per-em") || 1000); + var advX = parseFloat( (font.getAttributeNS(null, horizOrVert) || em) ); //字幅の設定 + var dx = parseFloat(ti.getAttributeNS(null, "x") || 0), fontSize = parseFloat(style.getPropertyValue("font-size")), dy = parseFloat(ti.getAttributeNS(null, "y") || 0), fe = fontSize / em; + var ds = false, npdlist = ["fill", + "fill-opacity", + "stroke", + "stroke-width", + "stroke-linecap", + "stroke-linejoin", + "stroke-miterlimit", + "stroke-dasharray", + "stroke-opacity", + "opacity", + "cursor"]; + if (isMSIE) { + /*IEのみ、font-sizeは自動で調整されているものを使った方がよい*/ + fontSize = parseFloat(ti._tar.currentStyle.fontSize); + fe = fontSize / em; + } + if (/a/[-1] === 'a') { //Firefoxならば + ds = true; + } else if (isMSIE || isTategaki) { + ds = true; + } + if (ds){ + while(node) { + data = node.data; + if (data !== void 0) { //dataがある場合 + var advanceX = [], glyphData = []; + for (var i=0,gli=glyphs.length;i<gli;++i) { + var glyph = glyphs[i], unicode = glyph.getAttributeNS(null, "unicode") || "なし"; //unicode属性に指定がない場合、処理させないようにする + var orientation = glyph.getAttributeNS(null, "orientation"), isVert = true, isOrientationAttribute = true; + if (orientation) { + if (orientation === "h") { + isVert = false; + } + } else { + isOrientationAttribute = false; + } + if ( (isTategaki && isVert) || !(isTategaki || isVert) || !isOrientationAttribute){ + //indexは該当する文字が何番目にあるかの数字 + var index = data.indexOf(unicode); + while (index > -1) { + advanceX[index] = parseFloat(glyph.getAttributeNS(null, horizOrVert) || advX); //字幅を収納 + glyphData[index] = glyph.getAttributeNS(null, "d"); + index = data.indexOf(unicode, index+1); + } + } + } + for (var i=0,adv=0;i<data.length;++i) { + if (advanceX[i] !== void 0) { //配列に含まれていれば + var path = ti.ownerDocument.createElementNS(svgns, "path"); + //advance、すなわち字幅の長さ分、ずらしていく + var matrix = ti.ownerDocument.documentElement.createSVGMatrix(); + matrix.a = fe; + matrix.d = -fe; + for (var j=0;j<npdlist.length;++j){ + var nj = npdlist[j], tg = ti.getAttributeNS(null, nj); + if (tg) { + path.setAttributeNS(null, nj, tg); + } + } + if (isTategaki) { + var y= dy + adv*fe, x = dx; + if ("、。".indexOf(data.charAt(i)) > -1) { //句読点の場合 + var fms = fontSize / Math.SQRT2; + x += fms; + y -= fms; + fms = null; + } + matrix.e = x; + matrix.f = y; + } else { + matrix.e = dx + adv*fe; + matrix.f = dy; + } + path.setAttributeNS(null, "transform", "matrix(" +matrix.a+ "," +matrix.b+ "," +matrix.c+ "," +matrix.d+ "," +matrix.e+ "," +matrix.f+ ")"); + path.setAttributeNS(null, "d", glyphData[i]); + ti.parentNode.insertBefore(path, ti); + adv += advanceX[i]; + matrix = null; + } + } + adv = advanceX = glyphData = null; + } else { + NAIBU._noie_createFont(node, font, isMSIE); + } + node = node.nextSibling; + } + if (isMSIE) { + var style = ti.ownerDocument.getOverrideStyle(ti, null); + style.setProperty("display", "none"); + style = null; + } else { + ti.setAttributeNS(null, "opacity", "0"); + } + } + data = isTategaki = horizOrVert = em = advX = dx = dy = fontSize = style = svgns = null; +}; + /*以下は、getComputedStyleメソッドで使うために、CSS2Propertiesの_listプロパティに、 *CSSprimitiveValueのリストを収納している。なお、その際に、writingModeなどはwriting-modeに変更している */ @@ -7773,16 +7963,17 @@ lis(); } }; + function unsvgtovml() { try { if ("stop" in NAIBU) { clearInterval(NAIBU.stop); } - window.dettachEvent("onload", NAIBU._main); window.onscroll = NAIBU.emptyFunction; + window.detachEvent("onload", NAIBU._main); Element = SVGElement = Attr = NamedNodeMap = CSS2Properties = CSSValue = CSSPrimitiveValue = NAIBU.xmlhttp = Node = Event = NAIBU = stlog = STLog = document = null; Array = ActiveXObject = null; - } catch(e) {} + } catch(e) {console.log(e.message);} } /*_main関数 *一番最初に起動するべき関数 @@ -7861,8 +8052,8 @@ oba.setAttribute("id","_NAIBU_outline"); document.body.appendChild(oba); var ob = document.getElementsByTagName("object"), em = document.getElementsByTagName("embed"); - var i = 0; - for (s=[];i<ob.length;++i) { + var i = 0, s=[]; + for (;i<ob.length;++i) { s[s.length] = new GetSVGDocument(ob[i]); } for (i=0;i<em.length;++i) { @@ -7878,6 +8069,16 @@ } s = null; } + } else { + var ob = document.getElementsByTagName("object"); + for (var i=0;i<ob.length;++i) { + if (ob[i].contentDocument) { + NAIBU._fontSearchURI({target:{ownerDocument:ob[i].contentDocument}}); + } else if (ob[i].getSVGDocument) { + ob[i].getSVGDocument().documentElement.addEventListener("SVGLoad", NAIBU._fontSearchURI, false); + } else { + } + } } xmlhttp = null; });