#define kMincho 0
#define kGothic 1
+#define kWhite 0xFF
+#define kBlack 0
+#define kGray 1
+
#define kMage 10
#define kRate 20
#define kResolution (1000 / kRate + 1) * 2
void cdDrawLine(double, double, double, double, int, int);
//kageic.c
void icPolygon(kPoint *, int);
+void icBox(int, int, int, int);
+void icDot(int, int);
#endif
-//kagedf.c\r
-//\r
-#include "kage.h"\r
-#include "kagecgi.h"\r
-\r
-void dfDrawFont(int a1, int a2, int a3,\r
- int x1, int y1,\r
- int x2, int y2,\r
- int x3, int y3,\r
- int x4, int y4){\r
- int tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4, v;\r
- double rad;\r
- \r
- if(kShotai == kMincho){\r
- switch(a1 % 100){\r
- case 0:\r
- break;\r
- case 1:\r
- if(a3 == 4){\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else{ v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, x2 - kMage, y2, 1, 14);\r
- }\r
- else{\r
- cdDrawLine(x1, y1, x2, y2, a2, a3);\r
- }\r
- break;\r
- case 2:\r
- case 12:\r
- if(a3 == 4){\r
- if(x2 == x3){\r
- tx1 = x3;\r
- ty1 = y3 - kMage;\r
- }\r
- else if(y2 == y3){\r
- tx1 = x3 - kMage;\r
- ty1 = y3;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx1 = x3 - kMage * cos(rad) * v;\r
- ty1 = y3 - kMage * sin(rad) * v;\r
- }\r
- cdDrawCurve(x1, y1, x2, y2, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x3, y3, x3 - kMage, y3, 1, 14);\r
- }\r
- else if(a3 == 5){\r
- cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, 15);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, a3);\r
- }\r
- break;\r
- case 3:\r
- if(a3 == 5){\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else{ v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- if(x2 == x3){\r
- if(y2 < y3){ v = 1; } else{ v = -1; }\r
- tx2 = x2;\r
- ty2 = y2 + kMage * v;\r
- }\r
- else if(y2 == y3){\r
- if(x2 < x3){ v = 1; } else { v = -1; }\r
- tx2 = x2 + kMage * v;\r
- ty2 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * cos(rad) * v;\r
- ty2 = y2 + kMage * sin(rad) * v;\r
- }\r
- tx3 = x3 - kMage;\r
- ty3 = y3;\r
- tx4 = x3 + kMage * 0.5;\r
- ty4 = y3 - kMage * 2;\r
- \r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);\r
- cdDrawLine(tx2, ty2, tx3, ty3, 6, 5); // bolder by force\r
- }\r
- else{\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else { v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- if(x2 == x3){\r
- if(y2 < y3){ v = 1; } else{ v = -1; }\r
- tx2 = x2;\r
- ty2 = y2 + kMage * v;\r
- }\r
- else if(y2 == y3){\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * v;\r
- ty2 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * cos(rad) * v;\r
- ty2 = y2 + kMage * sin(rad) * v;\r
- }\r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);\r
- cdDrawLine(tx2, ty2, x3, y3, 6, a3); // bolder by force\r
- }\r
- break;\r
- case 6:\r
- if(a3 == 5){\r
- /* only implimented for gothic\r
- tx1 = x4 - kMage;\r
- ty1 = y4;\r
- tx2 = x4 + kMage * 0.5;\r
- ty2 = y4 - kMage * 2;\r
- */\r
- cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, 15);\r
- /*\r
- if(a2 == 7 || a3 == 7){\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, 15);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, 15);\r
- }\r
- */\r
- }\r
- else{\r
- cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);\r
- /*\r
- if(a2 == 7 || a3 == 7){\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, a3);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, a3);\r
- }\r
- */\r
- }\r
- break;\r
- case 7:\r
- cdDrawLine(x1, y1, x2, y2, a2, 1);\r
- cdDrawCurve(x2, y2, x3, y3, x4, y4, 1, 7);\r
- break;\r
- case 9: // may not be exist\r
- kageCanvas[y1][x1] = 0;\r
- kageCanvas[y2][x2] = 0;\r
- break;\r
- default:\r
- break;\r
- }\r
- }\r
- \r
- else{ // gothic\r
- switch(a1 % 100){\r
- case 0:\r
- break;\r
- case 1:\r
- if(a3 == 4){\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else{ v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, x2 - kMage * 2, y2 - kMage * 0.5, 1, 0);\r
- }\r
- else{\r
- cdDrawLine(x1, y1, x2, y2, a2, a3);\r
- }\r
- break;\r
- case 2:\r
- case 12:\r
- if(a3 == 4){\r
- if(x2 == x3){\r
- tx1 = x3;\r
- ty1 = y3 - kMage;\r
- }\r
- else if(y2 == y3){\r
- tx1 = x3 - kMage;\r
- ty1 = y3;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx1 = x3 - kMage * cos(rad) * v;\r
- ty1 = y3 - kMage * sin(rad) * v;\r
- }\r
- cdDrawCurve(x1, y1, x2, y2, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x3, y3, x3 - kMage * 2, y3 - kMage * 0.5, 1, 0);\r
- }\r
- else if(a3 == 5){\r
- tx1 = x3 + kMage;\r
- ty1 = y3;\r
- tx2 = tx1 + kMage * 0.5;\r
- ty2 = y3 - kMage * 2;\r
- cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, 1);\r
- cdDrawCurve(x3, y3, tx1, ty1, tx2, ty2, 1, 0);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, a3);\r
- }\r
- break;\r
- case 3:\r
- if(a3 == 5){\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else{ v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- if(x2 == x3){\r
- if(y2 < y3){ v = 1; } else{ v = -1; }\r
- tx2 = x2;\r
- ty2 = y2 + kMage * v;\r
- }\r
- else if(y2 == y3){\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * v;\r
- ty2 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * cos(rad) * v;\r
- ty2 = y2 + kMage * sin(rad) * v;\r
- }\r
- tx3 = x3 - kMage;\r
- ty3 = y3;\r
- tx4 = x3 + kMage * 0.5;\r
- ty4 = y3 - kMage * 2;\r
- \r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);\r
- cdDrawLine(tx2, ty2, tx3, ty3, 1, 1);\r
- cdDrawCurve(tx3, ty3, x3, y3, tx4, ty4, 1, 0);\r
- }\r
- else{\r
- if(x1 == x2){\r
- if(y1 < y2){ v = 1; } else{ v = -1; }\r
- tx1 = x2;\r
- ty1 = y2 - kMage * v;\r
- }\r
- else if(y1 == y2){\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * v;\r
- ty1 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y2 - y1) / (double)(x2 - x1));\r
- if(x1 < x2){ v = 1; } else{ v = -1; }\r
- tx1 = x2 - kMage * cos(rad) * v;\r
- ty1 = y2 - kMage * sin(rad) * v;\r
- }\r
- if(x2 == x3){\r
- if(y2 < y3){ v = 1; } else{ v = -1; }\r
- tx2 = x2;\r
- ty2 = y2 + kMage * v;\r
- }\r
- else if(y2 == y3){\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * v;\r
- ty2 = y2;\r
- }\r
- else{\r
- rad = atan((double)(y3 - y2) / (double)(x3 - x2));\r
- if(x2 < x3){ v = 1; } else{ v = -1; }\r
- tx2 = x2 + kMage * cos(rad) * v;\r
- ty2 = y2 + kMage * sin(rad) * v;\r
- }\r
- \r
- cdDrawLine(x1, y1, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);\r
- cdDrawLine(tx2, ty2, x3, y3, 1, a3);\r
- }\r
- break;\r
- case 6:\r
- if(a3 == 5){\r
- tx1 = x4 - kMage;\r
- ty1 = y4;\r
- tx2 = x4 + kMage * 0.5;\r
- ty2 = y4 - kMage * 2;\r
- /*\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 1);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, tx1, ty1, 1, 1);\r
- */\r
- cdDrawBezier(x1, y1, x2, y2, x3, y3, tx1, ty1, a2, 1);\r
- cdDrawCurve(tx1, ty1, x4, y4, tx2, ty2, 1, 0);\r
- }\r
- else{\r
- /*\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 1);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, a3);\r
- */\r
- cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);\r
- }\r
- break;\r
- case 7:\r
- cdDrawLine(x1, y1, x2, y2, a2, 1);\r
- cdDrawCurve(x2, y2, x3, y3, x4, y4, 1, a3);\r
- break;\r
- case 9: // may not be exist\r
- kageCanvas[y1][x1] = 0;\r
- kageCanvas[y2][x2] = 0;\r
- break;\r
- default:\r
- break;\r
- }\r
- }\r
-}\r
+//kagedf.c
+//
+#include "kage.h"
+#include "kagecgi.h"
+
+void dfDrawFont(int a1, int a2, int a3,
+ int x1, int y1,
+ int x2, int y2,
+ int x3, int y3,
+ int x4, int y4){
+ int tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4, v;
+ double rad;
+
+ if(kShotai == kMincho){
+ switch(a1 % 100){
+ case 0:
+ break;
+ case 1:
+ if(a3 == 4){
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else{ v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, x2 - kMage, y2, 1, 14);
+ }
+ else{
+ cdDrawLine(x1, y1, x2, y2, a2, a3);
+ }
+ break;
+ case 2:
+ case 12:
+ if(a3 == 4){
+ if(x2 == x3){
+ tx1 = x3;
+ ty1 = y3 - kMage;
+ }
+ else if(y2 == y3){
+ tx1 = x3 - kMage;
+ ty1 = y3;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx1 = x3 - kMage * cos(rad) * v;
+ ty1 = y3 - kMage * sin(rad) * v;
+ }
+ cdDrawCurve(x1, y1, x2, y2, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x3, y3, x3 - kMage, y3, 1, 14);
+ }
+ else if(a3 == 5){
+ cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, 15);
+ }
+ else{
+ cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, a3);
+ }
+ break;
+ case 3:
+ if(a3 == 5){
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else{ v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ if(x2 == x3){
+ if(y2 < y3){ v = 1; } else{ v = -1; }
+ tx2 = x2;
+ ty2 = y2 + kMage * v;
+ }
+ else if(y2 == y3){
+ if(x2 < x3){ v = 1; } else { v = -1; }
+ tx2 = x2 + kMage * v;
+ ty2 = y2;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * cos(rad) * v;
+ ty2 = y2 + kMage * sin(rad) * v;
+ }
+ tx3 = x3 - kMage;
+ ty3 = y3;
+ tx4 = x3 + kMage * 0.5;
+ ty4 = y3 - kMage * 2;
+
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);
+ cdDrawLine(tx2, ty2, tx3, ty3, 6, 5); // bolder by force
+ }
+ else{
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else { v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ if(x2 == x3){
+ if(y2 < y3){ v = 1; } else{ v = -1; }
+ tx2 = x2;
+ ty2 = y2 + kMage * v;
+ }
+ else if(y2 == y3){
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * v;
+ ty2 = y2;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * cos(rad) * v;
+ ty2 = y2 + kMage * sin(rad) * v;
+ }
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);
+ cdDrawLine(tx2, ty2, x3, y3, 6, a3); // bolder by force
+ }
+ break;
+ case 6:
+ if(a3 == 5){
+ /* only implimented for gothic
+ tx1 = x4 - kMage;
+ ty1 = y4;
+ tx2 = x4 + kMage * 0.5;
+ ty2 = y4 - kMage * 2;
+ */
+ cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, 15);
+ }
+ else{
+ cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);
+ }
+ break;
+ case 7:
+ cdDrawLine(x1, y1, x2, y2, a2, 1);
+ cdDrawCurve(x2, y2, x3, y3, x4, y4, 1, 7);
+ break;
+ case 9: // may not be exist
+ icDot(x1, y1);
+ icDot(x2, y2);
+ break;
+ default:
+ break;
+ }
+ }
+
+ else{ // gothic
+ switch(a1 % 100){
+ case 0:
+ break;
+ case 1:
+ if(a3 == 4){
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else{ v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, x2 - kMage * 2, y2 - kMage * 0.5, 1, 0);
+ }
+ else{
+ cdDrawLine(x1, y1, x2, y2, a2, a3);
+ }
+ break;
+ case 2:
+ case 12:
+ if(a3 == 4){
+ if(x2 == x3){
+ tx1 = x3;
+ ty1 = y3 - kMage;
+ }
+ else if(y2 == y3){
+ tx1 = x3 - kMage;
+ ty1 = y3;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx1 = x3 - kMage * cos(rad) * v;
+ ty1 = y3 - kMage * sin(rad) * v;
+ }
+ cdDrawCurve(x1, y1, x2, y2, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x3, y3, x3 - kMage * 2, y3 - kMage * 0.5, 1, 0);
+ }
+ else if(a3 == 5){
+ tx1 = x3 + kMage;
+ ty1 = y3;
+ tx2 = tx1 + kMage * 0.5;
+ ty2 = y3 - kMage * 2;
+ cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, 1);
+ cdDrawCurve(x3, y3, tx1, ty1, tx2, ty2, 1, 0);
+ }
+ else{
+ cdDrawCurve(x1, y1, x2, y2, x3, y3, a2, a3);
+ }
+ break;
+ case 3:
+ if(a3 == 5){
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else{ v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ if(x2 == x3){
+ if(y2 < y3){ v = 1; } else{ v = -1; }
+ tx2 = x2;
+ ty2 = y2 + kMage * v;
+ }
+ else if(y2 == y3){
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * v;
+ ty2 = y2;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * cos(rad) * v;
+ ty2 = y2 + kMage * sin(rad) * v;
+ }
+ tx3 = x3 - kMage;
+ ty3 = y3;
+ tx4 = x3 + kMage * 0.5;
+ ty4 = y3 - kMage * 2;
+
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);
+ cdDrawLine(tx2, ty2, tx3, ty3, 1, 1);
+ cdDrawCurve(tx3, ty3, x3, y3, tx4, ty4, 1, 0);
+ }
+ else{
+ if(x1 == x2){
+ if(y1 < y2){ v = 1; } else{ v = -1; }
+ tx1 = x2;
+ ty1 = y2 - kMage * v;
+ }
+ else if(y1 == y2){
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * v;
+ ty1 = y2;
+ }
+ else{
+ rad = atan((double)(y2 - y1) / (double)(x2 - x1));
+ if(x1 < x2){ v = 1; } else{ v = -1; }
+ tx1 = x2 - kMage * cos(rad) * v;
+ ty1 = y2 - kMage * sin(rad) * v;
+ }
+ if(x2 == x3){
+ if(y2 < y3){ v = 1; } else{ v = -1; }
+ tx2 = x2;
+ ty2 = y2 + kMage * v;
+ }
+ else if(y2 == y3){
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * v;
+ ty2 = y2;
+ }
+ else{
+ rad = atan((double)(y3 - y2) / (double)(x3 - x2));
+ if(x2 < x3){ v = 1; } else{ v = -1; }
+ tx2 = x2 + kMage * cos(rad) * v;
+ ty2 = y2 + kMage * sin(rad) * v;
+ }
+
+ cdDrawLine(x1, y1, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x2, y2, tx2, ty2, 1, 1);
+ cdDrawLine(tx2, ty2, x3, y3, 1, a3);
+ }
+ break;
+ case 6:
+ if(a3 == 5){
+ tx1 = x4 - kMage;
+ ty1 = y4;
+ tx2 = x4 + kMage * 0.5;
+ ty2 = y4 - kMage * 2;
+ cdDrawBezier(x1, y1, x2, y2, x3, y3, tx1, ty1, a2, 1);
+ cdDrawCurve(tx1, ty1, x4, y4, tx2, ty2, 1, 0);
+ }
+ else{
+ cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);
+ }
+ break;
+ case 7:
+ cdDrawLine(x1, y1, x2, y2, a2, 1);
+ cdDrawCurve(x2, y2, x3, y3, x4, y4, 1, a3);
+ break;
+ case 9: // may not be exist
+ icDot(x1, y1);
+ icDot(x2, y2);
+ break;
+ default:
+ break;
+ }
+ }
+}
char buf[256];\r
\r
if(kMode == 0){ //normal\r
- fillPolygon(poly, number, 0, kageCanvas);\r
+ fillPolygon(poly, number, kBlack, kageCanvas);\r
}\r
else if(kMode == 1){ //output for svg\r
sprintf(buf, "<path d=\"M ");\r
kg_string_append(kResultText, "closepath\n");\r
}\r
}\r
+\r
+void icBox(int x1, int y1, int x2, int y2){\r
+ kageCanvas[y1][x1] = kGray;\r
+ kageCanvas[y2][x1] = kGray;\r
+ kageCanvas[y1][x2] = kGray;\r
+ kageCanvas[y2][x2] = kGray;\r
+}\r
+\r
+void icDot(int x, int y){\r
+ kageCanvas[y][x] = kGray;\r
+}\r
+\r
//kagepng.c
//
+#include "kage.h"
#include "sysdep.h"
png_bytepp initPng(int width, int height){
for(j = 0; j < height; j++) image[j] = (png_bytep)malloc(width * sizeof(png_byte));
for(i = 0; i < width; i++){
for(j = 0; j < height; j++){
- image[j][i] = 0xFF;
+ image[j][i] = kWhite;
}
}
return image;
}
int writePng(int width, int height, png_bytepp image, FILE *fp){
- png_structp pPng;
- png_infop pInfo;
- png_text pText[5];
- time_t gmt;
- png_time pngTime;
-
- pPng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if(pPng == NULL){
- return 1;
- }
- pInfo = png_create_info_struct(pPng);
- if(pInfo == NULL){
- png_destroy_write_struct(&pPng, (png_infopp)NULL);
- return 1;
- }
- if(setjmp(pPng->jmpbuf)){
- png_destroy_write_struct(&pPng, &pInfo);
- return 1;
- }
- png_init_io(pPng, fp);
- png_set_filter(pPng, 0, PNG_ALL_FILTERS);
- png_set_compression_level(pPng, Z_BEST_COMPRESSION);
- //png_set_IHDR(pPng, pInfo, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- png_set_IHDR(pPng, pInfo, width, height, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- png_set_gAMA(pPng, pInfo, 1.0);
-
- time(&gmt);
- png_convert_from_time_t(&pngTime, gmt);
- png_set_tIME(pPng, pInfo, &pngTime);
-
- pText[0].key = "Title";
- pText[0].text = "Kanji glyph generated by KAGE/cgi";
- pText[0].compression = PNG_TEXT_COMPRESSION_NONE;
- pText[1].key = "Author";
- pText[1].text = "KAGE/cgi version 0.4";
- pText[1].compression = PNG_TEXT_COMPRESSION_NONE;
- pText[2].key = "Description";
- pText[2].text = "see more information at http://fonts.jp/";
- pText[2].compression = PNG_TEXT_COMPRESSION_NONE;
- pText[3].key = "Creation Time";
- pText[3].text = png_convert_to_rfc1123(pPng, &pngTime);
- pText[3].compression = PNG_TEXT_COMPRESSION_NONE;
- pText[4].key = "Software";
- pText[4].text = "KAGE/cgi version 0.4";
- pText[4].compression = PNG_TEXT_COMPRESSION_NONE;
- png_set_text(pPng, pInfo, pText, 5);
-
- png_write_info(pPng, pInfo);
- png_write_image(pPng, image);
- png_write_end(pPng, pInfo);
- png_destroy_write_struct(&pPng, &pInfo);
-
- return 0;
+ png_structp pPng;
+ png_infop pInfo;
+ png_text pText[5];
+ time_t gmt;
+ png_time pngTime;
+ int i, j;
+
+ for(i = 0; i < width; i++){
+ for(j = 0; j < height; j++){
+ if(image[j][i] == kGray){ image[j][i] = kWhite; }
+ }
+ }
+
+ pPng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if(pPng == NULL){
+ return 1;
+ }
+ pInfo = png_create_info_struct(pPng);
+ if(pInfo == NULL){
+ png_destroy_write_struct(&pPng, (png_infopp)NULL);
+ return 1;
+ }
+ if(setjmp(pPng->jmpbuf)){
+ png_destroy_write_struct(&pPng, &pInfo);
+ return 1;
+ }
+ png_init_io(pPng, fp);
+ png_set_filter(pPng, 0, PNG_ALL_FILTERS);
+ png_set_compression_level(pPng, Z_BEST_COMPRESSION);
+ //png_set_IHDR(pPng, pInfo, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(pPng, pInfo, width, height, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_gAMA(pPng, pInfo, 1.0);
+
+ time(&gmt);
+ png_convert_from_time_t(&pngTime, gmt);
+ png_set_tIME(pPng, pInfo, &pngTime);
+
+ pText[0].key = "Title";
+ pText[0].text = "Kanji glyph generated by KAGE/cgi";
+ pText[0].compression = PNG_TEXT_COMPRESSION_NONE;
+ pText[1].key = "Author";
+ pText[1].text = "KAGE/cgi version 0.4";
+ pText[1].compression = PNG_TEXT_COMPRESSION_NONE;
+ pText[2].key = "Description";
+ pText[2].text = "see more information at http://fonts.jp/";
+ pText[2].compression = PNG_TEXT_COMPRESSION_NONE;
+ pText[3].key = "Creation Time";
+ pText[3].text = png_convert_to_rfc1123(pPng, &pngTime);
+ pText[3].compression = PNG_TEXT_COMPRESSION_NONE;
+ pText[4].key = "Software";
+ pText[4].text = "KAGE/cgi version 0.4";
+ pText[4].compression = PNG_TEXT_COMPRESSION_NONE;
+ png_set_text(pPng, pInfo, pText, 5);
+
+ png_write_info(pPng, pInfo);
+ png_write_image(pPng, image);
+ png_write_end(pPng, pInfo);
+ png_destroy_write_struct(&pPng, &pInfo);
+
+ return 0;
}
}\r
if(num != 0){\r
//(for debug)\r
- if(num % 2 != 0){\r
- fprintf(stderr,"y:%d(%d)\n",j,num);\r
- for(k=0;k<num;k++) fprintf(stderr,"%d+",cross[k]);\r
- }\r
+ //if(num % 2 != 0){\r
+ //fprintf(stderr,"y:%d(%d)\n",j,num);\r
+ //for(k=0;k<num;k++) fprintf(stderr,"%d+",cross[k]);\r
+ //}\r
//sort crossing point\r
for(k = 0; k < num - 1; k++){\r
for(l = num - 1; l > k; l--){\r
-//kagetool.c\r
-//\r
-\r
-#include "kage.h"\r
-#include "kagecgi.h"\r
-#include "sysdep.h"\r
-\r
-void DotsWidth(int *dlx, int *drx){\r
- int i, j;\r
- \r
- *dlx = 0;\r
- *drx = 0;\r
- for(i = 0; i < canvasWidth && *dlx == 0; i++){\r
- for(j = 0; j < canvasHeight; j++){\r
- if(kageCanvas[j][i] == 0){\r
- *dlx = i;\r
- break;\r
- }\r
- }\r
- }\r
- \r
- for(i = canvasWidth - 1; i >= 0 && *drx == 0; i--){\r
- for(j = 0; j < canvasHeight; j++){\r
- if(kageCanvas[j][i] == 0){\r
- *drx = i;\r
- break;\r
- }\r
- }\r
- }\r
-}\r
-\r
-void DotsHeight(int *dly, int *dry){\r
- int i, j;\r
- \r
- *dly = 0;\r
- *dry = 0;\r
- for(j = 0; j < canvasHeight && *dly == 0; j++){\r
- for(i = 0; i < canvasWidth; i++){\r
- if(kageCanvas[j][i] == 0){\r
- *dly = j;\r
- break;\r
- }\r
- }\r
- }\r
- \r
- for(j = canvasHeight - 1; j >= 0 && *dry == 0; j--){\r
- for(i = 0; i < canvasWidth; i++){\r
- if(kageCanvas[j][i] == 0){\r
- *dry = j;\r
- break;\r
- }\r
- }\r
- }\r
-}\r
-\r
-void PartsWidth(const KGString *in, int *lx, int *rx){\r
- int tempShotai;\r
- DrawBox();\r
- tempShotai = kShotai;\r
- kShotai = kGothic;\r
- drawGlyph(in, 1);\r
- kShotai = tempShotai;\r
- DotsWidth(lx, rx);\r
- /*\r
- int i;\r
- int *buf, strokes;\r
- double t, x;\r
- \r
- *lx = 1000; *rx = 0;\r
- buf = convertStroke(in->str, buf, &strokes);\r
- \r
- for(i = 0; i < strokes; i++){\r
- switch(buf[i * 11 + 0] % 10){\r
- \r
- case 0:\r
- case 9:\r
- break;\r
- case 1:\r
- if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];\r
- if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];\r
- if(*lx > buf[i * 11 + 5]) *lx = buf[i * 11 + 5];\r
- if(*rx < buf[i * 11 + 5]) *rx = buf[i * 11 + 5];\r
- break;\r
- case 2:\r
- for(t = 0; t <= 1; t = t + 0.05){\r
- x = (1.0 - t) * (1.0 - t) * buf[i * 11 + 3] + 2.0 * t * (1.0 - t) * buf[i * 11 + 5] + t * t * buf[i * 11 + 7];\r
- if(*lx > x) *lx = x;\r
- if(*rx < x) *rx = x;\r
- }\r
- break;\r
- case 3:\r
- if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];\r
- if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];\r
- if(*lx > buf[i * 11 + 5]) *lx = buf[i * 11 + 5];\r
- if(*rx < buf[i * 11 + 5]) *rx = buf[i * 11 + 5];\r
- if(*lx > buf[i * 11 + 7]) *lx = buf[i * 11 + 7];\r
- if(*rx < buf[i * 11 + 7]) *rx = buf[i * 11 + 7];\r
- break;\r
- case 6:\r
- for(t = 0; t < 1; t = t + 0.05){\r
- x = (1.0 - t) * (1.0 - t) * (1.0 - t) * buf[i * 11 + 3] + 3.0 * t * (1.0 - t) * (1.0 - t) * buf[i * 11 + 5] + 3 * t * t * (1.0 - t) * buf[i * 11 + 7] + t * t * t * buf[i * 11 + 9];\r
- if(*lx > x) *lx = x;\r
- if(*rx < x) *rx = x;\r
- }\r
- break;\r
- case 7:\r
- if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];\r
- if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];\r
- for(t = 0; t < 1; t = t + 0.05){\r
- x = (1.0 - t) * (1.0 - t) * buf[i * 11 + 5] + 2.0 * t * (1.0 - t) * buf[i * 11 + 7] + t * t * buf[i * 11 + 9];\r
- if(*lx > x) *lx = x;\r
- if(*rx < x) *rx = x;\r
- }\r
- }\r
- }\r
- free(buf);\r
- */\r
-}\r
-\r
-void PartsHeight(const KGString *in, int *ly, int *ry){\r
- int tempShotai;\r
- DrawBox();\r
- tempShotai = kShotai;\r
- kShotai = kGothic;\r
- drawGlyph(in, 1);\r
- kShotai = tempShotai;\r
- DotsHeight(ly, ry);\r
- /*\r
- int i;\r
- int *buf, strokes;\r
- double t, y;\r
- \r
- *ly = 1000; *ry = 0;\r
- buf = convertStroke(in->str, buf, &strokes);\r
- \r
- for(i = 0; i < strokes; i++){\r
- switch(buf[i * 11 + 0] % 10){\r
- \r
- case 0:\r
- case 9:\r
- break;\r
- case 1:\r
- if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];\r
- if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];\r
- if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];\r
- if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];\r
- break;\r
- case 2:\r
- for(t = 0; t <= 1; t = t + 0.05){\r
- y = (1.0 - t) * (1.0 - t) * buf[i * 11 + 4] + 2.0 * t * (1.0 - t) * buf[i * 11 + 6] + t * t * buf[i * 11 + 8];\r
- if(*ly > y) *ly = y;\r
- if(*ry < y) *ry = y;\r
- }\r
- break;\r
- case 3:\r
- if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];\r
- if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];\r
- if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];\r
- if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];\r
- if(*ly > buf[i * 11 + 8]) *ly = buf[i * 11 + 8];\r
- if(*ry < buf[i * 11 + 8]) *ry = buf[i * 11 + 8];\r
- break;\r
- case 6:\r
- for(t = 0; t < 1; t = t + 0.05){\r
- y = (1.0 - t) * (1.0 - t) * (1.0 - t) * buf[i * 11 + 4] + 3.0 * t * (1.0 - t) * (1.0 - t) * buf[i * 11 + 6] + 3 * t * t * (1.0 - t) * buf[i * 11 + 8] + t * t * t * buf[i * 11 + 10];\r
- if(*ly > y) *ly = y;\r
- if(*ry < y) *ry = y;\r
- }\r
- break;\r
- case 7:\r
- if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];\r
- if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];\r
- for(t = 0; t < 1; t = t + 0.05){\r
- y = (1.0 - t) * (1.0 - t) * buf[i * 11 + 6] + 2.0 * t * (1.0 - t) * buf[i * 11 + 8] + t * t * buf[i * 11 + 10];\r
- if(*ly > y) *ly = y;\r
- if(*ry < y) *ry = y;\r
- }\r
- }\r
- }\r
- free(buf);\r
- */\r
- /*\r
- int i;\r
- int *buf, strokes;\r
- \r
- buf = convertStroke(in->str, buf, &strokes);\r
- *ly = 1000; *ry = 0;\r
- \r
- for(i = 0; i < strokes; i++){\r
- if(buf[i * 11 + 0] % 10 == 0) continue;\r
- \r
- if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];\r
- if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];\r
- if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];\r
- if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];\r
- \r
- if(buf[i * 11 + 0] % 10 == 2 || buf[i * 11 + 0] % 10 == 3 || buf[i * 11 + 0] % 10 == 8){\r
- if(*ly > buf[i * 11 + 8]) *ly = buf[i * 11 + 8];\r
- if(*ry < buf[i * 11 + 8]) *ry = buf[i * 11 + 8];\r
- }\r
- if(buf[i * 11 + 0] % 10 == 4 || buf[i * 11 + 0] % 10 == 6 || buf[i * 11 + 0] % 10 == 7){\r
- if(*ly > buf[i * 11 + 10]) *ly = buf[i * 11 + 10];\r
- if(*ry < buf[i * 11 + 10]) *ry = buf[i * 11 + 10];\r
- }\r
- }\r
- free(buf);\r
- */\r
-}\r
-\r
-KGString * CalcSizes(const KGString *in, int mode){\r
- int i, j, k, basewidth, one_lineX, one_lineY;\r
- int dlx1, drx1, dly1, dry1;\r
- int px1, py1;\r
- double pr1, pry1;\r
- \r
- int mitsuT, flg_boxT, widthT, heightT;\r
- double tateT, yokoT;\r
- int cutx, cuty;\r
- \r
- int *buf, strokes;\r
- int tf[12];\r
- KGString *out;\r
- \r
- out = kg_string_new("");\r
- basewidth = pngWidth * 0.9;\r
- \r
- if(mode == 0){\r
- //temporary adjustment X-axis\r
- PartsWidth(in, &dlx1, &drx1);\r
- if(dlx1 == drx1){\r
- pr1 = 1.0;\r
- px1 = pngWidth / 2 - dlx1;\r
- one_lineX = 1;\r
- }\r
- else{\r
- pr1 = (double)basewidth/(drx1 - dlx1);\r
- px1 = (pngWidth-basewidth)/2 - (double)(dlx1 * pr1);\r
- one_lineX = 0;\r
- }\r
- \r
- //temporary adjustment Y-axis\r
- PartsHeight(in, &dly1, &dry1);\r
- if(dly1 == dry1){\r
- pry1 = 1.0;\r
- py1 = pngWidth / 2 - dly1;\r
- one_lineY = 1;\r
- }\r
- else{\r
- pry1 = (double)basewidth/(dry1 - dly1);\r
- py1 = (pngWidth-basewidth)/2 - (double)(dly1 * pry1);\r
- one_lineY = 0;\r
- }\r
- }\r
- else{\r
- PartsWidth(in, &dlx1, &drx1);\r
- PartsHeight(in, &dly1, &dry1);\r
- \r
- cutx = 0;\r
- cuty = 0;\r
- \r
- CalcOptions(in, &mitsuT, &flg_boxT, &yokoT, &tateT);\r
- \r
- widthT = basewidth;\r
- heightT = basewidth;\r
- \r
- if(flg_boxT % 2 / 1 != 0){\r
- widthT = widthT - kWidth * 3;\r
- cutx++;\r
- }\r
- if(flg_boxT % 4 / 2 != 0){\r
- widthT = widthT - kWidth * 3;\r
- cutx++;\r
- }\r
- if(flg_boxT % 8 / 4 != 0){\r
- heightT = heightT - kWidth * 3;\r
- cuty++;\r
- }\r
- if(flg_boxT % 16 / 8 != 0){\r
- heightT = heightT - kWidth * 3;\r
- cuty++;\r
- }\r
- \r
- //especially get small the 'mouth'\r
- if(mode == 2 && flg_boxT % 16 == 15){\r
- widthT = widthT - kWidth * (max(0, 16 - (int)yokoT * 4));\r
- heightT = heightT - kWidth * (max(0, 16 - (int)tateT * 4));\r
- }\r
- //'dot' as same as 'mouth'\r
- if(mode == 2 && tateT == 1 && yokoT == 1){\r
- widthT = pngWidth * 0.9 * 0.5;\r
- heightT = pngWidth * 0.9 * 0.5;\r
- }\r
- \r
- /*\r
-if(flg_boxT % 64 / 32 != 0){\r
- buf = convertStroke(in->str, buf, &strokes);\r
- for(i = 0; i < strokes; i++){\r
- if(buf[i * 11 + 0] == 0) j = buf[i * 11 + 4];// j : center line\r
- }\r
- free(buf);\r
- k = max(j - dlx1, drx1 - j);// k : distance from center line\r
- pr1 = (basewidth * 0.5) / k;\r
- \r
- if(k == j - dlx1) px1 = 0;\r
- else px1 = pngWidth * 0.5 - j * pr1;\r
- }\r
- else\r
-*/\r
- if(dlx1 == drx1){\r
- pr1 = 1.0;\r
- px1 = pngWidth / 2 - dlx1;\r
- }\r
- else{\r
- pr1 = (double)widthT/(drx1 - dlx1);\r
- px1 = pngWidth / 2 - (double)((dlx1 + drx1) / 2 * pr1);\r
- if(flg_boxT % 2 / 1 != 0 && flg_boxT % 4 / 2 == 0) px1 = px1 + kWidth * 1.5;\r
- if(flg_boxT % 2 / 1 == 0 && flg_boxT % 4 / 2 != 0) px1 = px1 - kWidth * 1.5;\r
- }\r
- \r
- if(dly1 == dry1){\r
- pry1 = 1.0;\r
- py1 = pngWidth / 2 - dly1;\r
- }\r
- else{\r
- pry1 = (double)heightT/(dry1 - dly1);\r
- py1 = pngWidth / 2 - (double)((dly1 + dry1) / 2 * pry1);\r
- if(flg_boxT % 8 / 4 != 0 && flg_boxT % 16 / 8 == 0) py1 = py1 + kWidth * 1.5;\r
- if(flg_boxT % 8 / 4 == 0 && flg_boxT % 16 / 8 != 0) py1 = py1 - kWidth * 1.5;\r
- }\r
- }\r
- \r
- //generate result\r
- tf[0] = px1;\r
- tf[1] = py1;\r
- tf[2] = px1 + pr1 * 200;\r
- tf[3] = py1 + pry1 * 200;\r
- addStrokeWithTransform(in, 1, tf, out, 0);\r
- return kg_string_new(out->str);\r
-}\r
-\r
-void DrawBox(){\r
- int i, j;\r
- \r
- for(i = 0; i < canvasWidth; i++){\r
- for(j = 0; j < canvasHeight; j++){\r
- kageCanvas[j][i] = 0xFF;\r
- }\r
- }\r
-}\r
-\r
-void CalcOptions(const KGString *in, int *mitsudo, int *flag, double *yoko, double *tate){\r
- int i, j, k, l, flg;\r
- int dlx1, drx1, dly1, dry1;\r
- int kari, mode;\r
- int tempShotai;\r
- int *buf, strokes;\r
- \r
- *flag = 0;\r
- \r
- DrawBox();\r
- tempShotai = kShotai;\r
- kShotai = kGothic;\r
- drawGlyph(in, 1);\r
- kShotai = tempShotai;\r
- DotsWidth(&dlx1, &drx1);\r
- DotsHeight(&dly1, &dry1);\r
- \r
- //check left side\r
- k = 0;\r
- l = 0;\r
- for(i = 0; i < pngWidth; i++){\r
- flg = 0;\r
- for(j = 0; j < kWidth; j++){\r
- if(kageCanvas[i][dlx1 + j] == 0) flg = 1;\r
- }\r
- if(flg == 1){\r
- k++;\r
- }\r
- else{\r
- if(k > l) l = k;\r
- k = 0;\r
- }\r
- }\r
- if(k > l) l = k;\r
- \r
- if(l > pngWidth * 0.9 / 4) *flag = *flag | 1;\r
- \r
- //check right side\r
- k = 0;\r
- l = 0;\r
- for(i = 0; i < pngWidth; i++){\r
- flg = 0;\r
- for(j = 0; j < kWidth; j++){\r
- if(kageCanvas[i][drx1 - j] == 0) flg = 1;\r
- }\r
- if(flg == 1) k++;\r
- else{\r
- if(k > l) l = k;\r
- k = 0;\r
- }\r
- }\r
- if(k > l) l = k;\r
- \r
- if(l > pngWidth * 0.9 / 4) *flag = *flag | 2;\r
- \r
- //check upper side\r
- k = 0;\r
- l = 0;\r
- for(i = 0; i < pngWidth; i++){\r
- flg = 0;\r
- for(j = 0; j < kWidth; j++){\r
- if(kageCanvas[dly1 + j][i] == 0) flg = 1;\r
- }\r
- if(flg == 1) k++;\r
- else{\r
- if(k > l) l = k;\r
- k = 0;\r
- }\r
- }\r
- if(k > l) l = k;\r
- \r
- if(l > pngWidth * 0.9 / 4) *flag = *flag | 4;\r
- \r
- //check bottom side\r
- k = 0;\r
- l = 0;\r
- for(i = 0; i < pngWidth; i++){\r
- flg = 0;\r
- for(j = 0; j < kWidth; j++){\r
- if(kageCanvas[dry1 - j][i] == 0) flg = 1;\r
- }\r
- if(flg == 1) k++;\r
- else{\r
- if(k > l) l = k;\r
- k = 0;\r
- }\r
- }\r
- if(k > l) l = k;\r
- \r
- if(l > pngWidth * 0.9 / 4) *flag = *flag | 8;\r
- \r
- //count black dots\r
- *mitsudo = 0;\r
- for(i = 0; i < pngHeight; i++){\r
- for(j = 0; j < pngWidth; j++){\r
- if(kageCanvas[i][j] == 0) *mitsudo += 1;\r
- }\r
- }\r
- \r
- //calculate X-axis complexity\r
- *yoko = 0;\r
- for(i = dly1; i <= dry1; i++){\r
- mode = 0;\r
- kari = 0;\r
- for(j = dlx1; j <= drx1; j++){\r
- if(kageCanvas[i][j] == 0 &&\r
- kageCanvas[i][j+1] == 0 &&\r
- kageCanvas[i][j+2] == 0){\r
- if(mode == 0){\r
- mode = 1;\r
- kari++;\r
- }\r
- }\r
- else if(mode == 1) mode = 0;\r
- }\r
- if(kari > *yoko) *yoko = kari;\r
- }\r
- \r
- //calculate Y-axis complexity\r
- *tate = 0;\r
- for(i = dlx1; i <= drx1; i++){\r
- mode = 0;\r
- kari = 0;\r
- for(j = dly1; j <= dry1; j++){\r
- if(kageCanvas[j][i] == 0 &&\r
- kageCanvas[j+1][i] == 0 &&\r
- kageCanvas[j+2][i] == 0){\r
- if(mode == 0){\r
- mode = 1;\r
- kari++;\r
- }\r
- }\r
- else if(mode == 1) mode = 0;\r
- }\r
- if(kari > *tate) *tate = kari;\r
- }\r
- \r
- //use user defined option if it exists\r
- buf = convertStroke(in->str, buf, &strokes);\r
- for(i = 0; i < strokes; i++){\r
- if(buf[i * 11 + 0] % 10 == 0){\r
- if(buf[i * 11 + 1] != 0) *yoko = (double)(buf[i * 11 + 1]) * 0.1;\r
- if(buf[i * 11 + 2] != 0) *tate = (double)(buf[i * 11 + 2]) * 0.1;\r
- if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3];\r
- }\r
- }\r
- free(buf);\r
-}\r
-\r
-void DoDrawParts(const KGString *in, const int lx1, const double rf1, const int ly1, const double rfy1){\r
- int i;\r
- int *buf, strokes;\r
- \r
- DrawBox();\r
- buf = convertStroke(in->str, buf, &strokes);\r
- for(i = 0; i < strokes; i++){\r
- dfDrawFont(buf[i * 11 + 0],\r
- buf[i * 11 + 1],\r
- buf[i * 11 + 2],\r
- buf[i * 11 + 3] * rf1 + lx1,\r
- buf[i * 11 + 4] * rfy1 + ly1,\r
- buf[i * 11 + 5] * rf1 + lx1,\r
- buf[i * 11 + 6] * rfy1 + ly1,\r
- buf[i * 11 + 7] * rf1 + lx1,\r
- buf[i * 11 + 8] * rfy1 + ly1,\r
- buf[i * 11 + 9] * rf1 + lx1,\r
- buf[i * 11 + 10] * rfy1 + ly1);\r
- }\r
- free(buf);\r
-}\r
-\r
-void DoDrawMixFont(const KGString *in1,\r
- const int lx1,\r
- const double rf1,\r
- const KGString *in2,\r
- const int lx2,\r
- const double rf2,\r
- const int ly1,\r
- const double rfy1,\r
- const int ly2,\r
- const double rfy2){\r
- int i;\r
- int *buf, strokes;\r
- \r
- DrawBox();\r
- buf = convertStroke(in1->str, buf, &strokes);\r
- for(i = 0; i < strokes; i++){\r
- dfDrawFont(buf[i * 11 + 0],\r
- buf[i * 11 + 1],\r
- buf[i * 11 + 2],\r
- buf[i * 11 + 3] * rf1 + lx1,\r
- buf[i * 11 + 4] * rfy1 + ly1,\r
- buf[i * 11 + 5] * rf1 + lx1,\r
- buf[i * 11 + 6] * rfy1 + ly1,\r
- buf[i * 11 + 7] * rf1 + lx1,\r
- buf[i * 11 + 8] * rfy1 + ly1,\r
- buf[i * 11 + 9] * rf1 + lx1,\r
- buf[i * 11 + 10] * rfy1 + ly1);\r
- }\r
- free(buf);\r
- \r
- buf = convertStroke(in2->str, buf, &strokes);\r
- for(i = 0; i < strokes; i++){\r
- dfDrawFont(buf[i * 11 + 0],\r
- buf[i * 11 + 1],\r
- buf[i * 11 + 2],\r
- buf[i * 11 + 3] * rf2 + lx2,\r
- buf[i * 11 + 4] * rfy2 + ly2,\r
- buf[i * 11 + 5] * rf2 + lx2,\r
- buf[i * 11 + 6] * rfy2 + ly2,\r
- buf[i * 11 + 7] * rf2 + lx2,\r
- buf[i * 11 + 8] * rfy2 + ly2,\r
- buf[i * 11 + 9] * rf2 + lx2,\r
- buf[i * 11 + 10] * rfy2 + ly2);\r
- }\r
- free(buf);\r
-}\r
-\r
+//kagetool.c
+//
+
+#include "kage.h"
+#include "kagecgi.h"
+#include "sysdep.h"
+
+void DotsWidth(int *dlx, int *drx){
+ int i, j;
+
+ *dlx = 0;
+ *drx = 0;
+ for(i = 0; i < canvasWidth && *dlx == 0; i++){
+ for(j = 0; j < canvasHeight; j++){
+ if(kageCanvas[j][i] != kWhite){
+ *dlx = i;
+ break;
+ }
+ }
+ }
+
+ for(i = canvasWidth - 1; i >= 0 && *drx == 0; i--){
+ for(j = 0; j < canvasHeight; j++){
+ if(kageCanvas[j][i] != kWhite){
+ *drx = i;
+ break;
+ }
+ }
+ }
+}
+
+void DotsHeight(int *dly, int *dry){
+ int i, j;
+
+ *dly = 0;
+ *dry = 0;
+ for(j = 0; j < canvasHeight && *dly == 0; j++){
+ for(i = 0; i < canvasWidth; i++){
+ if(kageCanvas[j][i] != kWhite){
+ *dly = j;
+ break;
+ }
+ }
+ }
+
+ for(j = canvasHeight - 1; j >= 0 && *dry == 0; j--){
+ for(i = 0; i < canvasWidth; i++){
+ if(kageCanvas[j][i] != kWhite){
+ *dry = j;
+ break;
+ }
+ }
+ }
+}
+
+void PartsWidth(const KGString *in, int *lx, int *rx){
+ int tempShotai;
+ DrawBox();
+ tempShotai = kShotai;
+ kShotai = kGothic;
+ drawGlyph(in, 1);
+ kShotai = tempShotai;
+ DotsWidth(lx, rx);
+ /*
+ int i;
+ int *buf, strokes;
+ double t, x;
+
+ *lx = 1000; *rx = 0;
+ buf = convertStroke(in->str, buf, &strokes);
+
+ for(i = 0; i < strokes; i++){
+ switch(buf[i * 11 + 0] % 10){
+
+ case 0:
+ case 9:
+ break;
+ case 1:
+ if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];
+ if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];
+ if(*lx > buf[i * 11 + 5]) *lx = buf[i * 11 + 5];
+ if(*rx < buf[i * 11 + 5]) *rx = buf[i * 11 + 5];
+ break;
+ case 2:
+ for(t = 0; t <= 1; t = t + 0.05){
+ x = (1.0 - t) * (1.0 - t) * buf[i * 11 + 3] + 2.0 * t * (1.0 - t) * buf[i * 11 + 5] + t * t * buf[i * 11 + 7];
+ if(*lx > x) *lx = x;
+ if(*rx < x) *rx = x;
+ }
+ break;
+ case 3:
+ if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];
+ if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];
+ if(*lx > buf[i * 11 + 5]) *lx = buf[i * 11 + 5];
+ if(*rx < buf[i * 11 + 5]) *rx = buf[i * 11 + 5];
+ if(*lx > buf[i * 11 + 7]) *lx = buf[i * 11 + 7];
+ if(*rx < buf[i * 11 + 7]) *rx = buf[i * 11 + 7];
+ break;
+ case 6:
+ for(t = 0; t < 1; t = t + 0.05){
+ x = (1.0 - t) * (1.0 - t) * (1.0 - t) * buf[i * 11 + 3] + 3.0 * t * (1.0 - t) * (1.0 - t) * buf[i * 11 + 5] + 3 * t * t * (1.0 - t) * buf[i * 11 + 7] + t * t * t * buf[i * 11 + 9];
+ if(*lx > x) *lx = x;
+ if(*rx < x) *rx = x;
+ }
+ break;
+ case 7:
+ if(*lx > buf[i * 11 + 3]) *lx = buf[i * 11 + 3];
+ if(*rx < buf[i * 11 + 3]) *rx = buf[i * 11 + 3];
+ for(t = 0; t < 1; t = t + 0.05){
+ x = (1.0 - t) * (1.0 - t) * buf[i * 11 + 5] + 2.0 * t * (1.0 - t) * buf[i * 11 + 7] + t * t * buf[i * 11 + 9];
+ if(*lx > x) *lx = x;
+ if(*rx < x) *rx = x;
+ }
+ }
+ }
+ free(buf);
+ */
+}
+
+void PartsHeight(const KGString *in, int *ly, int *ry){
+ int tempShotai;
+ DrawBox();
+ tempShotai = kShotai;
+ kShotai = kGothic;
+ drawGlyph(in, 1);
+ kShotai = tempShotai;
+ DotsHeight(ly, ry);
+ /*
+ int i;
+ int *buf, strokes;
+ double t, y;
+
+ *ly = 1000; *ry = 0;
+ buf = convertStroke(in->str, buf, &strokes);
+
+ for(i = 0; i < strokes; i++){
+ switch(buf[i * 11 + 0] % 10){
+
+ case 0:
+ case 9:
+ break;
+ case 1:
+ if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];
+ if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];
+ if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];
+ if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];
+ break;
+ case 2:
+ for(t = 0; t <= 1; t = t + 0.05){
+ y = (1.0 - t) * (1.0 - t) * buf[i * 11 + 4] + 2.0 * t * (1.0 - t) * buf[i * 11 + 6] + t * t * buf[i * 11 + 8];
+ if(*ly > y) *ly = y;
+ if(*ry < y) *ry = y;
+ }
+ break;
+ case 3:
+ if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];
+ if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];
+ if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];
+ if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];
+ if(*ly > buf[i * 11 + 8]) *ly = buf[i * 11 + 8];
+ if(*ry < buf[i * 11 + 8]) *ry = buf[i * 11 + 8];
+ break;
+ case 6:
+ for(t = 0; t < 1; t = t + 0.05){
+ y = (1.0 - t) * (1.0 - t) * (1.0 - t) * buf[i * 11 + 4] + 3.0 * t * (1.0 - t) * (1.0 - t) * buf[i * 11 + 6] + 3 * t * t * (1.0 - t) * buf[i * 11 + 8] + t * t * t * buf[i * 11 + 10];
+ if(*ly > y) *ly = y;
+ if(*ry < y) *ry = y;
+ }
+ break;
+ case 7:
+ if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];
+ if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];
+ for(t = 0; t < 1; t = t + 0.05){
+ y = (1.0 - t) * (1.0 - t) * buf[i * 11 + 6] + 2.0 * t * (1.0 - t) * buf[i * 11 + 8] + t * t * buf[i * 11 + 10];
+ if(*ly > y) *ly = y;
+ if(*ry < y) *ry = y;
+ }
+ }
+ }
+ free(buf);
+ */
+ /*
+ int i;
+ int *buf, strokes;
+
+ buf = convertStroke(in->str, buf, &strokes);
+ *ly = 1000; *ry = 0;
+
+ for(i = 0; i < strokes; i++){
+ if(buf[i * 11 + 0] % 10 == 0) continue;
+
+ if(*ly > buf[i * 11 + 4]) *ly = buf[i * 11 + 4];
+ if(*ry < buf[i * 11 + 4]) *ry = buf[i * 11 + 4];
+ if(*ly > buf[i * 11 + 6]) *ly = buf[i * 11 + 6];
+ if(*ry < buf[i * 11 + 6]) *ry = buf[i * 11 + 6];
+
+ if(buf[i * 11 + 0] % 10 == 2 || buf[i * 11 + 0] % 10 == 3 || buf[i * 11 + 0] % 10 == 8){
+ if(*ly > buf[i * 11 + 8]) *ly = buf[i * 11 + 8];
+ if(*ry < buf[i * 11 + 8]) *ry = buf[i * 11 + 8];
+ }
+ if(buf[i * 11 + 0] % 10 == 4 || buf[i * 11 + 0] % 10 == 6 || buf[i * 11 + 0] % 10 == 7){
+ if(*ly > buf[i * 11 + 10]) *ly = buf[i * 11 + 10];
+ if(*ry < buf[i * 11 + 10]) *ry = buf[i * 11 + 10];
+ }
+ }
+ free(buf);
+ */
+}
+
+KGString * CalcSizes(const KGString *in, int mode){
+ int i, j, k, basewidth, one_lineX, one_lineY;
+ int dlx1, drx1, dly1, dry1;
+ int px1, py1;
+ double pr1, pry1;
+
+ int mitsuT, flg_boxT, widthT, heightT;
+ double tateT, yokoT;
+ int cutx, cuty;
+
+ int *buf, strokes;
+ int tf[12];
+ KGString *out;
+
+ out = kg_string_new("");
+ basewidth = pngWidth * 0.9;
+
+ if(mode == 0){
+ //temporary adjustment X-axis
+ PartsWidth(in, &dlx1, &drx1);
+ if(dlx1 == drx1){
+ pr1 = 1.0;
+ px1 = pngWidth / 2 - dlx1;
+ one_lineX = 1;
+ }
+ else{
+ pr1 = (double)basewidth/(drx1 - dlx1);
+ px1 = (pngWidth-basewidth)/2 - (double)(dlx1 * pr1);
+ one_lineX = 0;
+ }
+
+ //temporary adjustment Y-axis
+ PartsHeight(in, &dly1, &dry1);
+ if(dly1 == dry1){
+ pry1 = 1.0;
+ py1 = pngWidth / 2 - dly1;
+ one_lineY = 1;
+ }
+ else{
+ pry1 = (double)basewidth/(dry1 - dly1);
+ py1 = (pngWidth-basewidth)/2 - (double)(dly1 * pry1);
+ one_lineY = 0;
+ }
+ }
+ else{
+ PartsWidth(in, &dlx1, &drx1);
+ PartsHeight(in, &dly1, &dry1);
+
+ cutx = 0;
+ cuty = 0;
+
+ CalcOptions(in, &mitsuT, &flg_boxT, &yokoT, &tateT);
+
+ widthT = basewidth;
+ heightT = basewidth;
+
+ if(flg_boxT % 2 / 1 != 0){
+ widthT = widthT - kWidth * 3;
+ cutx++;
+ }
+ if(flg_boxT % 4 / 2 != 0){
+ widthT = widthT - kWidth * 3;
+ cutx++;
+ }
+ if(flg_boxT % 8 / 4 != 0){
+ heightT = heightT - kWidth * 3;
+ cuty++;
+ }
+ if(flg_boxT % 16 / 8 != 0){
+ heightT = heightT - kWidth * 3;
+ cuty++;
+ }
+
+ //especially get small the 'mouth'
+ if(mode == 2 && flg_boxT % 16 == 15){
+ widthT = widthT - kWidth * (max(0, 16 - (int)yokoT * 4));
+ heightT = heightT - kWidth * (max(0, 16 - (int)tateT * 4));
+ }
+ //'dot' as same as 'mouth'
+ if(mode == 2 && tateT == 1 && yokoT == 1){
+ widthT = pngWidth * 0.9 * 0.5;
+ heightT = pngWidth * 0.9 * 0.5;
+ }
+
+ /*
+if(flg_boxT % 64 / 32 != 0){
+ buf = convertStroke(in->str, buf, &strokes);
+ for(i = 0; i < strokes; i++){
+ if(buf[i * 11 + 0] == 0) j = buf[i * 11 + 4];// j : center line
+ }
+ free(buf);
+ k = max(j - dlx1, drx1 - j);// k : distance from center line
+ pr1 = (basewidth * 0.5) / k;
+
+ if(k == j - dlx1) px1 = 0;
+ else px1 = pngWidth * 0.5 - j * pr1;
+ }
+ else
+*/
+ if(dlx1 == drx1){
+ pr1 = 1.0;
+ px1 = pngWidth / 2 - dlx1;
+ }
+ else{
+ pr1 = (double)widthT/(drx1 - dlx1);
+ px1 = pngWidth / 2 - (double)((dlx1 + drx1) / 2 * pr1);
+ if(flg_boxT % 2 / 1 != 0 && flg_boxT % 4 / 2 == 0) px1 = px1 + kWidth * 1.5;
+ if(flg_boxT % 2 / 1 == 0 && flg_boxT % 4 / 2 != 0) px1 = px1 - kWidth * 1.5;
+ }
+
+ if(dly1 == dry1){
+ pry1 = 1.0;
+ py1 = pngWidth / 2 - dly1;
+ }
+ else{
+ pry1 = (double)heightT/(dry1 - dly1);
+ py1 = pngWidth / 2 - (double)((dly1 + dry1) / 2 * pry1);
+ if(flg_boxT % 8 / 4 != 0 && flg_boxT % 16 / 8 == 0) py1 = py1 + kWidth * 1.5;
+ if(flg_boxT % 8 / 4 == 0 && flg_boxT % 16 / 8 != 0) py1 = py1 - kWidth * 1.5;
+ }
+ }
+
+ //generate result
+ tf[0] = px1;
+ tf[1] = py1;
+ tf[2] = px1 + pr1 * 200;
+ tf[3] = py1 + pry1 * 200;
+ addStrokeWithTransform(in, 1, tf, out, 0);
+ return kg_string_new(out->str);
+}
+
+void DrawBox(){
+ int i, j;
+
+ for(i = 0; i < canvasWidth; i++){
+ for(j = 0; j < canvasHeight; j++){
+ kageCanvas[j][i] = kWhite;
+ }
+ }
+}
+
+void CalcOptions(const KGString *in, int *mitsudo, int *flag, double *yoko, double *tate){
+ int i, j, k, l, flg;
+ int dlx1, drx1, dly1, dry1;
+ int kari, mode;
+ int tempShotai;
+ int *buf, strokes;
+
+ *flag = 0;
+
+ DrawBox();
+ tempShotai = kShotai;
+ kShotai = kGothic;
+ drawGlyph(in, 1);
+ kShotai = tempShotai;
+ DotsWidth(&dlx1, &drx1);
+ DotsHeight(&dly1, &dry1);
+
+ //check left side
+ k = 0;
+ l = 0;
+ for(i = 0; i < pngWidth; i++){
+ flg = 0;
+ for(j = 0; j < kWidth; j++){
+ if(kageCanvas[i][dlx1 + j] != kWhite) flg = 1;
+ }
+ if(flg == 1){
+ k++;
+ }
+ else{
+ if(k > l) l = k;
+ k = 0;
+ }
+ }
+ if(k > l) l = k;
+
+ if(l > pngWidth * 0.9 / 4) *flag = *flag | 1;
+
+ //check right side
+ k = 0;
+ l = 0;
+ for(i = 0; i < pngWidth; i++){
+ flg = 0;
+ for(j = 0; j < kWidth; j++){
+ if(kageCanvas[i][drx1 - j] != kWhite) flg = 1;
+ }
+ if(flg == 1) k++;
+ else{
+ if(k > l) l = k;
+ k = 0;
+ }
+ }
+ if(k > l) l = k;
+
+ if(l > pngWidth * 0.9 / 4) *flag = *flag | 2;
+
+ //check upper side
+ k = 0;
+ l = 0;
+ for(i = 0; i < pngWidth; i++){
+ flg = 0;
+ for(j = 0; j < kWidth; j++){
+ if(kageCanvas[dly1 + j][i] != kWhite) flg = 1;
+ }
+ if(flg == 1) k++;
+ else{
+ if(k > l) l = k;
+ k = 0;
+ }
+ }
+ if(k > l) l = k;
+
+ if(l > pngWidth * 0.9 / 4) *flag = *flag | 4;
+
+ //check bottom side
+ k = 0;
+ l = 0;
+ for(i = 0; i < pngWidth; i++){
+ flg = 0;
+ for(j = 0; j < kWidth; j++){
+ if(kageCanvas[dry1 - j][i] != kWhite) flg = 1;
+ }
+ if(flg == 1) k++;
+ else{
+ if(k > l) l = k;
+ k = 0;
+ }
+ }
+ if(k > l) l = k;
+
+ if(l > pngWidth * 0.9 / 4) *flag = *flag | 8;
+
+ //count black dots
+ *mitsudo = 0;
+ for(i = 0; i < pngHeight; i++){
+ for(j = 0; j < pngWidth; j++){
+ if(kageCanvas[i][j] != kWhite) *mitsudo += 1;
+ }
+ }
+
+ //calculate X-axis complexity
+ *yoko = 0;
+ for(i = dly1; i <= dry1; i++){
+ mode = 0;
+ kari = 0;
+ for(j = dlx1; j <= drx1; j++){
+ if(kageCanvas[i][j] != kWhite &&
+ kageCanvas[i][j+1] != kWhite &&
+ kageCanvas[i][j+2] != kWhite){
+ if(mode == 0){
+ mode = 1;
+ kari++;
+ }
+ }
+ else if(mode == 1) mode = 0;
+ }
+ if(kari > *yoko) *yoko = kari;
+ }
+
+ //calculate Y-axis complexity
+ *tate = 0;
+ for(i = dlx1; i <= drx1; i++){
+ mode = 0;
+ kari = 0;
+ for(j = dly1; j <= dry1; j++){
+ if(kageCanvas[j][i] != kWhite &&
+ kageCanvas[j+1][i] != kWhite &&
+ kageCanvas[j+2][i] != kWhite){
+ if(mode == 0){
+ mode = 1;
+ kari++;
+ }
+ }
+ else if(mode == 1) mode = 0;
+ }
+ if(kari > *tate) *tate = kari;
+ }
+
+ //use user defined option if it exists
+ buf = convertStroke(in->str, buf, &strokes);
+ for(i = 0; i < strokes; i++){
+ if(buf[i * 11 + 0] % 10 == 0){
+ if(buf[i * 11 + 1] != 0) *yoko = (double)(buf[i * 11 + 1]) * 0.1;
+ if(buf[i * 11 + 2] != 0) *tate = (double)(buf[i * 11 + 2]) * 0.1;
+ if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3];
+ }
+ }
+ free(buf);
+}
+
+void DoDrawParts(const KGString *in, const int lx1, const double rf1, const int ly1, const double rfy1){
+ int i;
+ int *buf, strokes;
+
+ DrawBox();
+ buf = convertStroke(in->str, buf, &strokes);
+ for(i = 0; i < strokes; i++){
+ dfDrawFont(buf[i * 11 + 0],
+ buf[i * 11 + 1],
+ buf[i * 11 + 2],
+ buf[i * 11 + 3] * rf1 + lx1,
+ buf[i * 11 + 4] * rfy1 + ly1,
+ buf[i * 11 + 5] * rf1 + lx1,
+ buf[i * 11 + 6] * rfy1 + ly1,
+ buf[i * 11 + 7] * rf1 + lx1,
+ buf[i * 11 + 8] * rfy1 + ly1,
+ buf[i * 11 + 9] * rf1 + lx1,
+ buf[i * 11 + 10] * rfy1 + ly1);
+ }
+ free(buf);
+}
+
+void DoDrawMixFont(const KGString *in1,
+ const int lx1,
+ const double rf1,
+ const KGString *in2,
+ const int lx2,
+ const double rf2,
+ const int ly1,
+ const double rfy1,
+ const int ly2,
+ const double rfy2){
+ int i;
+ int *buf, strokes;
+
+ DrawBox();
+ buf = convertStroke(in1->str, buf, &strokes);
+ for(i = 0; i < strokes; i++){
+ dfDrawFont(buf[i * 11 + 0],
+ buf[i * 11 + 1],
+ buf[i * 11 + 2],
+ buf[i * 11 + 3] * rf1 + lx1,
+ buf[i * 11 + 4] * rfy1 + ly1,
+ buf[i * 11 + 5] * rf1 + lx1,
+ buf[i * 11 + 6] * rfy1 + ly1,
+ buf[i * 11 + 7] * rf1 + lx1,
+ buf[i * 11 + 8] * rfy1 + ly1,
+ buf[i * 11 + 9] * rf1 + lx1,
+ buf[i * 11 + 10] * rfy1 + ly1);
+ }
+ free(buf);
+
+ buf = convertStroke(in2->str, buf, &strokes);
+ for(i = 0; i < strokes; i++){
+ dfDrawFont(buf[i * 11 + 0],
+ buf[i * 11 + 1],
+ buf[i * 11 + 2],
+ buf[i * 11 + 3] * rf2 + lx2,
+ buf[i * 11 + 4] * rfy2 + ly2,
+ buf[i * 11 + 5] * rf2 + lx2,
+ buf[i * 11 + 6] * rfy2 + ly2,
+ buf[i * 11 + 7] * rf2 + lx2,
+ buf[i * 11 + 8] * rfy2 + ly2,
+ buf[i * 11 + 9] * rf2 + lx2,
+ buf[i * 11 + 10] * rfy2 + ly2);
+ }
+ free(buf);
+}
+