Supports width adjustment of MAGE's tail.
[chise/kage.git] / engine / kage.js
index 0f7bb66..2d6d2ad 100755 (executable)
@@ -3,7 +3,7 @@ function Kage(size){
   function makeGlyph(polygons, buhin){ // void\r
     var glyphData = this.kBuhin.search(buhin);\r
     if(glyphData != ""){\r
-      this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko(this.adjustKakato(this.adjustTate(this.getEachStrokes(glyphData))))));\r
+      this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.getEachStrokes(glyphData)))))));\r
     }\r
   }\r
   Kage.prototype.makeGlyph = makeGlyph;\r
@@ -94,14 +94,14 @@ function Kage(size){
   \r
   function adjustTate(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
-      if((strokesArray[i][0] == 1 || strokesArray[i][3] || strokesArray[i][7]) && strokesArray[i][3] == strokesArray[i][5]){\r
+      if((strokesArray[i][0] == 1 || strokesArray[i][0] == 3 || strokesArray[i][0] == 7) && strokesArray[i][3] == strokesArray[i][5]){\r
         for(var j = 0; j < strokesArray.length; j++){\r
-          if(i != j && (strokesArray[j][0] == 1 || strokesArray[j][3] || strokesArray[j][7]) && strokesArray[j][3] == strokesArray[j][5] &&\r
+          if(i != j && (strokesArray[j][0] == 1 || strokesArray[j][0] == 3 || strokesArray[j][0] == 7) && strokesArray[j][3] == strokesArray[j][5] &&\r
              !(strokesArray[i][4] + 1 > strokesArray[j][6] || strokesArray[i][6] - 1 < strokesArray[j][4]) &&\r
-             Math.abs(strokesArray[i][3] - strokesArray[j][3]) < this.kMinWidthT * 4){\r
-            strokesArray[i][1] += (4 - Math.floor(Math.abs(strokesArray[i][3] - strokesArray[j][3]) / this.kMinWidthT)) * 100;\r
-            if(strokesArray[i][1] > this.kAdjustTateStep * 100){\r
-              strokesArray[i][1] = strokesArray[i][1] % 100 + this.kAdjustTateStep * 100;\r
+             Math.abs(strokesArray[i][3] - strokesArray[j][3]) < this.kMinWidthT * this.kAdjustTateStep){\r
+            strokesArray[i][1] += (this.kAdjustTateStep - Math.floor(Math.abs(strokesArray[i][3] - strokesArray[j][3]) / this.kMinWidthT)) * 1000;\r
+            if(strokesArray[i][1] > this.kAdjustTateStep * 1000){\r
+              strokesArray[i][1] = strokesArray[i][1] % 1000 + this.kAdjustTateStep * 1000;\r
             }\r
           }\r
         }\r
@@ -111,6 +111,30 @@ function Kage(size){
   }\r
   Kage.prototype.adjustTate = adjustTate;\r
   \r
+  function adjustMage(strokesArray){ // strokesArray\r
+    for(var i = 0; i < strokesArray.length; i++){\r
+      if((strokesArray[i][0] == 3) && strokesArray[i][6] == strokesArray[i][8]){\r
+        for(var j = 0; j < strokesArray.length; j++){\r
+          if(i != j && (\r
+             (strokesArray[j][0] == 1 && strokesArray[j][4] == strokesArray[j][6] &&\r
+              !(strokesArray[i][5] + 1 > strokesArray[j][5] || strokesArray[i][7] - 1 < strokesArray[j][3]) &&\r
+              Math.abs(strokesArray[i][6] - strokesArray[j][4]) < this.kMinWidthT * this.kAdjustMageStep) ||\r
+             (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] &&\r
+              !(strokesArray[i][5] + 1 > strokesArray[j][7] || strokesArray[i][7] - 1 < strokesArray[j][5]) &&\r
+              Math.abs(strokesArray[i][6] - strokesArray[j][6]) < this.kMinWidthT * this.kAdjustMageStep)\r
+             )){\r
+            strokesArray[i][2] += (this.kAdjustMageStep - Math.floor(Math.abs(strokesArray[i][6] - strokesArray[j][6]) / this.kMinWidthT)) * 1000;\r
+            if(strokesArray[i][2] > this.kAdjustMageStep * 1000){\r
+              strokesArray[i][2] = strokesArray[i][2] % 1000 + this.kAdjustMageStep * 1000;\r
+            }\r
+          }\r
+        }\r
+      }\r
+    }\r
+    return strokesArray;\r
+  }\r
+  Kage.prototype.adjustMage = adjustMage;\r
+  \r
   function adjustKirikuchi(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
       if(strokesArray[i][0] == 2 && strokesArray[i][1] == 32 &&\r
@@ -279,6 +303,8 @@ function Kage(size){
     this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length\r
     \r
     this.kAdjustTateStep = 4;\r
+    \r
+    this.kAdjustMageStep = 5;\r
   }\r
   \r
   this.kBuhin = new Buhin();\r