X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=kagecgi%2Fkagetool.c;h=e3fc89b5977d582a3655356050cc6e6e1abf66c5;hb=7a59f9631b96415cc5add984e077e99c579554a8;hp=91cacdfa342c48415dde8c18b9ac3a8aed1e75e1;hpb=b49960d176131cd8ed4af15542d7e868f944a351;p=chise%2Fkage.git diff --git a/kagecgi/kagetool.c b/kagecgi/kagetool.c index 91cacdf..e3fc89b 100755 --- a/kagecgi/kagetool.c +++ b/kagecgi/kagetool.c @@ -3,16 +3,15 @@ #include "kage.h" #include "kagecgi.h" -#include -#include +#include "sysdep.h" void DotsWidth(int *dlx, int *drx){ int i, j; *dlx = 0; *drx = 0; - for(i = 0; i <= pngWidth && *dlx == 0; i++){ - for(j = 0; j <= pngHeight; j++){ + for(i = 0; i < canvasWidth && *dlx == 0; i++){ + for(j = 0; j < canvasHeight; j++){ if(kageCanvas[j][i] == 0){ *dlx = i; break; @@ -20,8 +19,8 @@ void DotsWidth(int *dlx, int *drx){ } } - for(i = pngWidth; i >= 0 && *drx == 0; i--){ - for(j = 0; j <= pngHeight; j++){ + for(i = canvasWidth - 1; i >= 0 && *drx == 0; i--){ + for(j = 0; j < canvasHeight; j++){ if(kageCanvas[j][i] == 0){ *drx = i; break; @@ -35,8 +34,8 @@ void DotsHeight(int *dly, int *dry){ *dly = 0; *dry = 0; - for(j = 0; j <= pngHeight && *dly == 0; j++){ - for(i = 0; i <= pngWidth; i++){ + for(j = 0; j < canvasHeight && *dly == 0; j++){ + for(i = 0; i < canvasWidth; i++){ if(kageCanvas[j][i] == 0){ *dly = j; break; @@ -44,8 +43,8 @@ void DotsHeight(int *dly, int *dry){ } } - for(j = pngHeight; j >= 0 && *dry == 0; j--){ - for(i = 0; i <= pngWidth; i++){ + for(j = canvasHeight - 1; j >= 0 && *dry == 0; j--){ + for(i = 0; i < canvasWidth; i++){ if(kageCanvas[j][i] == 0){ *dry = j; break; @@ -54,34 +53,133 @@ void DotsHeight(int *dly, int *dry){ } } -void PartsWidth(const GString *in, int *lx, int *rx){ +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++){ - if(buf[i * 11 + 0] % 10 == 0) continue; + switch(buf[i * 11 + 0] % 10){ - 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(buf[i * 11 + 0] % 10 == 2 || buf[i * 11 + 0] % 10 == 3 || buf[i * 11 + 0] % 10 == 8){ + 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; + } } - if(buf[i * 11 + 0] % 10 == 4 || buf[i * 11 + 0] % 10 == 6 || buf[i * 11 + 0] % 10 == 7){ - if(*lx > buf[i * 11 + 9]) *lx = buf[i * 11 + 9]; - if(*rx < buf[i * 11 + 9]) *rx = buf[i * 11 + 9]; - } } free(buf); + */ } -void PartsHeight(const GString *in, int *ly, int *ry){ +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; @@ -106,9 +204,10 @@ void PartsHeight(const GString *in, int *ly, int *ry){ } } free(buf); + */ } -GString * CalcSizes(const GString *in, int mode){ +KGString * CalcSizes(const KGString *in, int mode){ int i, j, k, basewidth, one_lineX, one_lineY; int dlx1, drx1, dly1, dry1; int px1, py1; @@ -120,9 +219,9 @@ GString * CalcSizes(const GString *in, int mode){ int *buf, strokes; int tf[12]; - GString *out; + KGString *out; - out = g_string_new(""); + out = kg_string_new(""); basewidth = pngWidth * 0.9; if(mode == 0){ @@ -192,28 +291,31 @@ GString * CalcSizes(const GString *in, int mode){ 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 + /* +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){ + } + else +*/ + if(dlx1 == drx1){ pr1 = 1.0; px1 = pngWidth / 2 - dlx1; - } - else{ + } + 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; @@ -233,7 +335,7 @@ GString * CalcSizes(const GString *in, int mode){ tf[2] = px1 + pr1 * 200; tf[3] = py1 + pry1 * 200; addStrokeWithTransform(in, 1, tf, out, 0); - return g_string_new(out->str); + return kg_string_new(out->str); } void DrawBox(){ @@ -246,7 +348,7 @@ void DrawBox(){ } } -void CalcOptions(const GString *in, int *mitsudo, int *flag, double *yoko, double *tate){ +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; @@ -387,15 +489,15 @@ void CalcOptions(const GString *in, int *mitsudo, int *flag, double *yoko, doubl 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;fprintf(stderr,"@@@@@\r\n");} + 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] * 16; + if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3]; } } free(buf); } -void DoDrawParts(const GString *in, const int lx1, const double rf1, const int ly1, const double rfy1){ +void DoDrawParts(const KGString *in, const int lx1, const double rf1, const int ly1, const double rfy1){ int i; int *buf, strokes; @@ -417,10 +519,10 @@ void DoDrawParts(const GString *in, const int lx1, const double rf1, const int l free(buf); } -void DoDrawMixFont(const GString *in1, +void DoDrawMixFont(const KGString *in1, const int lx1, const double rf1, - const GString *in2, + const KGString *in2, const int lx2, const double rf2, const int ly1,