STM32 - EMWIN XBF format font display (21)

One, XBF format font production

First of all, we need to use the font converter to make the required XBF fonts. The STemWin source code we downloaded already contains the font converter: FontCvtST.exe
insert image description here
insert image description here
Next, we make 4 XBF font libraries, the fonts are all selected as Song type, the size is 12, 16, 24 and 36, the font type is "Extended, antialiased, 2bpp", which is an extended scale bitmap font, including 2bpp antialiasing.

1. Select the font type

insert image description here
insert image description here
insert image description here

2. Save the font

Click: File->Save As, the dialog box as shown in the figure appears, select the save type as .xbf
insert image description here
insert image description here
to copy the created XBF font to the specified file directory of the SD card: SYSTEM->EMWINFONT->XBF

2. XBF font related API functions

There are two functions related to XBF fonts: GUI_XBF_CreateFont() and GUI_XBF_DeleteFont()

1. GUI_XBF_CreateFont() function

Description
Creates and selects a font by passing a pointer to a callback function responsible for fetching data from an XBF font file.
prototype

int GUI_XBF_CreateFont( GUI_FONT *pFont,
 GUI_XBF_DATA *pxBF_Data,
 const GUI_XBF_TYPE *pFontType,
 GUI_XBF_GET_DATA_FUNC *pfGetData,
 void *pVoid );

insert image description here
insert image description here

2.GUI_XBF_DeleteFont()

Description
Deletes the XBF font indicated by the parameter pFont.
Prototype
void GUI_XBF_DeleteFont(GUI_FONT * pFont);
Parameter description
pFont: points to the font to be deleted.
Additional Information
After a font created with GUI_XBF_CreateFont(), it should be deleted if it is no longer used

#include "xbffontcreate.h"
#include "ff.h"

#if SYSTEM_SUPPORT_UCOS
#include "includes.h"					//ucos ʹÓÃ	  
#endif

//¶¨Òå×ÖÌå
GUI_FONT XBF12_Font;
GUI_FONT XBF16_Font;
GUI_FONT XBF24_Font;
GUI_FONT XBF36_Font;

GUI_XBF_DATA	XBF12_Data;
GUI_XBF_DATA	XBF16_Data;
GUI_XBF_DATA	XBF24_Data;
GUI_XBF_DATA	XBF36_Data;

FIL XBF16FontFile;
FIL XBF12FontFile;
FIL XBF24FontFile;
FIL XBF36FontFile;

//»Øµ÷º¯Êý£¬ÓÃÀ´»ñÈ¡×ÖÌåÊý¾Ý
//²ÎÊý£ºOff:		ÔÚXBFÖÐÆ«ÒÆ(λÖÃ)
//		NumBytes:	Òª¶ÁÈ¡µÄ×Ö½ÚÊý
//		pVoid:	Òª¶ÁÈ¡µÄÎļþ
//		pBuff:	¶ÁÈ¡µ½µÄÊý¾ÝµÄ»º³åÇø
//·µ»ØÖµ:0 ³É¹¦£¬1 ʧ°Ü
static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer) 
{
    
    
	int result;
	u16 bread; 
	FIL *hFile;

	#if SYSTEM_SUPPORT_UCOS
		OS_CPU_SR cpu_sr;
	#endif

	hFile = (FIL*)pVoid; 
	
	//ÉèÖÃÔÚÎļþÖеÄÆ«ÒÆ(λÖÃ)
	result = f_lseek(hFile,Off);
	if(result != FR_OK)	return 1; //·µ»Ø´íÎó

	//¶ÁÈ¡×ÖÌåÊý¾Ý
	#if SYSTEM_SUPPORT_UCOS
		OS_ENTER_CRITICAL();	//ÁÙ½çÇø
	#endif
		
	result = f_read(hFile,pBuffer,NumBytes,(UINT *)&bread); //¶ÁÈ¡Êý¾Ý
	
	#if SYSTEM_SUPPORT_UCOS
		OS_EXIT_CRITICAL();	//Í˳öÁÙ½çÇø
	#endif
	
	if(result != FR_OK) return 1; //·µ»Ø´íÎó
	return 0; 
}

//´´½¨XBF12×ÖÌ壬¹²EMWINʹÓÃ
//fxpath:XBF×ÖÌåÎļþ·¾¶
//·µ»ØÖµ:0£¬³É¹¦£»1£¬Ê§°Ü
u8 Create_XBF12(u8 *fxpath) 
{
    
    
	int result;
	result = f_open(&XBF12FontFile,(const TCHAR*)fxpath,FA_READ);	//´ò¿ª×Ö¿âÎļþ
	
	if(result != FR_OK) return 1;
	//´´½¨XBF16×ÖÌå
	GUI_XBF_CreateFont(	&XBF12_Font,    //Ö¸ÏòGUI_FONT½á¹¹
						&XBF12_Data, 	//Ö¸ÏòGUI_XBF_DATA½á¹¹
						GUI_XBF_TYPE_PROP_AA2_EXT,//Òª´´½¨µÄ×ÖÌåÀàÐÍ
						_cbGetData,   	//»Øµ÷º¯Êý
						&XBF12FontFile);  //´°Ìå¸ø»Øµ÷º¯Êý_cbGetDataµÄ²ÎÊý
	return 0;
}

//´´½¨XBF16×ÖÌ壬¹²EMWINʹÓÃ
//fxpath:XBF×ÖÌåÎļþ·¾¶
//·µ»ØÖµ:0£¬³É¹¦£»1£¬Ê§°Ü
u8 Create_XBF16(u8 *fxpath) 
{
    
    
	int result;
	result = f_open(&XBF16FontFile,(const TCHAR*)fxpath,FA_READ);	//´ò¿ª×Ö¿âÎļþ
	
	if(result != FR_OK) return 1;
	//´´½¨XBF16×ÖÌå
	GUI_XBF_CreateFont(	&XBF16_Font,    //Ö¸ÏòGUI_FONT½á¹¹
						&XBF16_Data, 	//Ö¸ÏòGUI_XBF_DATA½á¹¹
						GUI_XBF_TYPE_PROP_AA2_EXT,//Òª´´½¨µÄ×ÖÌåÀàÐÍ
						_cbGetData,   	//»Øµ÷º¯Êý
						&XBF16FontFile);  //´°Ìå¸ø»Øµ÷º¯Êý_cbGetDataµÄ²ÎÊý
	return 0;
}

//´´½¨XBF24×ÖÌ壬¹²EMWINʹÓÃ
//fxpath:XBF×ÖÌåÎļþ·¾¶
//·µ»ØÖµ:0£¬³É¹¦£»1£¬Ê§°Ü
u8 Create_XBF24(u8 *fxpath) 
{
    
    
	int result;
	result = f_open(&XBF24FontFile,(const TCHAR*)fxpath,FA_READ);	//´ò¿ª×Ö¿âÎļþ
	if(result != FR_OK) return 1;
	//´´½¨XBF16×ÖÌå
	GUI_XBF_CreateFont(	&XBF24_Font,    //Ö¸ÏòGUI_FONT½á¹¹
						&XBF24_Data, 	//Ö¸ÏòGUI_XBF_DATA½á¹¹
						GUI_XBF_TYPE_PROP_AA2_EXT,//Òª´´½¨µÄ×ÖÌåÀàÐÍ
						_cbGetData,   	//»Øµ÷º¯Êý
						&XBF24FontFile);  //´°Ìå¸ø»Øµ÷º¯Êý_cbGetDataµÄ²ÎÊý
	return 0;
}

//´´½¨XBF36×ÖÌ壬¹²EMWINʹÓÃ
//fxpath:XBF×ÖÌåÎļþ·¾¶
//·µ»ØÖµ:0£¬³É¹¦£»1£¬Ê§°Ü
u8 Create_XBF36(u8 *fxpath) 
{
    
    
	int result;
	result = f_open(&XBF36FontFile,(const TCHAR*)fxpath,FA_READ);	//´ò¿ª×Ö¿âÎļþ
	if(result != FR_OK) return 1;	
	//´´½¨XBF16×ÖÌå
	GUI_XBF_CreateFont(	&XBF36_Font,    //Ö¸ÏòGUI_FONT½á¹¹
						&XBF36_Data, 	//Ö¸ÏòGUI_XBF_DATA½á¹¹
						GUI_XBF_TYPE_PROP_AA2_EXT,//Òª´´½¨µÄ×ÖÌåÀàÐÍ
						_cbGetData,   	//»Øµ÷º¯Êý
						&XBF36FontFile);  //´°Ìå¸ø»Øµ÷º¯Êý_cbGetDataµÄ²ÎÊý
	return 0;
}

insert image description here
It is recommended to use F4, and F1 is very card.

Guess you like

Origin blog.csdn.net/qq_51963216/article/details/124077930