[Sie-announce] SIEコード [1423] 0. 54統合

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 11月 20日 (金) 22:04:06 JST


Revision: 1423
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1423
Author:   dhrname
Date:     2009-11-20 22:04:06 +0900 (Fri, 20 Nov 2009)

Log Message:
-----------
0.54統合

Modified Paths:
--------------
    branches/05x/sie.js

Property Changed:
----------------
    branches/05x/sie.js

Modified: branches/05x/sie.js
===================================================================
--- branches/05x/sie.js	2009-11-20 12:57:49 UTC (rev 1422)
+++ branches/05x/sie.js	2009-11-20 13:04:06 UTC (rev 1423)
@@ -94,8 +94,8 @@
   } else {
     if (/a/[-1] === 'a'){ //Firefoxだったらtrueを返す
       NAIBU.STObject.ffnext();
-      _noie_svgfont();
     }
+    _noie_svgfont();
   }
 }
 //他のページに移動する際に起動
@@ -149,7 +149,11 @@
 //SVGtoVML 本体。SVGDocumentの代わりを担う
 //object要素の幅と高さがwとh(単位はpxに統一)。svg要素の幅と高さがswi.valueとshi.value。svg要素にwidth属性が指定されていない場合、swi.value=wである。
 function SVGtoVML( /*element*/ obc, /*float*/ w, /*float*/ h, /*STLength*/ swi, /*STLength*/ shi) {
-  this.rootElement = obc; this.w = w; this.h = h; this.swi = swi; this.shi = shi;
+  this.rootElement = obc;
+  this.w = w;
+  this.h = h;
+  this.swi = swi;
+  this.shi = shi;
   return this;
 }
 SVGtoVML.prototype.read = function stvread(/*element*/ ob) {
@@ -157,7 +161,7 @@
   this.vi = new STViewSpec(this.rootElement);
   try{
   this.children = []; //子要素
-  var sw = this.swi.value,  sh = this.shi.value;
+  var sw = this.swi.value, sh = this.shi.value;
   this.getObject("USE", STUseElement, "use", sw, sh); //use要素を先に処理
   var mat = this.vi.set(sw, sh, ob); //返り値はMatrix型
   this.chset(this.rootElement, mat, sw, sh);
@@ -347,19 +351,19 @@
 //g要素の処理
 function STGroupElement( /*element*/ g, /*Matrix*/ matrix, /*float*/w, h) {
   try{
-  this.tar = g;
-  this.transformable = NAIBU.transformToCTM(g,matrix); //g要素のtransform属性を前もって処理
-  //以下、ツリーとして処理
-  this.children = [];
-  this.chset(g,this.transformable, w, h);
-  w = h = null;
+    this.tar = g;
+    this.transformable = NAIBU.transformToCTM(g,matrix); //g要素のtransform属性を前もって処理
+    //以下、ツリーとして処理
+    this.children = [];
+    this.chset(g,this.transformable, w, h);
+    w = h = null;
   } catch(e){stlog.add(e,3144);}
   return this;
 }
 STGroupElement.prototype.set = function (sw,sh) {
   try{
-  stvsetob(this.children,sw,sh);
-  this.children = this.transformable = null;
+    stvsetob(this.children,sw,sh);
+    this.children = this.transformable = null;
   } catch(e){stlog.addd(e,3145);}
 };
 STGroupElement.prototype.chset = SVGtoVML.prototype.chset;
@@ -411,6 +415,10 @@
 STText.prototype.set = function textset( /*float*/ w, /*float*/ h) {
   try {
   var ttm = this.transformable;
+  var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+  if (this.x._emToUnits(fontSize)) {
+    this.y._emToUnits(fontSize);
+  }
   var p = new Point(this.x.value,this.y.value);
   var ptm = p.matrixTransform(ttm);
   this.tar.w = w;
@@ -536,6 +544,11 @@
 STLine.prototype.set = function lineset(w,h) {
   try {
     var ttm = this.transformable;
+    var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+    if (this.x1._emToUnits(fontSize) || this.x2._emToUnits(fontSize)) {
+      this.y1._emToUnits(fontSize);
+      this.y2._emToUnits(fontSize);
+    }
     var list = ["m", this.x1.value, this.y1.value, "l", this.x2.value, this.y2.value];
     var pl = new PList(list);
     var plm = pl.matrixTransform(ttm);
@@ -686,9 +699,11 @@
     skip = 4;
   }
   for (var i = 1, Fli = F.length; i < Fli; i += 2) {
-    F[i] += x; F[i+1] += y;
+    F[i] += x;
+    F[i+1] += y;
     if ((i+1) % skip === 0) {
-      x = F[i]; y = F[i+1];
+      x = F[i];
+      y = F[i+1];
     }
   }
   return F;
@@ -761,10 +776,15 @@
 }
 //ベジェ曲線で円を表現する
 STCircle.prototype.set = function ovalset(w,h) {
+  var ttm = this.transformable;
+  var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+  if (this.cx._emToUnits(fontSize)) {
+    this.cy._emToUnits(fontSize);
+    this.r._emToUnits(fontSize);
+  }
   var cx = this.cx.value, cy = this.cy.value, rx = ry = this.r.value;
   var top = cy - ry, left = cx - rx, bottom = cy + ry, right = cx + rx;
   try {
-  var ttm = this.transformable;
   var rrx = rx * 0.55228, rry = ry * 0.55228;
   var list = ["m", cx,top, "c", cx-rrx,top, left,cy-rry, left,cy, left,cy+rry, cx-rrx,bottom, cx,bottom, cx+rrx,bottom, right,cy+rry, right,cy, right,cy-rry, cx+rrx,top, cx,top, "x e"];
   var pl = new PList(list);
@@ -795,10 +815,15 @@
   return this;
 }
 STEllipse.prototype.set = function elliset(w,h) {
+  var ttm = this.transformable;
+  var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+  if (this.cx._emToUnits(fontSize) || this.rx._emToUnits(fontSize)) {
+    this.cy._emToUnits(fontSize);
+    this.ry._emToUnits(fontSize);
+  }
   var cx = this.cx.value, cy = this.cy.value, rx = this.rx.value, ry = this.ry.value;
   var top = cy - ry, left = cx - rx, bottom = cy + ry, right = cx + rx;
   try {
-  var ttm = this.transformable;
   var rrx = rx * 0.55228, rry = ry * 0.55228;
   var list = ["m", cx,top, "c", cx-rrx,top, left,cy-rry, left,cy, left,cy+rry, cx-rrx,bottom, cx,bottom, cx+rrx,bottom, right,cy+rry, right,cy, right,cy-rry, cx+rrx,top, cx,top, "x e"];
   var pl = new PList(list);
@@ -841,9 +866,18 @@
 }
 STRectElement.prototype.set = function rectset(w,h) {
   try {
+    var ttm = this.transformable;
+    var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+    if (this.x._emToUnits(fontSize) || this.width._emToUnits(fontSize)) {
+      this.y._emToUnits(fontSize);
+      this.height._emToUnits(fontSize);
+    }
     var x = this.x.value, y = this.y.value, xw = x + this.width.value, yh = y + this.height.value;
     var list;
     if (this.rx) {
+      if (this.rx._emToUnits(fontSize)) {
+        this.ry._emToUnits(fontSize);
+      }
       var rx = this.rx.value, ry = this.ry.value;
       var rrx = rx * 0.55228, rry = ry * 0.55228;
       var a = xw - rx, b = x + rx, c = y + ry, d = yh - ry;
@@ -851,7 +885,6 @@
     } else {
       list = ["m",x,y, "l",x,yh, xw,yh, xw,y, "x e"];
     }
-    var ttm = this.transformable;
     var pl = new PList(list);
     var plm = pl.matrixTransform(ttm);
     var dat = plm.list.join(" ");
@@ -861,7 +894,7 @@
     ele.path = dat;
     ele.coordsize = w + " " + h;
     this.paint.set(w, h, ttm);
-    dat = list = pl = plm = this.paint = ttm = this.transformable = w = h = null; //解放
+    dat = list = pl = plm = this.paint = ttm = fontSize = this.transformable = w = h = null; //解放
   } catch(ee) {stlog.add(ee,576);}
 };
 
@@ -882,6 +915,11 @@
 STImage.prototype.set = function imagesets(w,h){
   try {
     var ttm = this.transformable;
+    var fontSize = fontset(this.paint["font-size"], w, h, ttm);
+    if (this.x._emToUnits(fontSize) || this.width._emToUnits(fontSize)) {
+      this.y._emToUnits(fontSize);
+      this.height._emToUnits(fontSize);
+    }
     var ts = this.tar.style;
     ts.position = "absolute";
     var pt = new Point(this.x.value, this.y.value);
@@ -978,7 +1016,8 @@
   strokedasharray: "none",
   strokeopacity: 1,
   opacity: 1,
-  cursor: "default"
+  cursor: "default",
+  "font-size": "12"
 };
 //キャッシュ用
 NAIBU.PaintColor.prototype.cache = {};
@@ -1441,28 +1480,63 @@
       deg = lis.match(NAIBU.degR);
       degli = deg.length;
       if (degli === 6) {
-        a = parseFloat(deg[0]); b = parseFloat(deg[1]); c = parseFloat(deg[2]); d = parseFloat(deg[3]); e = parseFloat(deg[4]); f = parseFloat(deg[5]);
+        a = parseFloat(deg[0]);
+        b = parseFloat(deg[1]);
+        c = parseFloat(deg[2]);
+        d = parseFloat(deg[3]);
+        e = parseFloat(deg[4]);
+        f = parseFloat(deg[5]);
       } else {
         rad = parseFloat(deg[0]) / 180 * Math.PI;
         if (degli === 3) {
           var cx = parseFloat(deg[1]), cy = parseFloat(deg[2]);
-          a = Math.cos(rad); b = Math.sin(rad); c = -b; d = a; e = (1-a)*cx-c*cy; f = -b*cx+(1-d)*cy;
+          a = Math.cos(rad);
+          b = Math.sin(rad);
+          c = -b;
+          d = a;
+          e = (1-a)*cx-c*cy;
+          f = -b*cx+(1-d)*cy;
         } else if (degli <= 2) {
           switch (com) {
           case "translate":
-            a = 1; b = 0; c = 0; d = 1; e = parseFloat(deg[0]); f = parseFloat(deg[1] || 0);
+            a = 1;
+            b = 0;
+            c = 0;
+            d = 1;
+            e = parseFloat(deg[0]);
+            f = parseFloat(deg[1] || 0);
           break;
           case "scale":
-            a = parseFloat(deg[0]); b = 0; c = 0; d = parseFloat(deg[1] || deg[0]); e = 0; f = 0;
+            a = parseFloat(deg[0]);
+            b = 0;
+            c = 0;
+            d = parseFloat(deg[1] || deg[0]);
+            e = 0;
+            f = 0;
           break;
           case "rotate":
-            a = Math.cos(rad); b = Math.sin(rad); c = -b; d = a; e = 0; f = 0;
+            a = Math.cos(rad);
+            b = Math.sin(rad);
+            c = -b;
+            d = a;
+            e = 0;
+            f = 0;
           break;
           case "skewX":
-            a = 1; b = 0; c = Math.tan(rad); d = 1; e = 0; f = 0;
+            a = 1;
+            b = 0;
+            c = Math.tan(rad);
+            d = 1;
+            e = 0;
+            f = 0;
           break;
           case "skewY":
-            a = 1; b = Math.tan(rad); c = 0; d = 1; e = 0; f = 0;
+            a = 1;
+            b = Math.tan(rad);
+            c = 0;
+            d = 1;
+            e = 0;
+            f = 0;
           break;
           }
         }
@@ -1479,7 +1553,8 @@
 
 //SVGPointを参照
 function Point( /*number*/ x, /*number*/ y) {
-  this.x = x; this.y = y;
+  this.x = x;
+  this.y = y;
   return this;
 }
 Point.prototype.matrixTransform = function ( /*Matrix*/ m) {
@@ -1487,7 +1562,7 @@
   var y = parseInt(m.b * this.x + m.d * this.y + m.f);
   if (-1 < x && x < 1) {x=1;}
   if (-1 < y && y < 1) {y=1;}
-  var s = new Point(x,y);
+  var s = new Point(x, y);
   return s;
 };
 
@@ -1515,12 +1590,18 @@
 
 //SVGMatrixを参照。行列
 function Matrix(a,b,c,d,e,f) { //引数はすべてNumber型
-  this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f;
+  this.a = a;
+  this.b = b;
+  this.c = c;
+  this.d = d;
+  this.e = e;
+  this.f = f;
   return this;
 }
 //Matrix同士の積を算出
 Matrix.prototype.multiply = function ( /*Matrix*/ m) {
-  var s = new Matrix(this.a * m.a + this.c * m.b,this.b * m.a + this.d * m.b,this.a * m.c + this.c * m.d,this.b * m.c + this.d * m.d,this.a * m.e + this.c * m.f + this.e,this.b * m.e + this.d * m.f + this.f);
+  var s = new Matrix(this.a * m.a + this.c * m.b, this.b * m.a + this.d * m.b, this.a * m.c + this.c * m.d,
+                     this.b * m.c + this.d * m.d, this.a * m.e + this.c * m.f + this.e, this.b * m.e + this.d * m.f + this.f);
   return s;
 };
 //行列式
@@ -1632,14 +1713,18 @@
 };
 
 //SVGRectを参照
-function STRect(x,y,w,h) { //引数はすべてNumber型
-  this.x = x; this.y = y;
-  this.width = w; this.height = h;
+function STRect(x, y, w, h) { //引数はすべてNumber型
+  this.x = x;
+  this.y = y;
+  this.width = w;
+  this.height = h;
   return this;
 }
 
 //SVGPreserveAspectRatioを参照
-function STPreserveAspectRatio( /*int*/ a, /*int*/ mos) {this.align=a;this.meetOrSlice=mos;
+function STPreserveAspectRatio( /*int*/ a, /*int*/ mos) {
+  this.align=a;
+  this.meetOrSlice=mos;
   return this;
 }
 
@@ -1655,15 +1740,18 @@
   return s;
 };
 //2つの点から角度を算出
-STArc.prototype.CVAngle = function starccvangle(ux,uy,vx,vy) {
+STArc.prototype.CVAngle = function starccvangle(ux, uy, vx, vy) {
   var rad = Math.atan2(vy, vx) - Math.atan2(uy, ux);
   return (rad >= 0) ? rad : 2 * Math.PI + rad;
 };
 //弧をベジェ曲線に変換
-STArc.prototype.set = function starcset(x1,y1,rx,ry,psai,fA,fS,x4,y4) {
+STArc.prototype.set = function starcset(x1, y1, rx, ry, psai, fA, fS, x4, y4) {
   var fS = parseFloat(fS), rx = parseFloat(rx), ry = parseFloat(ry), psai = parseFloat(psai),  x1 = parseFloat(x1),  x4 = parseFloat(x4),  y1 = parseFloat(y1),  y4 = parseFloat(y4);
-  if (rx === 0 || ry === 0) {throw "line";}
-  rx = Math.abs(rx); ry = Math.abs(ry);
+  if (rx === 0 || ry === 0) {
+    throw "line";
+  }
+  rx = Math.abs(rx);
+  ry = Math.abs(ry);
   var ccx = (x1 - x4) / 2,  ccy = (y1 - y4) / 2;
   var cpsi = Math.cos(psai*Math.PI/180), spsi = Math.sin(psai*Math.PI/180);
   var x1d = cpsi*ccx + spsi*ccy,  y1d = -1*spsi*ccx + cpsi*ccy;
@@ -1718,36 +1806,33 @@
 //setをできるだけ繰り返す
 STArc.prototype.sset = function starcsset( /*float*/ nox, /*float*/ noy, /*array*/ f, /*float*/ rx, /*float*/ ry) {
   for (var i=1,fli=f.length;i<fli+1;i+=7){
-    this.set(nox,noy,f[i],f[i+1],f[i+2],f[i+3],f[i+4],f[i+5]+rx,f[i+6]+ry);
-    nox = f[i+5]+rx; noy = f[i+6]+ry;
+    this.set(nox, noy, f[i], f[i+1], f[i+2], f[i+3], f[i+4], f[i+5]+rx, f[i+6]+ry);
+    nox = f[i+5]+rx;
+    noy = f[i+6]+ry;
   }
 };
 
 //SVGLengthを参照
-function STLength( /*string or number*/ d, /*float*/ wort, /*float*/ f) {
+function STLength( /*string or number*/ d, /*float*/ wort) {
   d += "";
   this.unitType = 0; //unknown
   if (wort === void 0) { //void 0 = undefined
     wort = 1;
   }
-  if (f === void 0) {
-    f = 12;
-  }
   try {
   this._n[1] *= wort;
-  this._n[2] = this._n[3] = f;
   var v = parseFloat(d);
   var tani = d.match(this._dR);
   var ut = 1;
-  if(tani) {
+  if (tani) {
     ut = this._tani[tani];
   }
   this.newValueSpecifiedUnits(ut,v);
-  d = wort = f = v = tani = ut = null; //解放
+  d = wort = v = tani = ut = null; //解放
   }  catch(e) {stlog.add(e,1133); this.value = 1000;}
   return this;
 };
-STLength.prototype._dR = /\D+$/; //RegExpオブジェクトをあらかじめ生成
+STLength.prototype._dR = /[a-z%]+$/; //RegExpオブジェクトをあらかじめ生成
 STLength.prototype._n = [1, 0.01, 1, 1, 1, 35.43307, 3.543307, 90, 1.25, 15]; //利用単位への変換値
 STLength.prototype._tani = { //単位に番号を振る
   "pt": 9,
@@ -1766,6 +1851,16 @@
   this.valueInSpecifiedUnits = value;
   this._n[1] = 0.01; //初期化
 };
+//単位がemの場合、変換を行う。変換するとtrueを返す
+STLength.prototype._emToUnits = function ( /*number*/ fontSize) {
+  if (this.unitType === 3) {
+    this.value *= fontSize;
+    return true;
+  } else if (this.unitType === 4) {
+    this.value *= fontSize * 0.5;
+    return true;
+  } 
+};
 //XLink言語を処理
 NAIBU.XLink = function( /*element*/ ele) {
   this.tar = ele;
@@ -1846,7 +1941,8 @@
   try {
     var tsrc = document.getElementsByTagName("FONTFACEURI");
     for (var i=0;i<tsrc.length;++i) {
-      var src = tsrc[i].getAttribute("xlink:href"), ids = src.substring(src.indexOf("#")+1, src.length);
+      var src = tsrc[i].getAttribute("xlink:href");
+      var ids = src.substring(src.indexOf("#")+1, src.length);
       getURL(src.replace(/#.+$/, ""), _ie_font, [ {id : ids, style:{}} ], 1);
     }
   } catch (e) {stlog.add(e,1847);}
@@ -1864,7 +1960,8 @@
     if (familyName && font.getAttribute("id") === data.obj[0].id) {
       var textElements = document.getElementsByTagName("div");
       for (var i=0,tli=textElements.length;i<tli;++i) {
-        var ti = textElements[i], ts = ti.style, tsff = (!!ts.fontFamily) ? ts.fontFamily : "serif";
+        var ti = textElements[i], ts = ti.style;
+        var tsff = (!!ts.fontFamily) ? ts.fontFamily : "serif";
         if (tsff.indexOf(familyName) > -1) {
           NAIBU._ie_createFont(ti, font);
         }
@@ -1873,29 +1970,43 @@
   }
 };
 NAIBU._ie_createFont = function(/*Element*/ ti, /*Element*/ font) {
-  var node = ti.firstChild, data, glyphs = font.getElementsByTagName("glyph"), em = parseFloat(font.getElementsByTagName("font-face").item(0).getAttribute("units-per-em") || 0);
-  var advX = parseFloat(font.getAttribute("horiz-adv-x")), originX = parseFloat(font.getAttribute("horiz-origin-x") || 0), originY = parseFloat(font.getAttribute("horiz-origin-y") || 0); //字幅とフォントの原点の設定
-  var dx = parseFloat(ti.style.left), fontSize = parseFloat(ti.style.fontSize), dy = parseFloat(ti.style.top) - fontSize * 0.25, fe = fontSize / em; //0.25はディセンダの調整をあらかじめしているため
-   while(node) {
+  var node = ti.firstChild, data, glyphs = font.getElementsByTagName("glyph");
+  var tistyle = ti.style;
+  //isTategakiは縦書きならば真
+  var isTategaki = ( tistyle.writingMode.indexOf("tb") === 0 ), horizOrVert = isTategaki ? "vert-adv-y" : "horiz-adv-x";
+  var em = parseFloat(font.getElementsByTagName("font-face").item(0).getAttribute("units-per-em") || 0);
+  var advX = parseFloat( (font.getAttribute(horizOrVert) || em) ); //字幅の設定
+  var dx = parseFloat(tistyle.left), fontSize = parseFloat(tistyle.fontSize), dy = parseFloat(tistyle.top) - fontSize * 0.25, fe = fontSize / em; //0.25はディセンダの調整をあらかじめしているため
+  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.getAttribute("unicode") || "なし"; //unicode属性に指定がない場合、処理させないようにする
         //indexは該当する文字が何番目にあるかの数字
-        var index = data.indexOf(glyphs[i].getAttribute("unicode"));
-        if (index > -1) {
-          advanceX[index] = parseFloat(glyphs[i].getAttribute("horiz-adv-x") || advX); //字幅を収納
-          glyphData[index] = glyphs[i].getAttribute("d");
+        var index = data.indexOf(unicode);
+        while (index > -1) {
+          advanceX[index] = parseFloat(glyph.getAttribute(horizOrVert) || advX); //字幅を収納
+          glyphData[index] = glyph.getAttribute("d");
+          index = data.indexOf(unicode, index+1);
         }
       }
       for (var i=0,adv=0;i<data.length;++i) {
         if (advanceX[i] !== void 0) { //配列に含まれていれば
           var path = document.createElement("v:shape");
           //advance、すなわち字幅の長さ分、ずらしていく
-          var x = dx + adv*fe;
+          if (isTategaki) {
+            var y= dy + adv*fe, x = dx;
+          } else {
+            var x = dx + adv*fe, y= dy;
+          }
           ti.parentNode.insertBefore(path, ti);
           path.style.cssText = ti.style.cssText;
-          NAIBU.pathData(glyphData[i], path, true, ti.w, ti.h, (new Matrix(fe, 0, 0, -fe, x, dy)));
+          if ("、。".indexOf(data.charAt(i)) > -1) { //句読点の場合
+            x += fontSize / Math.SQRT2;
+            y -= fontSize / Math.SQRT2;
+          }
+          NAIBU.pathData(glyphData[i], path, true, ti.w, ti.h, (new Matrix(fe, 0, 0, -fe, x, y)) );
           adv += advanceX[i];
         }
       }
@@ -1912,7 +2023,7 @@
   var obj = document.getElementsByTagName("object");
   for (var i=0;i<obj.length;++i) {
     var s, obji = obj[i];
-    if (obji.getSVGDocument !== void 0 && window.opera === void 0) { //Operaでなければ、かつ、void 0はundefinedのこと
+    if (obji.getSVGDocument !== void 0) { //Operaでなければ、かつ、void 0はundefinedのこと
       if (obji.contentDocument !== void 0) { //Firefoxの場合
         s = obji.contentDocument;
       } else {
@@ -1927,7 +2038,8 @@
 NAIBU._fontSearchURI = function(doc){
   var tsrc = doc.getElementsByTagNameNS(NAIBU.svgNameSpace, "font-face-uri");
   for (var i=0;i<tsrc.length;++i) {
-    var src = tsrc[i].getAttributeNS("http://www.w3.org/1999/xlink", "href"), ids = src.substring(src.indexOf("#")+1, src.length);
+    var src = tsrc[i].getAttributeNS("http://www.w3.org/1999/xlink", "href");
+    var ids = src.substring(src.indexOf("#")+1, src.length);
     getURL(src.replace(/#.+$/, ""), _noie_font, [ {id : ids, style : {}, docu : doc} ], 1);
   }
 };
@@ -1950,40 +2062,68 @@
   }
 };
 NAIBU._noie_createFont = function(/*Element*/ ti, /*Element*/ font) {
-  var style = ti.ownerDocument.defaultView.getComputedStyle(ti, '')
-  var node = ti.firstChild, data, glyphs = font.getElementsByTagNameNS(NAIBU.svgNameSpace, "glyph"), em = parseFloat(font.getElementsByTagNameNS(NAIBU.svgNameSpace, "font-face").item(0).getAttribute("units-per-em") || 0);
-  var advX = parseFloat(font.getAttributeNS(null, "horiz-adv-x")), originX = parseFloat(font.getAttributeNS(null, "horiz-origin-x") || 0), originY = parseFloat(font.getAttributeNS(null, "horiz-origin-y") || 0); //字幅とフォントの原点の設定
+  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;
-   while(node) {
-    data = node.data;
-    if (data !== void 0) { //dataがある場合
-      var advanceX = [], glyphData = [];
-      for (var i=0,gli=glyphs.length;i<gli;++i) {
-        //indexは該当する文字が何番目にあるかの数字
-        var index = data.indexOf(glyphs[i].getAttributeNS(null, "unicode"));
-        if (index > -1) {
-          advanceX[index] = parseFloat(glyphs[i].getAttributeNS(null, "horiz-adv-x") || advX); //字幅を収納
-          glyphData[index] = glyphs[i].getAttributeNS(null, "d");
+  var ds = false;
+  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属性に指定がない場合、処理させないようにする
+          //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 x = dx + adv*fe;
-          ti.parentNode.insertBefore(path, ti);
-          path.style.cssText = style.cssText;
-          NAIBU.pathData(glyphData[i], path, false, 0, 0, (new Matrix(fe, 0, 0, -fe, x, dy)));
-          adv += advanceX[i];
+        for (var i=0,adv=0;i<data.length;++i) {
+          if (advanceX[i] !== void 0) { //配列に含まれていれば
+            var path = ti.ownerDocument.createElementNS(NAIBU.svgNameSpace, "path");
+            //advance、すなわち字幅の長さ分、ずらしていく
+            ti.parentNode.insertBefore(path, ti);
+            path.style.cssText = style.cssText;
+            var matrix = new Matrix(fe, 0, 0, -fe, 0, 0);
+            if (isTategaki) {
+              var y= dy + adv*fe, x = dx;
+              if ("、。".indexOf(data.charAt(i)) > -1) { //句読点の場合
+                x += fontSize / Math.SQRT2;
+                y -= fontSize / Math.SQRT2;
+              }
+              matrix.e = x;
+              matrix.f = y;
+            } else {
+              matrix.e = dx + adv*fe;
+              matrix.f = dy;
+            }
+            NAIBU.pathData(glyphData[i], path, false, 0, 0, matrix);
+            adv += advanceX[i];
+            matrix = null;
+          }
         }
+        advanceX = glyphData = null;
+      } else {
+        NAIBU._noie_createFont(node, font);
       }
-      advanceX = glyphData = null;
-    } else {
-      NAIBU._noie_createFont(node, font);
+      node = node.nextSibling;
     }
-    node = node.nextSibling;
+    ti.style.opacity = "0";
   }
-  ti.style.opacity = "0";
 };
 NAIBU.pathData = function(/*string*/ data, /*Element*/ p, /*boolean*/ t, /*float*/ w, h, /*Matrix*/ matrix) {
   //CTMでフォントを移動させておく
@@ -2053,7 +2193,7 @@
 if (success  &&  data.success) {
   try {
     var obj = data.obj[data.num-1];
-    var obw = new STLength(obj.getAttribute("width"),obj.clientWidth),  obh = new STLength(obj.getAttribute("height"),obj.clientHeight);
+    var obw = new STLength(obj.getAttribute("width"),obj.clientWidth), obh = new STLength(obj.getAttribute("height"),obj.clientHeight);
     var obwidth = obw.value, obheight = obh.value;
   } catch(e) {stlog.add(e,1209);}
   //正規表現でソースをVML用に書き換え
@@ -2113,12 +2253,12 @@
   var regah = obc.getAttribute("svgheight") || obheight;
   var regw = new STLength(regaw,obwidth);
   var regh = new STLength(regah,obheight);
-  var regwv = regw.value,  reghv = regh.value;
+  var regwv = regw.value, reghv = regh.value;
   obst.width = regwv+ "px";
   obst.height = reghv+ "px";
   ob.coordsize = regwv  +" "+  reghv;
-  var STdocument = new SVGtoVML(obc,obwidth,obheight,regw,regh);
-  obj.parentNode.insertBefore(ob,obj);
+  var STdocument = new SVGtoVML(obc, obwidth, obheight, regw, regh);
+  obj.parentNode.insertBefore(ob, obj);
   STdocument.read(ob);
   STdocument.set(ob);
   STdocument = obw = obh = regw = regh = null;
@@ -2137,7 +2277,7 @@
     xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     xmlhttp.onreadystatechange = function() {
       if (xmlhttp.readyState === 4  &&  xmlhttp.status === 200) {
-        fn({success:true,content:xmlhttp.responseText,obj:ob,num:n});
+        fn( {success:true, content:xmlhttp.responseText, obj:ob, num:n} );
         xmlhttp = null;
       }
     };


Property changes on: branches/05x/sie.js
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/04x/040/sie.js:812-829
/branches/04x/041/sie.js:891-923
/branches/04x/042/sie.js:927-967
/branches/04x/043/sie.js:969-1013
/branches/04x/044/sie.js:1015-1067
/branches/04x/045/sie.js:1069-1078
/branches/04x/046/sie.js:1080-1129
/branches/04x/047/sie.js:1131-1164
/branches/04x/048/sie.js:1166-1180
/branches/04x/sie.js:830-1181
/branches/05x/050/sie.js:1183-1201
/branches/05x/051/sie.js:1207-1323
/branches/05x/052/sie.js:1325-1352
/branches/05x/053/sie.js:1354-1400
   + /branches/04x/040/sie.js:812-829
/branches/04x/041/sie.js:891-923
/branches/04x/042/sie.js:927-967
/branches/04x/043/sie.js:969-1013
/branches/04x/044/sie.js:1015-1067
/branches/04x/045/sie.js:1069-1078
/branches/04x/046/sie.js:1080-1129
/branches/04x/047/sie.js:1131-1164
/branches/04x/048/sie.js:1166-1180
/branches/04x/sie.js:830-1181
/branches/05x/050/sie.js:1183-1201
/branches/05x/051/sie.js:1207-1323
/branches/05x/052/sie.js:1325-1352
/branches/05x/053/sie.js:1354-1400
/branches/05x/054/sie.js:1403-1422




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