2018-02-21 19:36:38 +08:00
|
|
|
/**
|
|
|
|
* File: main.c
|
2018-05-15 09:31:58 +08:00
|
|
|
* Author: AWTK Develop Team
|
2018-02-21 19:36:38 +08:00
|
|
|
* Brief: bitmap font generator
|
|
|
|
*
|
2019-01-07 10:58:36 +08:00
|
|
|
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
2018-02-21 19:36:38 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* License file for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History:
|
|
|
|
* ================================================================
|
|
|
|
* 2018-01-21 Li XianJing <xianjimli@hotmail.com> created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-12-15 17:22:05 +08:00
|
|
|
#include "tkc/mem.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
#include "common/utils.h"
|
|
|
|
#include "font_gen.h"
|
2018-10-19 18:10:58 +08:00
|
|
|
#include "font_loader/font_loader_bitmap.h"
|
2019-09-03 17:59:12 +08:00
|
|
|
#ifdef WITH_STB_FONT
|
|
|
|
#include "font_loader/font_loader_stb.h"
|
|
|
|
#else
|
2019-08-11 16:52:45 +08:00
|
|
|
#include "font_loader/font_loader_ft.h"
|
2019-09-05 16:33:05 +08:00
|
|
|
#endif /*WITH_STB_FONT*/
|
2019-08-11 16:52:45 +08:00
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
uint32_t size = 0;
|
2019-08-11 16:52:45 +08:00
|
|
|
bool_t mono = FALSE;
|
2018-02-21 19:36:38 +08:00
|
|
|
font_t* font = NULL;
|
|
|
|
char* str_buff = NULL;
|
|
|
|
uint8_t* ttf_buff = NULL;
|
|
|
|
uint32_t font_size = 20;
|
|
|
|
const char* ttf_filename = NULL;
|
|
|
|
const char* str_filename = NULL;
|
2018-11-02 11:51:14 +08:00
|
|
|
const char* out_filename = NULL;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
2018-05-04 11:45:09 +08:00
|
|
|
TKMEM_INIT(4 * 1024 * 1024);
|
2018-02-22 11:37:13 +08:00
|
|
|
|
2019-08-11 16:52:45 +08:00
|
|
|
if (argc < 5) {
|
|
|
|
printf("Usage: %s ttf_filename str_filename out_filename font_size [mono]\n", argv[0]);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ttf_filename = argv[1];
|
|
|
|
str_filename = argv[2];
|
2018-11-02 11:51:14 +08:00
|
|
|
out_filename = argv[3];
|
2018-02-21 19:36:38 +08:00
|
|
|
font_size = atoi(argv[4]);
|
|
|
|
|
2019-08-12 10:47:09 +08:00
|
|
|
if (argc == 6 && tk_str_eq(argv[5], "mono")) {
|
2019-08-11 16:52:45 +08:00
|
|
|
mono = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-05 10:05:29 +08:00
|
|
|
exit_if_need_not_update_for_infiles(out_filename, 2, ttf_filename, str_filename);
|
2018-11-02 11:51:14 +08:00
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
ttf_buff = (uint8_t*)read_file(ttf_filename, &size);
|
|
|
|
return_value_if_fail(ttf_buff != NULL, 0);
|
2019-09-03 17:59:12 +08:00
|
|
|
#ifdef WITH_STB_FONT
|
|
|
|
if (mono) {
|
|
|
|
assert(!"not support mono font");
|
|
|
|
} else {
|
|
|
|
font = font_stb_create("default", ttf_buff, size);
|
|
|
|
}
|
|
|
|
#else
|
2019-08-11 16:52:45 +08:00
|
|
|
if (mono) {
|
|
|
|
font = font_ft_mono_create("default", ttf_buff, size);
|
|
|
|
} else {
|
2019-08-15 08:14:32 +08:00
|
|
|
font = font_ft_create("default", ttf_buff, size);
|
2019-08-11 16:52:45 +08:00
|
|
|
}
|
2019-09-05 16:33:05 +08:00
|
|
|
#endif /*WITH_STB_FONT*/
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
str_buff = read_file(str_filename, &size);
|
|
|
|
return_value_if_fail(str_buff != NULL, 0);
|
|
|
|
|
|
|
|
if (font != NULL) {
|
2018-11-02 11:51:14 +08:00
|
|
|
font_gen(font, (uint16_t)font_size, str_buff, out_filename);
|
2018-02-21 19:36:38 +08:00
|
|
|
}
|
|
|
|
|
2018-04-29 16:51:54 +08:00
|
|
|
TKMEM_FREE(ttf_buff);
|
|
|
|
TKMEM_FREE(str_buff);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
printf("done\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|