Display Chinese Characters in graphic mode

Source: Internet
Author: User

When writing some application software, in order to make the software more simple, easy to learn and easy to use, a user interface with Chinese characters is essential. In text mode, as long as the Chinese character operating system is supported, displaying Chinese characters is not a problem. You only need to use printf or cprintf. # Include Void main () {printf ("I'm learning C language! ");}
Displaying Chinese Characters in graphic mode is a little effort-consuming. Fortunately, many people have studied this issue and developed some functions for displaying Chinese characters. These functions do not need the support of the Chinese character system, but use the font files. For example, HZK16 of UCDOS.
The first step for displaying Chinese characters is to open the font file.
Function: int OpenHz (const char * Hz16Path); function: Open the font file Hz16Pathint handle;/* Open the font file pointer */int OpenHz (const char * Hz16Path) {return (handle = open (Hz16Path, O_RDONLY | O_BINARY);} after opening the font file, you can use the function described below to display the 16-dot-matrix Chinese characters.
Function: int WrtHz16 (int x, int y, int z, int color, char * p); function: display the Chinese character string p in color (x, y, the number of spaces between Chinese characters is z. IntWrtHz16 (int x, int y, int z, int color, char * p)
{
Unsigned int I, c1, c2, f = 0;/* x, y: write at (x, y );*/
Int rec, i1, i2, i3;/* z: space ;*/
Long l;/* color: txt color */
Char by [32];/* p: HZ str */
If (handle <0) return-1; while (I = * p ++ )! = 0 ){
If (I> 0xa1)
If (f = 0 ){
C1 = (i-0xa1) & 0x07f;
F = 1;
}
Else {
C2 = (i-0xa1) & 0x07f;
F = 0;
Rec = c1 * 94 + c2;
L = rec * 32L;
Lseek (handle, l, SEEK_SET );
Read (handle, by, 32 );
For (i1 = 0; i1 <16; i1 ++)
For (i2 = 0; i2 <2; i2 ++)
For (i3 = 0; i3 <8; i3 ++)
If (GetBit (by [i1*2 + i2], 7-i3 ))
Putpixel (x + i2 * 8 + i3, y + i1, color );
X = x + z + 16;
}
}
Return (x );
}
The GetBit function is defined as follows:
Function: int GetBit (unsigned char c, int n); function: obtains the dot matrix data of Chinese characters.
Int GetBit (unsigned char c, int n)
{
Return (c> n) & 1 );
}
When the Chinese character display ends, the font file should be closed.
Void CloseHz (void)
{
Close (handle );
}
# Include "CaicIncludeHz. h"
# Include
# Include Const char * Hz16Path = "\ UCDOS \ Hzk16 .";
Const char * HzStr = "clove C Language Learning Assistance software ";
Void main (){
Int gr = DETECT, gm;
Initgraph (& gr, & gm, "\ Caic \ Bgi ");
OpenHz (Hz16Path );
Wrt16Hz (20, 20, 4, RED, HzStr );
CloseHz ();
Getch ();
Closegraph ();
} Display a 24-digit dot matrix and enlarge Chinese Characters
The following describes how to display a 24-dot-matrix and enlarge Chinese characters. The 24-dot matrix font can also be found in any Chinese character system. For example, HZK24S of UCDOS.
Function: int WrtHz24 (int x, int y, int z, int color, int m, int n, char * p); function: Display 24-point matrix and enlarge Chinese characters.
Int WrtHz24 (int x, int y, int z, int color, int m, int n, char * p)
{
Unsigned int I, c1, c2, f = 0;/* z: space between Chinese characters */
Int i1, i2, i3, i4, i5, rec;/* x, y: first location (x, y )*/
Long l;/* color: Chinese Character color */
Char by [72];/* m: magnification of x */
/* N: magnification of the y direction */
If (handle <0) return-1;/* p: display the Chinese character string */while (I = * p ++ )! = 0 ){
If (I> 0xa1)
If (f = 0 ){
C1 = (i-0xa1) & 0x7f;
F = 1;
}
Else {
C2 = (i-0xa1) & 0x7f;
F = 0;
Rec = (c1-15) * 94 + c2;
L = rec * 72L;
Lseek (handle, l, SEEK_SET );
Read (handle, by, 72 );
For (i1 = 0; i1 <24 * m; i1 = i1 + m)
For (i4 = 0; i4 For (i2 = 0; i2 <= 2; i2 ++)
For (i3 = 0; i3 <8; i3 ++)
If (GetBit (by [i1/m * 3 + i2], 7-i3 ))
For (i5 = 0; i5 Putpixel (x + i1 + i4, y + i2 * 8 * n + i3 * n + i5, color );
X = x + 24 * m + z;
}
}
Return (x );
} Example of Wrt24Hz: # include "caic1_dehz. h"
# Include
# Include Const char * Hz24Path = "C: \ Ucdos \ fnt \ hzk24s ."
Const char * HzStr = "clove C Language Learning Assistance software ";
Void main (){
Int gr = DETECT, gm;
Initgraph (& gr, gm, "\ Caic \ Bgi ");
OpenHz (Hz24Path );
Wrt24Hz (20, 20,/* First in (x, y )*/
4,/* the space between Chinese characters is 4 */
RED,/* display in RED */
2,/* 2 times in the x direction */
4,/* 4 times in y direction */
HzStr);/* display string */
CloseHz ();
Getch ();
Closegraph ();
}

Related Article

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.