[Sie-announce] SIEコード [1417] SVGFontの縦書きへの対応

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 11月 18日 (水) 18:02:03 JST


Revision: 1417
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=1417
Author:   dhrname
Date:     2009-11-18 18:02:03 +0900 (Wed, 18 Nov 2009)

Log Message:
-----------
SVGFontの縦書きへの対応

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

Modified: branches/05x/054/sie.js
===================================================================
--- branches/05x/054/sie.js	2009-11-16 11:23:41 UTC (rev 1416)
+++ branches/05x/054/sie.js	2009-11-18 09:02:03 UTC (rev 1417)
@@ -1932,9 +1932,12 @@
 };
 NAIBU._ie_createFont = function(/*Element*/ ti, /*Element*/ font) {
   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("horiz-adv-x")); //字幅の設定
-  var dx = parseFloat(ti.style.left), fontSize = parseFloat(ti.style.fontSize), dy = parseFloat(ti.style.top) - fontSize * 0.25, fe = fontSize / em; //0.25はディセンダの調整をあらかじめしているため
+  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がある場合
@@ -1943,7 +1946,7 @@
         //indexは該当する文字が何番目にあるかの数字
         var index = data.indexOf(glyphs[i].getAttribute("unicode"));
         if (index > -1) {
-          advanceX[index] = parseFloat(glyphs[i].getAttribute("horiz-adv-x") || advX); //字幅を収納
+          advanceX[index] = parseFloat(glyphs[i].getAttribute(horizOrVert) || advX); //字幅を収納
           glyphData[index] = glyphs[i].getAttribute("d");
         }
       }
@@ -1951,10 +1954,14 @@
         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)));
+          NAIBU.pathData(glyphData[i], path, true, ti.w, ti.h, (new Matrix(fe, 0, 0, -fe, x, y)));
           adv += advanceX[i];
         }
       }
@@ -2010,10 +2017,12 @@
   }
 };
 NAIBU._noie_createFont = function(/*Element*/ ti, /*Element*/ font) {
-  var style = ti.ownerDocument.defaultView.getComputedStyle(ti, '')
+  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, "horiz-adv-x")); //字幅の設定
+  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;
@@ -2023,7 +2032,7 @@
         //indexは該当する文字が何番目にあるかの数字
         var index = data.indexOf((glyphs[i].getAttributeNS(null, "unicode") || "なし")); //unicode属性に指定がない場合、処理させないようにする
         if (index > -1) {
-          advanceX[index] = parseFloat(glyphs[i].getAttributeNS(null, "horiz-adv-x") || advX); //字幅を収納
+          advanceX[index] = parseFloat(glyphs[i].getAttributeNS(null, horizOrVert) || advX); //字幅を収納
           glyphData[index] = glyphs[i].getAttributeNS(null, "d");
         }
       }
@@ -2031,10 +2040,14 @@
         if (advanceX[i] !== void 0) { //配列に含まれていれば
           var path = ti.ownerDocument.createElementNS(NAIBU.svgNameSpace, "path");
           //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 = style.cssText;
-          NAIBU.pathData(glyphData[i], path, false, 0, 0, (new Matrix(fe, 0, 0, -fe, x, dy)));
+          NAIBU.pathData(glyphData[i], path, false, 0, 0, (new Matrix(fe, 0, 0, -fe, x, y)));
           adv += advanceX[i];
         }
       }




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