8 void generateGlyphByIDS(const KGString *in, KGString *out, int flag){
11 //pass this method if 'in' is not UCS parts
12 if((in->str)[0] != 'u'){
13 generateGlyph(in, out);
16 //pass this method if 'in' is place-variant-flag defined
17 if(in->len < 5 && 7 < in->len){
18 generateGlyph(in, out);
22 tmp1 = kg_string_new(in->str);
23 tmp2 = kg_string_new(in->str);
26 if(1 <= flag && flag <= 7){
27 if(tmp1->len != 7) kg_string_append(tmp1, "-");
28 if(flag == 1) kg_string_append(tmp1, "01");
29 else if(flag == 2) kg_string_append(tmp1, "02");
30 else if(flag == 3) kg_string_append(tmp1, "03");
31 else if(flag == 4) kg_string_append(tmp1, "04");
32 else if(flag == 5) kg_string_append(tmp1, "05");
33 else if(flag == 6) kg_string_append(tmp1, "06");
36 generateGlyph(tmp1, out);
37 if(out->len != 0) return;
38 generateGlyph(tmp2, out);
39 if(out->len != 0) return;
43 void generateGlyph(const KGString *in, KGString *out){
45 tmp = kg_string_new("");
46 kg_string_set_size(out, 0);
49 searchPartsData(in, tmp);
51 //fprintf(stderr, "partsFound:%s\n",tmp->str);
52 tmp = CalcSizes(tmp, 1);// this line may not be needed
53 out = kg_string_assign(out, tmp->str);
57 // fprintf(stderr, "partsNotFound:%s\n",in->str);
61 searchAliasData(in, tmp);
63 //fprintf(stderr, "aliasFound:%s(%d)\n",tmp->str,tmp->len);
64 generateGlyph(tmp, out);
65 if(out->len == 0) return;
66 //save to cache ... not yet
70 // fprintf(stderr, "aliasNotFound:%s\n",in->str);
76 if(out->len == 0) return;
77 //save to cache ... not yet
82 void doCombine(const KGString *in, KGString *out){
83 KGString *partIDS1, *partIDS2, *partIDS3;
84 KGString *partStroke1, *partStroke2, *partStroke3;
87 partIDS1 = kg_string_new("");
88 partIDS2 = kg_string_new("");
89 partIDS3 = kg_string_new("");
90 partStroke1 = kg_string_new("");
91 partStroke2 = kg_string_new("");
92 partStroke3 = kg_string_new("");
94 kg_string_set_size(out, 0);
97 if(strncmp(in->str, "u2ff", 4) != 0) return;
98 //switch by combine types
101 divideInto2(in, partIDS1, partIDS3);
102 if(partIDS1->len == 0) return;
104 generateGlyphByIDS(partIDS1, partStroke1, 1);
105 if(partStroke1->len == 0) return;
106 partStroke1 = CalcSizes(partStroke1, 0);
107 generateGlyphByIDS(partIDS3, partStroke3, 2);
108 if(partStroke3->len == 0) return;
109 partStroke3 = CalcSizes(partStroke3, 0);
112 divideInto2(in, partIDS1, partIDS3);
113 if(partIDS1->len == 0) return;
115 generateGlyphByIDS(partIDS1, partStroke1, 3);
116 if(partStroke1->len == 0) return;
117 partStroke1 = CalcSizes(partStroke1, 0);
118 generateGlyphByIDS(partIDS3, partStroke3, 4);
119 if(partStroke3->len == 0) return;
120 partStroke3 = CalcSizes(partStroke3, 0);
122 case '4': //full surround
123 case '5': //surround from above
124 case '6': //surround from below
125 case '7': //surround from left
126 case '8': //surround from upper left
127 case '9': //surround from upper right
128 case 'a': //surround from lower left
129 //case 'b': //overlaid (not supported)
130 divideInto2(in, partIDS1, partIDS3);
131 if(partIDS1->len == 0) return;
133 generateGlyphByIDS(partIDS1, partStroke1, 5);
134 if(partStroke1->len == 0) return;
135 partStroke1 = CalcSizes(partStroke1, 0);
136 generateGlyphByIDS(partIDS3, partStroke3, 6);
137 if(partStroke3->len == 0) return;
138 partStroke3 = CalcSizes(partStroke3, 0);
141 divideInto3(in, partIDS1, partIDS2, partIDS3);
142 if(partIDS1->len == 0) return;
144 generateGlyphByIDS(partIDS1, partStroke1, 1);
145 if(partStroke1->len == 0) return;
146 partStroke1 = CalcSizes(partStroke1, 0);
147 generateGlyphByIDS(partIDS2, partStroke2, 1);
148 if(partStroke2->len == 0) return;
149 partStroke2 = CalcSizes(partStroke2, 0);
150 generateGlyphByIDS(partIDS3, partStroke3, 2);
151 if(partStroke3->len == 0) return;
152 partStroke3 = CalcSizes(partStroke3, 0);
155 divideInto3(in, partIDS1, partIDS2, partIDS3);
156 if(partIDS1->len == 0) return;
158 generateGlyphByIDS(partIDS1, partStroke1, 3);
159 if(partStroke1->len == 0) return;
160 partStroke1 = CalcSizes(partStroke1, 0);
161 generateGlyphByIDS(partIDS2, partStroke2, 3);
162 if(partStroke2->len == 0) return;
163 partStroke2 = CalcSizes(partStroke2, 0);
164 generateGlyphByIDS(partIDS3, partStroke3, 4);
165 if(partStroke3->len == 0) return;
166 partStroke3 = CalcSizes(partStroke3, 0);
169 switch((in->str)[4]){
171 combineYoko2(partStroke1, partStroke3, result);
174 combineTate2(partStroke1, partStroke3, result);
177 combineYoko3(partStroke1, partStroke2, partStroke3, result);
180 combineTate3(partStroke1, partStroke2, partStroke3, result);
182 case '4': //full surround
183 combineHame2(partStroke1, partStroke3, result,
185 FLAG_SURROUND_RIGHT |
187 FLAG_SURROUND_BOTTOM);
189 case '5': //surround from above
190 combineHame2(partStroke1, partStroke3, result,
192 FLAG_SURROUND_RIGHT |
195 case '6': //surround from below
196 combineHame2(partStroke1, partStroke3, result,
198 FLAG_SURROUND_RIGHT |
199 FLAG_SURROUND_BOTTOM);
201 case '7': //surround from left
202 combineHame2(partStroke1, partStroke3, result,
205 FLAG_SURROUND_BOTTOM);
207 case '8': //surround from upper left
208 combineHame2(partStroke1, partStroke3, result,
212 case '9': //surround from upper right
213 combineHame2(partStroke1, partStroke3, result,
214 FLAG_SURROUND_RIGHT |
217 case 'a': //surround from lower left
218 combineHame2(partStroke1, partStroke3, result,
220 FLAG_SURROUND_BOTTOM);
222 //case 'b': //overlaid (not supported)
224 switch((in->str)[4]){
235 addStrokeWithTransform(partStroke1, 1, result, out, 1);
236 addStrokeWithTransform(partStroke3, 3, result, out, 1);
240 addStrokeWithTransform(partStroke1, 1, result, out, 1);
241 addStrokeWithTransform(partStroke2, 2, result, out, 1);
242 addStrokeWithTransform(partStroke3, 3, result, out, 1);
245 //fprintf(stderr,"%s\n",out->str);
248 void drawGlyph(const KGString *in, const int mode){
251 buf = convertStroke(in->str, buf, &j);
252 for(i = 0; i < j; i++){
253 if(mode == DRAW_GLYPH_MODE_NORMAL){ //normal
254 dfDrawFont(buf[i * 11 + 0],
266 else if(mode == DRAW_GLYPH_MODE_WITHOUT_DECORATION){ //without decoration
267 dfDrawFont(buf[i * 11 + 0],
283 KGString* finalAdjustment(const KGString *in){
284 int i, j, k, l, m, n;
290 temp = kg_string_new("");
293 drawGlyph(in, DRAW_GLYPH_MODE_WITHOUT_DECORATION);
295 buf = convertStroke(in->str, buf, &j);
296 for(i = 0; i < j; i++){
298 if(buf[i * 11 + 2] == 13){
299 for(k = buf[i * 11 + 5] - kMinWidthT; k < buf[i * 11 + 5] + kMinWidthT; k++){
300 for(l = buf[i * 11 + 6] + kWidth * kKakato * 0.5; l < buf[i * 11 + 6] + kWidth * kKakato + pngHeight * 0.1; l++){
301 if(0 <= l && l < canvasHeight && 0 <= k && k < canvasHeight && kageCanvas[l][k] != kWhite) m++;
304 if(m != 0) buf[i * 11 + 2] = 23;
307 convertArray(buf, temp, j, 0);
310 return kg_string_new(temp->str);