资源描述:
《构建GB2312汉字库的unicode码表》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、构建GB2312汉字库的unicode码表作者:乾坤一笑下载源代码 构建GB2312汉字库的unicode码表嵌入式系统总离不了处理汉字。一般汉字的处理方法是(以手机接受短信为例):比如你收到了一封短信,该短信解码后是按照UTF-16表示的,那么我们需要根据每一个汉字的unicode码找到它在GB2312库中的位置,然后再用对应的点阵数据在屏幕上显示出来。 于是乎,必须有一种手段将unicode码和汉字字模的数据对应起来。最常用的手段是做一个unicode码表,在该数组中查找到匹配的unicode码后,用匹配的index(数组索引)值在另外一个由该index值对
2、应的字模记录的数组中的数据去显示。+-----------------+查表+-----------------+同index+-------------------+
3、汉字的unicode码
4、==>
5、unicode码表数组
6、=======>
7、汉字字模数据数组
8、==>显示输出+-----------------++-----------------++-------------------+本文简要介绍一下如何生成unicode码表,其它相关的汉字处理技术不在本文的讨论范围之内。:)用下面两个函数可以把unicode码表构造出来(*注1):voidUnicodeTo
9、GB2312(unsignedchar*pOut,unsignedshortuData){WideCharToMultiByte(CP_ACP,NULL,&uData,1,pOut,sizeof(unsignedshort),NULL,NULL);return;}voidGb2312ToUnicode(unsignedshort*pOut,unsignedchar*gbBuffer){MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,gbBuffer,2,pOut,1);return;}一个简单的例子如下(随手写的一段代码,只是演示
10、一下构造数组的过程,不要挑刺儿啊!^_^):/*-----------------------------------------------*
11、GB2312unicodetableconstructor
12、
13、author:SparkSong
14、
15、file:build_uni_table.c
16、
17、date:2005-11-18
18、*-----------------------------------------------*/#include#includevoidUnicodeToGB2312(unsignedchar*pOu
19、t,unsignedshortuData);voidGb2312ToUnicode(unsignedshort*pOut,unsignedchar*gbBuffer);voidconstruct_unicode_table();intmain(intargc,char*argv[]){construct_unicode_table();return0;}voidconstruct_unicode_table(){#defineGB2312_MATRIX(94)#defineDELTA(0xA0)#defineFONT_ROW_BEGIN(16+DELTA)#defi
20、neFONT_ROW_END(87+DELTA)#defineFONT_COL_BEGIN(1+DELTA)#defineFONT_COL_END(GB2312_MATRIX+DELTA)#defineFONT_TOTAL(72*GB2312_MATRIX)inti,j;unsignedcharchr[2];unsignedshortuni;unsignedshortdata[FONT_TOTAL]={0};intindex=0;unsignedshortbuf;//生成unicode码表for(i=FONT_ROW_BEGIN;i<=FONT_ROW_END;i+
21、+)for(j=FONT_COL_BEGIN;j<=FONT_COL_END;j++){chr[0]=i;chr[1]=j;Gb2312ToUnicode(&uni,chr);data[index]=uni;index++;}//排个序,以后检索的时候就可以用binary-search了for(i=0;idata[j]){buf=data[i];data[i]=data[j];data[j]=buf;}//输出到STD_OUTprintf("constunsignedsh