settextstyle


Syntax
#include <graphics.h>
void settextstyle(int font, int direction, int charsize);
Description
settextstyle sets the text font, the direction in which text is displayed, and the size of the characters. A call to settextstyle affects all text output by outtext and outtextxy.

The parameters font, direction, and charsize passed to settextstyle are described in the following:

font: One 8x8 bit-mapped font and several "stroked" fonts are available. The 8x8 bit-mapped font is the default. The enumeration font_names, which is defined in graphics.h, provides names for these different font settings:

Name Value    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
SCRIPT_FONT 5 Stroked script font
SIMPLEX_FONT 6 Stroked triplex script font
TRIPLEX_SCR_FONT    7 Stroked triplex script font
COMPLEX_FONT 8 Stroked complex font
EUROPEAN_FONT 9 Stroked European font
BOLD_FONT 10 Stroked bold font
The default bit-mapped font is built into the graphics system. Stroked fonts are stored in *.CHR disk files, and only one at a time is kept in memory. Therefore, when you select a stroked font (different from the last selected stroked font), the corresponding *.CHR file must be loaded from disk.

To avoid this loading when several stroked fonts are used, you can link font files into your program. Do this by converting them into object files with the BGIOBJ utility, then registering them through registerbgifont.

direction: Font directions supported are horizontal text (left to right) and vertical text (rotated 90 degrees counterclockwise). The default direction is HORIZ_DIR. The size of each character can be magnified using the charsize factor. If charsize is nonzero, it can affect bit-mapped or stroked characters. A charsize value of 0 can be used only with stroked fonts.

Always use textheight and textwidth to determine the actual dimensions of the text.

Return Value

See also
gettextsettings
graphresults
installuserfont
settextjustify
setusercharsize
textheight
textwidth

Example
/* settextstyle example */ 

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

/* the names of the text styles supported */
char *fname[] = { "DEFAULT font",  "TRIPLEX font", 
                  "SMALL font",    "SANS SERIF_font", 
                  "GOTHIC_font",   "SCRIPT font",
                  "SIMPLEX font",  "TRIPLEX SCRIPT font",
                  "COMPLEX font",  "EUROPEAN font",
                  "BOLD font"};

int main(void)
{
   /* request autodetection */

   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\n", 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<=BOLD_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;
}

Back to index