| |

VerySource

 Forgot password?
 Register
Search
View: 727|Reply: 2

How does C language display GBK Chinese characters?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-14 15:40:01
| Show all posts |Read mode
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 ();
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-9 15:15:01
| Show all posts
GBK is no longer calculated by the location code like GB2312, and is directly given: high byte 0x81 ~ 0xFE, low byte 0x40 ~ 0xFE, it should be possible to place them in order. Pay attention to the endianness problem.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-9 14:30:01
| Show all posts
Thanks ls
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list