svnno****@sourc*****
svnno****@sourc*****
2010年 12月 7日 (火) 23:22:58 JST
Revision: 2213
http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2213
Author: dhrname
Date: 2010-12-07 23:22:58 +0900 (Tue, 07 Dec 2010)
Log Message:
-----------
SVG Font関連の関数NAIBU._fontなどを追加
Modified Paths:
--------------
branches/06x/066/org/w3c/dom/svg.js
Modified: branches/06x/066/org/w3c/dom/svg.js
===================================================================
--- branches/06x/066/org/w3c/dom/svg.js 2010-12-07 14:19:50 UTC (rev 2212)
+++ branches/06x/066/org/w3c/dom/svg.js 2010-12-07 14:22:58 UTC (rev 2213)
@@ -5361,6 +5361,108 @@
pattern: SVGPatternElement
};
+/*_font関数は、SVGFontで使う*/
+NAIBU._font = function (data) {
+ if (!!data.success) {
+ var doc = data.document;
+ //getElementByIdは使えないので注意(DOMParserを使った場合、DTDでの指定が必要)
+ var font = doc.getElementsByTagNameNS(NAIBU.svgNameSpace, "font").item(0);
+ var familyName = font.getElementsByTagNameNS(NAIBU.svgNameSpace, "font-face").item(0).getAttributeNS(null, "font-family");
+ if (familyName && font.getAttributeNS(null, "id") === data.obj[0].id) {
+ var textElements = data.obj[0].docu.getElementsByTagNameNS(NAIBU.svgNameSpace, "text");
+ for (var i=0,tli=textElements.length;i<tli;++i) {
+ var ti = textElements[i], style = data.obj[0].docu.defaultView.getComputedStyle(ti, '');
+ if (style.fontFamily.indexOf(familyName) > -1) {
+ NAIBU._noie_createFont(ti, font);
+ }
+ }
+ }
+ doc = data = null;
+ NAIBU.STObject.readSvgFont();
+ }
+};
+NAIBU._noie_createFont = function(/*Element*/ ti, /*Element*/ font) {
+ var style = ti.ownerDocument.defaultView.getComputedStyle(ti, '');
+ //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(NAIBU.svgNameSpace, "glyph");
+ var em = parseFloat(font.getElementsByTagNameNS(NAIBU.svgNameSpace, "font-face").item(0).getAttribute("units-per-em") || 0);
+ var advX = parseFloat( (font.getAttributeNS(null, horizOrVert) || em) ); //字幅の設定
+ var dx = parseFloat(ti.getAttributeNS(null, "x") || 0), fontSize = parseFloat(style.fontSize), dy = parseFloat(ti.getAttributeNS(null, "y") || 0), fe = fontSize / em;
+ var ds = false, npdlist = NAIBU.PaintColor.prototype.defaultsList;
+ if (/a/[-1] === 'a') { //Firefoxならば
+ ds = true;
+ } else {
+ if (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(NAIBU.svgNameSpace, "path");
+ //advance、すなわち字幅の長さ分、ずらしていく
+ var matrix = new Matrix(fe, 0, 0, -fe, 0, 0);
+ for (var j=0;j<npdlist.length;++j){
+ var nj = npdlist[j].replace(/(fill|stroke)(\w)/, "$1-$2");
+ path.setAttributeNS(null, nj, ti.getAttributeNS(null, nj));
+ }
+ 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);
+ }
+ node = node.nextSibling;
+ }
+ ti.style.opacity = "0";
+ }
+ data = isTategaki = horizOrVert = em = advX = dx = dy = fontSize = style = null;
+};
+
/*以下は、getComputedStyleメソッドで使うために、CSS2Propertiesの_listプロパティに、
*CSSprimitiveValueのリストを収納している。なお、その際に、writingModeなどはwriting-modeに変更している
*/