home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
decus
/
RB140
/
grlib03a.arj
/
EFONT.C
< prev
next >
Wrap
Text File
|
1988-12-19
|
16KB
|
694 lines
/************************************************************************/
/* */
/* File Name: EFONT.C Created: 24-Jan-85 */
/* */
/*----------------------------------------------------------------------*/
/* Update & Modification Table */
/* */
/* Current Version Number (if any): */
/* */
/* Date Action */
/* ==== ====== */
/* */
/* 01-Feb-85 Banner changed to double width, double height. */
/* Use any key to toggle a cell in */
/* */
/* 27-Apr-85 Conversion to MSDOS */
/* 15-May-85 Conversion to V3.0 of Graphics Library */
/* */
/*----------------------------------------------------------------------*/
/* */
/* Author: Ian Houlding, */
/* CISC Basingstoke, */
/* Hampshire. */
/* */
/* (c) Digital Equipment Co. Ltd. 1985 */
/* */
/************************************************************************/
#include <stdio.h>
#include <graph.h>
#include <color3.h>
#include <key.h>
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define US_CUR 4
#define BOX_CUR 5
#define ROW_MIN 30
#define ROW_MAX 120
#define COL_MIN 160
#define COL_MAX 216
#define CH_ROW ROW_MIN + 50
#define CH_COL COL_MAX + 24
#define ROW_1 190
#define ROW_2 160
#define COL_1 64
#define BEEP() putchar('\007')
#define x_pos t_x
#define y_pos t_y
int cell_idx,
cur_row,
cur_state,
cur_cnt;
char hdg[] = " GRAPHIC FONT GENERATOR ";
main(argc, argv)
int argc;
char *argv[];
{
if (argc < 2 || argc > 3) {
printf("usage: efont reference_font_name font_file_name\n");
exit(1);
}
if (openws(0, SMIDCOL) == EOF) exit(1);
if (argc == 3) init1(argv[1], argv[2]);
else init1(argv[1], "");
menu(argv[2]);
kill_gr();
}
init1(r_fnt, f_nam)
char *r_fnt, *f_nam;
{
register int i;
register unsigned char *s;
char fnt_nam[41];
strcpy(fnt_nam, r_fnt);
strcat(fnt_nam, ".set");
if (ld_font(fnt_nam, 0) == EOF) exit(1);
if (*f_nam) {
strcpy(fnt_nam, f_nam);
strcat(fnt_nam, ".set");
if (ld_font(fnt_nam, 1) == EOF) exit(1);
}
else {
s = tfonts[1] = malloc(2560);
for(i = 0; i < 2560; i++) *s++ = 0xFF;
}
s = tfonts[2] = malloc(2560);
for(i = 0; i < 2560; i++) *s++ = 0xFF;
cell_idx = 0;
s = tfonts[2]->f_char[2];
for(i = 0; i < 10; i++) *s++ = 0; /* solid block for large character */
s += 18;
*s++ = 0, *s++ = 0; /* underscore cursor */
*s++ = 0; /* box cursor */
for(i = 0; i < 8; i++) *s++ = 0x7E;
*s = 0;
g_on();
}
init2()
{
register int i;
int pnts[4];
cur_off(US_CUR);
clearws();
l_col = MAGENTA;
pnts[0] = CH_COL - 2;
pnts[1] = CH_ROW - 2;
pnts[2] = CH_COL + 9;
pnts[3] = CH_ROW + 11;
rectangle(pnts);
pnts[0] = COL_MIN - 1;
pnts[1] = ROW_MIN - 1;
pnts[2] = COL_MAX + 8;
pnts[3] = ROW_MAX + 10;
rectangle(pnts);
gtext(0,0,""); /* put graphics option into text mode */
x_pos = COL_1;
cur_row = y_pos = ROW_1;
t_font = 0;
disp_fnts();
t_sca = DH_DW;
g_string(0, 0, hdg, RED, CYAN);
t_sca = SH_SW;
i = 23 - (ROW_MAX / 10);
g_string(2, i, "Hex", YELLOW, BLACK); i += 2;
g_string(2, i, "Oct", YELLOW, BLACK); i += 2;
g_string(2, i, "Dec", YELLOW, BLACK); i += 2;
g_string(0, i, "Ascii", YELLOW, BLACK);
sho_big_cell(1, 0);
sho_data();
x_pos = COL_1;
cur_row = y_pos = ROW_1;
}
menu(argv)
char *argv;
{
int i, flag;
FILE *fptr;
char f_nam[41];
flag = 0;
RESTART:
if (flag) {
init2();
while ((i = getkey()) != EXIT) mod_font(i);
}
else flag++;
START:
if (argv) strcpy(f_nam, argv);
else f_nam[0] = '\0';
cur_off(US_CUR);
clearws();
t_font = 0;
t_sca = DH_DW;
g_string(0, 0, hdg, RED, CYAN);
t_sca = SH_SW;
g_string(7, 6, " 1 -- Enter FONT Generator ", RED, YELLOW);
g_string(7, 8, " 2 -- Save FONT in .SET file ", RED, YELLOW);
g_string(7, 10, " 3 -- Get FONT to edit ", RED, YELLOW);
g_string(7, 12, " 4 -- EXIT, IGNORE CHANGES ", RED, YELLOW);
i = (inkey() & 0x3F);
switch(i) {
case '1' :
goto RESTART;
case '2' :
g_string(0, 21, "Destination FONT file name -", YELLOW, BLACK);
g_string(29,21,((f_nam[0]) ? f_nam : " "),GREEN,DGREY);
g_string(29,21, "", GREEN, DGREY);
i = get_str(f_nam, 8);
if (i == EXIT) goto RESTART;
strcat(f_nam, ".set");
if ((fptr = fopen(f_nam, "wb")) == NULL) {
g_error(0, 23, " Unable to open destination file ");
goto START;
}
fwrite(tfonts[1], 2560, 1, fptr);
fclose(fptr);
goto START;
case '3' :
g_string(0, 21, " FONT file name to edit -", YELLOW, BLACK);
g_string(26,21,((f_nam[0]) ? f_nam : " "),GREEN,DGREY);
g_string(26,21, "", GREEN, DGREY);
i = get_str(f_nam, 8);
if (i == EXIT || f_nam[0] == 0) goto RESTART;
strcat(f_nam, ".set");
if ((fptr = fopen(f_nam, "rb")) == NULL) {
g_error(0, 23, " Unable to open source file ");
goto START;
}
ld_font(f_nam, 1);
fclose(fptr);
goto RESTART;
case '4' :
break;
}
}
mod_font(i)
int i;
{
int row_flag, tmpx, tmpy;
unsigned char *s, *d;
t_font = 1;
row_flag = FALSE;
switch(i) {
case HELP :
ef_help();
break;
case UP :
cell_idx -= 32;
if (cell_idx < 0) cell_idx += 256;
row_flag = TRUE;
if (cur_row == ROW_2) cur_row = ROW_1;
break;
case DOWN :
cell_idx += 32;
if (cell_idx > 255) cell_idx -= 256;
row_flag = TRUE;
if (cur_row == ROW_1) cur_row = ROW_2;
break;
case LEFT :
cell_idx--;
if (cell_idx < 0) cell_idx = 255;
if ((cell_idx % 32) == 31) {
row_flag = TRUE;
if (cur_row == ROW_2) cur_row = ROW_1;
}
break;
case RGHT :
cell_idx++;
if (cell_idx == 256) cell_idx = 0;
if ((cell_idx % 32) == 0) {
row_flag = TRUE;
if (cur_row == ROW_1) cur_row = ROW_2;
}
break;
case SEL :
cur_off(US_CUR);
s = tfonts[1]->f_char[cell_idx];
d = tfonts[2]->f_char[0];
for(i=0; i < 10; i++) *d++ = *s++;
i = chg_cell();
x_pos = COL_1 + ((cell_idx % 32) << 3);
y_pos = cur_row;
break;
case RET :
cell_idx -= (cell_idx % 32);
break;
case PF1 : /* lift reference font character */
s = tfonts[0]->f_char[cell_idx];
d = tfonts[2]->f_char[1];
for(i = 0; i < 10; i++) *d++ = *s++;
break;
case PF2 : /* lift new font character */
s = tfonts[1]->f_char[cell_idx];
d = tfonts[2]->f_char[1];
for(i = 0; i < 10; i++) *d++ = *s++;
break;
case PF3 : /* put lifted font character down */
s = tfonts[2]->f_char[1];
d = tfonts[1]->f_char[cell_idx];
for(i = 0; i < 10; i++) *d++ = *s++;
cur_off(US_CUR);
txt_col(CYAN, BLACK);
gchar(cell_idx);
x_pos -= 8;
break;
default :
if (i) BEEP();
i = 0;
}
if (i && i != SEL && i != EXIT && i != DO) {
cur_off(US_CUR);
sho_data();
x_pos = ((cell_idx % 32) << 3) + COL_1;
if (row_flag == TRUE) disp_fnts();
}
if (i == DO) {
s = tfonts[2]->f_char[0];
d = tfonts[1]->f_char[cell_idx];
for(i = 0; i < 10; i++) *d++ = *s++;
disp_fnts();
}
if (i) {
tmpx = x_pos, tmpy = y_pos;
x_pos = COL_MAX + 24, y_pos = ROW_MIN + 50;
txt_col(WHITE, BLACK);
gchar(cell_idx);
sho_big_cell(1, cell_idx);
t_font = 0;
x_pos = tmpx, y_pos = tmpy;
txt_col(WHITE, BLACK);
}
chk_cur(US_CUR);
}
get_char(y, ch, str)
int y;
char *ch, *str;
{
int i;
if (*ch == 0) g_string(32, y, " ", GREEN, DGREY);
x_pos -= 8;
while (i != EXIT && i != DO && i != RET) {
i = toupper(getkey());
if (i && in(i, str)) {
cur_off(US_CUR);
gchar(i);
*ch = i;
break;
}
chk_cur(US_CUR);
}
if (i == EXIT || i == DO) return(i);
else return(0);
}
in(i, str)
char i, *str;
{
while (*str) {
if (i == *str++) return(TRUE);
}
return(FALSE);
}
get_str(str, cnt)
char *str;
int cnt;
{
register int i, c;
char string[41];
int tx, tfnt;
tfnt = t_font;
t_font = 0;
for(i = 0; i < 9; string[i++] = 0);
c = 0;
while ((i = getkey()) != EXIT && i != RET && i != DO) {
if (i && c == 0) {
cur_off(US_CUR);
tx = x_pos;
for(c = cnt; c > 0; c--) gchar(' ');
x_pos = tx;
}
if (i == BS || i == DEL) {
if (c) {
cur_off(US_CUR);
x_pos -= 8;
gchar(' ');
x_pos -= 8;
string[--c] = 0;
}
else BEEP();
}
else if (i && c < cnt) {
i = toupper(i);
gchar(i);
string[c++] = i;
}
else if (i) BEEP();
chk_cur(US_CUR);
}
string[c] = 0;
cur_off(US_CUR);
if ((i == RET || i == DO) && string[0]) strcpy(str, string);
t_font = tfnt;
return(i);
}
char *spec_arry[4] = {"%3x","%03o","%3d"," %c"};
sho_data()
{
char num_str[4];
register int i, y;
int tmpx, tfnt;
tfnt = t_font;
t_font = 0;
tmpx = x_pos;
y = 23 - (ROW_MAX / 10);
for(i = 0; i < 4; i++) {
sprintf(num_str, spec_arry[i], cell_idx);
g_string(6, y, num_str, WHITE, BLACK);
y += 2;
}
x_pos = tmpx;
y_pos = cur_row;
t_font = tfnt;
}
disp_fnts()
{
int tmpx, tfnt;
tfnt = t_font;
tmpx = x_pos;
sho_fnt(0);
sho_fnt(1);
txt_col(DGREY, GREEN);
x_pos = tmpx;
y_pos = cur_row;
t_font = tfnt;
}
sho_fnt(fnt)
int fnt;
{
register int i, idx;
t_font = fnt;
x_pos = COL_1;
y_pos = ROW_1;
if (fnt == 0) {
txt_col(YELLOW, DGREY);
y_pos += 10;
}
else txt_col(CYAN, BLACK);
idx = cell_idx - (cell_idx % 32);
if (cur_row == ROW_2) {
idx -= 32;
if (idx < 0) idx += 256;
}
for(i = 0; i < 64; i++) {
gchar(idx++);
if (idx == 256) idx = 0;
if ((idx % 32) == 0) {
x_pos = COL_1;
y_pos -= 30;
}
}
}
chg_cell()
{
register int i, k;
int idx, tfnt;
tfnt = t_font;
t_font = 2;
sho_big_cell(2, 0);
x_pos = COL_MIN;
y_pos = ROW_MAX;
idx = 0;
while ((i = getkey()) != EXIT && i != DO) {
if ((i == UP || i == DOWN || i == LEFT || i == RGHT || i == RET)
&& cur_state == ON) cur_off(BOX_CUR);
switch(i) {
GO_UP: case UP :
y_pos += 10;
idx--;
if (y_pos > ROW_MAX) {
y_pos = ROW_MIN;
idx = 9;
}
break;
GO_DN: case DOWN :
y_pos -= 10;
idx++;
if (y_pos < ROW_MIN) {
y_pos = ROW_MAX;
idx = 0;
}
break;
case DEL :
case LEFT :
x_pos -= 8;
if (x_pos < COL_MIN) {
x_pos = COL_MAX;
goto GO_UP;
}
break;
case RGHT :
x_pos += 8;
GO_RT: if (x_pos > COL_MAX) {
x_pos = COL_MIN;
goto GO_DN;
}
break;
case RET :
x_pos = COL_MIN;
break;
case REM :
for(k = 0; k < 10; tfonts[2]->f_char[0][k++] = 0xff);
cur_off(BOX_CUR);
sho_big_cell(2, 0);
x_pos = COL_MIN;
y_pos = ROW_MAX;
idx = 0;
break;
default :
if (i >= ' ' && i < DEL) {
k = (128 >> ((x_pos - COL_MIN) >> 3));
tfonts[2]->f_char[0][idx] ^= k;
cur_off(BOX_CUR);
txt_col(DGREY, GREEN);
gchar((tfonts[2]->f_char[0][idx] & k) ? 2 : 3);
sho_char(2, 0);
goto GO_RT;
}
else if (i) BEEP();
}
chk_cur(BOX_CUR);
}
cur_off(BOX_CUR);
t_font = tfnt;
return(i);
}
sho_big_cell(fnt, fchar)
int fnt, fchar;
{
register int msk, x;
int idx, tfnt;
unsigned char str[9], *c;
tfnt = t_font;
t_font = 2;
c = tfonts[fnt]->f_char[fchar];
idx = str[8] = 0;
for(y_pos = ROW_MAX; y_pos >= ROW_MIN; idx++, y_pos -= 10) {
msk = 128;
for(x = 0; x < 8; msk >>= 1, x++) str[x] = (c[idx] & msk) ? 2 : 3;
sho_char(fnt, fchar);
g_string((COL_MIN >> 3), ((230 - y_pos) / 10), str, DGREY, GREEN);
}
t_font = tfnt;
}
sho_char(fnt, fchar)
int fnt, fchar;
{
int tmpx, tmpy, tfnt;
tfnt = t_font;
t_font = fnt;
tmpx = x_pos;
tmpy = y_pos;
x_pos = COL_MAX + 24;
y_pos = ROW_MIN + 50;
txt_col(WHITE, BLACK);
gchar(fchar);
x_pos = tmpx;
y_pos = tmpy;
t_font = tfnt;
}
cur_off(c)
char c;
{
if (cur_state == ON) put_cur(c);
cur_state = OFF;
cur_cnt = 0x200;
}
chk_cur(c)
char c;
{
if (--cur_cnt < 0) cur_cnt = 0x200;
if (cur_cnt) return;
else {
cur_state = (cur_state == ON) ? OFF : ON;
cur_cnt = (cur_state == ON) ? 0x300 : 0x200;
put_cur(c);
}
}
put_cur(c)
char c;
{
int tfnt, tcol;
tfnt = t_font;
tcol = fgbg;
t_font = 2;
setwmode(COMPLIMENT);
txt_col(DGREY, BLACK);
t_font = 2;
gchar(c);
x_pos -= 8;
setwmode(REPLACE);
fgbg = tcol;
gdc_nb();
a_fgbg();
t_font = tfnt;
}
g_error(x, y, str)
int x, y;
char *str;
{
int i, j;
for(i = 0; i < 10; i++) {
g_string(x, y, str, RED, YELLOW);
for(j = 0; j < 10000; j++);
g_string(x, y, str, BLACK, YELLOW);
for(j = 0; j < 10000; j++);
}
}
g_string(x, y, str, f, b)
int x, y, f, b;
char *str;
{
x_pos = (x << 3);
y_pos = 230 - (y * 10);
txt_col(f, b);
while (*str) gchar(*str++);
}
txt_col(f, b)
int f, b;
{
fgbg = ((f << 4) | b);
gdc_nb();
a_fgbg();
}
ef_help()
{
cur_off(US_CUR);
dis_gr();
save_ws(0);
openws(1, SHIGHCOL);
g_on();
if ((gr_data[1].ws_flags & WS_SAVED) == 0) {
t_sca = DH_DW;
g_string(24, 1, " FONT GENERATOR HELP PAGE ", RED, CYAN);
t_sca = SH_DW;
g_string(24, 2, " Type any key to continue ", YELLOW, CYAN);
g_string(0, 5," Select Mode ", RED, CYAN);
t_sca = SH_SW;
g_string(4, 7, "ARROW KEYS -", RED, BLACK);
g_string(17,7, "Enables you to move the cursor around the font to the desired position", YELLOW, BLACK);
g_string(4, 8, "RETURN -", RED, BLACK);
g_string(17,8, "Places the cursor at the start of the current row", YELLOW, BLACK);
g_string(4, 9, "Select -", RED, BLACK);
g_string(17,9, "Puts you into 'Modify' mode to change the character uder the cursor", YELLOW, BLACK);
g_string(4,10, "PF1 -", RED, BLACK);
g_string(17,10,"Picks up the character uder the cursor which is in the reference font (Top Rows)", YELLOW, BLACK);
g_string(4,11, "PF2 -", RED, BLACK);
g_string(17,11,"As for PF1 except it picks up the character in the edited font (Bottom Rows)", YELLOW, BLACK);
g_string(4, 12,"PF3 -", RED, BLACK);
g_string(17,12,"Drops the character picked up with PF1 or PF2 at the current position", YELLOW, BLACK);
g_string(4, 13,"EXIT -", RED, BLACK);
g_string(17,13,"Return to the Main Menu", YELLOW, BLACK);
t_sca = SH_DW;
g_string(0, 16," Modify Mode ", RED, CYAN);
t_sca = SH_SW;
g_string(4,18, "ARROW KEYS -", RED, BLACK);
g_string(17,18,"Moves the cursor to the required pixel location within the character cell", YELLOW, BLACK);
g_string(4,19, "RETURN -", RED, BLACK);
g_string(17,19,"Moves the cursor to the left hand end of the current row", YELLOW, BLACK);
g_string(4,20, "REMOVE -", RED, BLACK);
g_string(17,20,"Clears the whole area to the background colour", YELLOW, BLACK);
g_string(4,21, "DO -", RED, BLACK);
g_string(17,21,"Accepts all changes and reverts you to 'SELECT' mode", YELLOW, BLACK);
g_string(4,22, "EXIT -", RED, BLACK);
g_string(17,22,"As for DO but ignores any changes that have been made", YELLOW, BLACK);
g_string(4,23, "OTHER KEYS -", RED, BLACK);
g_string(17,23,"Toggles the current pixel location on or off", YELLOW, BLACK);
save_ws(1);
}
else restore_ws(1);
inkey();
dis_gr();
openws(0, SMIDCOL);
g_on();
restore_ws(0);
}