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

📄 afce_zi.c

📁 用于嵌入式系统的输入法程序 里面有完整的系统实现原码
💻 C
📖 第 1 页 / 共 5 页
字号:
        {
            /* dump candidates buffer */
        	/*utStrcpyUcs2(&chiContext_p->currentHzInfo.currentSelHz[i],&zi8param.pCandidates[i]);*/
        	chiContext_p->currentHzGroupInfo.currentSelHz[i]= (AgCharCode)zi8param.pCandidates[i];
        }
        /*turn back the elementbuffer*/
        zi8param.ElementCount = 0;
        chiContext_p->currentHzGroupInfo.beginHzInLib = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.currentHzIndex = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.endHzInLib = 
            chiContext_p->currentHzGroupInfo.beginHzInLib + zi8param.count -1;
        
    }      
    return(retVal);
}


/******************************************************************************
*   function:     afGetAssociation
*   Description:  get the hanzi information for user-input-value
******************************************************************************/
/*根据当前的字取出一组联想*/
static Boolean afGetAssociation(chiEditContext  *chiContext_p)
{ 
    Boolean retVal = FALSE;
    Int8 i = 0;
    
    memset (&elementBuffer[0], '\0', sizeof(elementBuffer));    

    zi8param.ElementCount=0;
    zi8param.count=0;    
    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;/*第一个*/
    zi8param.WordCharacterCount=1;	
	
    /*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++ )
        {
            /* dump candidates buffer */
        	/*utStrcpyUcs2(&chiContext_p->currentHzInfo.currentSelHz[i],&zi8param.pCandidates[i]);*/
        	chiContext_p->currentHzGroupInfo.currentSelHz[i]= (AgCharCode)zi8param.pCandidates[i];
        }
        /*turn back the elementbuffer*/
        zi8param.ElementCount = 0;
        chiContext_p->currentHzGroupInfo.beginHzInLib = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.currentHzIndex = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.endHzInLib = 
            chiContext_p->currentHzGroupInfo.beginHzInLib + zi8param.count -1;        
    }
    else
    { /*if can not find a word unload chineseInputHandler*/
       /*clear the element buffer*/
       /*取不到联想的情况现在不会出现的,因为如果没有联想字就会自动取一些常用字来代替*/
       elementBuffer[0] = 0;
       zi8param.ElementCount = 0;
      #if 0
       
       hzExitDataBody.handlerIsUnloaded = TRUE;
       hzExitDataBody.inputChineseFlag = TRUE;
       afglSendHandlerExitSig(chiContext_p->myHandlerId,
                              chiContext_p->parentHandlerId,
                              sizeof(AfHzExitDataBody),
                              &hzExitDataBody);
       afshUnloadHandler(chiContext_p->myHandlerId);
      #endif
      
       
    }      
    return(retVal);
}




/******************************************************************************
*   function:     afGetBhHzInfo
*   Description:  get the 8 bihua and hanzi information for user-input-value
******************************************************************************/
Boolean afGetBhHzInfo(chiEditContext  *chiContext_p)
{
    int 		 	  i;
    Boolean        retVal = TRUE;
    
    /*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 bihua*/
    memset (&elementBuffer[0], '\0', sizeof(elementBuffer));    
    
    
    zi8param.ElementCount = 0;
    zi8param.count = 0;
    zi8param.FirstCandidate = 0;  
    zi8param.Language = ZI8_LANG_ZH;
    zi8param.SubLanguage = ZI8_SUBLANG_ZH;
    zi8param.GetMode = ZI8_GETMODE_STROKES;
    zi8param.Context = ZI8_GETCONTEXT_SMS;
    zi8param.GetOptions = ZI8_GETOPTION_NOCOMPONENTS; 
    zi8param.MaxCandidates=MAX_HZ_PAGE_SIZE  ;
    zi8param.FirstCandidate = chiContext_p->currentHzGroupInfo.pageNo*8;/*第一个*/
    
    afConvertWmToBh(chiContext_p);
    Zi8GetCandidates( &zi8param );
    if( zi8param.count != 0)
    {
        /* AFCE_ZI004*/
        memset(chiContext_p->currentHzGroupInfo.currentSelHz,'\0',
             sizeof(chiContext_p->currentHzGroupInfo.currentSelHz));
             
        /*display the input stroke*/
        STRCPY(chiContext_p->currentPyBsh,elementBuffer);
        if (STRLEN(chiContext_p->currentPyBsh)>8)/*如果笔顺的长度大于8,就显示后8个*/
        {
        	AgCharCode tempBhString[9]= {0};
        	Int8   extendLen = STRLEN(chiContext_p->currentPyBsh)-8;
        	STRCPY(tempBhString,&chiContext_p->currentPyBsh[extendLen]);
        	STRCPY(chiContext_p->currentPyBsh,tempBhString);
        	chiContext_p->currentPyBsh[8] = '\0';
        }
        /*get the hz*/        
        for ( i = 0; i < zi8param.count; i++ )
        { /* dump candidates buffer */
      	/*utStrcpyUcs2(&chiContext_p->currentHzInfo.currentSelHz[i],&zi8param.pCandidates[i]);*/
      	    chiContext_p->currentHzGroupInfo.currentSelHz[i] = zi8param.pCandidates[i];
        }
        chiContext_p->currentHzGroupInfo.currentSelHz[zi8param.count]=0;
        /*turn back the elementbuffer*/
        zi8param.ElementCount = 0;        
        chiContext_p->currentHzGroupInfo.beginHzInLib = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.currentHzIndex = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.endHzInLib = 
            chiContext_p->currentHzGroupInfo.beginHzInLib + zi8param.count -1;
    }
    else if (zi8param.count ==0)
    { 
        retVal = FALSE;        
    }     
    return(retVal);
}

/******************************************************************************
*   function:     afGetStrokeHzInfo
*   Description:  get the component and hanzi information for user-input-value
******************************************************************************/
Boolean afGetStrokeHzInfo(chiEditContext  *chiContext_p)
{
    int 		 	  i;
    Boolean        retVal = TRUE;
    /*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 bihua*/
    
    /*decide if the selected stroke is a component*/
    if(Zi8IsComponent( elementBuffer[0]))
    {
        zi8param.ElementCount = 1;
    }
    else
    {
        memset (&elementBuffer[0], '\0', sizeof(elementBuffer));
        zi8param.ElementCount = 0;
    }
    zi8param.count = 0;
    zi8param.FirstCandidate = chiContext_p->currentHzGroupInfo.pageNo*8;/*第一个*/    
    
    zi8param.GetMode = ZI8_GETMODE_STROKES;  
    zi8param.Language = ZI8_LANG_ZH;
    zi8param.SubLanguage = ZI8_SUBLANG_ZH;
    zi8param.GetOptions =ZI8_GETOPTION_ALLCOMPONENTS ;
    zi8param.MaxCandidates=MAX_CANDIDATES_BUFFER_SIZE  ;
    
    afConvertWmToBh(chiContext_p);
    Zi8GetCandidates( &zi8param );
    if( zi8param.count  != 0)
    {/* AFCE_ZI004*/
        memset(chiContext_p->currentHzGroupInfo.currentSelHz,'\0',
             sizeof(chiContext_p->currentHzGroupInfo.currentSelHz));
        /*display the input stroke*/
        STRCPY(chiContext_p->currentPyBsh,elementBuffer);
       /*get the hz*/  
        for ( i = 0; i < zi8param.count; i++ )
        { /* dump candidates buffer */
      	    /*utStrcpyUcs2(&chiContext_p->currentHzInfo.currentSelHz[i],&zi8param.pCandidates[i]);*/
      	    chiContext_p->currentHzGroupInfo.currentSelHz[i] = zi8param.pCandidates[i];
        }
        chiContext_p->currentHzGroupInfo.currentSelHz[zi8param.count]=0;
        chiContext_p->currentHzGroupInfo.beginHzInLib = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.currentHzIndex = zi8param.FirstCandidate;
        chiContext_p->currentHzGroupInfo.endHzInLib = 
            chiContext_p->currentHzGroupInfo.beginHzInLib + zi8param.count -1;
    }  
    else if (zi8param.count ==0)
    {
        retVal = FALSE;
        //afClearInput(chiContext_p);
        chiContext_p->inputValue[--(chiContext_p->inputSerial)]='\0';
    }     
    return(retVal);
}

/******************************************************************************
*   function:     afGetSmartEnInfo
*   Description:  get the smart English information for user-input-value
******************************************************************************/
Boolean afGetSmartEnGroup(chiEditContext  *chiContext_p)
{
    Int8  key;
  
    int 		 	i = 0;
    int             j = 0;
    int             k = 0;
    Boolean         retVal = FALSE;
    Int16           firstSECandidateIndex = 0;
    AgCharCode      tempCharCode[32];     
    
    /*要取拼音组的第一个是库里的第几个需要计算一下,因为一行拼音的显示数目是动态变化的*/
    for(i=0; i<chiContext_p->pyOrSEcurrentPageNo;i++)
    {
        firstSECandidateIndex += 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 = firstSECandidateIndex;
    zi8param.Language = ZI8_LANG_EN;
    zi8param.GetMode = ZI8_GETMODE_DEFAULT;
    zi8param.SubLanguage = ZI8_SUBLANG_EN_ALL;
    zi8param.GetOptions = ZI8_GETOPTION_DEFAULT;
    zi8param.MaxCandidates = MAX_PY_PAGE_SIZE+1;/*最大值比可以显示的多取一个,来判断是否还有下一页*/
     /*将输入的按键转换为ZI需要的值*/
    afConvertWmToEn(chiContext_p);
    Zi8GetCandidates( &zi8param );
 /* AFCE_ZI006*/
    if (zi8param.count == 1 && candidatesBuffer[0] == 0xfff0 && (strlen(chiContext_p->inputValue) == 1))
    {
			zi8param.FirstCandidate = 1;
			Zi8GetCandidates( &zi8param );
    }
 /*这里要改为每一页显示的拼音数根据拼音的大小动态调整。如果拼音都比较短,则可以显示5个,如果都很长,可能只显示3个*/
 /*一次最多取出6个,放在BUFFER里面,然后计算宽度,将超过的舍去*/ 
    if( zi8param.count != 0)
    { 
        /* AFCE_ZI004*/
        memset (&chiContext_p->currentPyOrSEGroupInfo, '\0', sizeof(chiContext_p->currentPyOrSEGroupInfo));
        memset (&chiContext_p->currentPyBsh, '\0', sizeof(chiContext_p->currentPyBsh));   
   
        retVal = TRUE;
        /*现在将所有的SE全都放入cwordData里面来*/
        while (j<=zi8param.count-1)
        {            
            Zi8GetAlphaWordW(ZI8_LANG_EN, zi8param.pCandidates[j],
                            chiContext_p->currentPyOrSEGroupInfo.groupData[j],32);            
            j++;
            
        } 
         /*将拼音组信息COPY到currentPyBsh里面,用来显示*/    
        for (j = 0;j < zi8param.count; j++)
        {
            utStrcpyUcs2(tempCharCode, chiContext_p->currentPyOrSEGroupInfo.groupData[j]);
            if ((STRLEN(tempCharCode)+STRLEN(chiContext_p->currentPyBsh))< sizeof(chiContext_p->currentPyBsh)/2)
            {
            STRCAT(chiContext_p->currentPyBsh,tempCharCode);   
            }
            chiContext_p->currentPyBsh[STRLEN(chiContext_p->currentPyBsh)] = 0x20;
        }
        chiContext_p->currentPyBsh[STRLEN(chiContext_p->currentPyBsh)] = '\0'; 
         /*计算cwordData显示在屏幕上的话会有多长,将chiContext_p->currentPyBsh
         后面的截取掉,然后返回一个可取的COUNT*/
        zi8param.count = maxPyCountInThisPage(chiContext_p);
        
        
         /*取得拼音区的位置信息,由于是新取一组拼音,所以firstPyPosInLib=currentPyPosInLib*/
        chiContext_p->currentPyOrSEGroupInfo.firstPosInLib = firstSECandidateIndex;
        chiContext_p->currentPyOrSEGroupInfo.currentPosInLib = firstSECandidateIndex;
        chiContext_p->currentPyOrSEGroupInfo.lastPosInLib =  firstSECandidateIndex + 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;  
}









⌨️ 快捷键说明

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