1155
|
1 /*
|
|
2
|
|
3 mplayer font creator for central-europe (latin-1 etc) charset
|
|
4
|
|
5 This program uses gd & freetype2 library to draw each characters then
|
|
6 write the image to stdout.
|
|
7
|
|
8 Written by Sunjin Yang <lethean@realtime.ssu.ac.kr> May 03, 2001.
|
|
9 Modified by Arpad Gereoffy <arpi@thot.banki.hu> Jun 18, 2001.
|
|
10
|
|
11 */
|
|
12
|
|
13 #include <gd.h>
|
|
14 #include <stdio.h>
|
|
15 #include <string.h>
|
|
16 #include <errno.h>
|
|
17
|
|
18 #define UPSCALE_FACTOR 2
|
|
19
|
|
20 #define X_ALIGN (8*UPSCALE_FACTOR)
|
|
21 #define ALIGNED(x) (((x)+(X_ALIGN-1))&(~(X_ALIGN-1)))
|
|
22
|
|
23 #define DEF_FONT_SIZE 16.0
|
|
24
|
|
25 #define DEF_CHAR_GAP 6
|
|
26 #define CHAR_SKIP(gap) (gap / 4)
|
|
27
|
|
28 #define AUTHOR "Sunjin Yang <lethean@realtime.ssu.ac.kr>"
|
|
29 #define VERSION "0.1"
|
|
30
|
|
31 struct code_range {
|
|
32 int start, end;
|
|
33 };
|
|
34
|
|
35 /* basic alphabet character range */
|
|
36 //static struct code_range ascii_range = { 0x21, 0x7E };
|
|
37 static struct code_range ascii_range = { 0x20, 0x1FF };
|
|
38
|
|
39 #ifdef USE_UNIFIED_KOREAN
|
|
40
|
|
41 /* Unified Hangul Code Encoding */
|
|
42 static struct code_range first_byte_range[] = {
|
|
43 { 0x81, 0xFE }, { 0, 0 }
|
|
44 };
|
|
45 static struct code_range second_byte_range[] = {
|
|
46 { 0x41, 0x5A }, { 0x61, 0x7A }, { 0x81, 0x9F }, { 0xA0, 0xBF },
|
|
47 { 0xC0, 0xDF }, { 0xE0, 0xFE }, { 0, 0 }
|
|
48 };
|
|
49
|
|
50 #else
|
|
51
|
|
52 /* KSX 1001:1992 */
|
|
53 static struct code_range first_byte_range[] = {
|
|
54 { 0xA1, 0xAC }, { 0xB0, 0xFD }, { 0, 0 }
|
|
55 };
|
|
56 static struct code_range second_byte_range[] = {
|
|
57 { 0xA1, 0xAF }, { 0xB0, 0xBF }, { 0xC0, 0xCF }, { 0xD0, 0xDF },
|
|
58 { 0xE0, 0xEF }, { 0xF0, 0xFE }, { 0, 0 }
|
|
59 };
|
|
60
|
|
61 #endif
|
|
62
|
|
63 #define _output(msg...) fprintf(stdout, ##msg)
|
|
64
|
|
65 /* debugging macros */
|
|
66 #define _print(msg...) fprintf(stderr, ##msg)
|
|
67 #define _info(msg...) { _print("mpfc: "); _print(##msg); _print("\n"); }
|
|
68 #define _abort(msg...) { _info(##msg); exit(1); }
|
|
69
|
|
70 static double size;
|
|
71 static int gap,vgap;
|
|
72 static char *name, *font, *eng_font, *kor_font;
|
|
73 static int file_index;
|
|
74 static char filename[20];
|
|
75
|
|
76 static int base_x, char_count;
|
|
77 static gdImagePtr char_image[65536];
|
|
78
|
|
79 static gdImagePtr concat_char_images(void)
|
|
80 {
|
|
81 gdImagePtr ret;
|
|
82 int width, height, i, x,black, white;
|
|
83
|
|
84 /* get image's width & height */
|
|
85 height = size + (vgap * 2);
|
|
86 for (width = 0, i = 0; i < char_count; i++)
|
|
87 width += ALIGNED(char_image[i]->sx);
|
|
88
|
|
89 ret = gdImageCreate(width, height);
|
|
90
|
|
91 /* background color (first allocated) */
|
|
92 black = gdImageColorResolve(ret, 0, 0, 0);
|
|
93 // white = gdImageColorResolve(ret, 255, 255, 255);
|
|
94 for(x=1;x<=255;x++)
|
|
95 white = gdImageColorResolve(ret, x,x,x);
|
|
96
|
|
97 width = 0;
|
|
98 for (i = 0; i < char_count; i++) {
|
|
99 gdImageCopy(ret, char_image[i], /* dst, src */
|
|
100 width + 0, 0, /* dstX, dstY */
|
|
101 0, 0, /* srcX, srcY */
|
|
102 char_image[i]->sx, char_image[i]->sy); /* size */
|
|
103 width += ALIGNED(char_image[i]->sx);
|
|
104 gdImageDestroy(char_image[i]);
|
|
105 }
|
|
106 char_count = 0;
|
|
107
|
|
108 return ret;
|
|
109 }
|
|
110
|
|
111 static gdImagePtr create_char_image(int code)
|
|
112 {
|
|
113 gdImagePtr im;
|
|
114 int rect[8], black, white, width, height, x, y;
|
|
115 char *err;
|
|
116 char s[10];
|
|
117
|
|
118 #if 1
|
|
119 sprintf(s,"&#%d;",code);
|
|
120 #else
|
|
121 if(code>=0x100){
|
|
122 s[0]=code>>8;
|
|
123 s[1]=code&0xFF;
|
|
124 s[2]=0;
|
|
125 } else {
|
|
126 s[0]=code;
|
|
127 s[1]=0;
|
|
128 }
|
|
129 #endif
|
|
130
|
|
131 /* obtain border rectangle so that we can size the image. */
|
|
132 err = gdImageStringTTF(NULL, &rect[0], 0, font, size, .0, 0, 0, s);
|
|
133 if (err)
|
|
134 _abort("%s\n", err);
|
|
135
|
|
136 /* create an image big enough for a string plus a little whitespace. */
|
|
137 width = rect[2] - rect[6] + gap;
|
|
138 height = size + (vgap * 2);
|
|
139 im = gdImageCreate(width, height);
|
|
140
|
|
141 /* background color (first allocated) */
|
|
142 black = gdImageColorResolve(im, 0, 0, 0);
|
|
143 for(x=1;x<=255;x++)
|
|
144 white = gdImageColorResolve(im, x,x,x);
|
|
145 // white = gdImageColorResolve(im, 255, 255, 255);
|
|
146
|
|
147 /* render the string, offset origin to center string.
|
|
148 note that we use top-left coordinate for adjustment
|
|
149 since gd origin is in top-left with y increasing downwards. */
|
|
150 x = (gap / 2) - rect[6];
|
|
151 y = (vgap) - rect[7] + (size + rect[7]);
|
|
152 err = gdImageStringTTF(im, &rect[0], white, font, size, .0, x, y, s);
|
|
153 if (err)
|
|
154 _abort("%s\n", err);
|
|
155
|
|
156 //if (*s == '"') _output("'%s' ", s); else _output("\"%s\" ", s);
|
|
157 _output("0x%x %d %d\n", code,
|
|
158 (base_x + CHAR_SKIP(gap))/UPSCALE_FACTOR -1,
|
|
159 (base_x + width - CHAR_SKIP(gap))/UPSCALE_FACTOR - 0);
|
|
160 base_x += ALIGNED(width);
|
|
161 // base_x = (base_x+width+7)&(~7); // align to 8-pixel boundary for fast MMX code
|
|
162
|
|
163 return im;
|
|
164 }
|
|
165
|
|
166 void make_charset_font(struct code_range *first, struct code_range *second)
|
|
167 {
|
|
168 gdImagePtr im;
|
|
169 FILE *fd;
|
|
170 int i, j;
|
|
171
|
|
172 base_x = 0;
|
|
173 char_count = 0;
|
|
174
|
|
175 _output("[files]\n");
|
|
176 //_output("alpha %s%d_a.raw\n", name, file_index);
|
|
177 _output("alpha %s%02d_a.raw\n", name, file_index);
|
|
178 _output("bitmap %s%02d_b.raw\n\n", name, file_index);
|
|
179 _output("[characters]\n");
|
|
180
|
|
181 for (i = first->start; i <= first->end; i++) {
|
|
182 if (!second) {
|
|
183 char_image[char_count++] = create_char_image(i);
|
|
184 } else
|
|
185 for (j = second->start; j <= second->end; j++) {
|
|
186 char_image[char_count++]= create_char_image((i<<8)|j);
|
|
187 }
|
|
188 }
|
|
189
|
|
190 _output("\n");
|
|
191
|
|
192 /* concatenate each character images into one image. */
|
|
193 im = concat_char_images();
|
|
194
|
|
195 /* get filename and create one with it. */
|
|
196 sprintf(filename, "%s%02d_b.png", name, file_index++);
|
|
197 fd = fopen(filename, "w+");
|
|
198 if (!fd)
|
|
199 _abort(strerror(errno));
|
|
200
|
|
201 /* write image to the PNG file. */
|
|
202 gdImagePng(im, fd);
|
|
203
|
|
204 fclose(fd);
|
|
205
|
|
206 /* destroy it */
|
|
207 gdImageDestroy(im);
|
|
208 }
|
|
209
|
|
210 int main(int argc, char **argv)
|
|
211 {
|
|
212 int i, j;
|
|
213
|
|
214 if (argc < 4)
|
|
215 _abort("usage:%s name eng-ttf kor-ttf [size gap vgap]",argv[0]);
|
|
216
|
|
217 /* get program parameter like font names, size... */
|
|
218 name = argv[1];
|
|
219 eng_font = argv[2];
|
|
220 kor_font = argv[3];
|
|
221 size = DEF_FONT_SIZE;
|
|
222 gap = DEF_CHAR_GAP;
|
|
223 vgap = DEF_CHAR_GAP;
|
|
224 if (argc > 4) {
|
|
225 float __s; sscanf(argv[4], "%f", &__s);
|
|
226 size = (double)__s;
|
|
227 }
|
|
228 if (argc > 5)
|
|
229 sscanf(argv[5], "%d", &gap);
|
|
230 if (argc > 6)
|
|
231 sscanf(argv[6], "%d", &vgap);
|
|
232
|
|
233 /* write basic font information. */
|
|
234 _output("[info]\n");
|
|
235 _output("name \"%s version %s - created by %s\"\n",
|
|
236 name, VERSION, AUTHOR);
|
|
237 _output("descversion 1\n");
|
|
238 _output("spacewidth %d\n", (int)(size / 2));
|
|
239 _output("charspace -%d\n", CHAR_SKIP(gap) + 1);
|
|
240 _output("; height %d\n\n", (int)size + DEF_CHAR_GAP);
|
|
241
|
|
242 /* write general OSD fonts information. */
|
|
243 _output("[files]\n");
|
|
244 _output("alpha arpi_osd_a.raw\n");
|
|
245 _output("bitmap arpi_osd_b.raw\n\n");
|
|
246 _output("[characters]\n");
|
|
247 _output("0x01 0 36\n");
|
|
248 _output("0x02 35 71\n");
|
|
249 _output("0x03 70 106\n");
|
|
250 _output("0x04 116 152\n");
|
|
251 _output("0x05 164 200\n");
|
|
252 _output("0x06 209 245\n");
|
|
253 _output("0x07 256 292\n");
|
|
254 _output("0x08 305 342\n");
|
|
255 _output("0x09 354 400\n");
|
|
256 _output("0x0A 407 442\n");
|
|
257 _output("0x0B 457 494\n");
|
|
258 _output("[files]\n");
|
|
259 _output("alpha arpi_progress_a.raw\n");
|
|
260 _output("bitmap arpi_progress_b.raw\n\n");
|
|
261 _output("[characters]\n");
|
|
262 _output("0x10 4 21\n");
|
|
263 _output("0x11 30 41\n");
|
|
264 _output("0x12 50 66\n");
|
|
265 _output("0x13 74 85\n\n");
|
|
266
|
|
267
|
|
268 file_index = 0;
|
|
269
|
|
270 /* create basic alphabet character set. */
|
|
271 font = eng_font;
|
|
272 make_charset_font(&ascii_range, NULL);
|
|
273
|
|
274 #if 0
|
|
275 /* create korean character set. */
|
|
276 font = kor_font;
|
|
277 for (i = 0; first_byte_range[i].start != 0; i++)
|
|
278 for (j = 0; second_byte_range[j].start != 0; j++)
|
|
279 make_charset_font(&first_byte_range[i], &second_byte_range[j]);
|
|
280 #endif
|
|
281
|
|
282 return 0;
|
|
283 }
|
|
284
|