3 mplayer font creator for central-europe (latin-1 etc) charset
5 This program uses gd & freetype2 library to draw each characters then
6 write the image to stdout.
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.
18 #define UPSCALE_FACTOR 2
20 #define X_ALIGN (8*UPSCALE_FACTOR)
21 #define ALIGNED(x) (((x)+(X_ALIGN-1))&(~(X_ALIGN-1)))
23 #define DEF_FONT_SIZE 16.0
25 #define DEF_CHAR_GAP 6
26 #define CHAR_SKIP(gap) (gap / 4)
28 #define AUTHOR "Sunjin Yang <lethean@realtime.ssu.ac.kr>"
35 /* basic alphabet character range */
36 //static struct code_range ascii_range = { 0x21, 0x7E };
37 static struct code_range ascii_range
= { 0x20, 0x1FF };
39 #ifdef USE_UNIFIED_KOREAN
41 /* Unified Hangul Code Encoding */
42 static struct code_range first_byte_range
[] = {
43 { 0x81, 0xFE }, { 0, 0 }
45 static struct code_range second_byte_range
[] = {
46 { 0x41, 0x5A }, { 0x61, 0x7A }, { 0x81, 0x9F }, { 0xA0, 0xBF },
47 { 0xC0, 0xDF }, { 0xE0, 0xFE }, { 0, 0 }
53 static struct code_range first_byte_range
[] = {
54 { 0xA1, 0xAC }, { 0xB0, 0xFD }, { 0, 0 }
56 static struct code_range second_byte_range
[] = {
57 { 0xA1, 0xAF }, { 0xB0, 0xBF }, { 0xC0, 0xCF }, { 0xD0, 0xDF },
58 { 0xE0, 0xEF }, { 0xF0, 0xFE }, { 0, 0 }
63 #define _output(msg...) fprintf(stdout, ##msg)
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); }
72 static char *name
, *font
, *eng_font
, *kor_font
;
73 static int file_index
;
74 static char filename
[20];
76 static int base_x
, char_count
;
77 static gdImagePtr char_image
[65536];
79 static gdImagePtr
concat_char_images(void)
82 int width
, height
, i
, x
,black
, white
;
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
);
89 ret
= gdImageCreate(width
, height
);
91 /* background color (first allocated) */
92 black
= gdImageColorResolve(ret
, 0, 0, 0);
93 // white = gdImageColorResolve(ret, 255, 255, 255);
95 white
= gdImageColorResolve(ret
, x
,x
,x
);
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
]);
111 static gdImagePtr
create_char_image(int code
)
114 int rect
[8], black
, white
, width
, height
, x
, y
;
119 sprintf(s
,"&#%d;",code
);
131 /* obtain border rectangle so that we can size the image. */
132 err
= gdImageStringTTF(NULL
, &rect
[0], 0, font
, size
, .0, 0, 0, s
);
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
);
141 /* background color (first allocated) */
142 black
= gdImageColorResolve(im
, 0, 0, 0);
144 white
= gdImageColorResolve(im
, x
,x
,x
);
145 // white = gdImageColorResolve(im, 255, 255, 255);
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
);
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
166 void make_charset_font(struct code_range
*first
, struct code_range
*second
)
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");
181 for (i
= first
->start
; i
<= first
->end
; i
++) {
183 char_image
[char_count
++] = create_char_image(i
);
185 for (j
= second
->start
; j
<= second
->end
; j
++) {
186 char_image
[char_count
++]= create_char_image((i
<<8)|j
);
192 /* concatenate each character images into one image. */
193 im
= concat_char_images();
195 /* get filename and create one with it. */
196 sprintf(filename
, "%s%02d_b.png", name
, file_index
++);
197 fd
= fopen(filename
, "w+");
199 _abort(strerror(errno
));
201 /* write image to the PNG file. */
210 int main(int argc
, char **argv
)
215 _abort("usage:%s name eng-ttf kor-ttf [size gap vgap]",argv
[0]);
217 /* get program parameter like font names, size... */
221 size
= DEF_FONT_SIZE
;
225 float __s
; sscanf(argv
[4], "%f", &__s
);
229 sscanf(argv
[5], "%d", &gap
);
231 sscanf(argv
[6], "%d", &vgap
);
233 /* write basic font information. */
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
);
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");
270 /* create basic alphabet character set. */
272 make_charset_font(&ascii_range
, NULL
);
275 /* create korean character set. */
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
]);