improve font manage and update docs

This commit is contained in:
xianjimli 2018-05-04 16:17:12 +08:00
parent 2cb3d3888a
commit f5375677a8
8 changed files with 99 additions and 20 deletions

View File

@ -93,6 +93,9 @@ bin\demo1
## 最新动态
* 2018/05/03
* 增加locale支持多国语言字符串翻译。
* 2018/05/01
* 更新文档。

View File

@ -40,10 +40,10 @@
* picasso实现vgcanvas接口
* 支持窗口动画
* 资源管理器支持从ROM和文件中加载。
* 国际化支持字符串翻译。
## 短期计划(顺序不定)
* agg实现vgcanvas接口
* 国际化支持
* API doc到PDF转换工具
* image value
* combobox

View File

@ -59,13 +59,8 @@ int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline
#include "base/mem.h"
int main(void) {
#endif
system_info_t* info = system_info();
tk_init(320, 480, s_heap_mem, sizeof(s_heap_mem));
log_debug("system_info: lcd_w=%d lcd_h=%d lcd_type=%d device_pixel_ratio=%f\n", info->lcd_w,
info->lcd_h, info->lcd_type, info->device_pixel_ratio);
resource_init();
application_init();

View File

@ -22,10 +22,22 @@
#include "base/mem.h"
#include "base/font_manager.h"
font_manager_t* font_manager_create() {
static font_manager_t* s_font_manager = NULL;
font_manager_t* font_manager(void) {
return s_font_manager;
}
ret_t font_manager_set(font_manager_t* fm) {
s_font_manager = fm;
return RET_OK;
}
font_manager_t* font_manager_create(void) {
font_manager_t* fm = TKMEM_ZALLOC(font_manager_t);
return fm;
return font_manager_init(fm);
}
font_manager_t* font_manager_init(font_manager_t* fm) {
@ -92,12 +104,3 @@ ret_t font_manager_destroy(font_manager_t* fm) {
return RET_OK;
}
font_manager_t* font_manager() {
static font_manager_t* afm = NULL;
if (afm == NULL) {
afm = TKMEM_ZALLOC(font_manager_t);
font_manager_init(afm);
}
return afm;
}

View File

@ -27,20 +27,89 @@
BEGIN_C_DECLS
/**
* @class font_manager_t
*
* (使nanovgnanovg内部管理)
*/
typedef struct _font_manager_t {
array_t fonts;
} font_manager_t;
/**
* @method font_manager
*
* @constructor
* @return {font_manager_t*}
*/
font_manager_t* font_manager(void);
/**
* @method font_manager_set
*
* @param {font_manager_t*} fm
*
* @return {ret_t} RET_OK表示成功
*/
ret_t font_manager_set(font_manager_t* fm);
/**
* @method font_manager_create
*
* @constructor
*
* @return {font_manager_t*}
*/
font_manager_t* font_manager_create(void);
/**
* @method font_manager_init
*
* @constructor
* @param {font_manager_t*} fm
*
* @return {font_manager_t*}
*/
font_manager_t* font_manager_init(font_manager_t* fm);
/**
* @method font_manager_add
*
* @param {font_manager_t*} fm
* @param {char*} name
* @param {font_t*} font
*
* @return {ret_t} RET_OK表示成功
*/
ret_t font_manager_add(font_manager_t* fm, font_t* font);
/**
* @method font_manager_find
*
* @param {font_manager_t*} fm
* @param {char*} name NULL时使用STR_DEFAULT_FONT
* @param {uint16_t} size
*
* @return {font_t*}
*/
font_t* font_manager_find(font_manager_t* fm, const char* name, uint16_t size);
/**
* @method font_manager_deinit
*
* @param {font_manager_t*} fm
*
* @return {ret_t} RET_OK表示成功
*/
ret_t font_manager_deinit(font_manager_t* fm);
/**
* @method font_manager_destroy
*
* @param {font_manager_t*} fm
*
* @return {ret_t} RET_OK表示成功
*/
ret_t font_manager_destroy(font_manager_t* fm);
END_C_DECLS

View File

@ -138,6 +138,7 @@ ret_t image_manager_add(image_manager_t* imm, const char* name, const bitmap_t*
* @return {ret_t} RET_OK表示成功
*/
ret_t image_manager_lookup(image_manager_t* imm, const char* name, bitmap_t* image);
/**
* @method image_manager_deinit
*

View File

@ -82,18 +82,19 @@ ret_t tk_init(wh_t w, wh_t h, uint32_t* heap, uint32_t size) {
return_value_if_fail(platform_prepare() == RET_OK, RET_FAIL);
return_value_if_fail(mem_init(heap, size) == RET_OK, RET_FAIL);
return_value_if_fail(resource_manager_set(resource_manager_create(30)) == RET_OK, RET_FAIL);
return_value_if_fail(locale_set(locale_create(NULL, NULL)) == RET_OK, RET_FAIL);
return_value_if_fail(font_manager_set(font_manager_create()) == RET_OK, RET_FAIL);
return_value_if_fail(image_manager_set(image_manager_create(loader)) == RET_OK, RET_FAIL);
return_value_if_fail(window_manager_set(window_manager_create()) == RET_OK, RET_FAIL);
return main_loop_init(w, h);
}
ret_t tk_run() {
main_loop_run(main_loop());
static ret_t tk_exit(void) {
main_loop_destroy(main_loop());
font_manager_destroy(font_manager());
image_manager_destroy(image_manager());
resource_manager_destroy(resource_manager());
locale_destroy(locale());
@ -101,6 +102,12 @@ ret_t tk_run() {
return RET_OK;
}
ret_t tk_run() {
main_loop_run(main_loop());
return tk_exit();
}
static ret_t tk_quit_idle(const timer_info_t* timer) { return main_loop_quit(main_loop()); }
ret_t tk_quit() {

View File

@ -59,6 +59,7 @@ GTEST_API_ int main(int argc, char** argv) {
#else
image_manager_set(image_manager_create(NULL));
#endif /*WITH_STB_IMAGE*/
font_manager_set(font_manager_create());
window_manager_set(window_manager_create());
resource_init();