This blog is under construction

Saturday 14 September 2013

gettextsettings example in c

Header file:
    graphics.h

Synopsis:
      void gettextsettings(struct textsettingstype *typeinfo);
     struct textsettingstype {
          int font;  /* font style */
          int direction;  /* font direction */
          int charsize;  /* font size */
          int horiz;   /* horizontal justification - left, right or center */
          int vert;  /* vertical justification - bottom, center or top */
     }

     
Description:
     gettextsettings() gets current graphic text font settings.


gettextsettings function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, x, y, ht;
        struct textsettingstype textinfo;
        char style[64], tdir[64], csize[64];
        char vjustify[64], hjustify[64];
        char *font[] = {"Defualt", "Triplex", "small",
                             "Sans serif", "Gothic"};
        char *chardir[] = {"Horizontal", "vertical"};
        char *hjust[] = {"Left", "Center", "Right"};
        char *vjust[] = {"Bottom", "Center", "Top"};

        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,
                                              "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                getch();
                return 0;
        }

        /* get information about current text settings */
        gettextsettings(&textinfo);

        /* convert text information into strings */
        sprintf(style, "Text style: %s", font[textinfo.font]);
        sprintf(tdir, "Text direction: %s", chardir[textinfo.direction]);
        sprintf(csize, "Text size: %d", textinfo.charsize);
        sprintf(hjustify, "%s is the horizontal justification.",
                                                hjust[textinfo.horiz]);
        sprintf(vjustify, "%s is the vertical justification.",
                                                vjust[textinfo.vert]);

        /* display the information */
        delay(700);
        ht = textheight("W");
        x = 30, y = 20;
        settextstyle(SMALL_FONT, HORIZ_DIR, 5);
        outtextxy(x, y, style);
        outtextxy(x, y + 2 * ht, tdir);
        outtextxy(x, y + 4 * ht, csize);
        outtextxy(x, y + 6 * ht, hjustify);
        outtextxy(x, y + 8 * ht, vjustify);

        /* clean up */
        getch();
        closegraph();
        return 0;
  }





Output: (gettextsettings built-in function in c graphics.h)


1 comment: