How to display 12 or 16 o'clock in the C program

zhaozj2021-02-08  279

Display Chinese characters in the C program

Guo Shengde

In many C programming, you should use the Chinese characters to prompt or human-computer interaction, and the current Turbo C integrated development environment is not Chinese, how to develop C procedures that can display Chinese characters?

The following method can help you show Chinese characters in the Western environment. This method is to call the Chinese Chinese word library for Chinese characters. National Standards: The Chinese customs is divided into 94 districts, and 94 Chinese characters in each zone (in place are different), each Chinese is determined in the Chinese graph library, which is the location code of Chinese characters. Each Chinese character is stored in a dot pattern in the library, which is generally 16 × 16-point array (32 bytes), 24 × 24 o'clock (72 bytes), each point with a binary bit (0 or 1) Representation, the corresponding Chinese character is displayed on the screen.

Due to the Chinese environment, the internal code of Chinese characters, we must convert it into a zone code, calculate the offset, find the corresponding Chinese characters from the franchis, and display it.

The internal code conversion into a zone code method is as follows:

QH = C1-0XA0 WH = C2-0xa0

Its location code is:

Qw = QH * 0xFF WH

The location of the Chinese word in the font is:

OFFSET = (94 * (QH-1) (WH-1)) * 32L

Example:

#Include

#Include

#Include

#Include

#Include

#Include

#DEFINE ROW 1 // Collapse a large number of

#Define col 2 // Torched

void main ()

{

INT X, Y;

Char * s = "Chinese Character Display Procedure";

File * fp;

Char buffer [32]; // buffer is used to store a Chinese character

Register M, N, I, J, K;

Unsigned char qh,.

unsigned long offset;

INT GD = Detect, GM; // Graphics screen initialization

INITGRAPH (& GD, & GM, ");

IF ((fp = fopen ("hzk16", "rb") == null)

// Open the Chinese character library, the franchery can be found in UCDOS

{Printf ("Can't Open Haz16, please");

GetCh (); closegraph (); exit (0);

}

X = 20; y = 100; // Display position setting

While (* s)

{QH = * (s) -0xa0; // Chinese zone bit code

WH = * (S 1) -0xa0;

OFFSET = (94 * (QH-1) (WH-1)) * 32L; // Calculate the deviation of the Chinese in the font

FSeek (fp, offset, seek_set);

Fread (buffer, 32, 1, fp); // Take out the word of the Chinese characters 32 bytes to store into buffer (a Chinese character)

FOR (i = 0; i <16; i ) // Print 32-bit bytes of dot matrix in the screen (1: Print, 0: Do not print), display Chinese characters for (n = 0; n < Row; N )

For (j = 0; j <2; j )

FOR (k = 0; k <8; k )

FOR (m = 0; m )

IF ((Buffer [i * 2 j] >> (7-k)) & 0x1)! = NULL)

PUTPIXEL (X 8 * J * COL K * COL M, Y I * ROW N, GREEN);

S = 2; // Because a Chinese character is occupied by two bytes, S must add 2

X = 30;

}

Getch ();

Closegraph ();

}

The above program runs successfully under the Turbo C 2.0 compilation system, which enlarges Chinese characters. The reader can change it to a function to display Chinese characters in your program.

Example of GBA:

// First, you have to have the HZK12's font, write a program to switch each of the data into the unsigned char in the * .h file, define a // large array const u8 zkdata [] Void CDRAW :: DrawHztext (char * Str, int x, int y, u8 color) {char * buffer; // buffer is used to store a Chinese character char * s = Str; Register Int i, j, k; unsigned char qh, wh; unsigned long offset; while * S) {QH = * (s) -0xa0; WH = * (S 1) -0xa0; Offset = (94 * (QH-1) (WH-1)) * 24L; buffer = (char *) (ZKDATA OFFSET); for (i = 0; i <12; i ) for (j = 0; j <2; j ) for (k = 0; k <8; k ) IF ((Buffer [i * 2 J] >> (7-K)) & 0x1)! = 0) SetPixel (x 8 * J K, Y I, Color); S = 2; x = 12;}}

转载请注明原文地址:https://www.9cbs.com/read-3168.html

New Post(0)