home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
FGDEMO40.ZIP
/
SOURCE.COM
/
CHAR.C
< prev
next >
Wrap
Text File
|
1995-02-12
|
6KB
|
216 lines
/**********************************************************************\
* *
* char.c -- FGDEMO character display and management routines *
* *
\**********************************************************************/
#include "defs.h"
char *pfont;
int spacing[] = {
/* ! " # $ % & ' ( ) * + , - */
4, 7, 9, 8,13, 9, 4, 5, 5, 8, 8, 4, 6,
/* . / 0 1 2 3 4 5 6 7 8 9 : */
4, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 4,
/* ; < = > ? @ A B C D E F G */
4, 8, 8, 8, 8,13,10,10, 9,10, 9, 9,10,
/* H I J K L M N O P Q R S T */
10, 4, 7, 9, 9,12,10,10,10,10,11, 9,10,
/* U V W X Y Z [ \ ] ^ _ ` a */
10,10,16,12,12,11, 5, 6, 5, 7, 9, 6, 8,
/* b c d e f g h i j k l m n */
8, 8, 8, 8, 5, 8, 8, 4, 4, 8, 4,12, 8,
/* o p q r s t u v w x y z { */
8, 8, 8, 7, 8, 5, 8,10,12,10,10, 8, 6,
/* | } ~ */
5, 6,12};
/**********************************************************************\
* *
* center_pstring -- display proportional characters, centered *
* *
\**********************************************************************/
void center_pstring(char *string,int x1,int x2,int y)
{
register int x;
x = get_center(string,x1,x2);
put_pstring(string,x,y);
}
/**********************************************************************\
* *
* first_nonblank -- find first character that is not a blank *
* *
\**********************************************************************/
char first_nonblank(char *string)
{
register int i;
char c;
i = 0;
for(;;)
{
c = string[i++];
if (c == 0)
return(0);
else if (c > 32)
return(c);
}
}
/**********************************************************************\
* *
* get_center -- locate center for proportionally-spaced characters *
* *
\**********************************************************************/
get_center(char *string,int x1,int x2)
{
return(((x1 + x2) / 2) - (length_pstring(string)/ 2));
}
/**********************************************************************\
* *
* get_font -- retrieve the 14pt bitmapped font character definitions *
* *
\**********************************************************************/
void get_font()
{
register int i;
register int index;
int x, y;
int yoffset;
/* allocate dynamic memory for the fonts */
pfont = malloc(2632);
yoffset = 18;
/* if the allocate failed or the font file isn't present, go no farther */
if (pfont == (char *)NULL)
abort_program("Not enough memory to load font.\n");
if (!exists("FONT14.PCX"))
abort_program("File missing: FONT14.PCX.\n");
/* display the 14pt font on the hidden page */
fg_setpage(hidden);
fg_showpcx("FONT14.PCX",1);
/* retrieve the font */
fg_setcolor(11);
index = 0;
for (i = 0; i < 94; i++)
{
x = 1 + (i/13) * 16;
y = yoffset + (i%13) * (PTSIZE+1);
fg_move(x,y);
fg_getmap(&pfont[index*2],2,PTSIZE); /* put in bitmap array */
index += PTSIZE;
}
}
/**********************************************************************\
* *
* length_pstring -- compute the length of a proportional string *
* *
\**********************************************************************/
length_pstring(char *string)
{
register int i;
register int nchar;
int length;
char ch;
/* number of characters in the string */
nchar = strlen(string);
if (nchar == 0) return(0);
length = 0;
/* total up pixel width of each character */
for (i = 0; i < nchar; i++)
{
ch = string[i] - (char)33;
if (ch < 0)
length += 8;
else
length += spacing[ch];
}
return(length);
}
/**********************************************************************\
* *
* put_pstring -- display proportionally-spaced characters *
* *
\**********************************************************************/
void put_pstring(char *string,int x,int y)
{
register int i;
register int nchar;
int index;
char ch;
/* get the length of the string */
nchar = strlen(string);
if (nchar == 0) return;
/* display each character as a mode-independent bitmap */
for (i = 0; i < nchar; i++)
{
ch = string[i] - (char)33;
/* printable character: greater than ASCII 32 */
if (ch >= 0)
{
index = ch * (PTSIZE * 2);
fg_move(x,y);
fg_drawmap(&pfont[index],2,PTSIZE);
/* increment x depending on the proportional space */
x += spacing[ch];
}
/* assume that white space will be 8 pixels wide */
else
x += 8;
}
}
/**********************************************************************\
* *
* row_offset -- return the row offset in pixels for the font size *
* *
\**********************************************************************/
row_offset(int nrows)
{
return(nrows*PTSIZE);
}