This blog is under construction

Saturday, 14 September 2013

installuserfont example in c

Header file:
    graphics.h

Synopsis:
      int installuserfont(char *name);
     
Description:
     installuserfont() installs a user defined font file and returns the font ID which can be used as the font style parameter for settextstyle().


installuserfont function in c graphics



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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int font, err, midx, midy;

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

        /* read result of last graphics operation */
        err = graphresult();

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

        /* mid position in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* install a user defined font file */
        font = installuserfont("USER.CHR");

        err = graphresult();

        if (err != grOk) {
                /* error occurred */
                printf("Error in installing user font:%s",
                                                grapherrormsg(err));
                return 0;
        }

        /* select the user font */
        settextstyle(font, HORIZ_DIR, 10);

        /* output some text */
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        outtextxy(midx, midy, "Hello World!");

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





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


No comments:

Post a Comment