bf_t *bf_OpenFromFile(const char *bdf_filename, int is_verbose, int bbx_mode, const char *map_str, int font_format) { bf_t *bf; bf = bf_Open(is_verbose, bbx_mode); if ( bf != NULL ) { if ( bf_ParseFile(bf, bdf_filename) != 0 ) { bf_Map(bf, map_str); bf_CalculateSelectedNumberOfGlyphs(bf); bf_ReduceAllGlyph(bf); bf_CalculateMaxBBX(bf); //bf_ShowAllGlyphs(bf, &(bf->max)); bf_CalculateMinMaxDWidth(bf); bf_CalculateMaxBitFieldSize(bf); if ( font_format == 0 || font_format == 1 ) { bf_RLECompressAllGlyphs(bf); } else { bf_Generate8x8Font(bf); } if ( bf->bbx_mode != BDF_BBX_MODE_MINIMAL ) bf_ShowMonospaceStatistics(bf); /* Show stats only for none minimal mode. For minimal mode it will always be zero */ return bf; } bf_Close(bf); } return NULL; }
int main(int argc, char **argv) { bf_t *bf_desc_font; bf_t *bf; char *bdf_filename = NULL; int is_verbose = 0; char *map_str ="*"; char *desc_font_str = ""; unsigned y; argv++; /* if ( *argv == NULL ) { help(); exit(1); } */ for(;;) { if ( *argv == NULL ) break; if ( is_arg(&argv, 'h') != 0 ) { help(); exit(1); } else if ( is_arg(&argv, 'v') != 0 ) { is_verbose = 1; } else if ( is_arg(&argv, 'a') != 0 ) { font_picture_extra_info = 1; } else if ( is_arg(&argv, 't') != 0 ) { font_picture_test_string = 1; } else if ( is_arg(&argv, 'r') != 0 ) { runtime_test = 1; } else if ( get_num_arg(&argv, 'b', &build_bbx_mode) != 0 ) { } else if ( get_num_arg(&argv, 'f', &font_format) != 0 ) { } else if ( get_num_arg(&argv, 'l', &left_margin) != 0 ) { } else if ( get_str_arg(&argv, 'd', &desc_font_str) != 0 ) { } else if ( get_str_arg(&argv, 'o', &c_filename) != 0 ) { } else if ( get_str_arg(&argv, 'n', &target_fontname) != 0 ) { } else if ( get_str_arg(&argv, 'm', &map_str) != 0 ) { } else { bdf_filename = *argv; argv++; } } if ( bdf_filename == NULL ) { help(); exit(1); } bf_desc_font = NULL; if ( desc_font_str[0] != '\0' ) { bf_desc_font = bf_OpenFromFile(desc_font_str, 0, BDF_BBX_MODE_MINIMAL, "*", 0); /* assume format 0 for description */ if ( bf_desc_font == NULL ) { exit(1); } } if ( font_format == 1 ) { build_bbx_mode = BDF_BBX_MODE_M8; /* issue the following log message later, when there is a valid bf object */ /* bf_Log(bf, "Font mode 1: BBX mode set to 3"); */ } bf = bf_OpenFromFile(bdf_filename, is_verbose, build_bbx_mode, map_str, font_format); if ( bf == NULL ) { exit(1); } if ( font_format == 1 ) { /* now generate the log message */ bf_Log(bf, "Note: For font format 1 BBX mode has been set to 3"); } if ( bf_desc_font != NULL ) { tga_init(1024, 600); y = tga_draw_font(0, bdf_filename, bf_desc_font, bf); if ( runtime_test != 0 ) { long i; clock_t c = clock(); fd_t fd; fd_init(&fd); fd_set_font(&fd, bf->target_data); for( i = 0; i < 10000; i++ ) fd_draw_string(&fd, left_margin, y, "Woven silk pyjamas exchanged for blue quartz."); bf_Log(bf, "Runtime test: %.2lf sec", (double)(clock()-c)/(double)CLOCKS_PER_SEC); } tga_save("bdf.tga"); } if ( c_filename != NULL ) { /* write the encoded data in bf->target_data */ if ( font_format == 0 ) { bf_WriteUCGCByFilename(bf, c_filename, target_fontname, " "); } else { bf_WriteU8G2CByFilename(bf, c_filename, target_fontname, " "); } } bf_Close(bf); return 0; }