Loading....
Coupon Accepted Successfully!

 

Working With Texts

There are several functions for display texts in different fonts, sizes, and directions. Consider the following functions:

1.     outtextxy (int , int, string): This function is used to display the text in graphics mode.

2.     settextstyle(): This function has three integer arguments. The first argument indicates font; the second, direction; and the third, size.

Use of settextstyle() and outtextxy():

22.12 Write a program to display text in different fonts and sizes.

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

int main()

{

int gd =DETECT,gm;

initgraph(&gd,&gm,“c:\\tc\\bgi”);

settextstyle(3,4,30);

outtextxy(10,110,“AMIT”);

getch();

closegraph();

restorecrtmode();

return 0;

}

Explanation: After execution of the program, the string “AMIT” is displayed. This is performed by giving arguments in the settextstyle() function.

Another new function that can be used is settextjustify(), which takes care of alignment of the text. This function is explained in the following program:

22.13 Write a program to display text in different fonts and sizes.

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

int main()

{

int gd=DETECT,gm;

 

initgraph(&gd,&gm, “c:\\tc\\bgi”);

settextstyle(1,0,10);

settextjustify(0,2);

outtextxy (10,2,“Hello”);

settextjustify(2,3);

settextstyle(3,1,5);

outtextxy (14,150,“Hello”);

getche();

closegraph();

restorecrtmode();

return 0;

}

Explanation: In the above program, the settextjustify() function is used. The syntax of settextjustify() is as follows:

void far settext(int horiz, int vert);

The function settextjustify() is used to set the current text justification, that is, horizontal and vertical.

The table of settextjustify() has two arguments. They are as follows:

Name

Value

Direction

HORIZ_DIR

0

LEFT to RIGHT

VER_DIR

1

BOTTOM to TOP

After execution of the program, the string “Hello” is displayed horizontally and vertically with a different font and font size. This is performed by giving different values in the settextstyle() function. Another new function used is settextjustify(), which takes care of the alignment of text.

Stylish Lines

22.14 Write a program to display text in different fonts and sizes.

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

int main()

{

int gd =DETECT,gm;

initgraph(&gd,&gm, “c:\\tc\\bgi”);

clrscr();

line(20,9,200,9);

setlinestyle(1,1,1);

line(40,9,400,9);

setlinestyle(2,1,1);

line(60,9,60,70);

 

getch();

closegraph();

restorecrtmode();

return 0;

}

Explanation: In this program using setlinestyle() function lines are drawn in different style. It requires three integer arguments. The first represents style of line second represents pattern and the third represents thickness.





Test Your Skills Now!
Take a Quiz now
Reviewer Name