Chinese character display based on dot matrix font

Source: Internet
Author: User

Using the font HZK16, the font is a 16x16 bitmap font that complies with the GB2312 standard, requiring 32 bytes (16*16/8=32 bytes) to store each kanji. A formula for the offset address of a Chinese character in HZK16 (assuming the in-machine code is ABCD): offset=[(AB-0XA1) *94+ (CD-0XA1)]*32
Prove:

GB2312 encoding to the included characters are partitioned processing, a total of 94 areas, each zone contains 94 bits, this representation is called Location code.

such as "Ah" is located in the 16 district of 01, so its location code is 1601 (location code in decimal notation).

The ordinal number of a Chinese character in GB2312 is obtained by the location Code: order=94* (Area code-1) + (bit-1) (minus 1 is because the location number starts from 1).

Because the computer is stored in the in-machine code, the internal code of high and low bytes minus 0xa0 can be obtained location code:
Area code =ab-0xa0; bit number =cd-0xa0;
Therefore, by the in-machine code to get a Chinese character in the GB2312 sequence number: order=94* (AB-0XA1) + (CD-0XA1)
For the 16x16 bitmap font, each Chinese character accounts for 32 bytes, so the character in the font file in the distance file header offset byte number is:

offset=[(AB-0XA1) *94+ (CD-0XA1)]*32

Program:

#include <stdio.h>int main () {File*fp=fopen ("HZK16", "RB"), unsigned char buf[2];while (scanf ("%s", buf)!=eof) {  unsigned int order=94* (BUF[0]-0XA1) + (BUF[1]-0XA1);  unsigned int position=order*32;  Fseek (FP, position,0);      unsigned char tmp[32];  Fread (tmp,sizeof (unsigned char), 32,FP);  for (int i=0;i<32;i++)  {  //displays 8 bits in one byte, 1 displays ' * ', or 0 displays a space for  (int k=0;k<8;k++)  {  if ( Tmp[i]>> (7-k)) &0x01)  printf ("*");  else  printf ("");  }  if (i%2==1)//Every two bytes (16 bits) a newline      printf ("\ n");  }   Fseek (fp,0l,0);} Fclose (FP); return 0;}



Chinese character display based on dot matrix font

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.