From: Koichi KAMICHI Date: Tue, 25 Jan 2005 05:25:35 +0000 (+0000) Subject: Adjust LR combine function. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=a7d1a760ffc39e95255fa81a9f7347e8bdae3c97;p=chise%2Fkage.git Adjust LR combine function. --- diff --git a/kagecgi/kage.h b/kagecgi/kage.h index 2c5e4f0..0ec5dde 100755 --- a/kagecgi/kage.h +++ b/kagecgi/kage.h @@ -29,6 +29,8 @@ int kShotai; #define FLAG_FLAT_RIGHT 2 #define FLAG_FLAT_TOP 4 #define FLAG_FLAT_BOTTOM 8 +#define FLAG_REPLACE_2FF1_TO_2FF5 16 +#define FLAG_RADICAL_LEFT 32 #define FLAG_SURROUND_LEFT 1 #define FLAG_SURROUND_RIGHT 2 diff --git a/kagecgi/kagecgi.h b/kagecgi/kagecgi.h index aec5f0f..041b9bf 100755 --- a/kagecgi/kagecgi.h +++ b/kagecgi/kagecgi.h @@ -21,8 +21,8 @@ #define canvasWidth 400 #define canvasHeight 400 -#define min(x1,x2) ((x1) > (x2))? (x2):(x1) -#define max(x1,x2) ((x1) > (x2))? (x1):(x2) +#define min(x1,x2) (((x1) > (x2))? (x2):(x1)) +#define max(x1,x2) (((x1) > (x2))? (x1):(x2)) DB *kPartsdbDatabase; DB *kIdsdbDatabase; diff --git a/kagecgi/kagechar.c b/kagecgi/kagechar.c index 6223377..6d8a2eb 100755 --- a/kagecgi/kagechar.c +++ b/kagecgi/kagechar.c @@ -1,395 +1,395 @@ -//kagechar.c -// - -#include "kage.h" -#include "kagecgi.h" -#include "sysdep.h" - -int isIDS(const KGString *in){ - //check IDC "u2ff*" - if(strncmp(in->str, "u2ff", 4) == 0){ - //check the last char - if('0' <= (in->str)[4] && (in->str)[4] <= 'a') return 1; //true - } - return 0; //false -} - -void divideInto2(const KGString *in, KGString *partIDS1, KGString *partIDS3){ - KGString *buffer[16]; - char tmp[kMaxIDCLength + 1]; - int i, counter, pointer, flag; - - kg_string_set_size(partIDS1, 0); - - counter = 0; - pointer = 0; - for(i = 0; i < in->len; i++){ - if((in->str)[i] == '.'){ - strncpy(tmp, (in->str) + pointer, i - pointer); - tmp[i - pointer] = '\0'; - buffer[counter] = kg_string_new(tmp); - counter++; - pointer = i + 1; - } - } - strncpy(tmp, (in->str) + pointer, i - pointer); - tmp[i - pointer] = '\0'; - buffer[counter] = kg_string_new(tmp); - counter++; - - //reject over-length of IDS - if(counter > kMaxIDSSequenceLength) return; - - //1st scan - pointer = 1; - flag = 0; - while(flag >= 0 && pointer < counter){ - kg_string_append(partIDS1, (buffer[pointer])->str); - kg_string_append(partIDS1, "."); - if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ - switch (((buffer[pointer])->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - flag++; - break; - case '2': - case '3': - flag = flag + 2; - break; - } - } - else flag--; - pointer++; - } - kg_string_erase(partIDS1, partIDS1->len - 1, 1); - - //2nd scan - flag = 0; - while(flag >= 0 && pointer < counter){ - kg_string_append(partIDS3, (buffer[pointer])->str); - kg_string_append(partIDS3, "."); - if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ - switch (((buffer[pointer])->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - flag++; - break; - case '2': - case '3': - flag = flag + 2; - break; - } - } - else flag--; - pointer++; - } - kg_string_erase(partIDS3, partIDS3->len - 1, 1); -} - -void divideInto3(const KGString *in, KGString *partIDS1, KGString *partIDS2, KGString *partIDS3){ - KGString *buffer[16]; - char tmp[kMaxIDCLength + 1]; - int i, counter, pointer, flag; - - kg_string_set_size(partIDS1, 0); - - counter = 0; - pointer = 0; - for(i = 0; i < in->len; i++){ - if((in->str)[i] == '.'){ - strncpy(tmp, (in->str) + pointer, i - pointer); - tmp[i - pointer] = '\0'; - buffer[counter] = kg_string_new(tmp); - counter++; - pointer = i + 1; - } - } - strncpy(tmp, (in->str) + pointer, i - pointer); - tmp[i - pointer] = '\0'; - buffer[counter] = kg_string_new(tmp); - counter++; - - //reject over-length of IDS - if(counter > kMaxIDSSequenceLength) return; - - //1st scan - pointer = 1; - flag = 0; - while(flag >= 0 && pointer < counter){ - kg_string_append(partIDS1, (buffer[pointer])->str); - kg_string_append(partIDS1, "."); - if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ - switch (((buffer[pointer])->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - flag++; - break; - case '2': - case '3': - flag = flag + 2; - break; - } - } - else flag--; - pointer++; - } - kg_string_erase(partIDS1, partIDS1->len - 1, 1); - - //2nd scan - flag = 0; - while(flag >= 0 && pointer < counter){ - kg_string_append(partIDS2, (buffer[pointer])->str); - kg_string_append(partIDS2, "."); - if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ - switch (((buffer[pointer])->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - flag++; - break; - case '2': - case '3': - flag = flag + 2; - break; - } - } - else flag--; - pointer++; - } - kg_string_erase(partIDS2, partIDS2->len - 1, 1); - - //3rd scan - flag = 0; - while(flag >= 0 && pointer < counter){ - kg_string_append(partIDS3, (buffer[pointer])->str); - kg_string_append(partIDS3, "."); - if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ - switch (((buffer[pointer])->str)[4]){ - case '0': - case '1': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - flag++; - break; - case '2': - case '3': - flag = flag + 2; - break; - } - } - else flag--; - pointer++; - } - kg_string_erase(partIDS3, partIDS3->len - 1, 1); -} - -void addStrokeWithTransform(const KGString *stroke, const int num, const int *tf, KGString *out, int mode){ - int *buf, i, size; - KGString *tmp; - - tmp = kg_string_new(""); - buf = convertStroke(stroke->str, buf, &size); - - for(i = 0; i < size; i++){ - if(buf[i * 11 + 0] != 0 && buf[i * 11 + 0] != 99){ - buf[i * 11 + 3] = - tf[(num - 1) * 4 + 0] + buf[i * 11 + 3] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; - buf[i * 11 + 5] = - tf[(num - 1) * 4 + 0] + buf[i * 11 + 5] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; - buf[i * 11 + 7] = - tf[(num - 1) * 4 + 0] + buf[i * 11 + 7] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; - buf[i * 11 + 9] = - tf[(num - 1) * 4 + 0] + buf[i * 11 + 9] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; - buf[i * 11 + 4] = - tf[(num - 1) * 4 + 1] + buf[i * 11 + 4] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; - buf[i * 11 + 6] = - tf[(num - 1) * 4 + 1] + buf[i * 11 + 6] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; - buf[i * 11 + 8] = - tf[(num - 1) * 4 + 1] + buf[i * 11 + 8] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; - buf[i * 11 + 10] = - tf[(num - 1) * 4 + 1] + buf[i * 11 + 10] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; - } - } - convertArray(buf, tmp, size, mode); - if(out->len != 0) kg_string_append(out, "$"); - kg_string_append(out, tmp->str); - - free((void *)buf); -} - -void convertArray(int *buf, KGString *out, int size, int mode){ - int i; - char tmp[kMaxStrokeDataLength]; - - for(i = 0; i < size; i++){ - if(!(mode == 1 && (buf[i * 11 + 0] == 0 || buf[i * 11 + 0] == 99))){ - sprintf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d$", - buf[i * 11 + 0], - buf[i * 11 + 1], - buf[i * 11 + 2], - buf[i * 11 + 3], - buf[i * 11 + 4], - buf[i * 11 + 5], - buf[i * 11 + 6], - buf[i * 11 + 7], - buf[i * 11 + 8], - buf[i * 11 + 9], - buf[i * 11 + 10]); - kg_string_append(out, tmp); - } - } - out = kg_string_erase(out, (out->len - 1), 1); -} - -int * convertStroke(const char *in, int *a, int *size){ - int i, counter, pointer; - int a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10; - char tmp[kMaxStrokeDataLength + 1]; - - a = (int *)malloc(0); - counter = 0; - pointer = 0; - for(i = 0; i < strlen(in); i++){ - if(in[i] == '$'){ - strncpy(tmp, &in[pointer], i - pointer); - tmp[i - pointer] = '\0'; - a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1)); - sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", - &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10); - a[counter * 11 + 0] = a0; - a[counter * 11 + 1] = a1; - a[counter * 11 + 2] = a2; - a[counter * 11 + 3] = a3; - a[counter * 11 + 4] = a4; - a[counter * 11 + 5] = a5; - a[counter * 11 + 6] = a6; - a[counter * 11 + 7] = a7; - a[counter * 11 + 8] = a8; - a[counter * 11 + 9] = a9; - a[counter * 11 + 10] = a10; - counter++; - pointer = i + 1; - } - } - strncpy(tmp, &in[pointer], i - pointer); - tmp[i - pointer] = '\0'; - a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1)); - sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", - &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10); - a[counter * 11 + 0] = a0; - a[counter * 11 + 1] = a1; - a[counter * 11 + 2] = a2; - a[counter * 11 + 3] = a3; - a[counter * 11 + 4] = a4; - a[counter * 11 + 5] = a5; - a[counter * 11 + 6] = a6; - a[counter * 11 + 7] = a7; - a[counter * 11 + 8] = a8; - a[counter * 11 + 9] = a9; - a[counter * 11 + 10] = a10; - counter++; - *(size) = counter; - return a; -} - -void convert99(const KGString *in, KGString *out){ - int i, pointer; - char tmp[kMaxStrokeDataLength + 1]; - KGString *buf; - - kg_string_set_size(out, 0); - buf = kg_string_new(""); - pointer = 0; - for(i = 0; i < in->len; i++){ - if((in->str)[i] == '$'){ - strncpy(tmp, in->str + pointer, i - pointer); - tmp[i - pointer] = '\0'; - if(strncmp(tmp, "99:", 3) == 0){ - convert99calc(tmp, buf); - if(buf->len == 0){ - kg_string_set_size(out, 0); - return; - } - kg_string_append(out, buf->str); - } - else kg_string_append(out, tmp); - kg_string_append(out, "$"); - - pointer = i + 1; - } - } - strncpy(tmp, in->str + pointer, i - pointer); - tmp[i - pointer] = '\0'; - if(strncmp(tmp, "99:", 3) == 0){ - convert99calc(tmp, buf); - if(buf->len == 0){ - kg_string_set_size(out, 0); - return; - } - kg_string_append(out, buf->str); - } - else kg_string_append(out, tmp); -} - -void convert99calc(const char *in, KGString *out){ - KGString *buf1, *buf2; - int a1,x1,y1,x2,y2,option,option2; - char pname[kMaxStrokeDataLength]; - int tf[12]; - - kg_string_set_size(out, 0); - buf2 = kg_string_new(""); - - //get parts data - sscanf(in, "%d:%d:%d:%d:%d:%d:%d:%s", - &a1,&option,&option2,&x1,&y1,&x2,&y2,pname); - //end = strchr(pname, ':'); - //*end = '\0'; - buf1 = kg_string_new(pname); - generateGlyph(buf1, buf2); - if(buf2->len == 0) return; - - //convert - tf[0] = x1; - tf[1] = y1; - tf[2] = x2; - tf[3] = y2; - addStrokeWithTransform(buf2, 1, tf, out, 1); -} +//kagechar.c +// + +#include "kage.h" +#include "kagecgi.h" +#include "sysdep.h" + +int isIDS(const KGString *in){ + //check IDC "u2ff*" + if(strncmp(in->str, "u2ff", 4) == 0){ + //check the last char + if('0' <= (in->str)[4] && (in->str)[4] <= 'a') return 1; //true + } + return 0; //false +} + +void divideInto2(const KGString *in, KGString *partIDS1, KGString *partIDS3){ + KGString *buffer[16]; + char tmp[kMaxIDCLength + 1]; + int i, counter, pointer, flag; + + kg_string_set_size(partIDS1, 0); + + counter = 0; + pointer = 0; + for(i = 0; i < in->len; i++){ + if((in->str)[i] == '.'){ + strncpy(tmp, (in->str) + pointer, i - pointer); + tmp[i - pointer] = '\0'; + buffer[counter] = kg_string_new(tmp); + counter++; + pointer = i + 1; + } + } + strncpy(tmp, (in->str) + pointer, i - pointer); + tmp[i - pointer] = '\0'; + buffer[counter] = kg_string_new(tmp); + counter++; + + //reject over-length of IDS + if(counter > kMaxIDSSequenceLength) return; + + //1st scan + pointer = 1; + flag = 0; + while(flag >= 0 && pointer < counter){ + kg_string_append(partIDS1, (buffer[pointer])->str); + kg_string_append(partIDS1, "."); + if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ + switch (((buffer[pointer])->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + flag++; + break; + case '2': + case '3': + flag = flag + 2; + break; + } + } + else flag--; + pointer++; + } + kg_string_erase(partIDS1, partIDS1->len - 1, 1); + + //2nd scan + flag = 0; + while(flag >= 0 && pointer < counter){ + kg_string_append(partIDS3, (buffer[pointer])->str); + kg_string_append(partIDS3, "."); + if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ + switch (((buffer[pointer])->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + flag++; + break; + case '2': + case '3': + flag = flag + 2; + break; + } + } + else flag--; + pointer++; + } + kg_string_erase(partIDS3, partIDS3->len - 1, 1); +} + +void divideInto3(const KGString *in, KGString *partIDS1, KGString *partIDS2, KGString *partIDS3){ + KGString *buffer[16]; + char tmp[kMaxIDCLength + 1]; + int i, counter, pointer, flag; + + kg_string_set_size(partIDS1, 0); + + counter = 0; + pointer = 0; + for(i = 0; i < in->len; i++){ + if((in->str)[i] == '.'){ + strncpy(tmp, (in->str) + pointer, i - pointer); + tmp[i - pointer] = '\0'; + buffer[counter] = kg_string_new(tmp); + counter++; + pointer = i + 1; + } + } + strncpy(tmp, (in->str) + pointer, i - pointer); + tmp[i - pointer] = '\0'; + buffer[counter] = kg_string_new(tmp); + counter++; + + //reject over-length of IDS + if(counter > kMaxIDSSequenceLength) return; + + //1st scan + pointer = 1; + flag = 0; + while(flag >= 0 && pointer < counter){ + kg_string_append(partIDS1, (buffer[pointer])->str); + kg_string_append(partIDS1, "."); + if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ + switch (((buffer[pointer])->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + flag++; + break; + case '2': + case '3': + flag = flag + 2; + break; + } + } + else flag--; + pointer++; + } + kg_string_erase(partIDS1, partIDS1->len - 1, 1); + + //2nd scan + flag = 0; + while(flag >= 0 && pointer < counter){ + kg_string_append(partIDS2, (buffer[pointer])->str); + kg_string_append(partIDS2, "."); + if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ + switch (((buffer[pointer])->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + flag++; + break; + case '2': + case '3': + flag = flag + 2; + break; + } + } + else flag--; + pointer++; + } + kg_string_erase(partIDS2, partIDS2->len - 1, 1); + + //3rd scan + flag = 0; + while(flag >= 0 && pointer < counter){ + kg_string_append(partIDS3, (buffer[pointer])->str); + kg_string_append(partIDS3, "."); + if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){ + switch (((buffer[pointer])->str)[4]){ + case '0': + case '1': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'a': + case 'b': + flag++; + break; + case '2': + case '3': + flag = flag + 2; + break; + } + } + else flag--; + pointer++; + } + kg_string_erase(partIDS3, partIDS3->len - 1, 1); +} + +void addStrokeWithTransform(const KGString *stroke, const int num, const int *tf, KGString *out, int mode){ + int *buf, i, size; + KGString *tmp; + + tmp = kg_string_new(""); + buf = convertStroke(stroke->str, buf, &size); + + for(i = 0; i < size; i++){ + if(buf[i * 11 + 0] != 0 && buf[i * 11 + 0] != 99){ + buf[i * 11 + 3] = + tf[(num - 1) * 4 + 0] + buf[i * 11 + 3] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; + buf[i * 11 + 5] = + tf[(num - 1) * 4 + 0] + buf[i * 11 + 5] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; + buf[i * 11 + 7] = + tf[(num - 1) * 4 + 0] + buf[i * 11 + 7] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; + buf[i * 11 + 9] = + tf[(num - 1) * 4 + 0] + buf[i * 11 + 9] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth; + buf[i * 11 + 4] = + tf[(num - 1) * 4 + 1] + buf[i * 11 + 4] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; + buf[i * 11 + 6] = + tf[(num - 1) * 4 + 1] + buf[i * 11 + 6] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; + buf[i * 11 + 8] = + tf[(num - 1) * 4 + 1] + buf[i * 11 + 8] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; + buf[i * 11 + 10] = + tf[(num - 1) * 4 + 1] + buf[i * 11 + 10] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight; + } + } + convertArray(buf, tmp, size, mode); + if(out->len != 0) kg_string_append(out, "$"); + kg_string_append(out, tmp->str); + + free((void *)buf); +} + +void convertArray(int *buf, KGString *out, int size, int mode){ + int i; + char tmp[kMaxStrokeDataLength]; + + for(i = 0; i < size; i++){ + if(!(mode == 1 && (buf[i * 11 + 0] == 0 || buf[i * 11 + 0] == 99))){ + sprintf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d$", + buf[i * 11 + 0], + buf[i * 11 + 1], + buf[i * 11 + 2], + buf[i * 11 + 3], + buf[i * 11 + 4], + buf[i * 11 + 5], + buf[i * 11 + 6], + buf[i * 11 + 7], + buf[i * 11 + 8], + buf[i * 11 + 9], + buf[i * 11 + 10]); + kg_string_append(out, tmp); + } + } + out = kg_string_erase(out, (out->len - 1), 1); +} + +int * convertStroke(const char *in, int *a, int *size){ + int i, counter, pointer; + int a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10; + char tmp[kMaxStrokeDataLength + 1]; + + a = (int *)malloc(0); + counter = 0; + pointer = 0; + for(i = 0; i < strlen(in); i++){ + if(in[i] == '$'){ + strncpy(tmp, &in[pointer], i - pointer); + tmp[i - pointer] = '\0'; + a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1)); + sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10); + a[counter * 11 + 0] = a0; + a[counter * 11 + 1] = a1; + a[counter * 11 + 2] = a2; + a[counter * 11 + 3] = a3; + a[counter * 11 + 4] = a4; + a[counter * 11 + 5] = a5; + a[counter * 11 + 6] = a6; + a[counter * 11 + 7] = a7; + a[counter * 11 + 8] = a8; + a[counter * 11 + 9] = a9; + a[counter * 11 + 10] = a10; + counter++; + pointer = i + 1; + } + } + strncpy(tmp, &in[pointer], i - pointer); + tmp[i - pointer] = '\0'; + a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1)); + sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10); + a[counter * 11 + 0] = a0; + a[counter * 11 + 1] = a1; + a[counter * 11 + 2] = a2; + a[counter * 11 + 3] = a3; + a[counter * 11 + 4] = a4; + a[counter * 11 + 5] = a5; + a[counter * 11 + 6] = a6; + a[counter * 11 + 7] = a7; + a[counter * 11 + 8] = a8; + a[counter * 11 + 9] = a9; + a[counter * 11 + 10] = a10; + counter++; + *(size) = counter; + return a; +} + +void convert99(const KGString *in, KGString *out){ + int i, pointer; + char tmp[kMaxStrokeDataLength + 1]; + KGString *buf; + + kg_string_set_size(out, 0); + buf = kg_string_new(""); + pointer = 0; + for(i = 0; i < in->len; i++){ + if((in->str)[i] == '$'){ + strncpy(tmp, in->str + pointer, i - pointer); + tmp[i - pointer] = '\0'; + if(strncmp(tmp, "99:", 3) == 0){ + convert99calc(tmp, buf); + if(buf->len == 0){ + kg_string_set_size(out, 0); + return; + } + kg_string_append(out, buf->str); + } + else kg_string_append(out, tmp); + kg_string_append(out, "$"); + + pointer = i + 1; + } + } + strncpy(tmp, in->str + pointer, i - pointer); + tmp[i - pointer] = '\0'; + if(strncmp(tmp, "99:", 3) == 0){ + convert99calc(tmp, buf); + if(buf->len == 0){ + kg_string_set_size(out, 0); + return; + } + kg_string_append(out, buf->str); + } + else kg_string_append(out, tmp); +} + +void convert99calc(const char *in, KGString *out){ + KGString *buf1, *buf2; + int a1,x1,y1,x2,y2,option,option2; + char pname[kMaxStrokeDataLength]; + int tf[12]; + + kg_string_set_size(out, 0); + buf2 = kg_string_new(""); + + //get parts data + sscanf(in, "%d:%d:%d:%d:%d:%d:%d:%s", + &a1,&option,&option2,&x1,&y1,&x2,&y2,pname); + //end = strchr(pname, ':'); + //*end = '\0'; + buf1 = kg_string_new(pname); + generateGlyph(buf1, buf2); + if(buf2->len == 0) return; + + //convert + tf[0] = x1; + tf[1] = y1; + tf[2] = x2; + tf[3] = y2; + addStrokeWithTransform(buf2, 1, tf, out, 1); +} diff --git a/kagecgi/kagecomb.c b/kagecgi/kagecomb.c index 7860322..4fb99e7 100755 --- a/kagecgi/kagecomb.c +++ b/kagecgi/kagecomb.c @@ -18,6 +18,9 @@ void combineYoko2(const KGString *parts1, const KGString *parts3, int *result){ double yokoL, tateL, yokoR, tateR; int *buf, strokes; int tempShotai; + int bodyline1[pngWidth], bodyline2[pngWidth]; + double complex; + int tooclose; //initialize pxL = 0; @@ -42,6 +45,9 @@ void combineYoko2(const KGString *parts1, const KGString *parts3, int *result){ CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); + //get thin when the left parts is radical + if(flg_boxL & FLAG_RADICAL_LEFT) yokoL = yokoL / 2; + //left parts Y-axis processing #1 //if its upper and bottom are flat @@ -132,60 +138,89 @@ void combineYoko2(const KGString *parts1, const KGString *parts3, int *result){ prL = rL; prR = rR; - //calculate width of each parts #1 - PartsWidth(parts1, &lxL, &rxL); - PartsWidth(parts3, &lxR, &rxR); - g = 0; - - //calculate width of each parts #2 pxL = 0; pxR = pngWidth * prL; - DoDrawMixFont(parts1, pxL, prL, parts3, pxR, prR, pyL, pryL, pyR, pryR); - - //count dots for check crossing over - DotsHeight(&chk_y1, &chk_y2); - k = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_y1; j <= chk_y2; j++){ - if(kageCanvas[j][i] == 0) k++; + //scan body line of left parts + DoDrawParts(parts1, pxL, prL, pyL, pryL); + for(i = 0; i < pngWidth; i++){ + bodyline1[i] = 0; + for(j = pngWidth - 1; j >= 0; j--){ + if(kageCanvas[i][j] == 0 || + kageCanvas[i + 1][j] == 0 || + kageCanvas[i + 2][j] == 0 || + kageCanvas[i + 3][j] == 0 || + kageCanvas[i + 4][j] == 0 || + kageCanvas[i + 5][j] == 0 || + kageCanvas[i + 6][j] == 0 || + kageCanvas[i + 7][j] == 0){ +/* + kageCanvas[i + 7][j] == 0 || + kageCanvas[i + 8][j] == 0 || + kageCanvas[i + 9][j] == 0 || + kageCanvas[i + 10][j] == 0){ +*/ + bodyline1[i] = j; + j = -1; + } } } - l = k; - //get close both parts - h = pxR; - while(k - l < kMixdot && g < kWidth * 2 * kKasane * 2){ - g = g + 2; - f = pxR - g; - DoDrawMixFont(parts1, pxL, prL, parts3, f, prR, pyL, pryL, pyR, pryR); - - //FOR DEBUG - //char fn[256]; - //FILE *fp; - //snprintf(fn,sizeof(fn),"%03d.png",g); - //fp = fopen(fn, "w"); - //writePng(pngWidth, pngHeight, kageCanvas, fp); - //fclose(fp); - - l = 0; - for(i = 0; i < pngWidth * 1.1; i++){ - for(j = chk_y1; j <= chk_y2; j++){ - if(kageCanvas[j][i] == 0) l++; + //scan body line of right parts + DoDrawParts(parts3, pxR, prR, pyR, pryR); + for(i = 0; i < pngWidth; i++){ + bodyline2[i] = pngWidth; + for(j = 0; j < pngWidth; j++){ + if(kageCanvas[i][j] == 0 || + kageCanvas[i + 1][j] == 0 || + kageCanvas[i + 2][j] == 0 || + kageCanvas[i + 3][j] == 0 || + kageCanvas[i + 4][j] == 0 || + kageCanvas[i + 5][j] == 0 || + kageCanvas[i + 6][j] == 0 || + kageCanvas[i + 7][j] == 0){ +/* + kageCanvas[i + 7][j] == 0 || + kageCanvas[i + 8][j] == 0 || + kageCanvas[i + 9][j] == 0 || + kageCanvas[i + 10][j] == 0){ +*/ + bodyline2[i] = j; + j = pngWidth; } } } - pxR = f; - if(flg_boxL & FLAG_FLAT_RIGHT && flg_boxR & FLAG_FLAT_LEFT){ - if(kShotai == kMincho){ - pxR = pxR + kMinWidthT * 2 * kKasane * 3 / 2; - } else { - pxR = pxR + kWidth * 2 * kKasane * 3 / 2; + //calculate the most thin length of two parts and fix right parts + k = pngWidth; + for(i = 0; i < pngWidth; i++){ + if(bodyline2[i] - bodyline1[i] < k){ + k = bodyline2[i] - bodyline1[i]; } + } + if(k < 0){ k = 0; } + k = min(kMixdot, k); + pxR = pxR - k; + + //calculate if the two are too close + tooclose = 0; + for(i = 0; i < pngWidth; i++){ + if((bodyline2[i] - bodyline1[i]) - k < kWidth * 2){ // must be seperate with shotai? + tooclose++; + } + } + + //final adjustment + if(kShotai == kMincho){ + k = kMinWidthT; } else { - pxR = pxR + kWidth * 2 * kKasane * 2 / 2; + k = kWidth; } + complex = 1 / ((yokoL + yokoR) / 2); + if(tooclose > pngWidth * 0.25){ + complex = complex * 1.5; + } + pxR = pxR + pow((complex * (double)k), 2.3); //set results result[0] = pxL; @@ -272,6 +307,15 @@ void combineTate2(const KGString *parts1, const KGString *parts3, int *result){ CalcOptions(parts1, &mitsuL, &flg_boxL, &yokoL, &tateL); CalcOptions(parts3, &mitsuR, &flg_boxR, &yokoR, &tateR); + if(flg_boxL & FLAG_REPLACE_2FF1_TO_2FF5){ + combineHame2((KGString *)parts1, (KGString *)parts3, (int *)result, + FLAG_SURROUND_LEFT | + FLAG_SURROUND_RIGHT | + FLAG_SURROUND_TOP); + kShotai = tempShotai; + return; + } + //calculate ratio rL = tateL; rR = tateR; diff --git a/kagecgi/kagedf.c b/kagecgi/kagedf.c index 487255c..17273da 100755 --- a/kagecgi/kagedf.c +++ b/kagecgi/kagedf.c @@ -1,6 +1,7 @@ //kagedf.c // #include "kage.h" +#include "kagecgi.h" void dfDrawFont(int a1, int a2, int a3, int x1, int y1, @@ -186,6 +187,8 @@ void dfDrawFont(int a1, int a2, int a3, 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; @@ -362,6 +365,8 @@ void dfDrawFont(int a1, int a2, int a3, 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; diff --git a/kagecgi/kageeg.c b/kagecgi/kageeg.c index 785047a..810f723 100755 --- a/kagecgi/kageeg.c +++ b/kagecgi/kageeg.c @@ -234,6 +234,7 @@ void doCombine(const KGString *in, KGString *out){ addStrokeWithTransform(partStroke3, 3, result, out, 1); break; } + fprintf(stderr,"%s\n",out->str); } void drawGlyph(const KGString *in, const int mode){ diff --git a/kagecgi/kagetool.c b/kagecgi/kagetool.c index ab7627c..e3fc89b 100755 --- a/kagecgi/kagetool.c +++ b/kagecgi/kagetool.c @@ -291,28 +291,31 @@ KGString * CalcSizes(const KGString *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; @@ -488,7 +491,7 @@ void CalcOptions(const KGString *in, int *mitsudo, int *flag, double *yoko, doub 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] * 16; + if(buf[i * 11 + 3] != 0) *flag = *flag + buf[i * 11 + 3]; } } free(buf);