Use of hzk16 Chinese character 16*16 dot matrix font and sample programs

Source: Internet
Author: User
I recently bought a color screen for hardware and needed a font, so I took out the knowledge I had learned a long time ago. many of them are blurred. I have read the code on the Internet and there are many problems. Here I post my own code, no problem. the following is taken from the Internet. hzk16 font is in line with gb2312 Standard 16x16 dot matrix font, hzk16 GB2312-80 support 6763 Chinese characters, 682 symbols. among them, there are 3755 first-level Chinese characters, sorted by audio order, 3008 second-level Chinese characters, and arranged by radicals. we cannot use so many Chinese Character Fonts in some application scenarios, so we can extract only some fonts for our use. in the hzk16 font, a total of 256 Chinese characters are displayed, that is, 32 bytes are required to display a common Chinese character. we know that a gb2312 Chinese character is encoded in two bytes in the range of 0xa1a1 ~ 0xfefe. the A1-A9 is the symbol area, B0 to F7 is the Chinese character area. each zone has 94 characters (Note: This is only the permitted range of the encoding, not necessarily the corresponding fonts, for example, there are many blank areas of the Encoding Area ). the following uses the Chinese character "I" as an example to describe how to find the 32-byte data in the hzk16 file. as mentioned above, a Chinese character occupies two bytes. The first two bytes are the area code of the Chinese character, and the last byte is the location code of the word. 94 Chinese characters are recorded in each area, and the location number is the position of the word in the area. therefore, to locate "I" in the hzk16 database, you must obtain its location code and location code. area code: the first byte of the Chinese character-0xa0 (because the Chinese character code starts from the 0xa0 area, the first part of the file is the 0xa0 area, and the relative area code must be calculated) bit code: the second byte of the Chinese character-0xa0 so that we can get the absolute offset position of the Chinese character in hzk16: offset = (94 * (area code-1) + (bit code-1 )) * 32 Annotations:
1. the area code minus 1 is because the array starts with 0 and the area code number starts with 1. (94 * (area code-1) + position number-1) is the number of bytes occupied by a Chinese character model. the last multiply by 32 is because the Chinese font should record the font information of the word from the 32-byte information starting from the position (a Chinese character should be displayed in 32 bytes: | <--- 16-bit, 2-byte --> | + ○ ● ○ |-> 0x04, 0x80 ○ ●● ○ ●○ ○ |-> 0x0e, 0x78, 0x90 ○ |-> 0x08, 0x90 ○ |-> 0x08, 0x84 ●●●●●●●●●●●●●●○ |-> 0xff, 0xfe ○ |-> 0x08, 0x80 ○ | 16-> 0x08, 0x90 ○ | 2 bytes-> 0x0a, 0x90 ○ ● ○ |-> 0x0c, 0x60 ○ ● ○ |-> 0x18, 0x40 ○ ●● ○ ●○ ○ |-> 0x68, 0xa0 ○ |-> 0x09, 0x20 ○ ●○ ○ |-> 0x0a, 0x14 ○ ●○ ○ |-> 0x28, 0x14 ○ ● ○ +-> 0x10, 0x0c, the sequence of 'my' stored in the hzk16 16*16 dot matrix font is: saved in one row and one row, 16 rows in total, 2 bytes in each row, A total of 32 bytes 04 80 0e A0 78 90 08 90 08 84 ff Fe 08 80 08 900a 90 0C 60 18 40 68 A0 09 20 0a 14 28 14 10 0c

As shown below:

The following is an example program I wrote. You can change it to another data format. (very simple, so no comments are written) # include <stdio. h> int main (void) {file * fphzk = NULL; int I, J, K, offset; int flag; unsigned char buffer [32]; unsigned char word [3] = ""; unsigned char key [8] = {0x80, 0x40, 0x20, 0x10, 0x08,0x04,0x02,0x01 }; fphzk = fopen ("hzk16", "rb"); If (fphzk = NULL) {fprintf (stderr, "error hzk16 \ n"); return 1 ;} offset = (94 * (unsigned INT) (word [0]-0xa0-1) + (word [1]-0xa 0-1) * 32; fseek (fphzk, offset, seek_set); fread (buffer, 1, 32, fphzk); For (k = 0; k <32; k ++) {printf ("% 02x", buffer [k]) ;}for (k = 0; k <16; k ++) {for (j = 0; j <2; j ++) {for (I = 0; I <8; I ++) {flag = buffer [K * 2 + J] & Key [I]; printf ("% s", flag? "●": "○") ;}} Printf ("\ n") ;}fclose (fphzk); fphzk = NULL; return 0 ;}
// Version 2 # include <stdio. h> # include <stdlib. h> int main (void) {file * fphzk = NULL; int I, J, K, offset; int flag; unsigned char buffer [32]; unsigned char word [5]; unsigned char key [8] = {0x80, 0x40, 0x20, 0x10, 0x08,0x04,0x02,0x01}; fphzk = fopen ("hzk16", "rb "); if (fphzk = NULL) {fprintf (stderr, "error hzk16 \ n"); return 1 ;}while (1) {printf ("Enter the Chinese characters (multiple characters) to generate the model:"); For (;) {fgets (char *) Word, 3, stdin); If (* WORD = '\ n') break; offset = (94 * (unsigned INT) (word [0]-0xa0-1) + (word [1]-0xa0-1) * 32; fseek (fphzk, offset, seek_set); fread (buffer, 1, 32, fphzk); For (k = 0; k <16; k ++) {for (j = 0; j <2; j ++) {for (I = 0; I <8; I ++) {flag = buffer [K * 2 + J] & Key [I]; printf ("% s", flag? "●": "○") ;}} Printf ("\ n") ;}printf ("uchar Code Key [32] = {"); For (k = 0; k <31; k ++) {printf ("0x % 02x,", buffer [k]);} printf ("0x % 02x}; \ n ", buffer [31]); printf ("\ n") ;}} fclose (fphzk); fphzk = NULL; return 0 ;}

Program and source code download: http://files.cnblogs.com/nbsofer/mod.7z
All kinds of Font: http://pan.baidu.com/share/link? Consumer id = 2514580636 & UK = 320828865

Girl don't cry (QQ: 191035066) @ 2012-11-01 01:23:20 @ http://www.cnblogs.com/nbsofer

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.