⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 english_chinese_test.c

📁 某中文手写输入法公司的手写识别输入的实例源程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
		if(g_gbMMIGlobals.outputInfo.isShowIMWin)	{		if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_Pinyin)		{					if(g_gbMMIGlobals.outputInfo.syllableNum > 0)			{					for(i = 0; i < g_gbMMIGlobals.outputInfo.syllableNum; i++)				{																char putf_8[256];								if(i ==g_gbMMIGlobals.outputInfo.syllableIndex)												printf(" [");								else												printf("  ");								unicodeStr2utf8(g_gbMMIGlobals.outputInfo.syllables[i],putf_8,64);								printf("%s",putf_8);								if(i ==g_gbMMIGlobals.outputInfo.syllableIndex)												printf("] ");								else												printf("  ");				}			}					printf("\n");		}		else if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_Stroke 				|| g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_YinStroke//)				|| g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Korean)		{						unicodeStr2utf8(g_gbMMIGlobals.outputInfo.fullOutput,putf_8,64);						printf("%s ",putf_8);						//stroke			for(i = 0;i < g_gbMMIGlobals.outputInfo.strokeLen;i++)			{				if(g_gbMMIGlobals.outputInfo.stroke[i])				{					char putf_8[256];					memset(putf_8,0,sizeof(putf_8));					UnicodeToUTF_8(putf_8,&g_gbMMIGlobals.outputInfo.stroke[i]);					printf("%s ",putf_8);					//printf("%s ",g_gbMMIGlobals.outputInfo.stroke[i]);				}			}			//components			for(i = 0;i < g_gbMMIGlobals.outputInfo.componentsLen;i++)			{				if(g_gbMMIGlobals.outputInfo.components[i])				{					char putf_8[256];					memset(putf_8,0,sizeof(putf_8));					UnicodeToUTF_8(putf_8,&g_gbMMIGlobals.outputInfo.components[i]);					printf("%s ",putf_8);					//printf("%s ",g_gbMMIGlobals.outputInfo.components[i]);				}			}					printf("\n");		}		else if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_SmartLatin)		{				char putf_8[256];				unicodeStr2utf8(g_gbMMIGlobals.outputInfo.fullOutput,putf_8,64);				printf(" %s\n",putf_8);		}	}//	if(g_gbMMIGlobals.outputInfo.isShowIMWin && g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_Pinyin)//	{////		if(g_gbMMIGlobals.outputInfo.syllableNum > 0) //		{//			printf("current selected syllable item is \"%s\"\n",g_gbMMIGlobals.outputInfo.syllables[g_gbMMIGlobals.outputInfo.syllableIndex]);			//		}//	}	return rs;}void GBDrawCandidates(){	int i,ret;//	printf("候选栏: \r\n");	for(i = 0; i < g_gbMMIGlobals.outputInfo.candidatesNum; i++)	{					//显示候选索引下标					if(g_gbMMIGlobals.outputInfo.isSelectedCand)// && g_gbMMIGlobals.outputInfo.nInputMode != GBIM_Character)					{									//##sprintf(pOperation, "[%c]", INDEX_TO_NUM(i));									printf("%d", i+1);					}          else									printf(" ");					if(i ==g_gbMMIGlobals.outputInfo.candidateIndex)					{									printf("[");					}          else					{									printf(" ");					}					if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_Pinyin///< PinYin of chinese							|| g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_Stroke///< Stroke of chinese							|| g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Chn_YinStroke//)///< YinStroke(combination of PinYin and Stroke) of chinese						  || g_gbMMIGlobals.outputInfo.nInputMode == GBIM_Korean)					{									if(g_gbMMIGlobals.outputInfo.candidates[i] && g_gbMMIGlobals.outputInfo.candidates[i][0])									{													char putf_8[256];													unicodeStr2utf8(g_gbMMIGlobals.outputInfo.candidates[i],putf_8,64);													printf("%s",putf_8);									}					}					if(g_gbMMIGlobals.outputInfo.nInputMode ==GBIM_SmartLatin					||g_gbMMIGlobals.outputInfo.nInputMode ==GBIM_Character)					{									char putf_8[256];									unicodeStr2utf8(g_gbMMIGlobals.outputInfo.candidates[i],putf_8,64);									printf("%s",putf_8);					}					if(i ==g_gbMMIGlobals.outputInfo.candidateIndex)					{									printf("]  ");					}          else					{									printf("   ");					}          	}	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowLeftArrow)	{		printf("< ");			}  else  {		printf("  ");		  }	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowRightArrow)	{		//在实际手机平台中,这里应该加上绘制向右指示箭头的代码				printf(">");				}	  else	{		printf("");				}     if(g_gbMMIGlobals.outputInfo.otherInfo.isShowLeftArrow)		printf("←");	printf(" ");	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowRightArrow)		printf("→");	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowUpArrow)		printf("↑");	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowDownArrow)		printf("↓");	printf("\r\n");	printf("\n");//	if(g_gbMMIGlobals.outputInfo.candidatesNum)//	{//		printf("Current Selected Candidate Item is \"%s\"\n\n\n",g_gbMMIGlobals.outputInfo.candidates[g_gbMMIGlobals.outputInfo.candidateIndex]);//反显当前选择的候选项			//	}}//模拟getchint mygetch(){	int input;	while((input = getch()) ==27 || input ==91);//	printf("%d\n",input);	return input;	//###ifdef WIN32	//##    int input;	//##    if((input = getch()) == DIR_CHR || input == F_CHR)	//##    {	//##        return -getch();	//##    }	//##    return input;	//###else	//##    static char input[10] = "";	//##    static int i = 0;	//##    if(i >= strlen(input))	//##    {	//##        scanf("%10s", input);	//##        i = 1;	//##        return input[0];	//##    }	//##    else	//##    {	//##        return input[i++];	//##    }	//###endif}/* * 函数功能:选择输入法	 */int SelectIM(){	int input;	GBEvent event;	printf("Please Press 1 - 8 to Select a Chinese InputMode:\r\n" \			"\t[1] for Pinyin(拼音)\r\n" 			"\t[2] for Stroke(笔画)\r\n" 			"\t[3] for YinStroke(组合)\r\n" 			"\t[4] for SmartEnglish(智能英文)\r\n" 			"\t[5] for Character(字母)\r\n" 			"\t[6] for Number(数字)\r\n" 			"\t[7] for Korean(韩语)\r\n" 			"\t[8] for Quit\r\n");//	while(((input = mygetch()) < '1' || input > '7') && input != VK_ESCAPE);//	if(input == '7' || input == VK_ESCAPE)	while(((input = mygetch()) < '1' || input > '8') && input != VK_ESCAPE);	if(input == '8' || input == VK_ESCAPE)	{		return 0;	}	event.nType = GBET_In_ChgInputMode;	switch(input)	{		case '1':			event.param1 = GBIM_Chn_Pinyin;			event.param2 = GBL_Chinese;			break;		case '2':			event.param1 = GBIM_Chn_Stroke;					event.param2 = GBL_Chinese;			break;		case '3':			event.param1 = GBIM_Chn_YinStroke;					event.param2 = GBL_Chinese;			break;		case '4':			event.param1 = GBIM_SmartLatin;							event.param2 = GBL_English;			break;		case '5':			event.param1 = GBIM_Character;			event.param2 = GBL_English;			break;		case '6':			event.param1 = GBIM_Number;			event.param2 = GBL_NULL;			break;				case '7':			event.param1 = GBIM_Korean;			event.param2 = GBL_Chinese;			break;			}	/*	   各个输入法之间的切换可以通过GBET_In_ChgInputMode事件直接设置当前输入法	   实际开发中,使用*键切换输入法。	   切换输入法的条件是:keyValue == '*' && g_gbMMIGlobals.outputInfo.isShowIMWin == 1	 */	GBHandleInputEvent(&event);	return 1;}long GBGetStringWidth(const char * str_text){	return	(FONT_WIDTH / 2) * strlen((char*)str_text);}long GBGetWStringWidth(const unsigned short * str_text){	long len = (GBUINT16)gb_strlen((wchar_t*)str_text);	long str_width = 0;		const GBUINT16* ptravel =str_text;			while((long)(ptravel - str_text) < len)	{		if(0x80 < *ptravel)			str_width += FONT_WIDTH;		else			str_width += FONT_WIDTH / 2;		ptravel++;	}			return str_width;}void GBCombineString(){	if(g_gbMMIGlobals.outputInfo.isCanUpScreen == 1)	{		GBAddChar(g_gbMMIGlobals.outputInfo.upscreenStr,g_gbMMIGlobals.outputInfo.upscreenLen);//上屏	}}void GBAddChar(GBUINT16 * str,GBUINT16 len){   	if((historyISNLen + len) > ARRAY_DIM(historyISNs))	{		memmove(historyISNs, historyISNs + historyISNLen + len - ARRAY_DIM(historyISNs), 				(ARRAY_DIM(historyISNs) - len) * 2);		historyISNLen -= ((historyISNLen + len) - ARRAY_DIM(historyISNs));	}	memcpy(historyISNs + historyISNLen, str, 			len * sizeof(unsigned short));	historyISNLen += len;	}void ShowInputMethodInfo(enum __GBMMIInputMode inputMode){//int i;//  for(i =0;i <40;i++)//				printf("\n");								printf("─────────────────");					switch(inputMode)	{		case GBIM_Chn_Pinyin:			printf("拼音");			break;		case GBIM_Chn_Stroke:			printf("笔划");					break;		case GBIM_Chn_YinStroke:			printf("组合");							break;		case GBIM_SmartLatin:			printf("智能英文");							break;				case GBIM_Character:			printf("字母");							break;						case GBIM_Number:			printf("数字");							break;								case GBIM_Korean:			printf("韩语");							break;				default:			break;	}	printf("─────────────────");							printf("\n");				}void GBDrawCandPageArrow(){	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowUpArrow)	{		//在实际手机平台中,这里应该加上绘制上翻指示箭头的代码		if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_SmartLatin)			printf("按向上键切换上一个Header\n");		else			printf("按向上键向上翻页\n");			}	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowDownArrow)	{		//在实际手机平台中,这里应该加上绘制下翻指示箭头的代码				if(g_gbMMIGlobals.outputInfo.nInputMode == GBIM_SmartLatin)			printf("按向下键切换向一下Header\n");		else			printf("按向下键向下翻页\n");	}		if(g_gbMMIGlobals.outputInfo.otherInfo.isShowLeftArrow)	{		//在实际手机平台中,这里应该加上绘制向左指示箭头的代码				printf("按左键左移选择候选←↑→↓\n");			}	if(g_gbMMIGlobals.outputInfo.otherInfo.isShowRightArrow)	{		//在实际手机平台中,这里应该加上绘制向右指示箭头的代码				printf("按右键右移选择候选←↑→↓\n");				}	}void ShowInput(){#if 1	int ret = 0;	char buffer[1024];	memset(buffer,0,sizeof(buffer));#if 0 //!defined(EB_ENCODING) || EB_ENCODING == EB_ENCODING_UNICODE	ret = WideCharToMultiByte(CP_GB, 0, historyISNs, historyISNLen,			buffer, 199, NULL, NULL);#else	{		/*int i;		ret = 0;		for(i = 0; i < historyISNLen; i++)		{			strncpy(buffer + ret, (char *)(historyISNs + i), 2);			if(buffer[ret + 1] == 0)			{				ret++;			}			else			{				ret += 2;			}		}		*/		unicodeStr2utf8(historyISNs,buffer,historyISNLen);		}#endif	//buffer[ret] = 0;	printf("\n已经上屏的文本内容: \"%s\"\r\n", buffer);		#endif}void GBLoadSHData(){	/*	   以下是某个平台加载中英文自造词文件的方法,由于平台版本可能不同,仅供参考,	   由于版本不同,以用户的展迅平台版本来准#ifdef __GBSHDATA......	/*	加载中文自造词数据chn_name : 中文自造词文件名pChnSMData:中文自造词数据指针chn_size:中文自造词数组长度	 * /	 if(FFS_CheckExist(FS_UDISK,(const wchar*)chn_name))	 {		 fp_chn = FFS_fopen(FS_UDISK, (const wchar *)chn_name, "rb");	 if(PNULL != fp_chn)	 {	 ret = FFS_fread(FS_UDISK, (uint8 *)pChnSMData, 1, chn_size, fp_chn);				 if (ret == chn_size)	 {	 rs = TRUE;	 }	 }	 }	 else/ * 如果文件不存在则新建文件* /	 {	 fp_chn = FFS_fopen(FS_UDISK, (const wchar *)chn_name, "wb");	 if(PNULL != fp_chn)	 {	 ret = FFS_fwrite(FS_UDISK, (uint8 *)pChnSMData, 1, chn_size, fp_chn);					 if (ret == chn_size)	 {	 rs = TRUE;	 }			 }				 }	 FFS_fclose(FS_UDISK, fp_chn);	 / *	 加载英文自造词数据en_name : 英文自造词文件名pEnSMData:英文自造词数据指针en_size:英文自造词数组长度	 * /	 * /	 if(FFS_CheckExist(FS_UDISK,(const wchar*)en_name))	 {		 fp_en = FFS_fopen(FS_UDISK, (const wchar *)en_name, "rb");	 if(PNULL != fp_en)	 {	 ret = FFS_fread(FS_UDISK, pEnSMData, 1, en_size, fp_en);				 if (ret == en_size)	 {	 rs = TRUE;	 }	 }	 }	 else/ *如果文件不存在则新建文件* /	 {	 fp_en = FFS_fopen(FS_UDISK, (const wchar *)en_name, "wb");	 if(PNULL != fp_en)	 {	 ret = FFS_fwrite(FS_UDISK, pEnSMData, 1, en_size, fp_en);					 if (ret == en_size)	 {	 rs = TRUE;	 }			 }				 }	 FFS_fclose(FS_UDISK, fp_en);	 ......#endif	 */}void GBSaveSHData(){	/*	   以下是某个平台保存中英文自造词文件的方法,由于平台版本可能不同,仅供参考,	   由于版本不同,以用户的平台版本来准#ifdef __GBSHDATA/ *保存中文自造词数据chn_name : 中文自造词文件名pChnSMData:中文自造词数据指针chn_size:中文自造词数组长度	 * /	 fp_chn = FFS_fopen(FS_UDISK, (const wchar *)chn_name, "wb");	 if (PNULL != fp_chn)	 {		 ret = FFS_fwrite(FS_UDISK, (uint8 *)pChnSMData, 1, chn_size, fp_chn);	 if (ret != (SIZE_T)chn_size)	 {	 FFS_fclose(FS_UDISK, fp_chn);	 FFS_Delete(FS_UDISK, (const wchar *)chn_name);					 return rs;	 }			 rs = TRUE;	 }	 else	 {	 fp_chn = FFS_fopen(FS_UDISK, (const wchar *)chn_name, "wb");	 if(PNULL != fp_chn)	 {	 ret = FFS_fwrite(FS_UDISK, (uint8 *)pChnSMData, 1, chn_size, fp_chn);					 if(ret == chn_size)	 {	 rs = TRUE;	 }	 }			 }	 FFS_fclose(FS_UDISK, fp_chn);	 / *	 保存英文自造词数据en_name : 英文自造词文件名pEnSMData:英文自造词数据指针en_size:英文自造词数组长度	 * /	 fp_en = FFS_fopen(FS_UDISK, (const wchar *)en_name, "wb");	 if (PNULL != fp_en)	 {		 ret = FFS_fwrite(FS_UDISK, (uint8 *)pEnSMData, 1, en_size, fp_en);	 if (ret != (SIZE_T)en_size)	 {	 FFS_fclose(FS_UDISK, fp_en);	 FFS_Delete(FS_UDISK, (const wchar *)en_name);					 return rs;	 }			 rs = TRUE;	 }	 else	 {	 fp_en = FFS_fopen(FS_UDISK, (const wchar *)en_name, "wb");	 if(PNULL != fp_en)	 {	 ret = FFS_fwrite(FS_UDISK, (uint8 *)pEnSMData, 1, en_size, fp_en);					 if(ret == en_size)	 {	 rs = TRUE;	 }	 }			 }	 FFS_fclose(FS_UDISK, fp_en);#endif		return (rs);*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -