我们的基于minigui的嵌入式系统项目中使用了True Type字体,原以以为只要把字体文件应用程序所在路径下的字体文件夹(res/font)下就可以了,但实际运行时报错了:
NEWGAL>PCXVFB: /usr/local/bin/gvfb 12695 miniStudio Emulator 240x320-16bpp.rgb565 FONT>FT2: another error code means that the font file ... could not be opened or read. or simply that it is broken ... FONT>DevFont: error in loading font ttf-simkai-rrncnn-0-0-ISO8859-1,GB2312,UTF-8 from /usr/local/share/minigui/res//font/simkai.ttf file. FONT>FT2: another error code means that the font file ... could not be opened or read. or simply that it is broken ... FONT>DevFont: error in loading font ttf-simkai-rrncnn-0-0-ISO8859-1,GB2312,UTF-8 from font/simkai.ttf file. NEWGDI>InitGDI: Can not initialize fonts defined in section truetypefonts!上面的错误看出,minigui在初始化的时候还是去/usr/local/share/minigui/res/font下去找字体了。为了确认minigui初始化字体时的逻辑,查看了代码,下面是libminigui-3.2.0/src/font/devfont.c中的init_or_term_specifical_fonts函数的片段:
/*add devfont*/ if ((memres = (MEM_RES*)LoadResource (font_file, RES_TYPE_MEM_RES, 0))) { AddDevFont (font_name, memres->data, FALSE); added_num ++; } else { // 调用sysres_get_system_res_path获取minigui系统资源路径,组成字体资源路径font_path // 没有尝试从usr_res_path或pwd_res_path去寻找, // usr_res_path,pwd_res_path是libminigui-3.2.0/src/sysres/resmgr.c中定义的宏 if ((0 == mg_path_joint(font_path, MAX_PATH + 1, sysres_get_system_res_path(), font_file)) && ((AddDevFont (font_name, font_path, TRUE)) == TRUE)) added_num++; // 尝试从当前路径下font文件夹寻找, // 因为在MiniGUI.cfg中字体定义一般是这样的fontfile0=font/Courier-rr-8-13.vbf else if ((AddDevFont (font_name, font_file, TRUE)) == TRUE) added_num++; }minigui初始化字体时只会先在系统资源路径下寻找,然后在当前路径的font(不是res/font)文件夹下寻找。 所以如果你不想改minigui的源码,就把自己的字体文件文件放在/usr/local/share/minigui/res/font好了