|
Gb2312 can be found online (below)
But gbk-encoded fonts don't work.
The offset calculated using offset = ((ch1-0x81) * 190 + (ch2-0x40)-(ch2 / 128)) * 32L is still incorrect.
What should I do?
---- TC2323 Chinese character display -------
#include <graphics.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <stdlib.h>
#include <conio.h>
#define ROW 1 / * Vertical magnification * /
#define COL 1 / * abscissa magnification * /
void main ()
{
int x, y;
char * s = "Chinese character display program";
FILE * fp;
char buffer [32]; / * buffer is used to store a Chinese character * /
register m, n, i, j, k;
unsigned char qh, wh;
unsigned long offset;
int gd = DETECT, gm; / * Graphic screen initialization * /
initgraph (&gd,&gm, "");
if ((fp = fopen ("GBK16", "rb")) == NULL) / * Open the Chinese character library, which can be found in ucdos * /
{
printf ("Can't open haz16, Please add it");
getch (); closegraph (); exit (0);
}
Ranch
x = 20; y = 100; / * Display position setting * /
while (* s)
{
qh = * (s) -0xa0; / * Chinese character area code * /
wh = * (s + 1) -0xa0;
offset = (94 * (qh-1) + (wh-1)) * 32L; / * Calculate the offset of the Chinese character in the font * /
Ranch
fseek (fp, offset, SEEK_SET);
fread (buffer, 32,1, fp); / * Retrieve 32-byte dot matrix fonts of Chinese characters and store them in buffer (one Chinese character) * /
Ranch
for (i = 0; i <16; i ++) / * print the 32-bit byte matrix on the screen bit by bit (1: print, 0: 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 <COL; 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 code takes two bytes, s must be added by 2 * /
x + = 30;
} getch ();
closegraph ();
} |
|