中级会员
积分 313
金钱 313
注册时间 2013-10-11
在线时间 38 小时
1 金钱
emWin上使用TTF字体显示出现异常。创建6个不同尺寸的字体,在WM_INIT_DIALOG显示时,空格的尺寸是正常的,当窗体重绘时出现异常,空格尺寸不管字体大小,都变成了最大的那字体空格宽度了。请有原子429板的朋友测试一下下面的代码,是否也同样出现这问题?附上宋体字体文件。
#include "MainTask.h"
#include "includes.h"
GUI_TTF_CS Cs0, Cs1, Cs2, Cs3, Cs4, Cs5;
GUI_TTF_DATA Data;
GUI_FONT Font16, Font24, Font32, Font48, Font72, Font120;
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "TEST", 0, 0, 0, 800, 600,0, 0},
{ TEXT_CreateIndirect, "GUI_Font16B_ASCII is ok.", GUI_ID_TEXT0, 0, 100, 800, 16, 0,0},
{ TEXT_CreateIndirect, "TTF24 The width of the space is abnormal.", GUI_ID_TEXT1, 0, 116, 800, 24, 0,0},
{ TEXT_CreateIndirect, "TTF32 The width of the space is abnormal.", GUI_ID_TEXT2, 0, 140, 800, 32, 0,0},
{ TEXT_CreateIndirect, "TTF48 The width of the space is abnormal.", GUI_ID_TEXT3, 0, 172, 800, 48, 0,0},
{ TEXT_CreateIndirect, "TTF72 The width of the space is abnormal.", GUI_ID_TEXT4, 0, 220, 800, 72, 0,0},
{ TEXT_CreateIndirect, "TTF120 The width of the space is abnormal.", GUI_ID_TEXT5, 0, 292, 800, 120, 0,0},
};
void PaintDialog(WM_MESSAGE * pMsg)
{
// int X=0;
// WM_HWIN hWin = pMsg->hWin;
// GUI_SetFont(&Font16);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT0), "Abnormal display after WM_PAINT");
// GUI_SetFont(&Font24);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT1), "Abnormal display after WM_PAINT");
// GUI_SetFont(&Font32);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT2), "Abnormal display after WM_PAINT");
// GUI_SetFont(&Font32);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT3), "Abnormal display after WM_PAINT");
// GUI_SetFont(&Font32);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT4), "Abnormal display after WM_PAINT");
// GUI_SetFont(&Font32);
// X=GUI_GetCharDistX(0x20);
// TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT5), "Abnormal display after WM_PAINT");
}
void InitDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
FRAMEWIN_SetFont(hWin,&Font32);
FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER);
FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
FRAMEWIN_SetTitleHeight(hWin,35);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT0), GUI_BLACK);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT1), GUI_BLUE);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT2), GUI_ORANGE);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT3), GUI_MAGENTA);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT4), GUI_BLUE);
TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT5), GUI_RED);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT0), &GUI_Font16B_ASCII);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT1), &Font24);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT2), &Font32);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT3), &Font48);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT4), &Font72);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT5), &Font120);
}
static void _cbCallback(WM_MESSAGE * pMsg)
{
int NCode, Id;
WM_HWIN hWin = pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_PAINT:
PaintDialog(pMsg);
break;
case WM_INIT_DIALOG:
InitDialog(pMsg);
break;
default:
WM_DefaultProc(pMsg);
}
}
void LoadFontTTF(const char *sFilename)
{
U8 *_acBuffer;
GUI_HMEM hMem;
result = f_open(&file, sFilename, FA_OPEN_EXISTING | FA_READ | FA_OPEN_ALWAYS); //FatFS
if (result != FR_OK)
{
return;
}
hMem = GUI_ALLOC_AllocZero(file.fsize);
_acBuffer = GUI_ALLOC_h2p(hMem);
result = f_read(&file, _acBuffer, file.fsize, &bw);
if (result != FR_OK)
{
return;
}
Data.pData = _acBuffer;
Data.NumBytes = file.fsize;
Cs0.pTTF = &Data;
Cs0.PixelHeight = 16;
Cs0.FaceIndex = 0;
Cs1.pTTF = &Data;
Cs1.PixelHeight = 24;
Cs1.FaceIndex = 0;
Cs2.pTTF = &Data;
Cs2.PixelHeight = 32;
Cs2.FaceIndex = 0;
Cs3.pTTF = &Data;
Cs3.PixelHeight = 48;
Cs3.FaceIndex = 0;
Cs4.pTTF = &Data;
Cs4.PixelHeight = 72;
Cs4.FaceIndex = 0;
Cs5.pTTF = &Data;
Cs5.PixelHeight = 120;
Cs5.FaceIndex = 0;
GUI_TTF_CreateFontAA(&Font16, &Cs0);
GUI_TTF_CreateFontAA(&Font24, &Cs1);
GUI_TTF_CreateFontAA(&Font32, &Cs2);
GUI_TTF_CreateFontAA(&Font48, &Cs3);
GUI_TTF_CreateFontAA(&Font72, &Cs4);
GUI_TTF_CreateFontAA(&Font120, &Cs5);
f_close(&file);
}
void MainTask(void)
{
uint16_t i;
char cDispBuf[80];
GUI_Init();
WM_MULTIBUF_Enable(1);
GUI_SetBkColor(GUI_BLUE);
GUI_Clear();
GUI_SetFont(GUI_FONT_20_1);
GUI_DispStringAt("1. Please make sure the song.ttf is saved in SD", 0, 0);
GUI_DispStringAt("2. if the song.ttf is not saved in SD, this lab will fail", 0, 24);
GUI_DispStringAt("Loading song.ttf file from sdcard, please wait....", 0, 72);
GUI_UC_SetEncodeUTF8();
LoadFontTTF("song.ttf");
WM_SetDesktopColor(GUI_BLUE);
GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
while(1)
{
GUI_Delay(10);
}
}
我来回答