#include "IME.h"
const char graph_bar_imed[] = {0xFF,0xFF,0xE0,0x17,0x4E,0xE0,0xB2,0x5E,0xE0,0xB5,0x4E,0xE0,
0xB5,0x5A,0xA0,0xB7,0x5C,0x40,0x17,0x4E,0x80,0xFF,0xFF,0x0,};
char GetCharAlpha(int key)
{
switch (key)
{
case KEY_CTRL_XTT: return 'a';
case KEY_CHAR_LOG: return 'b';
case KEY_CHAR_LN: return 'c';
case KEY_CHAR_SIN: return 'd';
case KEY_CHAR_COS: return 'e';
case KEY_CHAR_TAN: return 'f';
case KEY_CHAR_FRAC: return 'g';
case KEY_CTRL_FD: return 'h';
case KEY_CHAR_LPAR: return 'i';
case KEY_CHAR_RPAR: return 'j';
case KEY_CHAR_COMMA: return 'k';
case KEY_CHAR_STORE: return 'l';
case KEY_CHAR_7: return 'm';
case KEY_CHAR_8: return 'n';
case KEY_CHAR_9: return 'o';
case KEY_CHAR_4: return 'p';
case KEY_CHAR_5: return 'q';
case KEY_CHAR_6: return 'r';
case KEY_CHAR_MULT: return 's';
case KEY_CHAR_DIV: return 't';
case KEY_CHAR_1: return 'u';
case KEY_CHAR_2: return 'v';
case KEY_CHAR_3: return 'w';
case KEY_CHAR_PLUS: return 'x';
case KEY_CHAR_MINUS: return 'y';
case KEY_CHAR_0: return 'z';
default: return 0;
}
}
int read_pinyin(char * pin)
{
unsigned char * b, * buf = 0;
FONTCHARACTER fontc[50];
int handle;
short size;
unsigned char * p;
CharToFont("\\\\fls0\\PINYIN.db", fontc);
handle = Bfile_OpenFile(fontc, _OPENMODE_READ);
size = Bfile_GetFileSize(handle);
b = (char*) malloc(size + 1);
Bfile_ReadFile(handle, b, size, 0);
memset(py, 0, 200);
buf = strstr(b, pin);
if (buf == 0)
{
free(b);
Bfile_CloseFile(handle);
return 0;
}
while (!(*(buf - 1) & 0x80))
{
buf = strstr(buf + 1, pin);
if (buf == 0)
{
free(b);
Bfile_CloseFile(handle);
return 0;
}
}
while (!((*++buf) & 0x80));
p = py;
while ((*buf) & 0x80)
*p++ = *buf++;
*p = 0;
free(b);
Bfile_CloseFile(handle);
}
void PinyinFace(char * p_srcbuf, int * p_p)
{
char sTmp[50], sInputBuf[50] = "";
int iTmpLen;
int iPYPage, key, i;
while (1) {
AreaClr(0, 0, 127, 55);
PrintChStr(p_srcbuf, 0, 0);
AreaClr(2, 26, 124, 52);
AreaClr(1, 56, 20, 63);
DrawPic(1, 56, 19, 8, graph_bar_imed);
PrintMini(5, 28, sInputBuf, 0);
if (*py)
for (i = 0; ; i += 2)
{
iTmpLen = (float) i / 2;
sprintf(sTmp, "%d.", iTmpLen + 1);
PrintMini(5 + 23 * iTmpLen, 42, sTmp, 0);
iTmpLen = 13 + 23 * ((float) i / 2);
PrintChChar(py[i + iPYPage * 10], py[i + iPYPage * 10 + 1], iTmpLen, 39);
if ((py[i + iPYPage * 10 + 1] == 0) || i >= 8) break;
}
GetKey(&key);
if (key == KEY_CTRL_F1)
{memset(py, 0, 200);
break;}
else if (key == KEY_CTRL_EXIT)
{
memset(py, 0, 200);
memset(sInputBuf, 0, 50);
}
else if (key == KEY_CTRL_EXE)
{
iPYPage = 0;
read_pinyin(sInputBuf);
}
else if (key == KEY_CTRL_DEL)
{
if (*sInputBuf)
sInputBuf[strlen(sInputBuf) - 1] = 0;
}
else if (key == KEY_CTRL_RIGHT && (iPYPage + 1) * 10 < strlen(py))
++iPYPage;
else if (key == KEY_CTRL_LEFT && iPYPage > 0)
--iPYPage;
else
{
if (*py) {
if ((key >= 0x31) && (key <= 0x35) && py[iPYPage * 10 + (key - 0x31) * 2])
{
p_srcbuf[++(*p_p)] = py[iPYPage * 10 + (key - 0x31) * 2];
p_srcbuf[++(*p_p)] = py[iPYPage * 10 + (key - 0x31) * 2 + 1];
memset(sInputBuf, 0, 50);
}
}
else {
if (GetCharAlpha(key))
sInputBuf[strlen(sInputBuf)] = GetCharAlpha(key);
}
}
}
}