这几天想做个MP3播放器,用到了中文,搞了一天,增加俩个文件,放在库文件目录下,字库是我从文件加载的,现在共享。
/*
*********************************************************************************************************
* uC/GUI V3.98
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
* ?C/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File : GUI_UC_EncodeNone.c
Purpose : Encoding routines for non unicode systems (default)
---------------------------END-OF-HEADER------------------------------
*/
#include "GUI_Private.h"
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _GetCharCode
*
* Purpose:
* Return the UNICODE character code of the current character.
*/
static U16 _GetCharCode(const char GUI_UNI_PTR * s) {
if((*s) > 0xA0)
return *(const U16 GUI_UNI_PTR *)s;
return *(const U8 GUI_UNI_PTR *)s;
}
/*********************************************************************
*
* _GetCharSize
*
* Purpose:
* Return the number of bytes of the current character.
*/
static int _GetCharSize(const char GUI_UNI_PTR * s) {
GUI_USE_PARA(s);
if((*s) > 0xA0) return 2;
return 1;
}
/*********************************************************************
*
* _CalcSizeOfChar
*
* Purpose:
* Return the number of bytes needed for the given character.
*/
static int _CalcSizeOfChar(U16 Char) {
GUI_USE_PARA(Char);
if(Char > 0xA0A0) return 2;
return 1;
}
/*********************************************************************
*
* _Encode
*
* Purpose:
* Encode character into 1/2/3 bytes.
*/
static int _Encode(char *s, U16 Char) {
if(Char > 0xA0A0)
{
*((U16 *)s) = (U16)(Char);
return 2;
}
*s = (U8)(Char);
return 1;
}
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _API_Table
*/
const GUI_UC_ENC_APILIST GUI_UC_None = {
_GetCharCode, /* return character code as U16 */
_GetCharSize, /* return size of character: 1 */
_CalcSizeOfChar, /* return size of character: 1 */
_Encode /* Encode character */
};
//const GUI_UC_ENC_APILIST GUI__API_TableNone = {
// _GetCharCode, /* return character code as U16 */
// _GetCharSize, /* return size of character: 1 */
// _CalcSizeOfChar, /* return size of character: 1 */
// _Encode /* Encode character */
//};
/*********************************************************************
*
* Exported code
*
**********************************************************************
*/
/*********************************************************************
*
* GUI_UC_SetEncodeNone
*/
// void GUI_UC_SetEncodeNone(void) {
// #if GUI_SUPPORT_UNICODE
// GUI_LOCK();
// GUI_Context.pUC_API = &GUI_UC_None;
// GUI_UNLOCK();
// #endif
// }
/*************************** End of file ****************************/
#include <stddef.h> /* needed for definition of NULL */
#include "GUI_Private.h"
#include <string.h>
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
//×???????????????×é,??????×?????×??ó×????????è?¨??
#define BYTES_PER_FONT 128
static U8 GUI_FontDataBuf[BYTES_PER_FONT];
extern unsigned char *_Hzk_16;
extern unsigned char *_Asc_16;
//???????????÷????×???????
static void GUI_GetDataFromMemory(const GUI_FONT_PROP GUI_UNI_PTR *pProp, U16P c)
{
U16 BytesPerFont;
U32 oft;
char *font = (char *)pProp->paCharInfo->pData;
BytesPerFont = GUI_pContext->pAFont->YSize * pProp->paCharInfo->BytesPerLine; //????×?????????×?????
if (BytesPerFont > BYTES_PER_FONT){BytesPerFont = BYTES_PER_FONT;}
if (c < 0x80) //????×?·????·??????·¨
{
oft = c * BytesPerFont;
}
else
{
oft = ((((c >> 8) - 0xA1)) + ((c & 0xFF) - 0xA1) * 94l) * BytesPerFont; //????×?·????·??????·¨°ü?¨·???
}
if (font[0] == 'a')
{
memcpy(GUI_FontDataBuf, _Asc_16 + oft, BytesPerFont);
}
else
memcpy(GUI_FontDataBuf, _Hzk_16 + oft, BytesPerFont);
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* GUIPROP_DispChar
*
* Purpose:
* This is the routine that displays a character. It is used by all
* other routines which display characters as a subroutine.
*/
void GUIPROP_X_DispChar(U16P c)
{
int BytesPerLine;
GUI_DRAWMODE DrawMode = GUI_pContext->TextMode;
const GUI_FONT_PROP GUI_UNI_PTR *pProp = GUI_pContext->pAFont->p.pProp;
//???÷?¨??×???????????
for (; pProp; pProp = pProp->pNext)
{
if ((c >= pProp->First) && (c <= pProp->Last))
{
break;
}
}
if (pProp)
{
GUI_DRAWMODE OldDrawMode;
const GUI_CHARINFO GUI_UNI_PTR * pCharInfo = pProp->paCharInfo;
GUI_GetDataFromMemory(pProp, c);//????×???????
BytesPerLine = pCharInfo->BytesPerLine;
OldDrawMode = LCD_SetDrawMode(DrawMode);
LCD_DrawBitmap(GUI_pContext->DispPosX, GUI_pContext->DispPosY,
pCharInfo->XSize, GUI_pContext->pAFont->YSize,
GUI_pContext->pAFont->XMag, GUI_pContext->pAFont->YMag,
1, /* Bits per Pixel */
BytesPerLine,
&GUI_FontDataBuf[0],
&LCD_BKCOLORINDEX
);
/* Fill empty pixel lines */
if (GUI_pContext->pAFont->YDist > GUI_pContext->pAFont->YSize)
{
int YMag = GUI_pContext->pAFont->YMag;
int YDist = GUI_pContext->pAFont->YDist * YMag;
int YSize = GUI_pContext->pAFont->YSize * YMag;
if (DrawMode != LCD_DRAWMODE_TRANS)
{
LCD_COLOR OldColor = GUI_GetColor();
GUI_SetColor(GUI_GetBkColor());
LCD_FillRect(GUI_pContext->DispPosX, GUI_pContext->DispPosY + YSize,
GUI_pContext->DispPosX + pCharInfo->XSize,
GUI_pContext->DispPosY + YDist);
GUI_SetColor(OldColor);
}
}
LCD_SetDrawMode(OldDrawMode); /* Restore draw mode */
// if (!GUI_MoveRTL)
GUI_pContext->DispPosX += pCharInfo->XDist * GUI_pContext->pAFont->XMag;
}
}
/*********************************************************************
*
* GUIPROP_GetCharDistX
*/
int GUIPROP_X_GetCharDistX(U16P c)
{
const GUI_FONT_PROP GUI_UNI_PTR * pProp = GUI_pContext->pAFont->p.pProp;
for (; pProp; pProp = pProp->pNext)
{
if ((c >= pProp->First) && (c <= pProp->Last))break;
}
return (pProp) ? (pProp->paCharInfo)->XSize * GUI_pContext->pAFont->XMag : 0;
}
GUI_CONST_STORAGE GUI_CHARINFO GUI_FontHZ16_CharInfo[2] =
{
{ 8, 8, 1, (void *)"a"},
{ 16, 16, 2, (void *)"b"},
};
GUI_CONST_STORAGE GUI_FONT_PROP GUI_FontHZ16_PropHZ = {
0xA1A1,
0xFFFF,
&GUI_FontHZ16_CharInfo[1],
(void *)0,
};
GUI_CONST_STORAGE GUI_FONT_PROP GUI_FontHZ16_PropASC = {
0x0000,
0x007F,
&GUI_FontHZ16_CharInfo[0],
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropHZ,
};
GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16 =
{
GUI_FONTTYPE_PROP_USER,
16,
16,
1,
1,
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropASC
};
GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16x2 =
{
GUI_FONTTYPE_PROP_USER,
16,
16,
2,
2,
(void GUI_CONST_STORAGE *)&GUI_FontHZ16_PropASC
};
在 gui_type.h 加
/*PROP_USER: chian */
#define GUI_FONTTYPE_PROP_USER \
GUIPROP_X_DispChar, \
GUIPROP_X_GetCharDistX, \
GUIMONO_GetFontInfo, \
GUIMONO_IsInFont, \
(GUI_GETCHARINFO *)0, \
(tGUI_ENC_APIList*)0
在 gui.h 加
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ12;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ16x2; 转载
|