A Problems with fonts in the C language
There are two ways of displaying in C language, that is, text mode and graphic mode. As I know, fonts can only be controlled in graphic mode.
Let's take a look at some of the fonts defined in C
Name index value Font description
Default_font 0 8x8 bit-mapped Font
Triplex_font 1 stroked triplex font
Small_font 2 stroked small font
Sans_serif_font 3 stroked Sans-serif font
Gothic_font 4 stroked Gothic font
(The English explanation in the font description does not need to be understood, in the demonstration of the example to see)
Take a look at the example (the online Help file from tc3.0)
Example One.
#include
#include
#include
#include
/* The names of the text styles supported * *
Char *fname[] = {"Default font",
"Triplex Font",
"Small Font",
"Sans serif font",
"Gothic Font"
};
int main (void)
{
* Request Auto Detection * *
int gdriver = detect, Gmode, errorcode;
int style, MIDX, Midy;
int size = 1;
/* Initialize graphics and local variables * *
Initgraph (&gdriver, &gmode, "");
/* Read result of initialization * *
ErrorCode = Graphresult ();
if (errorcode!= grok)/* An error occurred * *
{
printf ("Graphics error:%s", Grapherrormsg (ErrorCode));
printf ("Press any key to halt:");
Getch ();
Exit (1); /* Terminate with an error code * *
}
Midx = Getmaxx ()/2;
Midy = Getmaxy ()/2;
Settextjustify (Center_text, Center_text);
/* Loop through the available text styles * *
for (Style=default_font; style<=gothic_font; style++)
{
Cleardevice ();
if (style = = Triplex_font)
size = 4;
/* Select the text style * *
Settextstyle (style, horiz_dir, size);
/* Output a message * *
Outtextxy (Midx, Midy, Fname[style]);
Getch ();
}
/* Clean up/*
Closegraph ();
return 0;
}
Source Code Explanation:
In the example above, the control font is used with the Settextstyle function, the style parameter is the font selected, and the other parameter descriptions refer to the online Help. The OUTTEXTXY function is used to output text.
If the man is trying to show a variety of different fonts of Chinese words, that would be a bit of trouble. I don't want to talk about it, we only offer two kinds of solutions
(1) using the Ucdos of Chinese characters, using the printf function in C with special parameters, can refer to the relevant information (such as "computer enthusiasts" have said)
(2) In graphics mode, call the font file, with C function putpixel output. Recommended reference Books
[1] "C language of the latest programming skills in 200 cases" (revised) LU Bath Editor-in-Chief Electronics publishing House 1997