想讓STemWIN顯示中文字體首先要移植了文件系統(tǒng)和STemWIN才行.
#include"GUI.h"
#include "ff.h"
GUI_XBF_DATA XBF_Data;
GUI_FONT XBF_Font;
FIL Fontfile;//定義文件
FRESULT result;//文件操作標準
uint32_t br,bw;//
FATFSfatfs;//定義文件系統(tǒng)
/*
*********************************************************************************************************
*
* _cbGetData
*
* Function description
* Callback function for getting font data
*
* Parameters:
* Off - Position of XBF file to be read文件內(nèi)偏移量
* NumBytes - Number of requested bytes需要讀取的文件數(shù)量
* pVoid - Application defined pointer//文件指針
* pBuffer - Pointer to buffer to be filled by the function讀出來的文件數(shù)據(jù)緩沖區(qū)
*
* Return value:
* 0 on success, 1 on error
*********************************************************************************************************
*/
static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer)
{
FIL *FontFile;
/* The pVoid pointer may be used to get a file handle */
FontFile = (FIL *)pVoid;
/*
* Set file pointer to the required position
*/
result =f_lseek(FontFile, Off);
if (result != FR_OK)
{
return 1; /* Error */
}
/*
* Read data into buffer
*/
result = f_read(FontFile, pBuffer, NumBytes, &bw);
if (result != FR_OK)
{
return 1; /* Error */
}
return 0;
}
f_mount(0,&fatfs);
result = f_open(&Fontfile, "0:/Font.xbf", FA_OPEN_EXISTING | FA_READ | FA_OPEN_ALWAYS);//黑色字體的字符串是 字體的文件名
if (result != FR_OK)
{
return;
}
//
// Create XBF font
//
GUI_XBF_CreateFont(&XBF_Font, // Pointer to GUI_FONT structure in RAM(3)
&XBF_Data, // Pointer to GUI_XBF_DATA structure in RAM
GUI_XBF_TYPE_PROP_AA4_EXT, // Font type to be created
_cbGetData, // Pointer to callback function
&Fontfile);
GUI_UC_SetEncodeUTF8();
//紅色字體的代碼在主函數(shù)中調(diào)用
//這是顯示效果 上張圖片看看
|