利用Windows的IFELanguage接口,取得拼音笔划数其实很简单!



前言:以下的秘密其实不能算作是Windows的秘密,或许好多人都已经知道,但是知道的人或许并不是很多,我今天把它介绍出来,也算是我为BCB论坛中所有的Fans做了一点贡献!!虽然我是半年前就在csdn上注册的,但是由于工作原因,一直没有来这里,上个星期开始才算是真正向组织报的到,来了,总该有点见面礼吧,以下权当见面礼吧!
1。为什么要这么做?
   研究Windows中的汉字已经有好长一段时间了,其实目的只是为了汉语合成,基于音节的合成。但是进展总是很缓慢,在漫长的摸索中虽然自己的主要目标没有实现,倒是副产品产出了不少,前几天见ALNG(),一个很执著的程序员(大概是程序员的执著劲的一个典型的代表吧),在论坛上发了个关于取得汉语拼音以及笔划的贴子,很执著,大家讨论得也很热闹,好多方法我还是第一次见到,比如说数笔划(后来细查资料才知道通过数Stroke Font的汉字的笔划的确可以得到结果),自己又长见识了。只不过限于篇幅,自己也只是清描淡写的说了几句,没有太在意,倒是后来又忍不住去讲了一通通过IME的反向转换可以取得拼音和笔划,意犹未尽,想想今天还有点时间,就为大家做点事情吧!
   我不知道这知识可能会为你带来什么,但是可能有用,也可能没用,如果你想做一个自己的输入法,想做一个自己的tts,想做一个自己的手写识别软件,想得到任何一个汉字的笔划,笔划数,汉语拼音,我想这应该还是有点用的!


2。从字符映射表谈起


开始-->程序--->附件--->系统工具---〉字符映射表
这一连串的菜单想必大家都不会陌生,那就打开这个程序吧。看仔细了(唉,论坛上没地方插图片,不然下面就是一个字符映射表程序的图片了...呵呵,提个意见!!)
   我们先不管最上面的"字体"Edit框,先选字符集为Unicode(为什么选它?这里面最全嘛!什么字符都有!),分组先选"按拼音分类的简体中文"(先关注拼音嘛!),就会出来一个声母面板,上面有A-Z,我们每一次把鼠标放在A的序列。在主窗体的ComoboBox把鼠标放在第一行A上,看看状态烂,你看到"U+0041"的标示。继续放在"啊"字上,看状态栏你会看到:"U+554A",继续放在其他的字上,有以下类似结果:
   字       状态栏内容
   A         U+0041(0x41)
   啊        U+554A(0xB0A1)
   阿        U+963F(0xB0A2)
   呵        U+5475(0xBAC7)
   ....
   很显然,系统里有一张表来存放字以及字的发音,并且他们之间的存放位置是存在对应关系的,假设我们能够破译这种对应关系,那么我们的目的就基本达到了。那么这张表是什么表,存在哪里,入口在哪里,怎么去查这张表???一个迷!!在后面我们就会看到这个入口,并且能查到我们想要的东西!!期待!别走开!
 让我们看看更奇特的,仍然选字符集为Unicode(为什么选它?这里面最全嘛!什么字符都有!),分组先选"按偏旁部首分类的表意文字"(再关注笔划嘛!),如果你选中了"高级查看",就会有一个标题为"分组"的框弹出来,上面是基本部首按笔划数分类。我们选
 "一",主窗体的Comobobox就会出现所有部首为"一"汉字,注意观察:第一行全部是在
"一"这个部首上加一笔构成的汉字,第n行全部是在"一"上面加上n笔之后构成的汉字,也就是说:第i行的汉字笔划是本页的部首笔划m加上i之后构成的笔划数为m+i的汉字。
 假设能破译这张表我们的目的不也就达到了吗?这张表的入口究竟在那里呢??
 让我们再次把目光投向U+xxxx(0xyyyy)这个标示,猛然发现A后面那个括号的0x41怎么就那么眼熟呢?一想:噢,原来是A的ASCII码。
 那也就是说,这张表多多少少应该根ASCII码表有点联系了,再一查,果然,凡是ACSII码表中有的,这里面所对应0xYYYY的值跟ASCII码表中的全部一致!也就是说系统中有一张表包括了ASCII码表----Unicode编码表!


3.漫谈Uncode编码表
关于这张表,程序员都知道一点,关于说为什么要有Unicode,我也不细说了,那么最重要的,这张表是如何编码的呢:(懒了一点,以下的来自微软的某篇文档,我就直接贴出来,大家看了源汁源味的,或许理解更深:),我就胡乱解释了,
   Unicode
Unicode is a worldwide character-encoding standard. Windows NT, Windows 2000, and Windows XP use it exclusively at the system level for character and string manipulation. Unicode simplifies localization of software and improves multilingual text processing. By implementing it in your applications, you can enable the application with universal data exchange capabilities for global marketing, using a single binary file for every possible character code. 


Unicode defines semantics for each character, standardizes script behavior, provides a standard algorithm for bidirectional text, and defines cross-mappings to other standards. Among the scripts supported by Unicode are Latin, Greek, Han, Hiragana, and Katakana. Supported languages include, but are not limited to, German, French, English, Greek, Chinese, and Japanese. 


Unicode can represent all of the world's characters in modern computer use, including technical symbols and special characters used in publishing. Because each Unicode code value is 16 bits wide, it is possible to have separate values for up to 65,536 characters. Unicode-enabled functions are often referred to as "wide-character" functions. Note that the implementation of Unicode in 16-bit values is referred to as UTF-16. For compatibility with 8- and 7-bit environments, UTF-8 and UTF-7 are two transformations of 16-bit Unicode values. For more information, see The Unicode Standard, Version 2.0.


Windows supports applications that use either Unicode or the regular ANSI character set. Mixed use in the same application is also possible. Adding Unicode support to an application is easy, and you can even maintain a single set of sources from which to compile an application that supports either Unicode or the Windows ANSI character set. 


Functions support Unicode by assigning its strings a specific data type and providing a separate set of entry points and messages to support this new data type. A series of macros and naming conventions make transparent migration to Unicode, or even compiling both non-Unicode and Unicode versions of an application from the same set of sources, a straightforward matter. 


Implementing Unicode as a separate data type also enables the compiler's type checking to ensure that only Unicode parameters are used with functions expecting Unicode strings
Surrogates
There is a need to support more characters than the 65,536 that fit in the 16-bit Unicode code spa
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值