home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
USEFONT.ZIP
/
USEFONT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-04
|
4KB
|
215 lines
/**
*
* DESCRIPTION:
*
* USEFONT version 1.01 - OS/2 VIO mode font utility
*
* Copyright (C) 1991 Boon Song
* P.O. Box 2013, OIT
* Klamath Falls, OR 97601
*
* HISTORY:
*
* BY DATE COMMENT
* ---- ----- -------
* Boon 06/89 first started (version 1.00)
* Boon 10/91 revised (version 1.01)
*
* TERMS & CONDITIONS:
*
* May be used and/or distributed for non-profitable purposes only
*
**/
#define INCL_DOS
#define INCL_SUB
#include <os2.h>
#include <stdio.h>
#include <string.h>
#define VIO 0
#define EXT ".fon"
#define EGA 2
#define VGA 3
void VioClrScr(void)
{
VIOMODEINFO vmi;
USHORT i;
vmi.cb = sizeof(vmi);
VioGetMode(&vmi,0);
for(i=0 ; i < vmi.row ; i++)
VioWrtNChar(" ",vmi.col,i,0,0);
}
void main(int argc,char *argv[])
{
VIOCURSORINFO vcsi;
VIOFONTINFO vfi;
VIOCONFIGINFO vci;
VIOMODEINFO vmi;
FILESTATUS fs;
char FName[64];
char far *pFontBuf;
UCHAR FontPoint;
HFILE hFile;
USHORT i,
rc,
Action,
row,
Selector,
ByteRead;
/*
Known fonts : 3584,8,8,14,25,EGA
2048,8,8, 8,43,EGA
4096,9,8,16,25,VGA
2048,9,8, 8,50,VGA
*/
vci.cb = sizeof(vci);
if(rc=VioGetConfig(0,&vci,VIO)) {
printf("VioGetConfig error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
if(vci.adapter < EGA) {
printf("\nEGA or better adapter required.\n");
DosExit(EXIT_PROCESS,2);
}
if(argc < 2) {
puts("\nusefont v1.01\n\nusage: usefont fontfile[.ext]");
DosExit(EXIT_PROCESS,0);
}
vmi.cb = sizeof(vmi);
if(rc=VioGetMode(&vmi,VIO)) {
printf("\nVioGetMode error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
strcpy(FName,argv[1]);
i = strlen(FName);
while(i) {
if(FName[i]=='.')
break;
i--;
}
if(!i)
strcat(FName,EXT);
if(rc=DosOpen(FName,&hFile,&Action,0L,0x23,1,0x42,0L)) {
printf("\nCannot open file %s\nDosOpen error=%u\n",FName,rc);
DosExit(EXIT_PROCESS,1);
}
if(rc=DosQFileInfo(hFile,1,&fs,sizeof(fs))) {
printf("\nDosQFileInfo error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
FontPoint = (UCHAR) (fs.cbFile/256);
switch(FontPoint) {
case 14 : if(vci.adapter!=EGA) {
printf("\n%s - invalid font file for this adapter.\n",FName);
DosExit(EXIT_PROCESS,3);
}
vfi.cxCell = 8;
vfi.cyCell = 14;
row = 25;
break;
case 8 : if(vci.adapter==EGA) {
vfi.cxCell = 8;
vfi.cyCell = 8;
row = 43;
}
else {
vfi.cxCell = 9;
vfi.cyCell = 8;
row = 50;
}
break;
case 16 : if(vci.adapter!=VGA) {
printf("\n%s - invalid font file for this adapter.\n",FName);
DosExit(EXIT_PROCESS,3);
}
else {
vfi.cxCell = 9;
vfi.cyCell = 16;
row = 25;
}
break;
default : printf("\n%s - possibly not a font file.\n",FName);
DosExit(EXIT_PROCESS,3);
}
if(rc=VioGetCurType(&vcsi,VIO)) {
printf("\nVioGetCurType error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
if(vmi.row!=row) {
vmi.row = row;
if(rc=VioSetMode(&vmi,VIO)) {
printf("\nVioSetMode error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
vcsi.yStart = vfi.cyCell-2;
vcsi.cEnd = vfi.cyCell-1;
}
vcsi.attr = 0;
if(rc=DosAllocSeg(fs.cbFile,&Selector,0)) {
printf("\nDosAllocSeg error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
pFontBuf = (char far *) ((ULONG) Selector << 16);
if(rc=(int)DosRead(hFile,pFontBuf,fs.cbFile,&ByteRead)) {
printf("\nDosRead error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
VioClrScr();
vfi.cb = sizeof(vfi);
vfi.type = 0;
vfi.cbData = fs.cbFile;
vfi.pbData = pFontBuf;
if(rc=VioSetFont(&vfi,VIO)) {
printf("\nVioSetFont error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
vcsi.attr = 0;
if(rc=VioSetCurType(&vcsi,VIO)) {
printf("\nVioSetCurType error=%u\n",rc);
DosExit(EXIT_PROCESS,1);
}
DosExit(EXIT_PROCESS,0);
}