Analysis of logical fonts, multiple fonts, and multi-character sets
Source: Internet
Author: User
Article title: logical font, multi-font, and multi-character set implementation analysis. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1 Introduction
As mentioned in the first article about the MiniGUI architecture, MiniGUI adopts the object-oriented technology to support GAL, IAL, multiple fonts, and multi-character sets. Font and character set support is indispensable for any GUI system. However, various GUIs adopt different policies to support multiple fonts and multi-character sets. For example, to support multiple character sets, QT/Embedded is implemented based on UNICODE. this method is a commonly used method and is a solution suitable for general systems. However, this method brings about many problems, the most important of which is the conversion code table between UNICODE and other character sets, which will greatly increase the size of the GUI system. This is unacceptable for some embedded systems.
MiniGUI does not support multiple character sets based on UNICODE. The MiniGUI policy is to internally use an internal code that is exactly the same as that of a specific character set. Then, a series of abstract interfaces are used to provide consistent analysis interfaces for a specific character set text. This interface can be used for both the font module and multi-byte string analysis. To support a character set, you only need to implement the interface of the character set. So far, MiniGUI has achieved support for the single-byte character set of the ISO8859-x, as well as support for multi-byte character sets such as GB2312, BIG5, EUCKR, UJIS.
Similar to character sets, MiniGUI also defines a series of abstract interfaces for fonts. to support a certain font, you only need to implement the interface for this font type. So far, MiniGUI has implemented support for RBF and VBF fonts (two grating font formats defined by MiniGUI), TrueType, and Adobe Type1 fonts.
On the basis of multi-font and multi-character set abstract interfaces, MiniGUI provides consistent interfaces for applications through logical fonts.
This article focuses on the implementation of the logical font, multi-font, and multi-character set of MiniGUI. the EUCKR (Korean) character set and Adobe Type1 font are used as examples, describes how to implement a new character set support and a new font type support in MiniGUI.
2 Relationship between logical fonts, device fonts, and character sets
In MiniGUI, each logical font consists of at least one single-byte device font. A device font is a data structure directly associated with the underlying font. Each device font has an operation set (font_ops) that contains abstract interfaces such as get_char_width and get_char_bitmap. The font types supported by each MiniGUI, such as the same width grating font (RBF), the variable width grating font (VBF), the TrueType font, and the Adobe Type1 font all correspond to a set of font operation sets. With this font operation set, we can obtain the dot matrix (for the grating font) or outline (for the vector font) of a character from the corresponding font file ). Then, the plotting function at the upper layer of the MiniGUI can output the dot matrix to the screen, and finally the text displayed on the screen can be seen.
Figure 1 shows the relationship between logical fonts, device fonts, and character sets.
In the device font structure, there is also a character set operation set (charset_ops), which contains abstract interfaces such as len_first_char, char_offset, and len_first_substr. Each character set supported by MiniGUI, such as the ISO8859-x, GB2312, BIG5, and so on, corresponds to a set of character set operations. With this character set operation set, we can analyze the text of strings mixed with multiple character sets. For example, in the "ABC Chinese" string, the first three characters are ISO8859 characters, and the "Chinese" is GB2312 characters. By calling the functions in these two character sets, we can understand which characters in the string belong to ISO8859 and which are GB2312 characters, it can even perform more complex analysis. For example, the GetFirstWord function in MiniGUI can obtain the first word from this string. For example, the first word in the "abc def Chinese" string is "ABC", and the second word is "DEF ", the third and fourth words are "medium" and "text ". The function is implemented as follows:
This function first checks whether the logical font contains a multi-byte device font (whether mbc_devfont is empty). If yes, call the pos_first_char, len_first_substr, and get_next_word functions corresponding to the multi-byte character set to obtain the first word information and fill in the word_info structure. If the logical font only contains a single-byte device font, call the get_next_word operation function corresponding to the single-byte character set. In general, in functions such as GetFirstWord, we must first make some judgments on the multi-byte character set. for example, pos_first_char returns the position of the first character in the character set. If the return value is not zero, the first character is a single-byte character. if the return value is zero, other functions are called for operation.
With such logical fonts, device fonts, and character set structure definitions, when we need to add a new character set or font support, you only need to define the corresponding new operator set structure according to our font operator set and character set operator set, without any impact on upper-layer programs.
3. the character set in MiniGUI supports the 3.1 character set operation set.
In MiniGUI, each specific character set is represented by the corresponding character set operator set. The character set operation set is defined as follows (include/gdi. h. The preceding number indicates the number of rows in the file, the same below ):
250 typedef struct _ CHARSETOPS
251 {
252 int nr_chars; // Number of characters in the character set
253 int bytes_per_char; // average number of bytes per character
254 int bytes_maxlen_char; // maximum number of bytes
255 const char * name; // character set name
256 char def_char [MAX_LEN_MCHAR]; // Default Character
257
258 int (* len_first_char) (const unsigned char * mstr, int mstrlen );
259 int (* char_offset) (const unsigned char * mchar );
260
261 int (* nr_chars_in_str) (const unsigned char * mstr, int mstrlen );
262
263 int (* is_this_charset) (const unsigned char * charset );
264
265 int (* len_first_substr) (const unsigned char * mstr, int mstrlen );
266 const unsigned char * (* get_next_word) (const unsigned char * mstr,
267 int strlen, WORDINFO * word_info );
268
269 int (* pos_first_char) (const unsigned char * mstr, int mstrlen );
270
271 # ifndef _ LITE_VERSION
272 unsigned short (* conv_to_uc16) (const unsigned char * mchar, int len );
273 # endif /*! LITE_VERSION */
274} CHARSETOPS;
The first few fields (nr_chars, bytes_per_char, bytes_maxlen_char, name, and def_char) represent some basic information about the character set. For more information, see annotations. Here we need to explain bytes_maxlen_char and def_chat further:
Bytes_maxlen_char indicates the maximum number of characters in the character set. Generally, the length of each character in a character set is fixed, but there are many exceptions, such as in the GB18303, UNICODE character set, the maximum number of characters may exceed 4 bytes.
Def_char indicates the default character in the character set. This field is mainly used in combination with the font. When a font for this character set lacks some character definitions, you need to replace these missing characters with the default font.
In the operation set definition of the preceding character set, the last several fields are defined as function pointers, which are used for text analysis by the logical font interface:
Len_first_char returns the length of the first character in the multi-byte string that belongs to this character set. If it does not belong to this character set, 0 is returned.
Char_offset returns the position of a character in the character set. This information can be used by the device font to obtain the width or dot matrix of the character from a font file.
Nr_chars_in_str calculates the number of characters in the character set and returns the result. Note that all input strings must be of this character set.
Is_this_charset determines whether the given character set name indicates the character set. For a specific character set, the name does not match the name defined by the name field. For example, for GB2312 character set, there may be gb2312-1980.0, GB2312_80 and other different names. This function can help you determine whether a name indicates the character set.
Len_first_substr returns the length of the substring that belongs to the character set in a multi-byte string. If the first character does not belong to this character set, the return value is 0.
Get_next_word returns the information of the next word in a multi-byte string that belongs to the character set. For European and American languages, words are separated by spaces, punctuation marks, and tabs. for Asian languages, words are generally defined as characters.
Pos_first_char this function returns the position of the first character in the multi-byte string that belongs to this character set.
Conv_to_uc16 this function converts a character belonging to this character set to a UNICODE 16-bit internal code. This function is used to obtain the character outline information from the TrueType font. Because TrueType fonts use UNICODE to locate
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service