📄 gui_uc_encodebig5.c
字号:
#include "gui_core_kernel_private.h"
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _GetCharCode
*
* Purpose:
* Return the UNICODE character code of the current character.
*/
static U16 _GetCharCode(const char GUI_UNI_PTR * s) {
U16 r;
// U16 temp;
U8 Char = *(const U8*)s;
if (Char < 0x80) {
r = Char;
} else if (Char > 0xa1) { // changge 0xa1 to 0x80 for GBK
r = (Char & 0xff) << 8;
Char = *(++s);
Char &= 0xff;
r |= Char;
r = Big5_to_Unicode(r);
} else {
__inf("Illegal character during GB2312 decoding!\n");
r = 1;
}
return r;
}
/*********************************************************************
*
* _GetCharSize
*
* Purpose:
* Return the number of bytes of the current character.
*/
static int _GetCharSize(const char GUI_UNI_PTR * s) {
U8 Char = *s;
if (Char < 0xa1) {
return 1;
} else if (Char >0xa1 ) {
return 2;
}
__inf("Illegal character during GB2312 decoding!\n");
return 1;
}
/*********************************************************************
*
* _CalcSizeOfChar
*
* Purpose:
* Return the number of bytes needed for the given character.
*/
static int _CalcSizeOfChar(U16 Char) {
int r=0;
if ((Char>=0xa140)&&(Char< 0xf9ff)) { /* Single byte (ASCII) */
r = 2;
} else if (Char <0x80) { /* Double byte sequence */
r = 1;
}
return r;
}
/*********************************************************************
*
* _Encode
*
* Purpose:
* Encode character into 1/2/3 bytes.
*/
static int _Encode(char *s, U16 Char) {
int r;
r = _CalcSizeOfChar(Char);
switch (r) {
case 1:
*s = (char)Char;
break;
case 2:
*s++ = (Char >> 8)&0xff;
*s = Char & 0xFF00;
break;
}
return r;
}
/*********************************************************************
*
* _API_Table
*/
static const GUI_UC_ENC_APILIST _API_Table = {
_GetCharCode, /* return character code as U16 (Unicode) */
_GetCharSize, /* return size of character: 1/2/3 */
_CalcSizeOfChar, /* return size of character: 1/2/3 */
_Encode /* Encode character into 1/2/3 bytes */
};
/*********************************************************************
*
* Exported code
*
**********************************************************************
*/
/*********************************************************************
*
* GUI_UC_SetEncodeBig5
*/
void GUI_UC_SetEncodeBig5(void) {
GUI_LOCK();
GUI_Context.pUC_API = &_API_Table;
GUI_UNLOCK();
}
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -