输入法编辑器(IME)程序设计(3)

类别:VC语言 点击:0 评论:0 推荐:

Composition String

The composition string is the current text in the composition window. This is the text that the IME converts to final characters. Each composition string consists of one or more clauses, where a clause is the smallest combination of characters that the IME can convert to a final character. To get and set the composition string, call the ImmGetCompositionString and ImmSetCompositionString functions.

As the user enters text in the composition window, the IME tracks the status of the composition string. This status includes attribute information, clause information, typing information, and cursor position. You can retrieve the composition status by using the ImmGetCompositionString function.

In the attribute information array, all characters of one clause must have the same attribute. The attribute information is an array of 8-bit values that specifies the status of characters in the composition string. There is one value for each byte in the string, including one byte each for the lead and second bytes of any double-byte characters in the string. For each value in the array, bits 0 through 3 can be one combination of the following values.

       字母组合字符串(composition string)是指字母组合窗口中的当前文本。这是将被IME转换为最终字符的文本。每个字母组合字符串由一个或多个子串组成(clauses),子串是IME能转换成最终字符的最小字符组合。要获取或设置字母组合字符串,调用ImmGetCompositionStringImmSetCompositionString函数。

       当用户在字母组合窗口中输入文本时,IME会跟踪字母组合字符串的状态。这些状态包括属性信息、子串信息、录入信息和子串的位置。你可以通过使用ImmGetCompositionString函数来检索字母组合的状态。

       在属性信息数组中,同一个子串中的所有字母都必须具有相同的属性。属性信息是一个由8位值组成的数组,用于确定字母组合字符串中的字符。字符串中的每个字节都对应有一个值,其中,字符串中每个双字节字符的第一和第二字节也都对应的一个值。数组中的每个值,从第0位到第3位可以是下面各值的组合:

Value(值)

Meaning(含意)

ATTR_INPUT

Character being entered by the user. It is yet to be converted by the IME.

用户输入的字符。它将被IME转换。

ATTR_INPUT_ERROR

Character is an error character and cannot be converted by the IME. For example, some consonants cannot be put together.

字符是一个错误的字符,不能被IME所转换。使用某些辅音字母不能放在一起。

ATTR_TARGET_CONVERTED

Character converted by the IME. The user has selected this character and the IME has converted it.

被IME所转换了的字符。用户已经选择了这个字符并且IME已经将其转换。

ATTR_CONVERTED

A converted character. The IME has already converted this character.

一个已经转换了的字符。IME已经将其转换。

ATTR_TARGET_NOTCONVERTED

Character being converted. The user has selected this character but the IME has not yet converted it.

正在转换中的字符。用户已经选择了这个字符,但是IME还没有转换它。

ATTR_FIXEDCONVERTED

Characters that will not be converted. The IME will not convert these characters anymore.

不能被转换的字符。IME将不能再对其转换。

 

All other values are reserved. In Japanese, any unconverted character having the ATTR_INPUT attribute is a Hiragana, Katakana, or alphanumeric character. In Korean, this character is a Hangeul character that is not converted by IME yet. In Traditional and Simplified Chinese, each IME may limit its character in some range.

 

       其它值(大概是指8位中的)将被保留。在日文中,任何拥有ATTR_INPUT属性而不能被转换的字符都是一个平假名、片假名是数字字母。在韩文中,这样的字符是一个韩文字符,它也不能被IME所转换。在传统(也就是繁体)和简体中文中,各个IME(大概是指各个输入法)会以自己的范围内限制它的字符。

 

The clause information is an array of 32-bit values that specifies the positions of the clauses in the composition string. There is one value for each clause and a final value that specifies the length of the full string. Each value in the array specifies the offset, in bytes, from the beginning of the string to the clause. The first value is always 0 because the first clause always starts at the beginning of the string. For example, if a string has two clauses, the clause information has three values: the first value is 0, the second value is the offset of the second clause, and the third value is the length of the string. For Unicode, the position of a clause is the position counted in Unicode characters, and the length of a string is the size in Unicode characters.

 

       子串信息是一个32位值的数组,用于确定子串在字母组合字符串中的位置。每个子串对应一个值,最后一个值确定整个字母组合字符串的长度。数组中的每个值在字节级别上(以字节为单位)确定了子串由字符串算起的偏移量。第一个值总是0,因为第一个子串总是从字符串的起点开始。例如,如果字符串有两个子串,子串消息(数组)就会有三个值:第一个值是0,第二个值是第二个子串的偏移量,第三个值是字符串的长度。对于Unicode,子串的位置是用Unicode字符计算出的位置,并且字符串的长度也是以Unicode字符计数。

 

The typing information is a null-terminated character string representing the characters entered at the keyboard.

The cursor position is a value indicating the position of the cursor relative to the characters in the composition string. The value is the offset, in bytes, from the beginning of the string. If this value is 0, the cursor is immediately before the first character in the string. If the value is equal to the length of the string, the cursor is immediately after the last character. If –1, the cursor is not present. For Unicode, both position and length are measured in Unicode characters.

 

       录入信息是一个无终结字符(null-terminated character)字符串,代表由键盘输入的字符。光标位置(cursor position)是一个值,它指出光标相对于字母组合字符串中字符的位置。此值是个以字节计算的偏移量,从字符串的起点算起。如果值与字符串的长度相等,光标恰好处在最后一个字符的后面。如果值为-1,意味着没有光标(光标不显示)。对于Unicode,位置和长度都是以Unicode字符来度量的。

 

You can set the composition string or elements of the composition status by using the ImmSetCompositionString function. To ensure that the composition window updates its appearance based on these changes, the function allows you to send a notification message to the window. Applications that set a combination of composition status elements typically set the fNotify parameter to FALSE for all but the last call to this function so that only one notification message is generated for the composition window.

Finally, the edit control supports two messages for changing the IME's handling of composition strings. For more information, see EM_GETIMESTATUS and EM_SETIMESTATUS. For more information on the edit control, see Edit Controls.

 

       你可以使用ImmSetCompositionString函数来设置字母组合字符串或者其中元素的属性。为了确保字母组合窗口已经根据这些改变更新了它的外观显示,函数允许你向窗口发送一个通知消息。设定字母组合字符串状态元素组合的应用程序,默认情况下会把所有对此函数调用中的fNotify参数设置为FASLE,除了最后一个调用,所以对字母组合窗口只会生成一个通知消息。

       最后,编辑控件还支持两个IME的字母组合字符串处理消息。更多信息,参见EM_GETIMESTATUSEM_SETIMESTATUS。更多有关编辑控件的信息,参见Edit Controls。

本文地址:http://com.8s8s.com/it/it1104.htm