Use the drive in C to change fonts and colors

Source: Internet
Author: User
Tags error code int size printf

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

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.