Graphics in C-Scaling of text size using function setusercharsize()
Here is a simple program to
describe one more text setting function. Please type this program in your
editor.
#include<graphics.h>
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
/* Default font, normal(default) size */
outtextxy(0,100, "Hello
World");
/* set stroked triplex font */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
/* text display in normal(default) size */
outtextxy(0, 120, "Hello World");
/* default text width scaled by 2:1, and
height scaled by 3:2 */
setusercharsize(2, 1, 3, 2);
outtextxy(0, 150, "Hello World");
/* default text width scaled by 3:1, and
height scaled by 2:1 */
setusercharsize(3, 1, 2, 1);
outtextxy(0, 200, "Hello World");
getch();
closegraph();
restorecrtmode();
}
Compile and execute this
program. The output would be a “Hello
World” message in different sizes.
For changing the size I have
used the function setusercharsize(). Function setusercharsize() uses a user-defined character
magnification factor for stroked fonts. With function setusercharsize()
you specify the factors by which the width and height are scaled.
Declaration:
void far setusercharsize(int multx, int
divx, int multy, int divy);
Syntax for calling this
function is:
setusercharsize(multx, divx, multy,
divy);
where multx : divx is the scaling ratio for text width, and multy : divy is the scaling ratio for
height. It means the default width is scaled by multx : divx, and the default height is scaled by multy : divy.
Suppose you want to make the
text width double of the normal size, you should set multx = 2, divx = 1 (2 : 1), and text height triple of the normal
size, the values of multy, and divy would be ‘3’, and ‘1’ (3 : 1).
Function setusercharsize() can be used only for stroked fonts.
In the given program, I have
displayed a string in the default font and size.
outtextxy(0,100, "Hello
World");
Then I have set the font
style as ‘triplex font’ by function settextstyle() , since function setusercharsize()
can be used on stroked fonts only(triplex font is a stroked font. Enumerated
values 1 to 10 are stroked font styles. Triplex font has enumerated value ‘1’).
settextstyle(TRIPLEX_FONT, HORIZ_DIR,
0);
In this statement, I have
set charsize = 0, it is because of
the fact that values set by function setusercharsize() are effective
only if you set charsize to ‘0’ by a previous call to function settextstyle().
The statements:
setusercharsize(2, 1, 3, 2);
outtextxy(0, 150, "Hello
World");
display the text string “Hello World” in the size, default width
scaled by the factor (2 : 1), twice as wide as default
width, and default height scaled by the ratio (3 : 2), 50% taller than the default height.
The statements:
setusercharsize(3, 1, 2, 1);
outtextxy(0, 200, "Hello
World");
can also be explained the
same way.
Therefore, the explanation of this
simple function setusercharsize() is complete. For the
explanation of the remaining functions and terms, please refer my previous
posts.
OUTPUT:
You would also like these programs given below:
C Program to draw a line
C Program to draw a circle and a point
C Program to draw different types of ellipses
C Program to draw arc, pie-slice, and rectangle
C Program to draw a polygon
C Program to draw filled polygon, 2-D bar, and 3-D bar
C Program to create the user-defined fill-pattern
C Program to explain different line-styles
C Progarm to explain functions moveto() and lineto()
C Program to explain moverel() and linerel()
C Program to draw an elliptical pie-slice using sector()
C Program to write text in different font styles using settextstyle()
C Program to justify text using settextjustify()
C Program to explain function setusercharsize()
C Program to define palette of colors
C Program to generate captcha code
C Program for moving a ball on screen
C Program for creating animated circles
Playing with mouse using C language
C Program to restrict mouse pointer in a window
C Program for getting the position of mouse pointer
C Program to create a clock
Interrupt Handling With C
OUTPUT:
C Program to draw a line
C Program to draw a circle and a point
C Program to draw different types of ellipses
C Program to draw arc, pie-slice, and rectangle
C Program to draw a polygon
C Program to draw filled polygon, 2-D bar, and 3-D bar
C Program to create the user-defined fill-pattern
C Program to explain different line-styles
C Progarm to explain functions moveto() and lineto()
C Program to explain moverel() and linerel()
C Program to draw an elliptical pie-slice using sector()
C Program to write text in different font styles using settextstyle()
C Program to justify text using settextjustify()
C Program to explain function setusercharsize()
C Program to define palette of colors
C Program to generate captcha code
C Program for moving a ball on screen
C Program for creating animated circles
Playing with mouse using C language
C Program to restrict mouse pointer in a window
C Program for getting the position of mouse pointer
C Program to create a clock
Interrupt Handling With C
No comments:
Post a Comment
Please give your comment