📄 guicharset.c
字号:
ch1 = mstr[0];
if(ch1 == '\0')
return 0;
ch2 = mstr[1];
// the range of Shift-JIS
if((((ch1 >= 0x81)&&(ch1 <= 0x9F))||((ch1 >= 0xE0)&&(ch1 <= 0xEA))) &&
(((ch2 >= 0x40)&&(ch2 <= 0x7E))||((ch2 >= 0x80)&&(ch2 <= 0xFC))))
return 2;
return 0;
}
T_MODULE T_WORD SJIS_char_offset(T_CONST T_UBYTE *mchar)
{
unsigned short usicode;
usicode = mchar[0]*0x100+mchar[1];
return SJIS_Serch(usicode);
}
T_MODULE T_BOOL SJIS_is_this_charset(T_CONST T_UBYTE *charset)
{
T_WORD i;
T_BYTE name[LEN_FONT_NAME + 1];
for(i = 0; i < LEN_FONT_NAME + 1; i++)
{
if(charset[i] == '\0')
break;
name[i] = toupper(charset[i]);
}
name[i] = '\0';
if(strstr(name, "SJIS"))
return TRUE;
return FALSE;
}
T_MODULE T_WORD SJIS_len_first_substr(T_CONST T_UBYTE *mstr, T_WORD mstrlen)
{
T_UBYTE ch1;
T_UBYTE ch2;
T_WORD i, left;
T_WORD sub_len = 0;
left = mstrlen;
for(i = 0; i < mstrlen; i += 2)
{
if(left < 2)
return sub_len;
ch1 = mstr[i];
if(ch1 == '\0')
return sub_len;
ch2 = mstr[i + 1];
if((((ch1 >= 0x81)&&(ch1 <= 0x9F))||((ch1 >= 0xE0)&&(ch1 <= 0xEA))) &&
(((ch2 >= 0x40)&&(ch2 <= 0x7E))||((ch2 >= 0x80)&&(ch2 <= 0xFC))))
sub_len += 2;
else
return sub_len;
left -= 2;
}
return sub_len;
}
T_MODULE T_WORD SJIS_pos_first_char(T_CONST T_UBYTE *mstr, T_WORD mstrlen)
{
T_UBYTE ch1;
T_UBYTE ch2;
T_WORD i, left;
i = 0;
left = mstrlen;
while(left)
{
if(left < 2)
return -1;
ch1 = mstr[i];
if(ch1 == '\0')
return -1;
ch2 = mstr[i + 1];
if((((ch1 >= 0x81)&&(ch1 <= 0x9F))||((ch1 >= 0xE0)&&(ch1 <= 0xEA))) &&
(((ch2 >= 0x40)&&(ch2 <= 0x7E))||((ch2 >= 0x80)&&(ch2 <= 0xFC))))
return i;
i += 1;
left -= 1;
}
return -1;
}
T_MODULE T_GUI_CharsetOps CharsetOps_SJIS =
{
6879,
2,
2,
FONT_CHARSET_SJIS,
{'\x81', '\x40'},
SJIS_len_first_char,
SJIS_char_offset,
db_nr_chars_in_str,
SJIS_is_this_charset,
SJIS_len_first_substr,
db_get_next_word,
SJIS_pos_first_char,
};
#endif
/* all charsets supported */T_MODULE T_GUI_CharsetOps *Charsets[] ={ &CharsetOps_iso8859_1,#ifdef _GB_SUPPORT &CharsetOps_gb2312,#endif#ifdef _BIG5_SUPPORT &CharsetOps_big5,#endif
#ifdef _SJIS_SUPPORT
&CharsetOps_SJIS,
#endif};#define NR_CHARSETS (sizeof(Charsets)/sizeof(T_GUI_CharsetOps*))
/*****************************************************************
******************************************************************
******************************************************************
******************************************************************
****************************************************************** * FUNCTION: fnFNT_GetCharsetOps * * PURPOSE: * * * PARAMETERS * Input: T_CONST T_BYTE *charset_name -- the name of charset * Output: * InOut: * * Return value: T_CharsetOps * --- the charset operations * Reentrant : No *****************************************************************/T_GUI_CharsetOps *fnFNT_GetCharsetOps(T_CONST T_BYTE *charset_name){ T_WORD i; for(i = 0; i < NR_CHARSETS; i++) { if((*Charsets[i]->is_this_charset)(charset_name) == TRUE) return Charsets[i]; } return NULL;}/*************** API: code convert ******************/#ifdef _BIG5_SUPPORT
T_EXTERN T_UHWORD gbTable[];T_EXTERN T_UHWORD ubTable[];
/****************************************************************** * FUNCTION: fnGUI_Gb2Big * * PURPOSE: * convert the code of gb2312 to big5 * * PARAMETERS * Input: mchar--the string with GB2312 * Output:dest-- the string convertedcode of BIG5 * InOut: * Return value: * Reentrant : No *****************************************************************/ T_VOID fnGUI_Gb2Big(T_UBYTE *dest,T_CONST T_UBYTE *mchar){ T_WORD i; for(i=0;i<strlen(mchar);i++) { if(mchar[i]=='\0') break; else { if(mchar[i]>= 0xA1 && mchar[i] <= 0xFE && mchar[i+1] >= 0xA1 && mchar[i+1] <= 0xFE)
{ if(mchar[i]>0xA1&&mchar[i]<0xB0) /* graphic code */ { dest[i+1]=HIBYTE(gbTable[(mchar[i]-0xA1)*0x5E +mchar[i+1]-0xA1]); dest[i]=LOBYTE(gbTable[(mchar[i]-0xA1)*0x5E +mchar[i+1]-0xA1]); } else /* Chinese code */ { dest[i+1]=HIBYTE(gbTable[((mchar[i]-0xA7)*0x5E)+mchar[i+1]-0xA1]); dest[i]=LOBYTE(gbTable[((mchar[i]-0xA7)*0x5E)+mchar[i+1]-0xA1]); } i++; } else { memcpy((dest+i),(mchar+i),1); } } } dest[i]='\0';}/****************************************************************** * FUNCTION: fnGUI_Unic2Big * * PURPOSE: * convert the code of unicode to big5 * * PARAMETERS * Input: mchar-- the string with unicode len-- the length of string
* Output:dest --the string converted * InOut: * Return value: * Reentrant : No *****************************************************************/ T_VOID fnGUI_Unic2Big(T_UBYTE *dest,T_CONST T_UBYTE *mchar,T_UWORD len){ T_WORD i,m; T_UHWORD str;
m=0;
for(i=0;i<len*2;i+=2) {
if(mchar[i]==0 && mchar[i+1]==0) break; else {
str=0;
str =str| mchar[i+1];
str=str<<8;
str =str|mchar[i];
if(str<0xFF)
{
dest[m]=str;
m++;
}
else
{
dest[m+1]=HIBYTE(ubTable[str - 0xA2]);
dest[m]=LOBYTE(ubTable[str - 0xA2]); m += 2;
}
} } dest[m]='\0';}#endif#ifdef _GB_SUPPORTT_EXTERN T_UHWORD bigTable[];T_EXTERN T_UHWORD ugTable[];/****************************************************************** * FUNCTION: fnGUI_ Big2Gb * * PURPOSE: * convert the code of big5 to gb2312 * * PARAMETERS * Input:mchar-- the string with BIG5 * Output:dest-- the string conveted * InOut: * Return value: * Reentrant : No *****************************************************************/T_VOID fnGUI_Big2Gb(T_UBYTE *dest,T_CONST T_UBYTE *mchar){ T_WORD i; for(i=0;i<(T_WORD)strlen(mchar);i++) { if(mchar[i]=='\0') break; else { if (mchar[i]>= 0xA1 && mchar[i] <= 0xFE && ((mchar[i+1]>=0x40 && mchar[i+1] <= 0x7E) ||
(mchar[i+1] >= 0xA1 && mchar[i+1] <= 0xFE)))
{ dest[i+1]=HIBYTE(bigTable[(mchar[i]-0xA1)*0xBF+mchar[i+1]-0x40]); dest[i]=LOBYTE(bigTable[(mchar[i]-0xA1)*0xBF+mchar[i+1]-0x40]); i++; } else { memcpy((dest+i),(mchar+i),1); } } } dest[i]='\0';}/****************************************************************** * FUNCTION: fnGUI_UnictoGb * * PURPOSE: * convert the code of unicode to gb2312 * * PARAMETERS * Input: mchar -- the string with unicode len -- the length of string
* Output: dest -- the string converted * InOut: * Return value: * Reentrant : No*****************************************************************/T_VOID fnGUI_Unic2Gb(T_UBYTE *dest,T_CONST T_UBYTE *mchar,T_UWORD len){ T_WORD i,m;
T_UHWORD str;
m=0;
for(i=0;i<(T_WORD)len*2;i+=2) {
if(mchar[i]==0 && mchar[i+1]==0)
break;
else {
str=0;
str =str| mchar[i+1]; //
str=str<<8;
str =str|mchar[i]; //
if(str< 0xFF)
{
dest[m]=(T_UBYTE)str;
m++;
}
else
{
dest[m+1]=HIBYTE(ugTable[str - 0x20]);
dest[m]=LOBYTE(ugTable[str - 0x20]); m +=2;
}
} } dest[m]='\0';}#endif#ifdef _ToUnic_SUPPORTT_EXTERN T_UHWORD guTable[];T_EXTERN T_UHWORD buTable[];/****************************************************************** * FUNCTION: fnGUI_Gb2Unic * * PURPOSE: * convert the code of gb2312 to unicode * * PARAMETERS * Input: mchar-- the string with GB2312 * Output:dest -- the string converted * InOut: * Return value: * Reentrant : No*****************************************************************/ T_VOID fnGUI_Gb2Unic(T_UBYTE *dest,T_CONST T_UBYTE *mchar) { T_WORD i,m; m=0;
for(i=0;i<(T_WORD)strlen(mchar);i++) { if(mchar[i]=='\0') break; else { if(mchar[i]>= 0xA1 && mchar[i] <= 0xFE
&& mchar[i+1] >= 0xA1 && mchar[i+1] <= 0xFE)
{
dest[m+1]=HIBYTE(guTable[(mchar[i] - 0xA1) * 94 + mchar[i+1] - 0xA1]); dest[m]=LOBYTE(guTable[(mchar[i] - 0xA1) * 94 + mchar[i+1] - 0xA1]);
i++;
}
else
{
memcpy((dest+m),(mchar+i),1); dest[m+1]=0;
}
m +=2;
} } dest[m]='\0'; }/****************************************************************** * FUNCTION: fnGUI_Big2Unic * * PURPOSE: * convert the code of big5 to unicode * * PARAMETERS * Input: mchar--the string with BIG5 * Output: dest -- the string converted * InOut: * Return value: * Reentrant : No*****************************************************************/ T_VOID fnGUI_Big2Unic(T_UBYTE *dest,T_CONST T_UBYTE *mchar) { T_WORD i,m; m=0;
for(i=0;i<(T_WORD)strlen(mchar);i++) { if(mchar[i]=='\0') break; else {
if(mchar[i]>= 0xA1 && mchar[i] <= 0xFE &&
((mchar[i+1]>=0x40 && mchar[i+1] <= 0x7E) ||
(mchar[i+1] >= 0xA1 && mchar[i+1] <= 0xFE)))
{ if(mchar [i+1] & 0x80) {
dest[m+1]=HIBYTE(buTable[89*63+(mchar [i] - 0xA1) * 94 + mchar [i+1] - 0xA1]); dest[m]=LOBYTE(buTable[89*63+(mchar [i] - 0xA1) * 94 + mchar [i+1] - 0xA1]);
}
else {
dest[m+1]=HIBYTE(buTable[(mchar [i] - 0xA1) * 63 + mchar [i+1] - 0x40]);
dest[m]=LOBYTE(buTable[(mchar [i] - 0xA1) * 63 + mchar [i+1] - 0x40]);
}
i++;
}
else
{ memcpy((dest+m),(mchar+i),1); dest[m+1]=0;
}
m +=2;
} } dest[m]='\0'; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -