graphics.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
FONTS.C
                                             Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
/* FONTS.C illustrates font functions including:
 *   _registerfonts        _setfont            _outgtext
 *   _unregisterfonts      _getfontinfo        _getgtextextent
 *   _setgtextvector
 */
 
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graph.h>
 
#define NFONTS 6
 
unsigned char *face[NFONTS] =
{
    "Courier", "Helvetica", "Times Roman", "Modern", "Script", "Roman"
};
unsigned char *options[NFONTS] =
{
    "courier", "helv", "tms rmn", "modern", "script", "roman"
};
 
void main()
{
    unsigned char list[20];
    char fondir[_MAX_PATH];
    struct videoconfig vc;
    struct _fontinfo fi;
    short nfont, x, y;
 
    /* Read header info from .FON files in current or given directory. */
    if( _registerfonts( "*.FON" ) <= 0 )
    {
        _outtext( "Enter full path where .FON files are located: " );
        gets( fondir );
        strcat( fondir, "\\*.FON" );
        if( _registerfonts( fondir ) <= 0 )
        {
            _outtext( "Error: can't register fonts" );
            exit( 1 );
        }
    }
 
    /* Set highest available graphics mode and get configuration. */
    if( !_setvideomode( _MAXRESMODE ) )
        exit( 1 );
    _getvideoconfig( &vc );
 
    /* Display each font name centered on screen. */
    for( nfont = 0; nfont < NFONTS; nfont++ )
    {
        /* Build options string. */
        strcat( strcat( strcpy( list, "t'" ), options[nfont] ), "'");
        strcat( list, "h30w24b" );
 
        _clearscreen( _GCLEARSCREEN );
        if( _setfont( list ) >= 0 )
        {
            /* Use length of text and height of font to center text. */
            x = (vc.numxpixels / 2) - (_getgtextextent( face[nfont] ) / 2);
            y = (vc.numypixels / 2) + (_getgtextextent( face[nfont] ) / 2);
            if( _getfontinfo( &fi ) )
            {
                _outtext( "Error: Can't get font information" );
                break;
            }
            _moveto( x, y );
            if( vc.numcolors > 2 )
                _setcolor( nfont + 2 );
 
            /* Rotate and display text. */
            _setgtextvector( 1, 0 );
            _outgtext( face[nfont] );
            _setgtextvector( 0, 1 );
            _outgtext( face[nfont] );
            _setgtextvector( -1, 0 );
            _outgtext( face[nfont] );
            _setgtextvector( 0, -1 );
            _outgtext( face[nfont] );
        }
        else
        {
            _outtext( "Error: Can't set font: " );
            _outtext( list );
        }
        getch();
    }
    _unregisterfonts();
    _setvideomode( _DEFAULTMODE );
}