From: Koichi KAMICHI Date: Mon, 21 Feb 2005 02:05:20 +0000 (+0000) Subject: Abstract drawing function for adding 'gray' color. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=79507c20c31b15e08f14672e1a9705751f0dba2b;p=chise%2Fkage.git Abstract drawing function for adding 'gray' color. --- diff --git a/kagecgi/kage.h b/kagecgi/kage.h index 0ec5dde..1be95f9 100755 --- a/kagecgi/kage.h +++ b/kagecgi/kage.h @@ -10,6 +10,10 @@ int kShotai; #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 @@ -55,5 +59,7 @@ void cdDrawCurve(double, double, double, double, double, double, int, int); 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 diff --git a/kagecgi/kagedf.c b/kagecgi/kagedf.c index 17273da..df71407 100755 --- a/kagecgi/kagedf.c +++ b/kagecgi/kagedf.c @@ -1,375 +1,347 @@ -//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); - /* - if(a2 == 7 || a3 == 7){ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, 15); - } - else{ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, 15); - } - */ - } - else{ - cdDrawBezier(x1, y1, x2, y2, x3, y3, x4, y4, a2, a3); - /* - if(a2 == 7 || a3 == 7){ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, a3); - } - else{ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, 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 - kageCanvas[y1][x1] = 0; - kageCanvas[y2][x2] = 0; - 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; - /* - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 1); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, tx1, ty1, 1, 1); - */ - cdDrawBezier(x1, y1, x2, y2, x3, y3, tx1, ty1, a2, 1); - cdDrawCurve(tx1, ty1, x4, y4, tx2, ty2, 1, 0); - } - else{ - /* - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 1); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, a3); - */ - 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 - kageCanvas[y1][x1] = 0; - kageCanvas[y2][x2] = 0; - break; - default: - break; - } - } -} +//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; + } + } +} diff --git a/kagecgi/kageic.c b/kagecgi/kageic.c index 3edbe2f..9f05720 100755 --- a/kagecgi/kageic.c +++ b/kagecgi/kageic.c @@ -9,7 +9,7 @@ void icPolygon(kPoint *poly, int number){ char buf[256]; if(kMode == 0){ //normal - fillPolygon(poly, number, 0, kageCanvas); + fillPolygon(poly, number, kBlack, kageCanvas); } else if(kMode == 1){ //output for svg sprintf(buf, "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; } diff --git a/kagecgi/kagepoly.c b/kagecgi/kagepoly.c index 0a001a8..1e2f895 100755 --- a/kagecgi/kagepoly.c +++ b/kagecgi/kagepoly.c @@ -81,10 +81,10 @@ void fillPolygon(kPoint *p, int number, int col, unsigned char **image){ } if(num != 0){ //(for debug) - if(num % 2 != 0){ - fprintf(stderr,"y:%d(%d)\n",j,num); - for(k=0;k k; l--){ diff --git a/kagecgi/kagetool.c b/kagecgi/kagetool.c index e3fc89b..dbe6ad6 100755 --- a/kagecgi/kagetool.c +++ b/kagecgi/kagetool.c @@ -1,568 +1,568 @@ -//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] == 0){ - *dlx = i; - break; - } - } - } - - for(i = canvasWidth - 1; i >= 0 && *drx == 0; i--){ - for(j = 0; j < canvasHeight; j++){ - if(kageCanvas[j][i] == 0){ - *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] == 0){ - *dly = j; - break; - } - } - } - - for(j = canvasHeight - 1; j >= 0 && *dry == 0; j--){ - for(i = 0; i < canvasWidth; i++){ - if(kageCanvas[j][i] == 0){ - *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] = 0xFF; - } - } -} - -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] == 0) 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] == 0) 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] == 0) 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] == 0) 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] == 0) *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] == 0 && - kageCanvas[i][j+1] == 0 && - kageCanvas[i][j+2] == 0){ - 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] == 0 && - kageCanvas[j+1][i] == 0 && - kageCanvas[j+2][i] == 0){ - 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); -} - +//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); +} +