u8g2-copy/tools/font/build/build.c

214 lines
5.5 KiB
C
Raw Normal View History

2015-11-07 04:07:14 +08:00
2015-11-07 16:27:18 +08:00
#include <stdio.h>
#include <string.h>
2015-11-11 05:57:47 +08:00
#include <stdlib.h>
#include <unistd.h>
2015-11-07 16:27:18 +08:00
2015-11-07 04:07:14 +08:00
#define BM_T 1 /* Transparent = build mode 0 proportional */
#define BM_H 2 /* Common Height = build mode 1 */
#define BM_M 4 /* Monospace = build mode 2 */
#define BM_8 8 /* 8x8 = build mode 3 */
#define FM_C 1 /* u8g2 compressed font */
#define FM_8 2 /* u8x8 uncompressed font */
2015-11-07 16:27:18 +08:00
#define MM_F 1 /* full */
#define MM_R 2 /* reduced */
#define MM_N 4 /* numbers */
2015-11-11 05:57:47 +08:00
/*
fprintf(out_fp, "const uint8_t %s[%d] U8X8_FONT_SECTION(\"%s\") \n", fontname, bf->target_cnt, fontname);
fprintf(out_fp, "const uint8_t %s[%d] U8G2_FONT_SECTION(\"%s\") \n", fontname, bf->target_cnt, fontname);
*/
2015-11-07 16:27:18 +08:00
2015-11-07 04:07:14 +08:00
struct groupinfo
{
char *groupname;
};
struct fontinfo
{
int is_ttf; /* 0 = bdf, 1= ttf */
char *filename; /* filename including extension */
2015-11-07 16:27:18 +08:00
char *name;
int group; /* group-index */
2015-11-07 04:07:14 +08:00
int pt; /* point size, ttf only */
int build_mode; /* Or'd BM_T, BM_H, BM_M, BM_8 */
int font_mode; /* Or'd FM_C and FM_8 */
2015-11-07 16:27:18 +08:00
int map_mode; /* Or'd MM_F, FM_N and FM_R */
2015-11-07 04:07:14 +08:00
};
2015-11-10 05:30:06 +08:00
typedef void (*cbfn_t)(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms);
2015-11-07 04:07:14 +08:00
2015-11-07 16:27:18 +08:00
struct groupinfo gi[] = {
{ "X11" },
};
2015-11-07 04:18:07 +08:00
struct fontinfo fi[] = {
2015-11-07 16:27:18 +08:00
{ 0, "6x10.bdf", "6x10", 0, 1, BM_T|BM_M|BM_8, FM_C|FM_8, MM_F|MM_R|MM_N }
};
char *bdf_path = "../bdf/";
2015-11-11 05:57:47 +08:00
char *bdfconv_path = "../bdfconv/bdfconv";
2015-11-10 05:30:06 +08:00
FILE *u8g2_font_list_fp;
FILE *u8x8_font_list_fp;
2015-11-07 16:27:18 +08:00
char target_font_identifier[1024];
char bdf_cmd[2048];
2015-11-10 05:30:06 +08:00
void bdfconv(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms)
2015-11-07 16:27:18 +08:00
{
2015-11-11 05:57:47 +08:00
strcpy(bdf_cmd, bdfconv_path);
strcat(bdf_cmd, " ");
2015-11-07 16:27:18 +08:00
if ( fm == FM_C ) strcat(bdf_cmd, " -f 1");
if ( fm == FM_8 ) strcat(bdf_cmd, " -f 2");
if ( bm == BM_T ) strcat(bdf_cmd, " -b 0");
if ( bm == BM_H ) strcat(bdf_cmd, " -b 1");
if ( bm == BM_M ) strcat(bdf_cmd, " -b 2");
if ( bm == BM_8 ) strcat(bdf_cmd, " -b 3");
if ( mm == MM_F ) strcat(bdf_cmd, " -m '32-255>32'");
if ( mm == MM_R ) strcat(bdf_cmd, " -m '32-127>32'");
if ( mm == MM_N ) strcat(bdf_cmd, " -m '32,42-58>32'");
strcat(bdf_cmd, " ");
strcat(bdf_cmd, bdf_path);
strcat(bdf_cmd, fi[i].filename);
strcat(bdf_cmd, " -n ");
strcat(bdf_cmd, target_font_identifier);
strcat(bdf_cmd, " -o ");
2015-11-11 05:57:47 +08:00
//strcat(bdf_cmd, target_font_identifier);
strcat(bdf_cmd, "font");
strcat(bdf_cmd, ".c");
if ( fm == FM_8 )
strcat(bdf_cmd, " && cat font.c >>u8x8_fonts.c");
else
strcat(bdf_cmd, " && cat font.c >>u8g2_fonts.c");
2015-11-07 16:27:18 +08:00
2015-11-11 05:57:47 +08:00
printf("%s\n", bdf_cmd);
system(bdf_cmd);
2015-11-10 05:30:06 +08:00
}
void fontlist_identifier(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms)
{
if ( fm == FM_C )
{
fprintf(u8g2_font_list_fp, " %s,\n", target_font_identifier);
}
if ( fm == FM_8 )
{
fprintf(u8x8_font_list_fp, " %s,\n", target_font_identifier);
}
}
void fontlist_name(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms)
{
if ( fm == FM_C )
{
fprintf(u8g2_font_list_fp, " \"%s\",\n", target_font_identifier);
}
if ( fm == FM_8 )
{
fprintf(u8x8_font_list_fp, " \"%s\",\n", target_font_identifier);
}
2015-11-07 16:27:18 +08:00
}
2015-11-10 05:30:06 +08:00
void gen_font(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms, cbfn_t cb )
{
if ( fm == FM_8 )
if ( bm != BM_8 )
return;
strcpy(target_font_identifier, fms);
strcat(target_font_identifier, "_");
strcat(target_font_identifier, fi[i].name);
strcat(target_font_identifier, "_");
strcat(target_font_identifier, bms);
strcat(target_font_identifier, mms);
cb(i, fm,fms,bm,bms,mm,mms);
}
void map_font(int i, int fm, char *fms, int bm, char *bms, cbfn_t cb)
2015-11-07 16:27:18 +08:00
{
if ( (fi[i].map_mode & MM_F) != 0 )
2015-11-10 05:30:06 +08:00
gen_font(i, fm, fms, bm, bms, MM_F, "f", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].map_mode & MM_R) != 0 )
2015-11-10 05:30:06 +08:00
gen_font(i, fm, fms, bm, bms, MM_R, "r", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].map_mode & MM_N) != 0 )
2015-11-10 05:30:06 +08:00
gen_font(i, fm, fms, bm, bms, MM_N, "n", cb);
2015-11-07 16:27:18 +08:00
}
2015-11-10 05:30:06 +08:00
void build_font(int i, int fm, char *fms, cbfn_t cb)
2015-11-07 16:27:18 +08:00
{
if ( (fi[i].build_mode & BM_T) != 0 )
2015-11-10 05:30:06 +08:00
map_font(i, fm, fms, BM_T, "t", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].build_mode & BM_H) != 0 )
2015-11-10 05:30:06 +08:00
map_font(i, fm, fms, BM_H, "h", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].build_mode & BM_M) != 0 )
2015-11-10 05:30:06 +08:00
map_font(i, fm, fms, BM_M, "m", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].build_mode & BM_8) != 0 )
2015-11-10 05:30:06 +08:00
map_font(i, fm, fms, BM_8, "8", cb);
2015-11-07 16:27:18 +08:00
}
2015-11-10 05:30:06 +08:00
void process_font(int i, cbfn_t cb)
2015-11-07 16:27:18 +08:00
{
if ( (fi[i].font_mode & FM_C) != 0 )
2015-11-10 05:30:06 +08:00
build_font(i, FM_C, "u8g2", cb);
2015-11-07 16:27:18 +08:00
if ( (fi[i].font_mode & FM_8) != 0 )
2015-11-10 05:30:06 +08:00
build_font(i, FM_8, "u8x8", cb);
2015-11-07 16:27:18 +08:00
}
2015-11-10 05:30:06 +08:00
void do_font_loop(cbfn_t cb)
2015-11-07 16:27:18 +08:00
{
int i, cnt;
cnt = sizeof(fi)/sizeof(*fi);
for( i = 0; i < cnt; i++ )
{
2015-11-10 05:30:06 +08:00
process_font(i, cb);
2015-11-07 16:27:18 +08:00
}
}
int main(void)
{
2015-11-11 05:57:47 +08:00
unlink("u8x8_fonts.c");
unlink("u8g2_fonts.c");
2015-11-10 05:30:06 +08:00
do_font_loop(bdfconv);
u8g2_font_list_fp = fopen("u8g2_font_list.c", "w");
u8x8_font_list_fp = fopen("u8x8_font_list.c", "w");
fprintf(u8g2_font_list_fp, "/* u8g2_font_list.c */\n");
fprintf(u8x8_font_list_fp, "/* u8x8_font_list.c */\n");
fprintf(u8g2_font_list_fp, "#include \"u8g2.h\"\n");
fprintf(u8x8_font_list_fp, "#include \"u8g2.h\"\n");
fprintf(u8g2_font_list_fp, "uint8_t *u8g2_font_list[] = {\n");
fprintf(u8x8_font_list_fp, "uint8_t *u8x8_font_list[] = {\n");
do_font_loop(fontlist_identifier);
fprintf(u8g2_font_list_fp, " NULL\n};\n");
fprintf(u8x8_font_list_fp, " NULL\n};\n");
fprintf(u8g2_font_list_fp, "uint8_t *u8g2_font_names[] = {\n");
fprintf(u8x8_font_list_fp, "uint8_t *u8x8_font_names[] = {\n");
do_font_loop(fontlist_name);
fprintf(u8g2_font_list_fp, " NULL\n};\n");
fprintf(u8x8_font_list_fp, " NULL\n};\n");
fclose(u8g2_font_list_fp);
fclose(u8x8_font_list_fp);
2015-11-07 16:27:18 +08:00
return 0;
}