home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / utils / convfont.c next >
Encoding:
C/C++ Source or Header  |  1993-08-10  |  1.8 KB  |  74 lines

  1. /* Convert standard binary font to codepage format */
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7.  
  8. int fontheight;
  9. int sfontsize;
  10. int font_nuchars;
  11. unsigned char sfontbuf[32 * 256];
  12. unsigned char tfontbuf[32 * 256];
  13. FILE *sf;
  14. FILE *tf;
  15.  
  16.  
  17. main( int argc, char **argv ) {
  18.         int i;
  19.         if (argc != 4) {
  20.             printf( "Syntax: convfont fontfile fontheight vgafontfile\n" );
  21.             printf(
  22.             "\nconvfont - convert standard format binary font to codepage format\n"
  23.             "The converted font is written to vgafontfile.\n");
  24.         printf(
  25.             "A binary font file of any number of characters up to 256 can be used, although\n"
  26.             "at least defining the first 128 characters is a good idea. The fontheight\n"
  27.             "should be in the range 1-32.\n"
  28.         );
  29.         exit( 1 );
  30.     } 
  31.     if ((sf = fopen( argv[1], "rb" )) == NULL) {
  32.         printf( "convfont: Unable to open file.\n" );
  33.         exit( 1 );
  34.     }
  35.     if ((tf = fopen( argv[3], "wb" )) == NULL) {
  36.         printf( "convfont: Unable to create file.\n" );
  37.         exit( 1 );
  38.     }
  39.     fontheight = atoi( argv[2] );
  40.     if (fontheight < 1 || fontheight > 32) {
  41.         printf( "convfont: Invalid fontheight.\n" );
  42.         exit( 1 );
  43.     }
  44.  
  45.     fseek( sf, 0, SEEK_END );
  46.     sfontsize = ftell( sf );
  47.     fseek( sf, 0, SEEK_SET );
  48.     font_nuchars = sfontsize / fontheight;
  49.     printf( "Converting %d characters\n", font_nuchars );
  50.     if (font_nuchars < 1 || font_nuchars > 256) {
  51.         printf( "convfont: Invalid number of characters in font.\n" );
  52.         exit( 1 );
  53.     }
  54.     fread( sfontbuf, 1, sfontsize, sf );
  55.     fclose(sf);
  56.     for (i = 0; i < font_nuchars; i++) {
  57.         int j;
  58.  
  59.         for (j = 0; j < fontheight; j++)
  60.             tfontbuf[i * 32 + j] =
  61.                 sfontbuf[i * fontheight + j];
  62.  
  63.         for (j = 0; j < 32 - fontheight; j++)
  64.             tfontbuf[i * 32 + fontheight] = 0;
  65.     }
  66.     /* clear remaining characters */
  67.     for (i = font_nuchars * 32; i < 32 * 256; i++)
  68.         tfontbuf[i] = 0;
  69.     printf("Writing font file.\n");
  70.     fwrite(tfontbuf, 1, 32 * 256, tf);
  71.     fclose(tf);
  72.     exit( 0 );
  73. }
  74.