Chinese characters are square characters. Chinese character libraries with the same width and height are widely used in the embedded field, and their resolution is relatively simple.
The index of Chinese characters in the Chinese Character Library generally follows the gb2312/GBK encoding rules. gb2312/GBK requires that the Chinese character encoding consists of two bytes, of which the low byte code and the high byte is the bit code. In this article, the hzk16 font of 16x16 in UCDOS is used to demonstrate the display method of Chinese characters. The Chinese Characters in hzk16 are stored in the gb2312 encoding sequence, and the dot matrix data of each Chinese Character occupies 32 bytes, each byte represents the status of 8 points. The status of each line from left to right corresponds to the bit values of the byte from high to low.
The following provides a complete demo for your reference,
# Include <stdio. h> # define font_size (16)/* font size * // * obtain the index position of Chinese characters in the Chinese font according to gb2312/GBK encoding rules, the low-byte Hz [0] of Chinese characters is a zone code, and the high-byte Hz [1] is a bit code. The Chinese character library stores Chinese characters starting from the zone code 0xa1a1 */# define hz_index (HZ) (HZ [0]-0xa1) * 94 + (HZ [1]-0xa1) # define dots_bytes (font_size * font_size/8) /* number of bytes occupied by Chinese Character dot matrix data */INT main (INT argc, char * argv []) {file * hzk; unsigned char song [2] = "\ xcb \ xce";/* The location code of "" is 0 xcbce */unsigned char dots [dots_bytes]; unsigned char B; int I, j, k;/* open the Chinese Character Library hzk16 and extract the dot matrix data of the word "song" */If (hzk = fopen ("hzk16 ", "rb") = NULL) {return-1;} fseek (hzk, hz_index (Song) * dots_bytes, seek_set); fread (dots, sizeof (unsigned char ), dots_bytes, hzk); fclose (hzk);/* use the "*" sign to display the "song" word */for (I = 0; I <font_size; I ++) {/* font_size/8 bytes in each row */For (j = 0; j <font_size/8; j ++) {B = dots [I * 2 + J];/* the vertices from left to right correspond to the byte bit values from high to low */For (k = 0; k <8; k ++) {If (B & 0x80) printf ("% C", '*'); elseprintf (""); B <= 1 ;}}printf ("\ n");} return 0 ;}
After the program is compiled and run, the following results are displayed,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *