minigui:自定義字型檔案的安裝位置(install location for custom font)
阿新 • • 發佈:2018-11-01
我們的基於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
好了