Use hash instead of array.
[chise/kage.git] / engine / kage.js
index 0fe9bdc..69fbee5 100755 (executable)
@@ -1,9 +1,9 @@
-function Kage(){\r
+function Kage(size){\r
   // method\r
   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.getEachStrokes(glyphData)))));\r
+      this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.getEachStrokes(glyphData))))))));\r
     }\r
   }\r
   Kage.prototype.makeGlyph = makeGlyph;\r
@@ -63,7 +63,7 @@ function Kage(){
   }\r
   Kage.prototype.getEachStrokesOfBuhin = getEachStrokesOfBuhin;\r
   \r
-       function adjustUroko(strokesArray){ // strokesArray\r
+  function adjustUroko(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
       if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0){ // no operation for TATE\r
         for(var k = 0; k < this.kAdjustUrokoLengthStep; k++){\r
@@ -91,8 +91,77 @@ function Kage(){
     return strokesArray;\r
   }\r
   Kage.prototype.adjustUroko = adjustUroko;\r
-       \r
-       function adjustKirikuchi(strokesArray){ // strokesArray\r
+  \r
+  function adjustUroko2(strokesArray){ // strokesArray\r
+    for(var i = 0; i < strokesArray.length; i++){\r
+      if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0 && strokesArray[i][4] == strokesArray[i][6]){\r
+        var pressure = 0;\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][3] + 1 > strokesArray[j][5] || strokesArray[i][5] - 1 < strokesArray[j][3]) &&\r
+              Math.abs(strokesArray[i][4] - strokesArray[j][4]) < this.kAdjustUroko2Length) ||\r
+             (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] &&\r
+              !(strokesArray[i][3] + 1 > strokesArray[j][7] || strokesArray[i][5] - 1 < strokesArray[j][5]) &&\r
+              Math.abs(strokesArray[i][4] - strokesArray[j][6]) < this.kAdjustUroko2Length)\r
+             )){\r
+            pressure += Math.pow(this.kAdjustUroko2Length - Math.abs(strokesArray[i][4] - strokesArray[j][6]), 1.1);\r
+          }\r
+        }\r
+        var result = Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100;\r
+        if(strokesArray[i][2] < result){\r
+          strokesArray[i][2] = strokesArray[i][2] % 100 + Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100;\r
+        }\r
+      }\r
+    }\r
+    return strokesArray;\r
+  }\r
+  Kage.prototype.adjustUroko2 = adjustUroko2;\r
+  \r
+  function adjustTate(strokesArray){ // strokesArray\r
+    for(var i = 0; i < strokesArray.length; i++){\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][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 * 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
+      }\r
+    }\r
+    return strokesArray;\r
+  }\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
          strokesArray[i][3] > strokesArray[i][5] &&\r
@@ -110,7 +179,7 @@ function Kage(){
     return strokesArray;\r
   }\r
   Kage.prototype.adjustKirikuchi = adjustKirikuchi;\r
-       \r
+  \r
   function adjustKakato(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
       if(strokesArray[i][0] == 1 &&\r
@@ -121,6 +190,8 @@ function Kage(){
                                strokesArray[i][6] + this.kAdjustKakatoRangeY[k],\r
                                strokesArray[i][5] + this.kAdjustKakatoRangeX / 2,\r
                                strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])\r
+             | strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1] > 200 // adjust for baseline\r
+             | strokesArray[i][6] - strokesArray[i][4] < this.kAdjustKakatoRangeY[k + 1] // for thin box\r
              ){\r
             strokesArray[i][2] += (3 - k) * 100;\r
             k = Infinity;\r
@@ -213,29 +284,58 @@ function Kage(){
   Kage.prototype.kMincho = 0;\r
   Kage.prototype.kGothic = 1;\r
   this.kShotai = this.kMincho;\r
-       \r
+  \r
   this.kRate = 100;\r
-       \r
-  this.kMinWidthY = 2;\r
-  this.kMinWidthT = 6;\r
-  this.kWidth = 5;\r
-  this.kKakato = 3;\r
-  this.kL2RDfatten = 1.1;\r
-  this.kMage = 10;\r
-  this.kUseCurve = 0;\r
-       \r
-  this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300\r
-  this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300\r
-  this.kAdjustKakatoRangeX = 20; // check area width\r
-  this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking\r
-  this.kAdjustKakatoStep = 3; // number of steps\r
-       \r
-  this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300\r
-  this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300\r
-  this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking\r
-  this.kAdjustUrokoLengthStep = 3; // number of steps\r
-  this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length\r
-       \r
+  \r
+  if(size == 1){\r
+    this.kMinWidthY = 1.2;\r
+    this.kMinWidthT = 3.6;\r
+    this.kWidth = 3;\r
+    this.kKakato = 1.8;\r
+    this.kL2RDfatten = 1.1;\r
+    this.kMage = 6;\r
+    this.kUseCurve = 0;\r
+    \r
+    this.kAdjustKakatoL = ([8, 5, 3, 1]); // for KAKATO adjustment 000,100,200,300\r
+    this.kAdjustKakatoR = ([4, 3, 2, 1]); // for KAKATO adjustment 000,100,200,300\r
+    this.kAdjustKakatoRangeX = 12; // check area width\r
+    this.kAdjustKakatoRangeY = ([1, 11, 14, 18]); // 3 steps of checking\r
+    this.kAdjustKakatoStep = 3; // number of steps\r
+    \r
+    this.kAdjustUrokoX = ([14, 12, 9, 7]); // for UROKO adjustment 000,100,200,300\r
+    this.kAdjustUrokoY = ([7, 6, 5, 4]); // for UROKO adjustment 000,100,200,300\r
+    this.kAdjustUrokoLength = ([13, 21, 30]); // length for checking\r
+    this.kAdjustUrokoLengthStep = 3; // number of steps\r
+    this.kAdjustUrokoLine = ([13, 15, 18]); // check for crossing. corresponds to length\r
+  } else {\r
+    this.kMinWidthY = 2;\r
+    this.kMinWidthT = 6;\r
+    this.kWidth = 5;\r
+    this.kKakato = 3;\r
+    this.kL2RDfatten = 1.1;\r
+    this.kMage = 10;\r
+    this.kUseCurve = 0;\r
+    \r
+    this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300\r
+    this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300\r
+    this.kAdjustKakatoRangeX = 20; // check area width\r
+    this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking\r
+    this.kAdjustKakatoStep = 3; // number of steps\r
+    \r
+    this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300\r
+    this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300\r
+    this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking\r
+    this.kAdjustUrokoLengthStep = 3; // number of steps\r
+    this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length\r
+    \r
+    this.kAdjustUroko2Step = 3;\r
+    this.kAdjustUroko2Length = 40;\r
+    \r
+    this.kAdjustTateStep = 4;\r
+    \r
+    this.kAdjustMageStep = 5;\r
+  }\r
+  \r
   this.kBuhin = new Buhin();\r
   \r
   return this;\r