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

📄 afce_zi.c

📁 用于嵌入式系统的输入法程序 里面有完整的系统实现原码
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (chiContext_p->chineseInputMethod==AG_PINYIN_INPUT_METHOD)
            {
                if ((AgCharCode)eventInd_p->event < '2')
                {                    
                    keyValid = FALSE;
                }
                else
                {
                afInitContext(chiContext_p);
                chiContext_p->imeState = IME_STATE_PY_INPUT;
                }
                
            }
            else if (chiContext_p->chineseInputMethod==AG_BISHUN_INPUT_METHOD)
            {
               if ((AgCharCode)eventInd_p->event < '1'||(AgCharCode)eventInd_p->event == '6')
               {
               	   keyValid = FALSE;
               }
               else
               {
                afInitContext(chiContext_p);
                chiContext_p->imeState = IME_STATE_BISHUN_INPUT;
               }		             
            }		             
            else if (chiContext_p->chineseInputMethod==AG_COMPONENT_INPUT_METHOD)
            {
            
                if ((AgCharCode)eventInd_p->event < '1')
                {                    
                    keyValid = FALSE;
                }
                else
                {
                afInitContext(chiContext_p);
                chiContext_p->imeState = IME_STATE_COMPONENT_INPUT;
                }
            }
    }
    
    
    
    switch (chiContext_p->imeState)
    {  
    	 case IME_STATE_PY_INPUT: /*正在输入拼音*/
            /*拼音下输入0或1无效,并且拼音不可能超过6个。zhuang最多6个*/
            if ((AgCharCode)eventInd_p->event < '2'||chiContext_p->inputSerial>=6)
            {
                keyValid = FALSE;
            }
            else
            {
                /*将拼音的当前页保存在这里,如果输入有效,则取新的一组拼音,当前页为0,否则,还要返回当前页*/
                Int8 savedPyOrSEcurrentPageNo =  chiContext_p->pyOrSEcurrentPageNo;
                /*将输入的内容保存在inputValue中*/
                chiContext_p->inputValue[chiContext_p->inputSerial++] = (AgCharCode)eventInd_p->event;                
                /*根据输入的内容取一组拼音*/                   
                chiContext_p->pyOrSEcurrentPageNo = 0;                
                keyValid = afGetPyGroup(chiContext_p);
                if (keyValid == TRUE)
                {
                     /*根据第一个拼音,取汉字*/
                    chiContext_p->currentPyOrSEGroupInfo.currentPosInLib = 0;       
                    memset(&chiContext_p->currentHzGroupInfo,'\0',
                       sizeof(chiContext_p->currentHzGroupInfo));
                    afGetPyHzGroup(chiContext_p);
                }
                else
                {
                    chiContext_p->pyOrSEcurrentPageNo =  savedPyOrSEcurrentPageNo;
                    chiContext_p->inputValue[--(chiContext_p->inputSerial)]='\0';
                     /* AFCE_ZI004*/
                    // afGetPyGroup(chiContext_p);
                    //afGetPyHzGroup(chiContext_p);
                }

            }
            break;

        case IME_STATE_BISHUN_INPUT: /*正在输入笔顺*/
    	    /*笔顺下输入0无效,并且笔顺不可能超过30个,第一个6键无用*/
            if ((AgCharCode)eventInd_p->event < '1'||chiContext_p->inputSerial>=22||
                ((AgCharCode)eventInd_p->event == '6'&&chiContext_p->inputSerial == 0))
            {
                keyValid = FALSE;
            }
            else        	    
            {
                Int8 savedHzPageNo =  chiContext_p->currentHzGroupInfo.pageNo;
                chiContext_p->inputValue[chiContext_p->inputSerial++] = (AgCharCode)eventInd_p->event;                
                /*在输入取值的时候,将pageNo置为0,如果取值无效,再置回来*/
                chiContext_p->currentHzGroupInfo.pageNo = 0;
                keyValid = afGetBhHzInfo(chiContext_p);
                if (keyValid == FALSE)/*如果输入无效,chiContext_p->currentHzGroupInfo内容为0,重新取值*/
                {
                	chiContext_p->inputValue[--(chiContext_p->inputSerial)] = '\0';
                	chiContext_p->currentHzGroupInfo.pageNo = savedHzPageNo;                	
                	//afGetBhHzInfo(chiContext_p);
                }
                
            }
            break;
   	     
   	     case IME_STATE_COMPONENT_INPUT: /*正在输入部件*/
    	    /*部件下输入0无效,并且笔顺不可能超过30个。*/
    	    if ((AgCharCode)eventInd_p->event < '1'||chiContext_p->inputSerial>=30)
    	    {
    	    	keyValid = FALSE;
    	    }
    	    else        	    
    	    {   		     
   	         /*部件*/
   	            Int8 savedHzPageNo =  chiContext_p->currentHzGroupInfo.pageNo;
   	            chiContext_p->inputValue[chiContext_p->inputSerial++] = (AgCharCode)eventInd_p->event;
                chiContext_p->currentHzGroupInfo.pageNo = 0;
                keyValid = afGetStrokeHzInfo(chiContext_p);
                if (keyValid == FALSE)/*如果输入无效,chiContext_p->currentHzGroupInfo内容为0,重新取值*/
                {
                	chiContext_p->inputValue[--(chiContext_p->inputSerial)] = '\0';
                	chiContext_p->currentHzGroupInfo.pageNo = savedHzPageNo;                	
                }
   	        }
   	        break; 
   	        
        case IME_STATE_SE_INPUT: /*正在输入SE*/
            /*SE下输入0无效,并且笔顺不可能超过30个。*/
            /*AFCE_ZI001*/
            if ((AgCharCode)eventInd_p->event < '1'||chiContext_p->inputSerial>=30)
            {
            	keyValid = FALSE;
            }            
            else        	    
            {
                /*将拼音的当前页保存在这里,如果输入有效,则取新的一组拼音,当前页为0,否则,还要返回当前页*/
                Int8 savedPyOrSEcurrentPageNo =  chiContext_p->pyOrSEcurrentPageNo;
                /*将输入的内容保存在inputValue中*/
                chiContext_p->inputValue[chiContext_p->inputSerial++] = (AgCharCode)eventInd_p->event;                
                /*根据输入的内容取一组拼音*/                   
                chiContext_p->pyOrSEcurrentPageNo = 0;                
                keyValid = afGetSmartEnGroup(chiContext_p);                
                if (keyValid == FALSE)
                {
                    chiContext_p->pyOrSEcurrentPageNo =  savedPyOrSEcurrentPageNo;
                    chiContext_p->inputValue[--(chiContext_p->inputSerial)]='\0';
                    /* AFCE_ZI004*/
                    //afGetSmartEnGroup(chiContext_p);
                }

            }
            break;
	
	    
        default:
            keyValid = FALSE;		      
            break;  
    }
    
    if (keyValid == FALSE)/*如果按键无效,则保存非法按键表 AFCE_ZI001*/
    {
    	  chiContext_p->invalidSEkeyTable[eventInd_p->event-'0'] = eventInd_p->event;
    } 
    else/*如果输入有效,取得新的一组内容,非法按键表清空*/
    {    	
    	 for (i=0; i<10; i++)
    	 {
             chiContext_p->invalidSEkeyTable[i] = 0;
         }
            
    }          
               
               
               
               
              
               
               
   	 /*记录KEYVALID决定是否刷新*/
    chiContext_p->keyValid = keyValid;
   	return keyValid;
}

/*根据输入,取出一组拼音*/
static Boolean afGetPyGroup(chiEditContext  *chiContext_p)
{
    
    int 		 	i = 0;
    int             j = 0;
    int             k = 0;
    Boolean         retVal = FALSE;
    Int16           firstPyCandidateIndex = 0;
    AgCharCode      tempCharCode[10];

    /*要取拼音组的第一个是库里的第几个需要计算一下,因为一行拼音的显示数目是动态变化的*/
    for(i=0; i< chiContext_p->pyOrSEcurrentPageNo;i++)
    {
        firstPyCandidateIndex += chiContext_p->pyOrSEgroupNumTable[i];
        
    }
    /*clear the candidatesBuffer*/
    memset (&candidatesBuffer[0], '\0', sizeof(candidatesBuffer));
    /*clear the value of Selected Word buffer*/
    memset (&wordBuffer[0],'\0',sizeof(wordBuffer));
    /*using eZiText Core Library, get the corresponding pinyin*/
    /*clear the elementBuffer*/
    memset (&elementBuffer[0], '\0', sizeof(elementBuffer));




    zi8param.ElementCount = 0;
    zi8param.count = 0;
    zi8param.FirstCandidate = firstPyCandidateIndex;
    zi8param.Language = ZI8_LANG_ZH;
    zi8param.GetMode = ZI8_GETMODE_1KEYPRESS_PINYIN;
    zi8param.SubLanguage = ZI8_SUBLANG_ZH;
    zi8param.GetOptions = ZI8_GETOPTION_GET_SPELLING;
    zi8param.MaxCandidates = MAX_PY_PAGE_SIZE+1;/*最大值比可以显示的多取一个,来判断是否还有下一页*/
    /*将输入的按键转换为ZI需要的值*/
    afConvertWmToPy(chiContext_p);/*zi8param.ElementCount的值另外计算了*/
    Zi8GetCandidates( &zi8param );


 /*这里要改为每一页显示的拼音数根据拼音的大小动态调整。如果拼音都比较短,则可以显示5个,如果都很长,可能只显示3个*/
 /*一次最多取出6个,放在BUFFER里面,然后计算宽度,将超过的舍去*/ 
    if( zi8param.count != 0)
    { 
        retVal = TRUE;
        /* AFCE_ZI004*/
        memset (&chiContext_p->currentPyOrSEGroupInfo.groupData, '\0',
             sizeof(chiContext_p->currentPyOrSEGroupInfo.groupData));
        
        
        /*现在将所有的拼音全都放入cwordData里面来*/
        memset (&chiContext_p->currentPyBsh, '\0', sizeof(chiContext_p->currentPyBsh));
        i = 0;
        while (j<=zi8param.count-1)
        {
            /*每个拼音取完了,都会取到零,这时加一个空格,并且将拼音数目的计数器加1*/
            if (zi8param.pCandidates[i]==0)
            {
               chiContext_p->currentPyOrSEGroupInfo.groupData[j][k] = 0x20;
               j++;
               k = 0;
            }
            else/*否则就将取出的内容转换为小写字母保存起来*/
            {
                chiContext_p->currentPyOrSEGroupInfo.groupData[j][k] = zi8param.pCandidates[i] - ZI8_BASE_PINYIN+0x61;
                k++;
            }
            i++;
        }
 
         /*将拼音组信息COPY到currentPyBsh里面,用来显示*/    
        for (j = 0;j < zi8param.count; j++)
        {
            utStrcpyUcs2(tempCharCode, chiContext_p->currentPyOrSEGroupInfo.groupData[j]);/*AFCE_ZI006*/
            STRCAT(chiContext_p->currentPyBsh,tempCharCode);     	
        }
         
         /*计算cwordData显示在屏幕上的话会有多长,将chiContext_p->currentPyBsh
         后面的截取掉,然后返回一个可取的COUNT*/
        zi8param.count = maxPyCountInThisPage(chiContext_p);
        
        
         /*取得拼音区的位置信息*/
        chiContext_p->currentPyOrSEGroupInfo.firstPosInLib = firstPyCandidateIndex;
        chiContext_p->currentPyOrSEGroupInfo.lastPosInLib =  firstPyCandidateIndex + zi8param.count -1;
        /*记录一下当前页中有几个拼音*/    
        chiContext_p->pyOrSEgroupNumTable[chiContext_p->pyOrSEcurrentPageNo] = zi8param.count;
    }
    else //if (zi8param.count =='\0')
    {
        retVal = FALSE;
        //afClearInput(chiContext_p);
       // chiContext_p->inputValue[--(chiContext_p->inputSerial)]='\0';
    }
    return retVal;
}

/******************************************************************************
*   function:     afGetPyHzGroup
*   Description:  get the hanzi information for user-input-value
******************************************************************************/
/*根据当前的拼音,取出一组汉字*/
static Boolean afGetPyHzGroup(chiEditContext  *chiContext_p)
{
    Boolean retVal = FALSE;
    Int8 i = 0;
    /*当前取的拼音是这一页中的第几个,从0开始计数*/
    Int8 currentPyIndex = chiContext_p->currentPyOrSEGroupInfo.currentPosInLib - \
                              chiContext_p->currentPyOrSEGroupInfo.firstPosInLib ;
   
    /*根据当前一组拼音信息,取得需要取汉字的ZI数据elementBuffer*/
    while (chiContext_p->currentPyOrSEGroupInfo.groupData[currentPyIndex][i]!=0x20)
    {
   	    elementBuffer[i] = \
           (ZI8_BASE_PINYIN + chiContext_p->currentPyOrSEGroupInfo.groupData[currentPyIndex][i]- 'a');
        i++;
    }
    elementBuffer[i] = ZI8_CODE_PINYIN_SEPARATOR;/*在拼音的后面要加一个标志*/
   
    /*我们来取汉字*/
    zi8param.ElementCount = i;
    zi8param.Language = ZI8_LANG_ZH;
    zi8param.GetMode = ZI8_GETMODE_PINYIN;
    zi8param.SubLanguage = ZI8_SUBLANG_ZH;
    zi8param.GetOptions = ZI8_GETOPTION_DEFAULT;
    zi8param.MaxCandidates = MAX_HZ_PAGE_SIZE  ;/*8*/    
    zi8param.FirstCandidate = chiContext_p->currentHzGroupInfo.pageNo*8;/*第一个*/

    /*Zi8SetMaxNamesInUse(200);*/
    Zi8GetCandidates( &zi8param );
    if (zi8param.count != 0)
    {
        retVal = TRUE;
        memset(chiContext_p->currentHzGroupInfo.currentSelHz,'\0',
           sizeof(chiContext_p->currentHzGroupInfo.currentSelHz));
    
        /*将和这个拼音对应的当前页的汉字放到currentHzInfo.currentSelHz里面,来显示*/
        for ( i = 0; i < zi8param.count; i++ )

⌨️ 快捷键说明

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