Chinese Character Display

Source: Internet
Author: User

I. Chinese character location code and machine internal code

1. Location Code

In order to make every Chinese character has a unified national code, in 1980, China issued the first Chinese character encoding National Standard: GB2312-80 "information exchange with Chinese character encoding Character Set" basic set, this character set is the Development Basis of Chinese Information Processing Technology in China and also the unified standard of all Chinese character systems in China.

All Chinese characters and symbols of the national standard form a 94 × 94 matrix. In this square matrix, each row is called a "area", and each column is called a "bit". Therefore, this square matrix actually forms a Chinese character set with 94 areas (0 1 to 94 area numbers respectively) and 94 places (bits are 01 to 94) in each area. The area code and location code of a Chinese character are simply combined to form the "location code" of the Chinese character ". In the Chinese character location code, the upper two digits are the area code, and the lower two digits are the bit numbers.

In the location code, the 01-09 area contains 682 special characters, 16 ~ Area 87 is the Chinese character area, which contains 6763 Chinese characters. Areas 16-55 are primary Chinese characters (3755 most commonly used Chinese characters are listed in the order of Pinyin letters) and 56-87 are secondary Chinese characters (3008 Chinese characters are listed in the first order ).

From: Chinese character location code

According to this rule, a Chinese character corresponds to a location code, and a Chinese character can be uniquely identified from a location code. For example, the region code is 16 and the location code is 1. For more information, see the gb2312 Simplified Chinese encoding table.

2. Internal machine code

Computers only recognize code consisting of 0 and 1. ASCII code is the standard encoding for English information processing. Chinese character information processing must also have a unified standard encoding. The Chinese Character Exchange Code is mainly used for Chinese character information exchange. In May 1981, the National Bureau of Standards issued the "Chinese character encoding character set for information exchange-basic set", code as GB2312-80, A total of 6763 Chinese characters and 682 graphic characters are encoded.

The encoding principle is: Chinese characters are expressed in two bytes. In principle, two bytes can represent 256 × 256 = 65536 different symbols, which is feasible as the basis for Chinese character encoding expression. However, considering the relationship between Chinese character encoding and other universal international codes, such as ASCII and Spanish character encoding, the National Bureau of Standards of China adopted the two-byte Chinese character encoding scheme corrected, it uses only seven characters below two bytes. This solution can accommodate 128x128 = 16384 different Chinese characters, but to be compatible with standard ASCII codes, each byte cannot contain 32 spaces and 127 operation codes. Therefore, each byte can only contain 94 encodings. In this way, the number of words that can be expressed by the double seven digits is 94 × 94 = 8836.

From: internal machine code

3. Mutual Conversion

  • Convert incode to location code

Location Code: area code = internal code high byte-0xa0

Bit code = internal code low byte-0xa0

For example, the "country" Internal code is 0xb9, 0xfa

Its location code: 2590

  • Convert a location code to an inner code

Internal code: Internal code high byte = area code + 0xa0

Low byte = bit code + 0xa0

For example, the "Sea" location code is 2603

Internal code: 0xba, 0xa3

2. Model

Chinese characters are displayed in the form of dot matrix. commonly seen are 16*16 lattice, 24*24 dot matrix, and 32*32 dot matrix. For example, the 16*16 lattice pattern of "ah" is as follows: 256 bits in total, occupying 32 bytes:

0x00,0x00,0xf7,0x7e,0x95,0x04,0x95,0x04,0x96,0x74,0x96,0x54,0x95,0x54,0x95,0x54,0x95,0x54,0xf5,0x54,0x97,0x74,0x04,0x04,0x04,0x04,0x05,0x04,0x04,0x14,0x04,0x08

When the mode is displayed, a line of pixels is represented in two bytes, and 16 rows constitute a complete mode. When the screen is displayed, 1 is highlighted, and 0 is the background color, so that the font can be displayed. Use the C test program to display 1 as "*" and 0 as blank. The effect is as follows:

3. Font Library

A font is a collection of all Chinese character fonts. Obviously, some order (rules) is required for the orchestration of these fonts, and this rule is "internal machine code ". Based on the Chinese character layout of the internal machine code, the corresponding Chinese character model is integrated to form a font file. In use, the application finds the corresponding storage location from the font library based on the internal code of the Chinese characters, retrieves the model, and displays it.The internal code is the index of Chinese characters in the font.

In the location code, the 01-09 area contains 682 special characters, 16 ~ Area 87 contains 6768 valid Chinese characters. Delete special characters when creating a font. Only valid Chinese characters are used. That is to say, we start to collect the word model from the first place in Area 16th. When the collection ends in Area 1st, we collect the data in Area 16th until the orchestration ends in Area 17th. A total of 6768 Chinese characters are collected, occupying 216576 bytes.

☆Relationship between inner code and font offset

Offset = (host code high byte-0xb0) * 94 + host code low byte-0xa1) * 32

Iv. Test Procedure

# Include <stdio. h> void showoneword (const char * Str); int getgbkcode (unsigned char * pbuffer, const char * C); void showwords (const char * Str ); /*** @ brief main function * @ Param nove * @ retval nove */INT main (void) {showwords ("test Chinese character display"); Return 0 ;} /*** @ brief show multiple Chinese words * @ Param STR: Point to Chinese Location Code * @ retval nove */void showwords (const char * Str) {If (null = Str) retur N; while (* Str! = 0) {showoneword (STR); STR + = 2 ;}}/*** @ brief show one Chinese word * @ Param STR: point to Chinese Location Code * @ retval nove */void showoneword (const char * Str) {unsigned char buffer [32]; int I, j; unsigned char K; getgbkcode (buffer, str); for (I = 0; I <16; I ++) {for (j = 0; j <8; j ++) {k = buffer [2 * I] <j; If (K & 0x80) {printf ("*") ;}else {printf ("");}} for (j = 0; j <8; j ++) {k = buffer [2 * I + 1] <j; If (K & 0x80) {printf ("*") ;}else {printf ("") ;}} printf ("\ n ");} printf ("\ n");}/*** @ brief get type matrix from hzlib. bin based on Chinese Location Code * @ Param pbuffer: Point to 32 bytes type Matrix buffer * C: Point to Chinese Location Code * @ retval 0 (SUCCESS)-1 (fail) */INT getgbkcode (unsigned char * pbuffer, const char * c) {unsigned char high8bit, low8bit; unsigned int Pos; file * FP; high 8bit = * C; low8bit = * (C + 1); Pos = (High8bit-0xa0-16) * 94 + Low8bit-0xa0-1) * 2*16; // get type Matrix location fp = fopen ("hzlib. bin "," R "); // Open Type matrix file if (FP! = NULL) {fseek (FP, POs, seek_set); // set read start point fread (pbuffer, 1, 32, FP); // read 32 bytes fclose (FP ); return 0;} else return-1 ;}
View code

5. Note

1. Chinese characters are expressed in internal codes in the program, while English characters are ASCII characters. The internal codes of Chinese characters occupy two bytes.

2. When a Chinese character is expressed, it is enclosed in double quotation marks to represent a string with only one Chinese character. It actually occupies three bytes of storage space.

 

Appendix eclipse test code: chinese_test.zip

Reference: stm32 Library Development Practice Guide

Gb2312 Simplified Chinese encoding table

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.