home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / USEFONT.ZIP / USEFONT.C < prev    next >
C/C++ Source or Header  |  1991-10-04  |  4KB  |  215 lines

  1. /**
  2.  *
  3.  *  DESCRIPTION:
  4.  *
  5.  *      USEFONT version 1.01 - OS/2 VIO mode font utility
  6.  *
  7.  *      Copyright (C) 1991 Boon Song
  8.  *      P.O. Box 2013, OIT
  9.  *      Klamath Falls, OR 97601
  10.  *
  11.  *  HISTORY:
  12.  *
  13.  *     BY     DATE    COMMENT
  14.  *     ----   -----   -------
  15.  *     Boon   06/89   first started (version 1.00)
  16.  *     Boon   10/91   revised       (version 1.01)
  17.  *
  18.  *  TERMS & CONDITIONS:
  19.  *
  20.  *     May be used and/or distributed for non-profitable purposes only
  21.  *
  22.  **/
  23.  
  24. #define INCL_DOS
  25. #define INCL_SUB
  26. #include <os2.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #define VIO 0
  30. #define EXT ".fon"
  31. #define EGA 2
  32. #define VGA 3
  33.  
  34. void VioClrScr(void)
  35. {
  36.   VIOMODEINFO vmi;
  37.   USHORT i;
  38.  
  39.   vmi.cb = sizeof(vmi);
  40.  
  41.   VioGetMode(&vmi,0);
  42.  
  43.   for(i=0 ; i < vmi.row ; i++)
  44.     VioWrtNChar(" ",vmi.col,i,0,0);
  45. }
  46.  
  47. void main(int argc,char *argv[])
  48. {
  49.   VIOCURSORINFO vcsi;
  50.   VIOFONTINFO    vfi;
  51.   VIOCONFIGINFO vci;
  52.   VIOMODEINFO    vmi;
  53.   FILESTATUS    fs;
  54.  
  55.   char       FName[64];
  56.   char far *pFontBuf;
  57.   UCHAR    FontPoint;
  58.  
  59.   HFILE  hFile;
  60.  
  61.   USHORT i,
  62.      rc,
  63.      Action,
  64.      row,
  65.      Selector,
  66.      ByteRead;
  67.  
  68. /*
  69.    Known fonts : 3584,8,8,14,25,EGA
  70.          2048,8,8, 8,43,EGA
  71.          4096,9,8,16,25,VGA
  72.          2048,9,8, 8,50,VGA
  73. */
  74.  
  75.   vci.cb = sizeof(vci);
  76.  
  77.   if(rc=VioGetConfig(0,&vci,VIO)) {
  78.     printf("VioGetConfig error=%u\n",rc);
  79.     DosExit(EXIT_PROCESS,1);
  80.   }
  81.  
  82.   if(vci.adapter < EGA) {
  83.     printf("\nEGA or better adapter required.\n");
  84.     DosExit(EXIT_PROCESS,2);
  85.   }
  86.  
  87.   if(argc < 2) {
  88.     puts("\nusefont v1.01\n\nusage: usefont fontfile[.ext]");
  89.     DosExit(EXIT_PROCESS,0);
  90.   }
  91.  
  92.   vmi.cb = sizeof(vmi);
  93.  
  94.   if(rc=VioGetMode(&vmi,VIO)) {
  95.     printf("\nVioGetMode error=%u\n",rc);
  96.     DosExit(EXIT_PROCESS,1);
  97.   }
  98.  
  99.   strcpy(FName,argv[1]);
  100.  
  101.   i = strlen(FName);
  102.  
  103.   while(i) {
  104.     if(FName[i]=='.')
  105.       break;
  106.     i--;
  107.   }
  108.  
  109.   if(!i)
  110.     strcat(FName,EXT);
  111.  
  112.   if(rc=DosOpen(FName,&hFile,&Action,0L,0x23,1,0x42,0L)) {
  113.     printf("\nCannot open file %s\nDosOpen error=%u\n",FName,rc);
  114.     DosExit(EXIT_PROCESS,1);
  115.   }
  116.  
  117.   if(rc=DosQFileInfo(hFile,1,&fs,sizeof(fs))) {
  118.     printf("\nDosQFileInfo error=%u\n",rc);
  119.     DosExit(EXIT_PROCESS,1);
  120.   }
  121.  
  122.   FontPoint = (UCHAR) (fs.cbFile/256);
  123.  
  124.   switch(FontPoint) {
  125.     case 14 : if(vci.adapter!=EGA) {
  126.         printf("\n%s - invalid font file for this adapter.\n",FName);
  127.         DosExit(EXIT_PROCESS,3);
  128.           }
  129.           vfi.cxCell = 8;
  130.           vfi.cyCell = 14;
  131.           row = 25;
  132.           break;
  133.  
  134.     case  8 : if(vci.adapter==EGA) {
  135.         vfi.cxCell = 8;
  136.         vfi.cyCell = 8;
  137.         row = 43;
  138.           }
  139.           else {
  140.         vfi.cxCell = 9;
  141.         vfi.cyCell = 8;
  142.         row = 50;
  143.           }
  144.           break;
  145.  
  146.    case  16 : if(vci.adapter!=VGA) {
  147.         printf("\n%s - invalid font file for this adapter.\n",FName);
  148.         DosExit(EXIT_PROCESS,3);
  149.           }
  150.           else {
  151.         vfi.cxCell = 9;
  152.         vfi.cyCell = 16;
  153.         row = 25;
  154.           }
  155.           break;
  156.  
  157.     default : printf("\n%s - possibly not a font file.\n",FName);
  158.           DosExit(EXIT_PROCESS,3);
  159.  
  160.   }
  161.  
  162.   if(rc=VioGetCurType(&vcsi,VIO)) {
  163.     printf("\nVioGetCurType error=%u\n",rc);
  164.     DosExit(EXIT_PROCESS,1);
  165.   }
  166.  
  167.   if(vmi.row!=row) {
  168.  
  169.     vmi.row = row;
  170.  
  171.     if(rc=VioSetMode(&vmi,VIO)) {
  172.       printf("\nVioSetMode error=%u\n",rc);
  173.       DosExit(EXIT_PROCESS,1);
  174.     }
  175.  
  176.     vcsi.yStart = vfi.cyCell-2;
  177.     vcsi.cEnd    = vfi.cyCell-1;
  178.   }
  179.  
  180.   vcsi.attr = 0;
  181.  
  182.   if(rc=DosAllocSeg(fs.cbFile,&Selector,0)) {
  183.     printf("\nDosAllocSeg error=%u\n",rc);
  184.     DosExit(EXIT_PROCESS,1);
  185.   }
  186.  
  187.   pFontBuf = (char far *) ((ULONG) Selector << 16);
  188.  
  189.   if(rc=(int)DosRead(hFile,pFontBuf,fs.cbFile,&ByteRead)) {
  190.     printf("\nDosRead error=%u\n",rc);
  191.     DosExit(EXIT_PROCESS,1);
  192.   }
  193.  
  194.   VioClrScr();
  195.  
  196.   vfi.cb = sizeof(vfi);
  197.   vfi.type = 0;
  198.   vfi.cbData = fs.cbFile;
  199.   vfi.pbData = pFontBuf;
  200.  
  201.   if(rc=VioSetFont(&vfi,VIO)) {
  202.     printf("\nVioSetFont error=%u\n",rc);
  203.     DosExit(EXIT_PROCESS,1);
  204.   }
  205.  
  206.   vcsi.attr = 0;
  207.  
  208.   if(rc=VioSetCurType(&vcsi,VIO)) {
  209.     printf("\nVioSetCurType error=%u\n",rc);
  210.     DosExit(EXIT_PROCESS,1);
  211.   }
  212.  
  213.   DosExit(EXIT_PROCESS,0);
  214. }
  215.