Creating various types of texts and fonts
Using different graphics functions available for text formatting in C-Language, Write a C program for displaying text in different sizes, different colors, different font styles?
Aim: To write a C-program for displaying text in different sizes, different colors and different font styles by using graphics functions.
Description:
The following graphics functions are available for text formatting in C.
- Outtext()-------- for displaying text on output screen
- Outtextxy()----- for displaying text on output screen at location (x,y).
- Settextstyle()--- used for specifying font style, font display direction(vertical or horizontal), font
- Setcolor()------- setcolor function is used to change the current drawing e.g. setcolor(RED) orsetcolor(4) changes the current drawing color to RED. Remember that the default drawing color is WHITE.
Outtext: outtext function displays text at the current position.
Eg: outtext("To display text at a particular position on the screen use outtextxy");
Outtextxy(): outtextxy function display text or string at a specified point(x,y) on the screen. Eg: outtextxy(100, 100, "Outtextxy function");--displays the message "Outtextxy function" At screen location of (100, 100).
Settextstyle():Settextstyle function is used to change the way in which text appears, using it we can modify the size of text, change direction of text and change the font of text.
Eg: settextstyle(font,direction,charsize);--settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
Font –font style- it may be font name or integer value from 0- 9.
Different fonts are:
size(0-9)
| DEFAULT_FONT, TRIPLEX_FONT, SMALL_FONT, SANS_SERIF_FONT, GOTHIC_FONT, SCRIPT_FONT, SIMPLEX_FONT, TRIPLEX_SCR_FONT, COMPLEX_FONT, EUROPEAN_FONT, BOLD_FONT |
Directions are two.
Character
|
1. Horizontal direction(HORIZ_DIR or 0) 2. Vertical direction(VERT_DIR or 1) |
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x=25,y=25,font=10;
initgraph(&gd,&gm,"C:\\turboC3\\BGI");
for(font=0;font<=4;font++)
{
settextstyle(font,HORIZ_DIR,font+1);
// sets font type, font direction, size setcolor(font+1);
// sets color for text.
outtextxy(x,y,"text with different fonts"); // prints message on screen at (x,y) y=y+25;
}
for(font=0;
font<=2;font++)
{
settextstyle(font,VERT_DIR,font+2);
setcolor(font+1);
x=250; y=100;
outtextxy(x,y,"text in vertical direction");
y=y+25;
}
getch();
closegraph();
}
Output:
