How to change fonts (graphics.h)

Hi! I am just a beginner and this is also for my project. I just wanna know if is it possible to edit the specific word or string, font. I would like to change the width and height of "H"(#16), "Li"(#20) and "Be"(#24) or let's say to get bigger than the other string. But, i don't know how to do it. Please help me? Thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define r rectangle
#define a outtextxy
#define b settextstyle
int main()
{
 int gm,gd;
 gd=VGA;
 gm=VGAHI;
 initgraph(&gd,&gm,"");

 /*HYDROGEN (H)*/
 b(SMALL_FONT,HORIZ_DIR,2);
 a(32,8,"1");a(32,20,"H");a(32,30,"Hydrogen");
 r(30,7,65,40);

 /*LITHIUM (Li)*/
 a(32,41,"3");a(32,52,"Li");a(32,63,"Lithium");
 r(30,40,65,81);

 /*BERYLLIUM (Be)*/
 a(67,40,"4");a(67,50,"Be");a(67,63,"Beryllium");
 r(65,40,100,81);

 getch();

 closegraph();
 }
Last edited on
Hi sir thomas! I already know the discussion about there and i already know how to used it. i just want to know is how am i going to change the font of one single string? do you have any idea sir?
If you want to change the font for only one output then you need to save the old font first, then change it for the next output and finally restore the old one.
The function you need is gettextsettings :
https://www.cs.colorado.edu/~main/bgi/doc/gettextsettings.html
Well, to be honest sir thomas. It is hard for me to understand of how to use gettextsettings to a begginer like me. Could you please teach me how to use it to make the one string change the font using it? thank you!
I am not sure what your problem is.
Run this demo it show how to change the font before the output.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

int main()
{
  int gm, gd;
  gd = VGA;
  gm = VGAHI;
  initgraph(&gd, &gm, "");

  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
  outtextxy(32, 8, "SANS_SERIF_FONT");

  settextstyle(DEFAULT_FONT, HORIZ_DIR, 4);
  outtextxy(32, 58, "DEFAULT_FONT");

  settextstyle(GOTHIC_FONT, HORIZ_DIR, 4);
  outtextxy(32, 108, "GOTHIC_FONT");

  settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
  outtextxy(32, 158, "SCRIPT_FONT");

  getch();

  closegraph();
}
I am sorry for not explaining clearly the problem is.

In the three out text that i encode on the Hydrogen part is: 1, H, Hydrogen (at the 16th line). I set the font for all and it is already done. So my problem is, the "H", which is in the middle of 1 and Hydrogen, must be bigger and also, for the rest elements that in there. So, i must do the same which how it form in the Periodic table. "1" is in the upper, "H" is in the middle and must be bigger and "Hydrogen" is at the bottom. So is it possible to change the size or font of the "H" only?
Have a look at this, you might need to play around with different font sizes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

int main()
{
  int gm, gd;
  gd = VGA;
  gm = VGAHI;
  initgraph(&gd, &gm, "");

  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 3);
  outtextxy(32, 8, "1");

  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
  outtextxy(60, 8, "H");

  settextstyle(SANS_SERIF_FONT, VERT_DIR, 3);
  outtextxy(100, 8, "Hydrogen");

  getch();

  closegraph();
}
ohh... i see. Thank you so much sir! Sorry for being too slow. Welll, i am okay now. Godbless!
Topic archived. No new replies allowed.