-//kagechar.c\r
-//\r
-\r
-#include "kage.h"\r
-#include "kagecgi.h"\r
-#include "sysdep.h"\r
-\r
-int isIDS(const KGString *in){\r
- //check IDC "u2ff*"\r
- if(strncmp(in->str, "u2ff", 4) == 0){\r
- //check the last char\r
- if('0' <= (in->str)[4] && (in->str)[4] <= 'a') return 1; //true\r
- }\r
- return 0; //false\r
-}\r
-\r
-void divideInto2(const KGString *in, KGString *partIDS1, KGString *partIDS3){\r
- KGString *buffer[16];\r
- char tmp[kMaxIDCLength + 1];\r
- int i, counter, pointer, flag;\r
- \r
- kg_string_set_size(partIDS1, 0);\r
- \r
- counter = 0;\r
- pointer = 0;\r
- for(i = 0; i < in->len; i++){\r
- if((in->str)[i] == '.'){\r
- strncpy(tmp, (in->str) + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- buffer[counter] = kg_string_new(tmp);\r
- counter++;\r
- pointer = i + 1;\r
- }\r
- }\r
- strncpy(tmp, (in->str) + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- buffer[counter] = kg_string_new(tmp);\r
- counter++;\r
- \r
- //reject over-length of IDS\r
- if(counter > kMaxIDSSequenceLength) return;\r
- \r
- //1st scan\r
- pointer = 1;\r
- flag = 0;\r
- while(flag >= 0 && pointer < counter){\r
- kg_string_append(partIDS1, (buffer[pointer])->str);\r
- kg_string_append(partIDS1, ".");\r
- if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){\r
- switch (((buffer[pointer])->str)[4]){\r
- case '0':\r
- case '1':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- case 'a':\r
- case 'b':\r
- flag++;\r
- break;\r
- case '2':\r
- case '3':\r
- flag = flag + 2;\r
- break;\r
- }\r
- }\r
- else flag--;\r
- pointer++;\r
- }\r
- kg_string_erase(partIDS1, partIDS1->len - 1, 1);\r
- \r
- //2nd scan\r
- flag = 0;\r
- while(flag >= 0 && pointer < counter){\r
- kg_string_append(partIDS3, (buffer[pointer])->str);\r
- kg_string_append(partIDS3, ".");\r
- if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){\r
- switch (((buffer[pointer])->str)[4]){\r
- case '0':\r
- case '1':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- case 'a':\r
- case 'b':\r
- flag++;\r
- break;\r
- case '2':\r
- case '3':\r
- flag = flag + 2;\r
- break;\r
- }\r
- }\r
- else flag--;\r
- pointer++;\r
- }\r
- kg_string_erase(partIDS3, partIDS3->len - 1, 1);\r
-}\r
-\r
-void divideInto3(const KGString *in, KGString *partIDS1, KGString *partIDS2, KGString *partIDS3){\r
- KGString *buffer[16];\r
- char tmp[kMaxIDCLength + 1];\r
- int i, counter, pointer, flag;\r
- \r
- kg_string_set_size(partIDS1, 0);\r
- \r
- counter = 0;\r
- pointer = 0;\r
- for(i = 0; i < in->len; i++){\r
- if((in->str)[i] == '.'){\r
- strncpy(tmp, (in->str) + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- buffer[counter] = kg_string_new(tmp);\r
- counter++;\r
- pointer = i + 1;\r
- }\r
- }\r
- strncpy(tmp, (in->str) + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- buffer[counter] = kg_string_new(tmp);\r
- counter++;\r
- \r
- //reject over-length of IDS\r
- if(counter > kMaxIDSSequenceLength) return;\r
- \r
- //1st scan\r
- pointer = 1;\r
- flag = 0;\r
- while(flag >= 0 && pointer < counter){\r
- kg_string_append(partIDS1, (buffer[pointer])->str);\r
- kg_string_append(partIDS1, ".");\r
- if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){\r
- switch (((buffer[pointer])->str)[4]){\r
- case '0':\r
- case '1':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- case 'a':\r
- case 'b':\r
- flag++;\r
- break;\r
- case '2':\r
- case '3':\r
- flag = flag + 2;\r
- break;\r
- }\r
- }\r
- else flag--;\r
- pointer++;\r
- }\r
- kg_string_erase(partIDS1, partIDS1->len - 1, 1);\r
- \r
- //2nd scan\r
- flag = 0;\r
- while(flag >= 0 && pointer < counter){\r
- kg_string_append(partIDS2, (buffer[pointer])->str);\r
- kg_string_append(partIDS2, ".");\r
- if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){\r
- switch (((buffer[pointer])->str)[4]){\r
- case '0':\r
- case '1':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- case 'a':\r
- case 'b':\r
- flag++;\r
- break;\r
- case '2':\r
- case '3':\r
- flag = flag + 2;\r
- break;\r
- }\r
- }\r
- else flag--;\r
- pointer++;\r
- }\r
- kg_string_erase(partIDS2, partIDS2->len - 1, 1);\r
- \r
- //3rd scan\r
- flag = 0;\r
- while(flag >= 0 && pointer < counter){\r
- kg_string_append(partIDS3, (buffer[pointer])->str);\r
- kg_string_append(partIDS3, ".");\r
- if(strncmp((buffer[pointer])->str, "u2ff", 4) == 0){\r
- switch (((buffer[pointer])->str)[4]){\r
- case '0':\r
- case '1':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- case 'a':\r
- case 'b':\r
- flag++;\r
- break;\r
- case '2':\r
- case '3':\r
- flag = flag + 2;\r
- break;\r
- }\r
- }\r
- else flag--;\r
- pointer++;\r
- }\r
- kg_string_erase(partIDS3, partIDS3->len - 1, 1);\r
-}\r
-\r
-void addStrokeWithTransform(const KGString *stroke, const int num, const int *tf, KGString *out, int mode){\r
- int *buf, i, size;\r
- KGString *tmp;\r
- \r
- tmp = kg_string_new("");\r
- buf = convertStroke(stroke->str, buf, &size);\r
- \r
- for(i = 0; i < size; i++){\r
- if(buf[i * 11 + 0] != 0 && buf[i * 11 + 0] != 99){\r
- buf[i * 11 + 3] =\r
- tf[(num - 1) * 4 + 0] + buf[i * 11 + 3] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth;\r
- buf[i * 11 + 5] =\r
- tf[(num - 1) * 4 + 0] + buf[i * 11 + 5] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth;\r
- buf[i * 11 + 7] =\r
- tf[(num - 1) * 4 + 0] + buf[i * 11 + 7] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth;\r
- buf[i * 11 + 9] =\r
- tf[(num - 1) * 4 + 0] + buf[i * 11 + 9] * (tf[(num - 1) * 4 + 2] - tf[(num - 1) * 4 + 0]) / pngWidth;\r
- buf[i * 11 + 4] =\r
- tf[(num - 1) * 4 + 1] + buf[i * 11 + 4] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight;\r
- buf[i * 11 + 6] =\r
- tf[(num - 1) * 4 + 1] + buf[i * 11 + 6] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight;\r
- buf[i * 11 + 8] =\r
- tf[(num - 1) * 4 + 1] + buf[i * 11 + 8] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight;\r
- buf[i * 11 + 10] =\r
- tf[(num - 1) * 4 + 1] + buf[i * 11 + 10] * (tf[(num - 1) * 4 + 3] - tf[(num - 1) * 4 + 1]) / pngHeight;\r
- }\r
- }\r
- convertArray(buf, tmp, size, mode);\r
- if(out->len != 0) kg_string_append(out, "$");\r
- kg_string_append(out, tmp->str);\r
- \r
- free((void *)buf);\r
-}\r
-\r
-void convertArray(int *buf, KGString *out, int size, int mode){\r
- int i;\r
- char tmp[kMaxStrokeDataLength];\r
- \r
- for(i = 0; i < size; i++){\r
- if(!(mode == 1 && (buf[i * 11 + 0] == 0 || buf[i * 11 + 0] == 99))){\r
- sprintf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d$",\r
- buf[i * 11 + 0],\r
- buf[i * 11 + 1],\r
- buf[i * 11 + 2],\r
- buf[i * 11 + 3],\r
- buf[i * 11 + 4],\r
- buf[i * 11 + 5],\r
- buf[i * 11 + 6],\r
- buf[i * 11 + 7],\r
- buf[i * 11 + 8],\r
- buf[i * 11 + 9],\r
- buf[i * 11 + 10]);\r
- kg_string_append(out, tmp);\r
- }\r
- }\r
- out = kg_string_erase(out, (out->len - 1), 1);\r
-}\r
-\r
-int * convertStroke(const char *in, int *a, int *size){\r
- int i, counter, pointer;\r
- int a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10;\r
- char tmp[kMaxStrokeDataLength + 1];\r
- \r
- a = (int *)malloc(0);\r
- counter = 0;\r
- pointer = 0;\r
- for(i = 0; i < strlen(in); i++){\r
- if(in[i] == '$'){\r
- strncpy(tmp, &in[pointer], i - pointer);\r
- tmp[i - pointer] = '\0';\r
- a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1));\r
- sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",\r
- &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10);\r
- a[counter * 11 + 0] = a0;\r
- a[counter * 11 + 1] = a1;\r
- a[counter * 11 + 2] = a2;\r
- a[counter * 11 + 3] = a3;\r
- a[counter * 11 + 4] = a4;\r
- a[counter * 11 + 5] = a5;\r
- a[counter * 11 + 6] = a6;\r
- a[counter * 11 + 7] = a7;\r
- a[counter * 11 + 8] = a8;\r
- a[counter * 11 + 9] = a9;\r
- a[counter * 11 + 10] = a10;\r
- counter++;\r
- pointer = i + 1;\r
- }\r
- }\r
- strncpy(tmp, &in[pointer], i - pointer);\r
- tmp[i - pointer] = '\0';\r
- a = (int *)realloc(a, sizeof(int) * 11 * (counter + 1));\r
- sscanf(tmp, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",\r
- &a0,&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10);\r
- a[counter * 11 + 0] = a0;\r
- a[counter * 11 + 1] = a1;\r
- a[counter * 11 + 2] = a2;\r
- a[counter * 11 + 3] = a3;\r
- a[counter * 11 + 4] = a4;\r
- a[counter * 11 + 5] = a5;\r
- a[counter * 11 + 6] = a6;\r
- a[counter * 11 + 7] = a7;\r
- a[counter * 11 + 8] = a8;\r
- a[counter * 11 + 9] = a9;\r
- a[counter * 11 + 10] = a10;\r
- counter++;\r
- *(size) = counter;\r
- return a;\r
-}\r
-\r
-void convert99(const KGString *in, KGString *out){\r
- int i, pointer;\r
- char tmp[kMaxStrokeDataLength + 1];\r
- KGString *buf;\r
- \r
- kg_string_set_size(out, 0);\r
- buf = kg_string_new("");\r
- pointer = 0;\r
- for(i = 0; i < in->len; i++){\r
- if((in->str)[i] == '$'){\r
- strncpy(tmp, in->str + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- if(strncmp(tmp, "99:", 3) == 0){\r
- convert99calc(tmp, buf);\r
- if(buf->len == 0){\r
- kg_string_set_size(out, 0);\r
- return;\r
- }\r
- kg_string_append(out, buf->str);\r
- }\r
- else kg_string_append(out, tmp);\r
- kg_string_append(out, "$");\r
- \r
- pointer = i + 1;\r
- }\r
- }\r
- strncpy(tmp, in->str + pointer, i - pointer);\r
- tmp[i - pointer] = '\0';\r
- if(strncmp(tmp, "99:", 3) == 0){\r
- convert99calc(tmp, buf);\r
- if(buf->len == 0){\r
- kg_string_set_size(out, 0);\r
- return;\r
- }\r
- kg_string_append(out, buf->str);\r
- }\r
- else kg_string_append(out, tmp);\r
-}\r
-\r
-void convert99calc(const char *in, KGString *out){\r
- KGString *buf1, *buf2;\r
- int a1,x1,y1,x2,y2,option,option2;\r
- char pname[kMaxStrokeDataLength];\r
- int tf[12];\r
- \r
- kg_string_set_size(out, 0);\r
- buf2 = kg_string_new("");\r
- \r
- //get parts data\r
- sscanf(in, "%d:%d:%d:%d:%d:%d:%d:%s",\r
- &a1,&option,&option2,&x1,&y1,&x2,&y2,pname);\r
- //end = strchr(pname, ':');\r
- //*end = '\0';\r
- buf1 = kg_string_new(pname);\r
- generateGlyph(buf1, buf2);\r
- if(buf2->len == 0) return;\r
- \r
- //convert\r
- tf[0] = x1;\r
- tf[1] = y1;\r
- tf[2] = x2;\r
- tf[3] = y2;\r
- addStrokeWithTransform(buf2, 1, tf, out, 1);\r
-}\r
+//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);
+}
double yokoL, tateL, yokoR, tateR;
int *buf, strokes;
int tempShotai;
+ int bodyline1[pngWidth], bodyline2[pngWidth];
+ double complex;
+ int tooclose;
//initialize
pxL = 0;
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
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;
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;