2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
5 Desc: Convert Amiga font to C code.
12 #include <proto/exec.h>
13 #include <proto/graphics.h>
14 #include <proto/dos.h>
15 #include <proto/diskfont.h>
16 #include <graphics/text.h>
18 #include <dos/rdargs.h>
22 #include <aros/debug.h>
24 struct Library
*DiskfontBase
;
25 struct GfxBase
*GfxBase
;
27 static VOID
font2c(struct TextFont
*tf
, FILE * fh
, STRPTR prestring
);
29 int main (int argc
, char **argv
)
32 UBYTE outfilename
[200];
33 UBYTE prestring_buf
[200], *prestring
= NULL
;
38 STRPTR args
[4] = {NULL
, NULL
, NULL
, NULL
};
40 int error
= RETURN_OK
;
43 SDInit(); /* Init debugging */
44 rda
= ReadArgs("NAME,SIZE,OUTFILE,PRESTRING/K", (IPTR
*)args
, NULL
);
47 if (args
[0] == NULL
|| args
[1] == NULL
|| args
[2] == NULL
)
49 printf("Usage: NAME,SIZE,OUTFILE,PRESTRING/K\n");
54 strcpy(fontname
, args
[0]);
55 ysize
= atoi(args
[1]);
56 strcpy(outfilename
, args
[2]);
59 strcpy(prestring_buf
, args
[3]);
60 strcat(prestring_buf
, "_");
61 prestring
= prestring_buf
;
72 if (error
== RETURN_OK
)
74 /* Look for .font, append it if it doesn't exist */
75 if (( s
= strrchr(fontname
, '.')))
77 if (0 != strcmp(s
, ".font"))
78 strcat(fontname
, ".font");
82 strcat(fontname
, ".font");
85 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 37);
88 printf("Could not open gfx.library v37\n");
93 DiskfontBase
= OpenLibrary("diskfont.library", 37);
96 printf("Couldn't open diskfont.library v37\n");
100 /* Open output file */
102 outfile
= fopen(outfilename
, "w");
105 printf("Could not open outfile \"%s\"", outfilename
);
112 fontname
, ysize
, 0, 0
115 tf
= OpenDiskFont(&ta
);
118 printf("Could not open textfont\n");
122 if (tf
->tf_Style
& FSF_COLORFONT
)
124 printf("Does not handle color fonts yet\n");
128 font2c(tf
, outfile
, prestring
);
134 } /* if (outfile opened) */
136 CloseLibrary(DiskfontBase
);
138 } /* if (diskfont opened) */
140 CloseLibrary((struct Library
*)GfxBase
);
142 } /* if (gfx opened) */
144 } /* if (ReadArgs went ok) */
150 #define NUMCHARS(tf) ((tf->tf_HiChar - tf->tf_LoChar) + 2)
152 static VOID
print_word_array( UWORD
*array
, ULONG len
, FILE *fh
);
153 static VOID
print_long_array( ULONG
*array
, ULONG len
, FILE *fh
);
155 static VOID
print_chardata_ascii( struct TextFont
*tf
, FILE *fh
);
158 const STRPTR font_styles
[] =
170 const STRPTR font_flags
[] =
182 static UBYTE
print_tf_flags(struct TextFont
*tf
, FILE *fh
, const STRPTR
*nametab
, UBYTE flags
)
185 BOOL flag_found
= FALSE
;
188 for (i
= 0; i
< 8; i
++)
190 if (flags
& (1L << i
))
195 fprintf(fh
, "%s", nametab
[i
]);
205 static VOID UpdateIndent(UBYTE indent, UBYTE *tabs)
212 static VOID
font2c(struct TextFont
*tf
, FILE * fh
, STRPTR prestring
)
214 ULONG numchars
= NUMCHARS(tf
);
219 updateindent(ind, tabs);
221 fprintf(fh
, "#include <graphics/text.h>\n");
223 fprintf(fh
, "\n\n\n");
224 print_chardata_ascii(tf
, fh
);
226 fprintf(fh
, "\n\n\n");
228 if ((tf
->tf_Style
& FSF_COLORFONT
) == 0)
230 fprintf(fh
, "const UWORD %schardata[] =\n", prestring
);
231 print_word_array((UWORD
*)tf
->tf_CharData
, (tf
->tf_YSize
* tf
->tf_Modulo
) / 2, fh
);
232 /* We divide by two since we want number of *words*, not bytes */
237 fprintf(fh
, "\n\n\n");
238 fprintf(fh
, "const ULONG %scharloc[] =\n", prestring
);
239 print_long_array((ULONG
*)tf
->tf_CharLoc
, numchars
, fh
);
244 fprintf(fh
, "\n\n\n");
245 fprintf(fh
, "const UWORD %scharkern[] =\n", prestring
);
246 print_word_array((UWORD
*)tf
->tf_CharKern
, numchars
, fh
);
251 if (tf
->tf_CharSpace
)
253 fprintf(fh
, "\n\n\n");
254 fprintf(fh
, "const WORD %scharspace[] =\n", prestring
);
255 print_word_array((UWORD
*)tf
->tf_CharKern
, numchars
, fh
);
259 /*------------------------------------- */
261 fprintf(fh
, "\n\n\n");
263 fprintf(fh
, "const struct TextFont %stf =\n", prestring
);
267 fprintf(fh
, "\t{\t/* tf_Message */\n");
268 fprintf(fh
, "\t\t{\t/* mn_Node */\n");
270 fprintf(fh
, "\t\t\tNULL,\n"); /* ln_Succ */
271 fprintf(fh
, "\t\t\tNULL,\n"); /* ln_Pred */
273 /* See <exec/nodes.h> */
274 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
275 fprintf(fh
, "\t\t\t%d,\n", tf
->tf_Message
.mn_Node
.ln_Type
); /* ln_Type */
276 fprintf(fh
, "\t\t\t0,\n"); /* ln_Pri */
277 fprintf(fh
, "\t\t\t\"%s\"\n", tf
->tf_Message
.mn_Node
.ln_Name
);
279 fprintf(fh
, "\t\t\t\"%s\",\n", tf
->tf_Message
.mn_Node
.ln_Name
);
280 fprintf(fh
, "\t\t\t%d,\n", tf
->tf_Message
.mn_Node
.ln_Type
); /* ln_Type */
281 fprintf(fh
, "\t\t\t0\n"); /* ln_Pri */
283 fprintf(fh
, "\t\t},\n");
284 fprintf(fh
, "\t\tNULL,\n"); /* mn_ReplyPort */
285 fprintf(fh
, "\t\t0\n"); /* mn_Length */
286 fprintf(fh
, "\t},\n");
288 fprintf(fh
, "\t%d,\t/* YSize */\n", tf
->tf_YSize
);
291 if (!print_tf_flags(tf
, fh
, font_styles
, tf
->tf_Style
))
292 fprintf(fh
, "FS_NORMAL");
294 fprintf(fh
, ",\t/* Style */\n");
297 print_tf_flags(tf
, fh
, font_flags
, tf
->tf_Flags
);
299 fprintf(fh
, ",\t/* Flags */\n");
301 fprintf(fh
, "\t%d,\t/* XSize */\n", tf
->tf_XSize
);
302 fprintf(fh
, "\t%d,\t/* Baseline */\n", tf
->tf_Baseline
);
303 fprintf(fh
, "\t%d,\t/* Boldsmear */\n", tf
->tf_BoldSmear
);
304 fprintf(fh
, "\t%d,\t/* Accessors */\n", tf
->tf_Accessors
);
305 fprintf(fh
, "\t%d,\t/* LoChar */\n", tf
->tf_LoChar
);
306 fprintf(fh
, "\t%d,\t/* HiChar */\n", tf
->tf_HiChar
);
308 fprintf(fh
, "\t(APTR)%schardata,\t/* CharData */\n", prestring
);
310 fprintf(fh
, "\t%d,\t/* Modulo */\n", tf
->tf_Modulo
);
313 fprintf(fh
, "\t(APTR)%scharloc,\t/* CharLoc */\n", prestring
);
315 fprintf(fh
, "\tNULL,\t/* CharLoc */\n");
317 if (tf
->tf_CharSpace
)
318 fprintf(fh
, "\t(APTR)%scharspace,\t/* CharSpace */\n", prestring
);
320 fprintf(fh
, "\tNULL,\t/* CharSpace */\n");
323 fprintf(fh
, "\t(APTR)%scharkern,\t/* CharKern */\n", prestring
);
325 fprintf(fh
, "\tNULL\t/* CharKern */\n");
334 static VOID
print_word_array(UWORD
*array
, ULONG len
, FILE *fh
)
339 for (i
= 0; i
< len
- 1; i
++) /* len - 1 because last item needs ',' removed */
345 fprintf(fh
,"0x%.4x, ", *array
++);
348 /* print last entry without ',' at the end */
353 fprintf(fh
, "0x%.4x\n", *array
);
359 static VOID
print_long_array(ULONG
*array
, ULONG len
, FILE *fh
)
365 for (i
= 0; i
< len
- 1; i
++) /* numchars - 1 because last item needs ',' removed */
371 fprintf(fh
,"0x%.8lx, ", *array
++);
374 /* print last entry without ',' at the end */
379 fprintf(fh
, "0x%.8lx\n", *array
);
386 static VOID
print_chardata_ascii(struct TextFont
*tf
, FILE *fh
)
388 UWORD i
, numchars
= NUMCHARS(tf
);
391 for (i
= 0; i
< numchars
; i
++ )
399 /* Warning: Should these be used for something? */
403 charptr
= tf
->tf_CharData
;
405 /* tf_CharLoc is *allways* non-NULL */
406 charloc
= ((ULONG
*)tf
->tf_CharLoc
)[i
];
408 for (row
= 0; row
< tf
->tf_YSize
; row
++)
412 bitno
= charloc
>> 16;
413 width
= charloc
& 0xFFFF;
414 /* Extract data for this glyph */
419 if ( charptr
[bitno
>> 3] & (1 << ((~bitno
) & 0x07)) )
430 /* Go to next row in glyph */
431 charptr
+= tf
->tf_Modulo
;
433 fprintf(fh
, " */\n");
435 } /* for (each row in the glyph) */
437 } /* for (each glyph) */