想让STemWIN显示中文字体首先要移植了文件系统和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;//定义文件系统
/*
*********************************************************************************************************
*
* _cbGetData
*
* Function description
* Callback function for getting font data
*
* Parameters:
* Off - Position of XBF file to be read文件内偏移量
* NumBytes - Number of requested bytes需要读取的文件数量
* pVoid - Application defined pointer//文件指针
* pBuffer - Pointer to buffer to be filled by the function读出来的文件数据缓冲区
*
* 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();
//红色字体的代码在主函数中调用
//这是显示效果 上张图片看看
|