home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
programs
/
amiga
/
pastex
/
archives
/
bm2font.lha
/
bm2font
/
bm2font.c.orig
< prev
next >
Wrap
Text File
|
1992-09-29
|
103KB
|
4,634 lines
/* Output from p2c, the Pascal-to-C translator */
/* From input file "bm2font.p" */
/*1:*/
#include "p2c.h"
/* p2c: bm2font.p, line 1: Note:
* Unexpected name "texfile" in program header [262] */
/* p2c: bm2font.p, line 1: Note:
* Unexpected name "tfmfile" in program header [262] */
/* p2c: bm2font.p, line 1: Note:
* Unexpected name "pxlfile" in program header [262] */
/* p2c: bm2font.p, line 1: Note:
* Unexpected name "bitmap" in program header [262] */
/* p2c: bm2font.p, line 1: Note:
* Unexpected name "tmpfil" in program header [262] */
/*logfile,*/
typedef uchar ebts;
typedef short halfk;
typedef long dynlong[26][129];
typedef unsigned short dynword[26][129];
typedef short korbyte[511];
typedef short spreadbyte[256];
/*55:*/
typedef unsigned short pxlstr;
typedef ebts pxla[65522L];
/*:55*/
/*59:*/
typedef short pxlba[32761];
/*:59*/
/*93:*/
typedef uchar dmatrix[7][7];
/*:93*/
#define maxmemsize 32760
/*94:*/
Static dmatrix ditherm = {
{ 1, 3, 6, 10, 18, 26, 38 },
{ 2, 4, 8, 12, 20, 28, 40 },
{ 5, 7, 9, 14, 22, 30, 42 },
{ 11, 13, 15, 16, 24, 32, 44 },
{ 17, 19, 21, 23, 25, 34, 46 },
{ 27, 29, 31, 33, 35, 36, 48 },
{ 37, 39, 41, 43, 45, 47, 49 }
};
/*:94*/
/*:1*/
/*2:*/
Static ebts hrep, vrep, xrep, yrep, patswitch, usecol,
pminval, pmaxval, bufsh, nextbuf, tmpcolor,
invbyte, invbit, xratio, yratio;
Static unsigned short tpal[256];
Static long bitspsam, rowspstrip;
Static unsigned short photoinf;
Static short colpos;
Static ebts pxllook[256];
Static ebts lutone[256];
Static ebts lutvga[256];
Static ebts lutsl[256];
Static double spreadcol, patref, greyunit;
Static short greykor;
Static short *gkorh, *gkordivp;
Static short *spreadvals;
Static short hktab[256];
Static boolean cspread;
Static unsigned short pxlcolor;
Static boolean greypxl, egastretch, ledprinter, distribute,
giftemp, pcxtemp;
Static short maxcol;
Static long usepxl, vusepxl, brightness;
Static short greypix;
Static ebts pattern[4][197][7];
Static unsigned short tab[64][3];
Static uchar ccol;
Static Char cref[77];
Static ebts b1[3000];
Static ebts b2[3000];
Static ebts b3[3000];
Static ebts b4[3000];
Static long linepos_, posbit;
Static halfk dbuf;
Static boolean zeroline, zerorow, nameok, fok;
Static Char cmd[256];
Static Char bmname[256];
Static Char font[256];
Static Char tmpname[256];
Static Char fontpre[256];
Static Char fontupc[256];
Static ebts curpat[2];
Static short gbufp, gbufpp;
Static halfk pxlinlen, zeropads;
Static short mapwidth, mapheight, maplines, freelines;
Static long mapinlen, newwidth, newheight;
Static short a, b, f, g, ly, lx, minx, maxx, i, j, v, k, pk,
pkn;
Static uchar pm, pn;
Static unsigned short pl, pb;
Static uchar c, cb;
Static long fh, sh, fw, sw;
Static unsigned short lf, lh, bc, ec, nw, nh, nd, ni, nl,
nk, ne, np;
Static union {
uchar b[4];
long i;
} cx;
Static long checksum, dsize;
Static long tabdsize[26];
Static long (*width)[129], (*height)[129];
Static unsigned short (*yoffset)[129], (*pwidth)[129],
(*pheight)[129];
Static long dirpoint[129];
Static pxlstr pkpoint[129];
Static long hres, vres;
Static double truehres, truevres;
Static long noffonts, nofchars, charpf;
/*logfile,*/
Static FILE *texfile;
Static FILE *bitmap, *pxlfile, *tmpfil;
Static short filestat;
Static unsigned short gi;
Static boolean invert;
Static unsigned short cv, dv, lv;
Static Char comment[256];
Static Char aliasname[256];
Static boolean aliasused;
Static double mapdiv; /*pxlmod:boolean;*/
Static long pkwidth, pkheight;
Static boolean nowhite;
Static pxlstr nextmemfree;
/*25:*/
Static ebts cutrep, outputbyte;
Static halfk cutlen;
Static boolean cutgrey; /*:25*/
/*53:*/
Static Char tfmstr[256];
Static uchar tfmb;
Static FILE *tfmfile;
/*:53*/
/*56:*/
Static uchar *pxlbm;
Static pxlstr pxlbmi;
/*:56*/
/*58:*/
Static uchar *pkbm;
Static short *repbm;
Static pxlstr pkloc;
/*:58*/
/*62:*/
Static short bitweight;
/*:62*/
/*64:*/
Static ebts car;
/*:64*/
/*69:*/
Static short cxoff, cyoff;
/*:69*/
/*73:*/
Static short power[9]; /*:73*/
/*95:*/
Static double valinc, redval, grx, grxzero;
Static long gradint;
Static uchar *greymem;
Static long pgreymem;
Static boolean randomst, newrandom;
Static Char texfile_NAME[_FNSIZE];
Static Char bitmap_NAME[_FNSIZE];
Static Char pxlfile_NAME[_FNSIZE];
Static Char tmpfil_NAME[_FNSIZE];
Static Char tfmfile_NAME[_FNSIZE];
/*:95*/
/*:2*/
/*6:*/
Static uchar korrlastb(uchar i, short j)
{
ebts k;
k = 8 - j;
if (k > 0) {
i >>= k;
i <<= k;
}
return i;
}
/*:6*/
/*7:*/
Static uchar pxladd(uchar i, uchar j, short k)
{
i = (i << k) & 255;
j >>= k;
return (i | j);
}
/*:7*/
/*8:*/
Static unsigned short getcolor(void)
{
halfk j, k;
unsigned short a, o;
ebts savcol, lcol, rcol, l, r;
if (cutgrey) {
if ((cutrep & 127) == 0) {
if (cutrep == 128)
colpos++;
cutrep = b1[(halfk)colpos];
colpos++;
}
savcol = b1[(halfk)colpos];
if (cutrep < 128)
colpos++;
cutrep--;
return savcol;
}
a = colpos;
colpos += bitspsam;
o = a + bitspsam - 1;
l = a & 7;
r = (o + 1) & 7;
k = o >> 3;
j = a >> 3;
lcol = b1[j];
rcol = b1[k];
if (k != j) {
savcol = lcol << l;
savcol = (savcol >> (l - r)) ^ (rcol >> (8 - r));
return savcol;
}
savcol = lcol << l;
savcol >>= l;
if (r > 0)
savcol >>= 8 - r;
return savcol;
}
/*:8*/
/*9:*/
Static Char *numtostr(Char *Result, long i)
{
Char nstr[256];
sprintf(nstr, "%ld", i);
return strcpy(Result, nstr);
}
/*:9*/
/*10:*/
Static void korrfont(void)
{
uchar i, j;
i = strpos2(font, "/", 1);
while (i > 0) {
strdelete((void *)font, 1, i);
i = strpos2(font, "/", 1);
}
j = strlen(font);
i = strpos2(font, ".", 1);
if (i != 0)
strdelete((void *)font, i, j - i + 1);
if (strlen(font) > 7)
font[7] = '\0';
}
/*:10*/
/*11:*/
Static void whatistrue(void)
{
hres = (long)floor(truehres + 0.5);
vres = (long)floor(truevres + 0.5);
hres /= 2;
vres /= 2;
hres -= hres & 7;
if (hres * vres <= 262136L)
return;
if (truehres > truevres) {
hres = (long)sqrt(262136.0) - 31;
vres = (long)(hres * truevres / truehres);
return;
}
if (truevres > truehres) {
vres = (long)sqrt(262136.0) - 31;
hres = (long)(vres * truehres / truevres);
} else {
hres = (long)sqrt(262136.0) - 31;
vres = hres;
}
} /*:11*/
/*12:*/
Static void outfix(long k)
{
short a;
long f;
char j;
long delta;
union {
ebts b[4];
long i;
} ax;
char dig[12];
ax.i = k;
#ifdef INTEL
a = (long)ax.b[3] * 16 + ax.b[2] / 16;
f = ((ax.b[2] & 15) * 256 + ax.b[1]) * 256 + ax.b[0];
#else
a = (long)ax.b[0] * 16 + ax.b[1] / 16;
f = ((ax.b[1] & 15) * 256 + ax.b[2]) * 256 + ax.b[3];
#endif
if (a > 2047) {
putc('-', texfile);
a = 4096 - a;
if (f > 0) {
f = 1048576L - f;
a--;
}
}
j = 0;
do {
dig[j] = a % 10;
a /= 10;
j++;
} while (a != 0);
do {
j--;
fprintf(texfile, "%d", dig[j]);
} while (j != 0);
putc('.', texfile);
f = f * 10 + 5;
delta = 10;
do {
if (delta > 1048576L)
f += 524288L - delta / 2;
fprintf(texfile, "%ld", f / 1048576L);
f = f % 1048576L * 10;
/* p2c: bm2font.p, line 98:
* Note: Using % for possibly-negative arguments [317] */
delta *= 10;
} while (f > delta);
}
/*:12*/
/*13:*/
Static void fileproblem(void)
{
printf("file-error %d : ", filestat);
switch (filestat) {
case 2:
printf("file not found");
break;
case 3:
printf("path not found");
break;
case 4:
printf("too many files open");
break;
case 5:
printf("file access denied");
break;
case 6:
printf("invalid file handle");
break;
case 12:
printf("invalid file access mode");
break;
case 15:
printf("invalid drive number");
break;
case 101:
printf("disk full");
break;
default:
printf("ask a tpc guru");
break;
}
printf("!\n");
if (pcxtemp)
/* p2c: bm2font.p, line 108:
* Note: Called procedure Exec [285] */
Exec("rm", "pcxtemp.tmp");
if (giftemp)
/* p2c: bm2font.p, line 108:
* Note: Called procedure Exec [285] */
Exec("rm", "giftemp.tmp");
if (greypxl)
/* p2c: bm2font.p, line 108:
* Note: Called procedure Exec [285] */
Exec("rm", tmpname);
}
/*:13*/
/*14:*/
Static void opentempfile(void)
{
strcpy(tmpname, "pcxtemp.tmp");
strcpy(tmpfil_NAME, "pcxtemp.tmp");
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("tempfile pcxtemp.tmp not accessable, abort\n");
fileproblem();
_Escape(0);
}
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
_SETIO(tmpfil != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (!fok)
return;
printf("Unable to create pcxtmp.tmp, abort\n");
fileproblem();
_Escape(0);
}
/*:14*/
/*15:*/
Static void picstretch(void)
{
short FORLIM;
printf("Stretching the picture because of odd aspect ratio\n");
posbit = 0;
giftemp = true;
strcpy(tmpname, "giftemp.tmp");
strcpy(tmpfil_NAME, "giftemp.tmp");
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("tempfile giftemp.tmp not accessable, abort\n");
fileproblem();
_Escape(0);
}
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
if (tmpfil == NULL)
_EscIO(FileNotFound);
while (!P_eof(bitmap)) {
fread(b1, mapinlen, 1, bitmap);
if (posbit == xratio) {
if (bitspsam == 8) {
FORLIM = mapinlen;
for (gbufp = 0; gbufp < FORLIM; gbufp++)
b3[gbufp] = ((unsigned)(b3[gbufp] + b1[gbufp])) >> 1;
} else if (bitspsam == 4) {
FORLIM = mapinlen;
for (gbufp = 0; gbufp < FORLIM; gbufp++) {
b = ((unsigned)
((b3[gbufp] >> 4) + (b1[gbufp] >> 4))) >> 1;
c = ((unsigned)
((b3[gbufp] & 15) + (b1[gbufp] & 15))) >> 1;
b3[gbufp] = (b << 4) + c;
}
}
_SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
posbit = 0;
}
posbit++;
if (posbit == xratio) {
FORLIM = mapinlen;
for (gbufp = 0; gbufp < FORLIM; gbufp++)
b3[gbufp] = b1[gbufp];
}
_SETIO(fwrite(b1, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
strcpy(bitmap_NAME, "giftemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
posbit = 0;
cutgrey = false;
if (pcxtemp) {
/* p2c: bm2font.p, line 136:
* Note: Called procedure Exec [285] */
Exec("rm", "pcxtemp.tmp");
pcxtemp = false;
}
}
/*:15*/
/*16:*/
Static void scaling(void)
{ /*17:*/
long newh, newv, counth, countv;
double scaleh, scalev, ledfac, repfac;
boolean grver, grhor, remlast;
short FORLIM;
if (ledprinter)
ledfac = 0.5;
else
ledfac = 0.0;
if (hrep != 1)
repfac = 2.0;
else
repfac = 1.0;
if (!greypxl) {
usepxl = 1;
vusepxl = 1;
bitspsam = 1;
}
if (newwidth != 0)
newwidth = (long)floor(newwidth * truehres / 25.4 /
(repfac * (usepxl + ledfac)) + 0.5);
if (newheight != 0)
newheight = (long)floor(newheight * truevres / 25.4 /
(repfac * (vusepxl + ledfac)) + 0.5);
if (newheight == 0)
newheight = (long)floor(
(double)mapheight / mapwidth * newwidth + 0.5);
if (newwidth == 0)
newwidth = (long)floor(
(double)mapwidth / mapheight * newheight + 0.5);
printf("Scaling the picture from %dx%d",
mapwidth, mapheight);
printf(" to %ldx%ld pixels\n", newwidth, newheight);
grver = (newheight > mapheight);
grhor = (newwidth > mapwidth);
if (grhor)
scaleh = newwidth / (newwidth - mapwidth + 1.0);
else
scaleh = mapwidth / (mapwidth - newwidth + 1.0);
if (grver) /*:17*/
scalev = newheight / (newheight - mapheight + 1.0);
else
scalev = mapheight / (mapheight - newheight + 1.0);
/*18:*/
if (giftemp)
strcpy(tmpname, "pcxtemp.tmp");
else
strcpy(tmpname, "giftemp.tmp");
strcpy(tmpfil_NAME, tmpname);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("tempfile %s not accessable, abort\n", tmpname);
fileproblem();
_Escape(0);
}
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
if (tmpfil == NULL)
_EscIO(FileNotFound);
/*:18*/
pxlinlen = (halfk)
(((unsigned long)(mapwidth * bitspsam + 7)) >> 3);
greypix = mapwidth;
if (cutgrey) {
checksum = mapheight;
pxlinlen = cutlen;
} else
checksum = mapheight;
pl = 0;
fseek(bitmap, posbit, SEEK_SET);
for (pk = 0; pk <= 255; pk++)
lutsl[pk] = pk << (8 - bitspsam);
newv = 1;
countv = 0;
remlast = false;
do {
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
colpos = 0;
cutrep = 0;
gbufpp = (newwidth * bitspsam + 7) / 8;
memset(b4, invbyte, 3000);
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b4[pk] = getcolor();
if (remlast) {
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b4[pk] = (b2[pk] * 2 + b4[pk]) / 3;
remlast = false;
}
gbufp = 0;
cb = 0;
memset(b3, invbyte, gbufpp);
newh = 1;
counth = 0;
pk = 0;
while (pk < greypix) { /*19:*/
cb = lutsl[b4[pk]];
dbuf = ((unsigned)gbufp) >> 3;
bufsh = gbufp & 7;
nextbuf = bufsh + bitspsam;
switch (bufsh) {
case 0:
b3[dbuf] = cb;
break;
default:
b3[dbuf] ^= cb >> bufsh;
if (nextbuf > 8)
b3[dbuf + 1] = cb << (8 - bufsh);
break;
}
gbufp += bitspsam;
pk++;
counth++;
if (counth != (long)floor(newh * scaleh + 0.5))
continue;
if (grhor) {
while (counth >= (long)floor(newh * scaleh + 0.5)) {
if (pk == greypix)
cb = lutsl[(b4[pk - 1] * 2 + b4[pk - 2]) / 3];
else
cb = lutsl[(b4[pk] * 2 + b4[pk - 1]) / 3];
dbuf = ((unsigned)gbufp) >> 3;
bufsh = gbufp & 7;
nextbuf = bufsh + bitspsam;
switch (bufsh) {
case 0:
b3[dbuf] = cb;
break;
default:
b3[dbuf] ^= cb >> bufsh;
if (nextbuf > 8)
b3[dbuf + 1] = cb << (8 - bufsh);
break;
}
gbufp += bitspsam;
counth++;
newh++;
}
continue;
}
while (counth == (long)floor(newh * scaleh + 0.5)) {
b4[pk + 1] = (b4[pk + 1] * 2 + b4[pk]) / 3;
pk++;
newh++;
counth++;
}
} /*:19*/
if (bitspsam == 1) {
dbuf = ((unsigned)gbufp) >> 3;
bufsh = gbufp & 7;
if (dbuf < gbufpp) {
cb = invbyte;
b3[dbuf] ^= cb >> bufsh;
}
}
fwrite(b3, gbufpp, 1, tmpfil);
checksum--; /*20:*/
countv++;
if (cutgrey)
pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 +
b1[pxlinlen - 2] + 2);
if (countv == (long)floor(newv * scalev + 0.5)) {
/*:20*/
if (grver) {
while (countv >= (long)floor(newv * scalev + 0.5)) {
fwrite(b3, gbufpp, 1, tmpfil);
countv++;
newv++;
}
} else {
while (countv == (long)floor(newv * scalev + 0.5)) {
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
colpos = 0;
cutrep = 0;
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b2[pk] = getcolor();
remlast = true;
if (checksum > 0)
checksum--;
if (cutgrey)
pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 +
b1[pxlinlen - 2] + 2);
newv++;
countv++;
}
}
}
} while (checksum != 0);
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL; /*21:*/
if (giftemp) { /*:21*/
/* p2c: bm2font.p, line 202:
* Note: Called procedure Exec [285] */
Exec("rm", "giftemp.tmp");
giftemp = false;
pcxtemp = true;
} else {
/* p2c: bm2font.p, line 202:
* Note: Called procedure Exec [285] */
Exec("rm", "pcxtemp.tmp");
giftemp = true;
pcxtemp = false;
}
strcpy(bitmap_NAME, tmpname);
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
posbit = 0;
cutgrey = false;
mapheight = newheight;
mapwidth = newwidth;
if (bitspsam == 1)
pxlinlen = (mapwidth + 7) / 8;
mapheight = P_maxpos(bitmap) / ((mapwidth * bitspsam + 7) / 8);
} /*:16*/
/* Local variables for tifint: */
struct LOC_tifint {
boolean le;
uchar tb[3000];
} ;
/*:22*/
/*23:*/
Local unsigned short tifword(unsigned short ba,
struct LOC_tifint *LINK)
{
if (LINK->le)
return ((unsigned short)LINK->tb[ba] +
(unsigned short)LINK->tb[ba + 1] * 256);
else
return ((unsigned short)(LINK->tb[ba] * 256) +
(unsigned short)LINK->tb[ba + 1]);
}
Local long tiflong(unsigned short ba,
struct LOC_tifint *LINK)
{
if (LINK->le)
return ((long)tifword(ba, LINK) +
(long)tifword(ba + 2, LINK) * 65536L);
else
return (LINK->tb[ba] * 16777216 + LINK->tb[ba + 1] * 65536 +
LINK->tb[ba + 2] * 256 + (long)LINK->tb[ba + 3]);
}
Local unsigned short tiftwobyte(unsigned short ba,
struct LOC_tifint *LINK)
{
if (LINK->le)
return ((unsigned short)LINK->tb[ba] +
(unsigned short)LINK->tb[ba + 1] * 256);
else
return ((unsigned short)(LINK->tb[ba] * 256) +
(unsigned short)LINK->tb[ba + 1]);
}
/*22:*/
Static void tifint(void)
{ /*:23*/
struct LOC_tifint V;
unsigned short i, j, l, m, tl;
long ll;
uchar tp;
boolean strips;
unsigned short ttype;
long tiftemp;
uchar FORLIM1;
/*24:*/
strips = false;
tl = fread(V.tb, 1, 2398, bitmap);
V.le = (V.tb[1] == 'I');
ll = tiflong(4, &V);
if (ll > 900) {
printf("I can't digest this\n");
_Escape(0);
}
l = ll;
m = tiftwobyte(l, &V);
l += 2;
for (i = 1; i <= m; i++) {
j = tiftwobyte(l, &V);
ttype = tiftwobyte(l + 2, &V);
if (ttype == 3)
tiftemp = tifword(l + 8, &V);
else
tiftemp = tiflong(l + 8, &V);
switch (j) {
case 256:
mapwidth = tiftemp;
break;
case 257:
mapheight = tiftemp;
break;
case 258:
if (tiftemp > 1) {
greypxl = true;
bitspsam = tiftemp;
if (bitspsam > 8) {
printf("Only up to 256 greyshades supported\n");
_Escape(0);
}
mapdiv = 1.0;
FORLIM1 = bitspsam;
for (tp = 1; tp <= FORLIM1; tp++)
mapdiv *= 2;
mapdiv /= 16;
}
break;
case 259:
if (tiftemp > 1) {
printf("No compression supported\n");
_Escape(0);
}
break;
case 262:
photoinf = tiftemp;
if (photoinf > 1) {
printf("No RGB colours supported\n");
_Escape(0);
}
if (photoinf == 0)
invert = !invert;
if (invert) {
invbit = 0;
invbyte = 0;
} else {
invbit = 1;
invbyte = 255;
}
photoinf = 15;
break;
case 273:
if (tiflong(l + 4, &V) != 1)
strips = true;
posbit = tiftemp;
break;
case 277:
if (tiftemp != 1) {
printf("Only monochrome images supported\n");
_Escape(0);
}
break;
case 278:
rowspstrip = tiftemp;
break;
case 290:
greyunit = 1.0;
FORLIM1 = tifword(l + 4, &V);
for (tp = 1; tp <= FORLIM1; tp++)
greyunit /= 10;
break;
case 291:
FORLIM1 = tiflong(l + 4, &V);
for (tp = 0; tp < FORLIM1; tp++)
tpal[tp] = V.tb[l + tp + 8];
break;
}
l += 12;
if (l >= tl) {
tl = fread(V.tb, 1, 2398, bitmap);
l = 0;
}
}
if (!strips)
return;
fseek(bitmap, posbit, SEEK_SET);
l = fread(V.tb, 1, 4, bitmap);
posbit = tiflong(0, &V);
}
/*:24*/
/*26:*/
Static void cutint(void)
{
long FORLIM;
short FORLIM1;
pxlinlen = 8;
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
if (pxlinlen != 8) {
printf("CUT file too small!\n");
_Escape(0);
}
mapheight = b1[3] * 256 + b1[2];
mapwidth = b1[1] * 256 + b1[0];
photoinf = 15;
mapdiv = 16.0;
posbit = 8;
cutlen = b1[7] * 256 + b1[6] + 2;
bitspsam = 8;
cutgrey = true;
greypxl = true;
if (!egastretch)
return;
mapinlen = mapwidth;
printf("Shrinking the CUT picture because of odd aspect ratio\n");
giftemp = true;
strcpy(tmpname, "giftemp.tmp");
strcpy(tmpfil_NAME, "giftemp.tmp");
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("tempfile giftemp.tmp not accessable, abort\n");
fileproblem();
_Escape(0);
}
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
if (tmpfil == NULL)
_EscIO(FileNotFound);
xratio = 2;
posbit = 0;
pxlinlen = cutlen;
FORLIM = mapheight;
for (checksum = 1; checksum <= FORLIM; checksum++) {
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
colpos = 0;
cutrep = 0;
FORLIM1 = mapinlen;
for (pk = 0; pk < FORLIM1; pk++)
b2[pk] = getcolor();
posbit++;
FORLIM1 = mapinlen;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b3[gbufp] = b2[gbufp];
if (posbit < xratio) {
_SETIO(fwrite(b2, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
if (posbit > xratio) {
FORLIM1 = mapinlen;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b3[gbufp] = ((unsigned)(b3[gbufp] + b2[gbufp])) >> 1;
_SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
posbit = 0;
if (xratio == 2)
xratio = 3;
else
xratio = 2;
}
pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 +
b1[pxlinlen - 2] + 2);
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
strcpy(bitmap_NAME, "giftemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
cutgrey = false;
posbit = 0;
}
typedef unsigned short tabcode[4097];
typedef uchar bytecod[4097];
typedef uchar ilaced[4];
typedef uchar ebts_;
typedef long gifmask[13];
/* Local variables for gifint: */
struct LOC_gifint {
ilaced ioff, ijump;
long lvr, linepos;
ebts_ logvr, codesample, modus, gifshift, nextbuf, bufsh;
unsigned short maxcode, hh;
short ec, ki;
unsigned short hell[256];
ebts_ gifbuf[3000];
unsigned short codepos, gifinlen, gotinlen;
long codesav;
unsigned short dbuf, linebytes;
} ;
/*:27*/
/*28:*/
Local uchar getgif(struct LOC_gifint *LINK)
{
fread(b1, 1, 1, bitmap);
return (b1[0]);
}
Local void gifout(unsigned short b, struct LOC_gifint *LINK)
{
short i, FORLIM;
ebts_ ibits;
if (gbufpp < 3000)
b2[gbufpp] = LINK->hell[b];
gbufpp++;
if (gbufpp != LINK->hh)
return;
LINK->codepos = 0;
memset(LINK->gifbuf, 0, LINK->linebytes);
FORLIM = LINK->hh;
for (i = 0; i < FORLIM; i++) {
LINK->dbuf = LINK->codepos / 8;
LINK->bufsh = LINK->codepos & 7;
LINK->nextbuf = LINK->bufsh + bitspsam;
cb = lutsl[b2[i]];
if (LINK->bufsh == 0)
LINK->gifbuf[LINK->dbuf] = cb;
else {
LINK->gifbuf[LINK->dbuf] |= cb >> LINK->bufsh;
if (LINK->nextbuf > 8)
LINK->gifbuf[LINK->dbuf + 1] = cb << (8 - LINK->bufsh);
}
LINK->codepos += bitspsam;
}
if (LINK->modus == 1)
fseek(tmpfil, LINK->linepos, SEEK_SET);
if (bitspsam == 1) {
i = 8 - (LINK->hh & 7);
if (i != 8) {
cb = LINK->gifbuf[LINK->dbuf] >> i;
cb <<= i;
LINK->gifbuf[LINK->dbuf] = cb;
cb = invbit;
for (ibits = 1; ibits <= i; ibits++) {
LINK->gifbuf[LINK->dbuf] ^= cb;
cb <<= 1;
}
}
}
_SETIO(fwrite(LINK->gifbuf, LINK->linebytes, 1, tmpfil) ==
1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
LINK->lvr++;
gbufpp = 0;
LINK->linepos += LINK->linebytes * LINK->ijump[LINK->logvr];
if (LINK->linepos >= P_maxpos(tmpfil) - 1) {
LINK->logvr++;
LINK->linepos = LINK->ioff[LINK->logvr] * LINK->linebytes;
}
}
Local unsigned short gifcode(struct LOC_gifint *LINK)
{
unsigned short Result;
static gifmask codemask = {
0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095
};
long codebyte;
while (LINK->gifshift < LINK->codesample) {
codebyte = b1[gbufp];
gbufp++;
if (gbufp == LINK->gifinlen) {
LINK->gifinlen = getgif(LINK);
LINK->gotinlen = fread(b1, 1, LINK->gifinlen, bitmap);
gbufp = 0;
if (LINK->gifinlen == 0)
printf("Code zero, proceeding\n");
if (LINK->gotinlen != LINK->gifinlen) {
b1[LINK->gotinlen] = LINK->ec;
LINK->gifinlen = LINK->gotinlen + 1;
}
}
LINK->codesav |= codebyte << LINK->gifshift;
LINK->gifshift += 8;
}
Result = LINK->codesav & codemask[LINK->codesample];
LINK->codesav = ((unsigned long)LINK->codesav) >>
LINK->codesample;
LINK->gifshift -= LINK->codesample;
LINK->ki++;
if (LINK->ki > LINK->maxcode && LINK->codesample < 12) {
LINK->codesample++;
LINK->maxcode = 1 << LINK->codesample;
}
return Result;
}
/*:26*/
/*27:*/
Static void gifint(void)
{ /*:28*/
struct LOC_gifint V;
static ilaced ioff = {
0, 4, 2, 1
};
static ilaced ijump = {
8, 8, 4, 2
};
unsigned short a, g, hi, vi, vh, hr, vr;
short merk, ic, codegif, i;
ebts_ colmap, b, col, bpp;
ebts_ gpal[256][3];
unsigned short *codtab;
unsigned short folge, minhell, maxhell;
uchar *anf;
Char hexbyte[7];
short FORLIM;
/*29:*/
memcpy(V.ioff, ioff, sizeof(ilaced));
memcpy(V.ijump, ijump, sizeof(ilaced));
printf("Decoding GIF file\n");
V.logvr = 0;
V.codesav = 0;
V.lvr = 0;
minhell = 9999;
maxhell = 0;
codtab = Malloc(sizeof(tabcode));
anf = Malloc(sizeof(bytecod));
opentempfile();
*hexbyte = '\0';
for (i = 1; i <= 3; i++) {
sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
/* p2c: bm2font.p, line 309:
* Note: Possible string truncation in assignment [145] */
}
if (strcmp(hexbyte, "GIF")) {
printf("This file is NOT a gif file!\n");
_Escape(0);
}
for (i = 1; i <= 3; i++) {
sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
/* p2c: bm2font.p, line 311:
* Note: Possible string truncation in assignment [145] */
}
if (strcmp(hexbyte, "GIF87a") && strcmp(hexbyte, "GIF89a")) {
printf("The program only supports version 87a and 89a!\n");
_Escape(0);
}
b = getgif(&V);
hr = b;
b = getgif(&V);
hr += b * 256;
b = getgif(&V);
vr = b;
b = getgif(&V);
vr += b * 256;
if (hr == 640 && vr == 350) {
xratio = 3;
yratio = 4;
}
b = getgif(&V);
colmap = b & 128;
colmap >>= 7;
col = b & 112;
col >>= 4;
col++;
bitspsam = b & 7;
bitspsam++;
b = getgif(&V);
b = getgif(&V);
if (colmap == 1) { /*30:*/
g = 1;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
g *= 2;
for (i = 0; i < g; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getgif(&V);
V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i]
[1] * 0.589 + gpal[i]
[2] * 0.114 + 0.5);
if (V.hell[i] > maxhell)
maxhell = V.hell[i];
}
for (i = 0; i < g; i++) /*:30*/
V.hell[i] = (long)floor(
(double)V.hell[i] / maxhell * (g - 1) + 0.5);
}
b = getgif(&V);
if (b != 44) { /*31:*/
while (b != 44) { /*:31*/
b = getgif(&V);
switch (b) {
case 249:
a = getgif(&V);
for (g = 0; g <= a; g++)
b = getgif(&V);
break;
case 254:
a = getgif(&V);
while (a != 0) {
for (g = 0; g <= a; g++)
b = getgif(&V);
a = b;
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
break;
case 1:
case 255:
a = getgif(&V);
for (g = 1; g <= a; g++)
b = getgif(&V);
a = getgif(&V);
while (a != 0) {
for (g = 0; g <= a; g++)
b = getgif(&V);
a = b;
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
break;
}
b = getgif(&V);
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
}
b = getgif(&V);
hi = b;
b = getgif(&V);
hi += b * 256;
b = getgif(&V);
vi = b;
b = getgif(&V);
vi += b * 256;
b = getgif(&V);
V.hh = b;
b = getgif(&V);
V.hh += b * 256;
b = getgif(&V);
vh = b;
b = getgif(&V);
vh += b * 256;
if (V.hh != hr || vh != vr)
printf("No fragments supported!\n");
V.linebytes = (V.hh * bitspsam + 7) / 8;
if (V.linebytes > 3000) {
V.linebytes = 3000;
printf("Sorry, had to cut picture to a width of 3000 bytes\n");
}
b = getgif(&V);
col = b & 128;
col >>= 7;
if (col != 0) {
bitspsam = b & 7;
bitspsam++; /*30:*/
g = 1;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
g *= 2;
for (i = 0; i < g; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getgif(&V);
V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i]
[1] * 0.589 + gpal[i]
[2] * 0.114 + 0.5);
if (V.hell[i] > maxhell)
maxhell = V.hell[i];
}
for (i = 0; i < g; i++) /*:30*/
V.hell[i] = (long)floor(
(double)V.hell[i] / maxhell * (g - 1) + 0.5);
}
for (pk = 0; pk <= 255; pk++)
lutsl[pk] = pk << (8 - bitspsam);
V.modus = b << 1;
V.modus >>= 7;
if (V.modus == 0)
printf("Image is loaded sequentially.\n");
else
printf(
"Interlaced mode, loading the image will take more time.\n");
if (V.modus != 0) {
memset(V.gifbuf, 0, V.linebytes);
for (i = 1; i <= vh; i++) {
_SETIO(fwrite(V.gifbuf, V.linebytes, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
V.linepos = 0;
V.logvr = 0;
fseek(tmpfil, 0, SEEK_SET);
}
bpp = b << 5;
bpp >>= 5;
bpp++;
bpp = getgif(&V);
g = 1 << bpp;
ic = 1 << bpp;
V.ec = ic + 1;
V.codesample = bpp + 1;
V.maxcode = 1 << V.codesample;
for (i = 0; i <= 4095; i++)
codtab[i] = 4098;
V.ki = V.ec + 1;
a = 4098;
gbufpp = 0;
V.gifshift = 0;
V.gifinlen = getgif(&V);
fread(b1, V.gifinlen, 1, bitmap);
gbufp = 0;
if (V.gifinlen == 0)
_Escape(0);
merk = 0; /*32:*/
while (V.lvr < vh) { /*:32*/
codegif = gifcode(&V);
if (codegif == V.ec) {
printf("End of code before gif image completed!\n");
V.lvr = vh;
continue;
}
if (codegif == ic) {
for (i = 0; i <= 4095; i++)
codtab[i] = 4098;
V.ki = V.ec + 1;
V.codesample = bpp + 1;
V.maxcode = 1 << V.codesample;
a = 4098;
continue;
}
if (codegif < ic)
gifout(codegif, &V);
else {
if (codtab[codegif] == 4098) {
if (codegif != V.ki - 2) {
printf("Bytes are mangled!\n");
_Escape(0);
}
folge = a;
merk++;
while (folge > ic)
folge = codtab[folge];
b3[merk] = folge;
anf[V.ki - 2] = folge;
folge = a;
} else
folge = codegif;
while (folge > ic && folge <= 4095) {
merk++;
b3[merk] = anf[folge];
folge = codtab[folge];
}
merk++;
b3[merk] = folge;
while (merk > 0) {
gifout(b3[merk], &V);
merk--;
}
}
if (a != 4098) {
codtab[V.ki - 2] = a;
if (codegif == V.ki - 2) {
folge = a;
while (folge > ic)
folge = codtab[folge];
anf[V.ki - 2] = folge;
} else {
folge = codegif;
while (folge > ic)
folge = codtab[folge];
anf[V.ki - 2] = folge;
}
}
a = codegif;
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (bitspsam > 1)
greypxl = true;
mapinlen = V.linebytes;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*:29*/
/*33:*/
Static uchar getpcx(void)
{
uchar Result;
if (gbufp == pxlinlen) {
gbufp = 0;
pxlinlen = fread(b1, 1, 640, bitmap);
}
Result = b1[gbufp];
gbufp++;
return Result;
}
/*:33*/
/*34:*/
Static long longpcx(void)
{
long bl;
ebts pb;
pb = getpcx();
bl = pb;
pb = getpcx();
bl += pb * 256;
pb = getpcx();
bl += pb * 65536;
pb = getpcx();
bl += pb * 16777216;
return bl;
}
/*:34*/
/*35:*/
Static unsigned short wordpcx(void)
{
unsigned short bl;
ebts pb;
pb = getpcx();
bl = pb;
pb = getpcx();
bl += pb * 256;
return bl;
} /*:35*/
/*36:*/
Static void pcxint(void)
{
unsigned short i, ki, k, hi, hh, vi, vh, hr, vr, bzf;
ebts xb, j, b, a, col, bps, ibits, pcxver, pcxcomp;
ebts gpal[256][3];
ebts hell[256];
unsigned short FORLIM;
short FORLIM1;
printf("Analysing PCX file %s\n", bmname);
gbufp = 640;
pxlinlen = 640;
b = getpcx();
if (b != 10 && b != 205) {
printf("What a bad joke!\n");
printf("This is NOT a PCX file!\n");
_Escape(0);
}
if (b == 205)
printf("First byte 205, file seems to be captured!\n");
/*37:*/
pcxver = getpcx();
pcxcomp = getpcx();
bps = getpcx();
hi = getpcx();
b = getpcx();
hi += b * 256;
vi = getpcx();
b = getpcx();
vi += b * 256;
hh = getpcx();
b = getpcx();
hh += b * 256;
vh = getpcx();
b = getpcx();
vh += b * 256;
hr = getpcx();
b = getpcx();
hr += b * 256;
vr = getpcx();
b = getpcx();
vr += b * 256;
if (hr == 640 && vr == 350) {
xratio = 3;
yratio = 4;
}
if (hr == 320 && vr == 200) {
xratio = 5;
yratio = 6;
}
hh += 1 - hi;
vh -= vi;
mapwidth = hh;
for (i = 0; i <= 15; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getpcx();
}
b = getpcx();
col = getpcx();
bzf = getpcx();
b = getpcx();
bzf += b * 256;
hh = bzf;
b = getpcx();
b = getpcx();
for (i = 70; i <= 127; i++)
b = getpcx();
bitspsam = bps;
if (col == 4) {
bitspsam = 4;
greypxl = true;
} else if (bps > 1) {
bitspsam = bps;
greypxl = true;
}
mapinlen = ((unsigned long)(mapwidth * bitspsam + 7)) >> 3;
/*:37*/
/*38:*/
for (i = 0; i <= 15; i++)
hell[i] = (long)(gpal[i][0] / 16.0 * 0.287 + gpal[i]
[1] / 16.0 * 0.589 + gpal[i][2] / 16.0 * 0.114);
for (i = 0; i <= 15; i++) {
if (hell[i] > 15)
hell[i] = 15;
}
opentempfile(); /*:38*/
if (pcxver == 5 && bitspsam > 4) { /*39:*/
gbufp = 640;
pxlinlen = 640;
posbit = P_maxpos(bitmap);
posbit -= 769;
fseek(bitmap, posbit, SEEK_SET);
b = getpcx();
if (b != 12) {
printf("No valid information in 256 colors palette\n");
printf("Using standard 16 colors palette\n");
} else {
for (i = 0; i <= 255; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getpcx();
hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i]
[1] * 0.589 + gpal[i]
[2] * 0.114 + 0.5);
}
}
fseek(bitmap, 128, SEEK_SET);
gbufp = 640;
pxlinlen = 640;
}
/*:39*/
/*40:*/
a = 0;
for (i = 0; i <= vh; i++) { /*:40*/
FORLIM1 = mapinlen;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
b3[gbufpp] = 0;
for (j = 0; j < col; j++) {
gbufpp = 0;
for (k = 1; k <= hh; k++) {
if (a == 0) {
b = getpcx();
if ((b & 0xc0) == 0xc0) {
a = (b & 0x3f) - 1;
b = getpcx();
}
} else
a--;
if (col == 4) {
for (ibits = 0; ibits <= 7; ibits++) {
ki = gbufpp * 4 + (ibits >> 1);
xb = b << ibits;
xb >>= 7;
xb <<= j;
xb <<= (1 - (ibits & 1)) << 2;
b3[ki] ^= xb;
}
} else {
b3[gbufpp] = b;
if (gbufpp == mapinlen - 1 && bitspsam == 1) {
ki = 8 - (mapwidth & 7);
if (ki != 8) {
xb = b3[gbufpp] >> ki;
xb <<= ki;
b3[gbufpp] = xb;
xb = invbit;
for (ibits = 1; ibits <= ki; ibits++) {
b3[gbufpp] ^= xb;
xb <<= 1;
}
}
}
}
gbufpp++;
}
}
if (col == 4) {
gbufpp = 0;
hi = (hh - 1) * 4 + 3;
for (k = 0; k <= hi; k++) {
b3[gbufpp] = (hell[b3[k] >> 4] << 4) + hell[b3[k] & 15];
gbufpp++;
}
} else if (bps == 8 && pcxver == 5) {
hi = hh - 1;
for (k = 0; k <= hi; k++)
b3[k] = hell[b3[k]];
gbufpp = hh;
}
_SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
if (hr == 640 && vr == 200) {
_SETIO(fwrite(b3, mapinlen, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/* Local variables for iffint: */
struct LOC_iffint {
unsigned short hi, hh, vi, vh, compr;
uchar a, b, col, bps;
uchar gpal[256][3];
uchar hell[256];
Char bmstr[256];
long bmsize, bmoff, bl;
} ;
/*:41*/
/*42:*/
Local long ifflong(struct LOC_iffint *LINK)
{
ebts k;
fread(b1, 4, 1, bitmap);
LINK->bl = b1[0];
for (k = 1; k <= 3; k++)
LINK->bl = LINK->bl * 256 + b1[k];
return LINK->bl;
}
/*:42*/
/*43:*/
Local unsigned short iffword(struct LOC_iffint *LINK)
{
fread(b1, 2, 1, bitmap);
return (b1[0] * 256 + b1[1]);
}
/*:43*/
/*44:*/
Local void junkchunk(struct LOC_iffint *LINK)
{
if (LINK->bmsize > P_maxpos(bitmap)) {
printf("File endend while reading junk\n");
_Escape(0);
}
while (LINK->bmsize > 0) {
fread(&LINK->b, 1, 1, bitmap);
LINK->bmsize--;
}
} /*:44*/
/*45:*/
Local void checkchunk(struct LOC_iffint *LINK)
{
short i, j, FORLIM;
if (!strcmp(LINK->bmstr, "BMHD")) {
LINK->bmsize = ifflong(LINK);
if (LINK->bmsize & 1)
LINK->bmsize++;
LINK->hh = iffword(LINK);
LINK->vh = iffword(LINK);
LINK->hi = iffword(LINK);
LINK->vi = iffword(LINK);
fread(&LINK->bps, 1, 1, bitmap);
fread(&LINK->b, 1, 1, bitmap);
fread(&LINK->b, 1, 1, bitmap);
LINK->compr = LINK->b;
for (i = 1; i <= 4; i++)
fread(&xratio, 1, 1, bitmap);
fread(&yratio, 1, 1, bitmap);
LINK->bmsize -= 16;
junkchunk(LINK);
if (LINK->bps == 1) {
LINK->col = 1;
return;
}
if (LINK->bps == 4)
LINK->col = 15;
else
LINK->col = 255;
return;
}
if (!strcmp(LINK->bmstr, "CMAP")) {
LINK->bmsize = ifflong(LINK);
LINK->col = LINK->bmsize / 3 - 1;
FORLIM = LINK->col;
for (i = 0; i <= FORLIM; i++) {
for (j = 0; j <= 2; j++) {
fread(&LINK->b, 1, 1, bitmap);
LINK->gpal[i][j] = LINK->b;
}
LINK->hell[i] = (long)floor(
LINK->gpal[i][0] * 0.287 + LINK->gpal[i]
[1] * 0.589 + LINK->gpal[i][2] * 0.114 + 0.5);
}
if (LINK->bmsize & 1)
fread(&LINK->b, 1, 1, bitmap);
return;
}
if (!strcmp(LINK->bmstr, "CRNG")) {
LINK->bmsize = ifflong(LINK);
LINK->bmoff = iffword(LINK);
LINK->bmoff = iffword(LINK);
LINK->bmoff = iffword(LINK);
fread(&LINK->b, 1, 1, bitmap);
fread(&LINK->a, 1, 1, bitmap);
if (LINK->bps == 4) {
if (LINK->b < LINK->a) {
FORLIM = LINK->a;
for (i = LINK->b; i <= FORLIM; i++)
LINK->hell[i] = i;
} else if (LINK->b > LINK->a) {
FORLIM = LINK->b;
for (i = LINK->a; i <= FORLIM; i++)
LINK->hell[i] = i;
}
}
if (LINK->bmsize & 1)
fread(&LINK->b, 1, 1, bitmap);
return;
}
LINK->bmsize = ifflong(LINK);
if (LINK->bmsize & 1)
LINK->bmsize++;
junkchunk(LINK);
}
/*:36*/
/*41:*/
Static void iffint(void)
{ /*:45*/
struct LOC_iffint V;
uchar cb;
short FORLIM, FORLIM1;
/*46:*/
printf("Analysing IFF file %s\n", bmname);
opentempfile();
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
if (strcmp(V.bmstr, "FORM")) {
printf("Graphic file not stored as Interchange File Format\n");
_Escape(0);
}
V.bmsize = ifflong(&V) + 8;
if (V.bmsize != P_maxpos(bitmap)) {
printf("File is incomplete, should contain %ld\n",
V.bmsize);
_Escape(0);
}
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
if (strcmp(V.bmstr, "ILBM"))
printf("Type of file is %s, should be ILBM\n", V.bmstr);
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
while (strcmp(V.bmstr, "BODY")) {
if (P_eof(bitmap)) {
printf("No graphics information available\n");
_Escape(0);
}
checkchunk(&V);
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
}
V.bmsize = ifflong(&V);
V.hh = (V.hh * V.bps + 7) / 8;
FORLIM = V.vh;
for (i = 1; i <= FORLIM; i++) {
if (P_eof(bitmap)) {
printf("ende\n");
_Escape(0);
}
if (V.compr == 0)
fread(b3, V.hh, 1, bitmap);
else { /*47:*/
gbufp = 0;
while (gbufp < V.hh) {
fread(&V.b, 1, 1, bitmap);
V.bmoff++;
if (V.b < 128) {
V.b++;
fread(&b3[gbufp], V.b, 1, bitmap);
gbufp += V.b;
continue;
}
if (V.b <= 128)
continue;
fread(&V.a, 1, 1, bitmap);
V.b = 257 - V.b;
while (V.b > 0) {
b3[gbufp] = V.a;
gbufp++;
V.b--;
}
}
} /*:47*/
if (V.bps == 4) { /*48:*/
gi = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
b2[gbufpp] = 0;
V.a = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
V.b = b3[gbufpp];
for (j = 0; j <= 3; j++) {
cb = V.b & 128;
cb >>= V.a;
b2[gi] ^= cb;
V.b <<= 1;
cb = V.b & 128;
cb >>= V.a + 4;
b2[gi] ^= cb;
V.b <<= 1;
gi++;
}
if (gi >= V.hh) {
gi = 0;
V.a++;
}
}
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
b3[gbufpp] = b2[gbufpp];
gi = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
b2[gi] = (V.hell[b3[gbufpp] >> 4] << 4) +
V.hell[b3[gbufpp] & 15];
gi++;
} /*:48*/
} else if (V.bps == 8) {
FORLIM1 = V.hh;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b2[gbufp] = V.hell[b3[gbufp]];
} else {
FORLIM1 = V.hh;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b2[gbufp] = b3[gbufp];
}
_SETIO(fwrite(b2, V.hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
mapinlen = V.hh;
bitspsam = V.bps;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
if (bitspsam > 1)
greypxl = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
} /*:46*/
/*49:*/
Static void bmpint(void)
{
unsigned short i, k, hi, hh, hhl, vi, vh, compr, lcol;
uchar j, b, a, col, bps;
uchar gpal[256][4];
uchar hell[256];
Char bmstr[256];
long bmsize, bmoff;
unsigned short FORLIM;
printf("Analysing BMP file %s\n", bmname);
opentempfile();
fread(bmstr, 2, 1, bitmap);
bmstr[2] = '\0';
if (strcmp(bmstr, "BM")) {
printf("No windows bitmap %s\n", bmstr);
_Escape(0);
}
gbufp = 640;
pxlinlen = 640;
bmsize = longpcx();
for (i = 1; i <= 4; i++)
b = getpcx();
bmoff = longpcx();
bmsize = longpcx();
bmoff -= bmsize;
if (bmsize > 12) {
hi = longpcx();
vi = longpcx();
b = getpcx();
b = getpcx();
bps = wordpcx();
if (bps > 8) {
printf("only up to 256 colors supported\n");
_Escape(0);
}
hh = hi;
vh = vi;
compr = longpcx();
for (i = 1; i <= 4; i++)
b = getpcx();
xratio = longpcx();
yratio = longpcx();
lcol = longpcx();
lcol--;
if (col == 0) {
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
}
col = longpcx();
col--;
} else {
hi = wordpcx();
vi = wordpcx();
b = getpcx();
b = getpcx();
bps = wordpcx();
if (bps > 8) {
printf("only up to 256 colors supported\n");
_Escape(0);
}
hh = hi;
vh = vi;
compr = 0;
xratio = 1;
yratio = 1;
col = 0;
}
if (lcol == 0) {
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
}
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
for (i = 0; i <= col; i++) {
if (bmsize > 12) {
for (j = 0; j <= 3; j++)
gpal[i][j] = getpcx();
} else {
for (j = 0; j <= 2; j++)
gpal[i][j] = getpcx();
}
hell[i] = (long)((gpal[i][0] * 0.287 + gpal[i]
[1] * 0.589 + gpal[i]
[2] * 0.114) / (256.0 / (col + 1)));
}
if (bmsize > 12)
bmoff -= (col + 1) * 4;
else
bmoff -= (col + 1) * 3;
if (compr != 0) {
printf("compression not supported yet\n");
_Escape(0);
}
hh = (hh * bps + 7) / 8;
hhl = (hh + 3) / 4 * 4 - 1;
a = 8 - ((hi * bps) & 7);
memset(b3, 0, hhl + 1);
for (i = 1; i <= vh; i++) { /*$I-*/
_SETIO(fwrite(b3, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
if (tmpfil == NULL)
_EscIO(FileNotFound);
bmoff = (vh - 1) * (long)hh;
for (i = 0; i < vh; i++) {
for (k = 0; k <= hhl; k++)
b3[k] = getpcx();
if (bps == 4) {
gi = 0;
for (k = 0; k < hh; k++) {
b2[gi] = (hell[b3[k] / 16] << 4) + hell[b3[k] & 15];
gi++;
}
} else if (bps == 8) {
for (k = 0; k < hh; k++)
b2[k] = hell[b3[k]];
} else {
for (k = 0; k < hh; k++)
b2[k] = b3[k];
}
if (a < 8) {
for (k = 0; k < a; k++)
b2[hh - 1] ^= invbit >> k;
}
fseek(tmpfil, bmoff, SEEK_SET);
bmoff = bmoff - (long)hh;
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
mapinlen = hh;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
bitspsam = bps;
if (bitspsam > 1)
greypxl = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*50:*/
Static void imgint(void)
{
unsigned short i, ki, hi, hh, bzf, imgpat;
short vh;
uchar mi, cb, j, b, a, col, bps;
uchar hell[16];
uchar linerep;
unsigned short FORLIM;
printf("Analysing IMG file %s\n", bmname);
invert = !invert;
if (invert) { /*51:*/
invbit = 0;
invbyte = 0;
} else {
invbit = 1;
invbyte = 255;
}
hell[0] = 0;
hell[1] = 1;
hell[2] = 6;
hell[3] = 8;
hell[4] = 3;
hell[5] = 2;
hell[6] = 7;
hell[7] = 11;
hell[8] = 4;
hell[9] = 5;
hell[10] = 12;
hell[11] = 13;
hell[12] = 10;
hell[13] = 9;
hell[14] = 14;
hell[15] = 15;
opentempfile(); /*:51*/
gbufp = 640;
pxlinlen = 640;
a = getpcx();
b = getpcx();
if (a * 256 + b != 1) { /*52:*/
printf("File does not contain GEM Image File Format\n");
_Escape(0);
}
b = getpcx();
bzf = b * 256;
b = getpcx();
bzf += b;
b = getpcx();
bps = b * 256;
b = getpcx();
bps += b;
b = getpcx();
imgpat = b * 256;
b = getpcx();
imgpat += b;
b = getpcx();
xratio = b * 256;
b = getpcx();
xratio += b;
b = getpcx();
yratio = b * 256;
b = getpcx();
yratio += b;
if (xratio != yratio) {
mapdiv = (double)yratio / xratio;
xratio = 0;
yratio = 0;
while (xratio == yratio) {
xratio++;
yratio = (long)floor(xratio * mapdiv + 0.5);
}
}
b = getpcx();
hi = b * 256;
b = getpcx();
hi += b;
b = getpcx();
vh = b * 256;
b = getpcx();
vh += b; /*:52*/
hh = (hi * bps + 7) / 8;
if (bzf > 8) {
for (i = 1; i <= (bzf - 8) * 2; i++)
b = getpcx();
}
linerep = 0;
gi = 0;
while (vh > 0) {
for (gi = 0; gi <= hh; gi++)
b3[gi] = 0;
gi = 0;
while (gi < hh) {
b = getpcx();
if (b != 0 && b != 128) {
a = b & 127;
cb = ((unsigned)(b - a)) >> 7;
if (cb == 1)
cb = 255;
for (ki = 1; ki <= a; ki++) {
b3[gi] = cb;
gi++;
}
continue;
}
if (b == 128) {
a = getpcx();
for (ki = 1; ki <= a; ki++) {
b3[gi] = getpcx();
gi++;
}
continue;
}
a = getpcx();
if (a <= 0) {
b = getpcx();
linerep = getpcx();
continue;
}
for (ki = 1; ki <= imgpat; ki++)
b2[ki] = getpcx();
for (ki = 1; ki <= a; ki++) {
for (mi = 1; mi <= imgpat; mi++) {
b = b2[mi];
b3[gi] = b;
gi++;
}
}
}
if (bps == 4) { /*48:*/
gi = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++)
b2[gbufpp] = 0;
a = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++) {
b = b3[gbufpp];
for (j = 0; j <= 3; j++) {
cb = b & 128;
cb >>= a;
b2[gi] ^= cb;
b <<= 1;
cb = b & 128;
cb >>= a + 4;
b2[gi] ^= cb;
b <<= 1;
gi++;
}
if (gi >= hh) {
gi = 0;
a++;
}
}
for (gbufpp = 0; gbufpp < hh; gbufpp++)
b3[gbufpp] = b2[gbufpp];
gi = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++) {
b2[gi] = (hell[b3[gbufpp] >> 4] << 4) +
hell[b3[gbufpp] & 15];
gi++;
} /*:48*/
} else {
for (ki = 0; ki < hh; ki++)
b2[ki] = b3[ki];
}
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
vh--;
if (linerep <= 0)
continue;
for (i = 1; i <= linerep; i++) { /*$I-*/
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
vh += 1 - linerep;
linerep = 0;
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (col == 4) {
bitspsam = 4;
greypxl = true;
} else if (bps > 1) {
bitspsam = bps;
greypxl = true;
}
mapinlen = hh;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
pcxtemp = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*54:*/
Static void tfmhword(long hword)
{
union {
uchar b[4];
long i;
} ax;
short i;
ax.i = hword;
#ifdef INTEL
for (i = 1; i >= 0; i--)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#else
for (i = 2; i <= 3; i++)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#endif
}
Static void tfmword(long lword)
{
union {
uchar b[4];
long i;
} ax;
short i;
ax.i = lword;
#ifdef INTEL
for (i = 3; i >= 0; i--)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#else
for (i = 0; i <= 3; i++)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#endif
}
/*:54*/
/*57:*/
/*procedure pxlhword(hword:word);
var ax:record case boolean of true:(b:array[0..1]of ebts);
false:(w:word)end;i:integer;
[EMBED
#ifdef INTEL
]
begin ax.w:=hword;pxlbm^[pxlbmi]:=ax.b[1];inc(pxlbmi);
pxlbm^[pxlbmi]:=ax.b[0];inc(pxlbmi);end;
[EMBED
#else
]
begin ax.w:=hword;pxlbm^[pxlbmi]:=ax.b[0];inc(pxlbmi);
pxlbm^[pxlbmi]:=ax.b[1];inc(pxlbmi);end;
[EMBED
#endif
]
*/
Static void pxlmap(long lword)
{
union {
ebts b[4];
long i;
} ax;
uchar i;
ax.i = lword;
for (i = 0; i <= 3; i++) {
pxlbm[pxlbmi] = ax.b[i];
pxlbmi++;
}
}
/*procedure pxlword(lword:longint);
var ax:record case boolean of true:(b:array[0..3]of ebts);
false:(i:longint)end;i:byte;begin ax.i:=lword;
[EMBED
#ifdef INTEL
]
for i:=3 downto 0 do begin pxlbm^[pxlbmi]:=ax.b[i];inc(pxlbmi);end;
[EMBED
#else
]
for i:=0 to 3 do begin pxlbm^[pxlbmi]:=ax.b[i];inc(pxlbmi);end;
[EMBED
#endif
]
end;*/
/*:57*/
/*61:*/
Static void pkbyte(uchar b)
{
pkbm[pkloc] = b;
pkloc++;
}
Static void pkhalfword(short a)
{
union {
ebts b[2];
short w;
} ax;
ax.w = a;
#ifdef INTEL
pkbyte(ax.b[1]);
pkbyte(ax.b[0]);
#else
pkbyte(ax.b[0]);
pkbyte(ax.b[1]);
#endif
}
Static void pkthreebytes(long a)
{
union {
ebts b[4];
long i;
} ax;
ax.i = a;
#ifdef INTEL
pkbyte(ax.b[2]);
pkbyte(ax.b[1]);
pkbyte(ax.b[0]);
#else
pkbyte(ax.b[1]);
pkbyte(ax.b[2]);
pkbyte(ax.b[3]);
#endif
}
Static void pkword(long a)
{
union {
ebts b[4];
long i;
} ax;
ax.i = a;
#ifdef INTEL
pkbyte(ax.b[3]);
pkbyte(ax.b[2]);
pkbyte(ax.b[1]);
pkbyte(ax.b[0]);
#else
pkbyte(ax.b[0]);
pkbyte(ax.b[1]);
pkbyte(ax.b[2]);
pkbyte(ax.b[3]);
#endif
}
Static void pknyb(uchar a)
{
if (bitweight == 16) {
outputbyte = a << 4;
bitweight = 1;
} else {
pkbyte(outputbyte + a);
bitweight = 16;
}
}
/*:61*/
/*63:*/
Static void writepreamble(void)
{
short i;
Char nstr[256];
sprintf(nstr, "%ld", (long)floor(truehres + 0.5));
sprintf(cmd, "%s%c.%spk", font, fontpre[f], nstr);
strcpy(pxlfile_NAME, cmd);
if (pxlfile != NULL)
pxlfile = freopen(pxlfile_NAME, "wb", pxlfile);
else
pxlfile = fopen(pxlfile_NAME, "wb");
_SETIO(pxlfile != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 3 || filestat == 5) {
strcpy(cmd, bmname);
sprintf(cmd + strlen(cmd), "%c.pk", fontupc[f]);
strcpy(pxlfile_NAME, cmd);
if (pxlfile != NULL)
pxlfile = freopen(pxlfile_NAME, "wb", pxlfile);
else
pxlfile = fopen(pxlfile_NAME, "wb");
_SETIO(pxlfile != NULL, FileNotFound);
filestat = P_ioresult;
}
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("error occurred when ");
printf("allocating pkfile ");
puts(cmd);
fileproblem();
_Escape(0);
}
pkloc = 0;
pkbyte(247);
pkbyte(89);
pkbyte(14);
strcpy(comment, "BM2FONT output");
for (i = 0; i <= 13; i++)
pkbyte(comment[i]);
pkword(tabdsize[f]);
pkword(checksum);
pkword((long)floor(truehres * 65536L / 72.27 + 0.5));
pkword((long)floor(truevres * 65536L / 72.27 + 0.5));
nextmemfree = 0;
printf("Packing font %s\n", cmd);
}
/*:63*/
/*65:*/
Static void writepostamble(void)
{
pkbyte(245);
while ((pkloc & 3) != 0)
pkbyte(246);
_SETIO(fwrite(pkbm, pkloc, 1, pxlfile) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing font %s!\n",
cmd) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
if (pxlfile != NULL)
fclose(pxlfile);
pxlfile = NULL;
printf(" \n");
printf("Font %s at %ld dots per inch written\n",
cmd, (long)floor(truehres + 0.5));
for (i = 0; i <= 128; i++)
pkpoint[i] = 0;
pxlbmi = 4;
}
/*:65*/
/*67:*/
Static boolean equal(pxlstr row1, pxlstr row2)
{
short i;
boolean temp;
i = pkwidth;
temp = true;
while (i > 0 && temp) {
if (pxlbm[row1] != pxlbm[row2])
temp = false;
row1++;
row2++;
i -= 8;
}
return temp;
}
/*:67*/
/*68:*/
Static boolean equalzo(pxlstr row1, short row2)
{
short i;
boolean temp;
i = pkwidth;
temp = true;
while (i > 0 && temp) {
if (pxlbm[row1] != (repbm[row2] & 255))
temp = false;
row1++;
row2++;
i -= 8;
}
return temp;
}
/*:68*/
/*70:*/
Static void shipcharacter(void)
{ /*:87*/
pxlstr crst;
short wwid;
long compsize;
unsigned short horesc;
/*72:*/
short l;
long i, j, k;
short rowzero, onesrow, repptr, bitcounts;
ebts fillbytes, longind, mixbyte, restbyte, pkshift,
dshift;
long longtab[20];
/*:72*/
/*77:*/
long count;
short test, curptr, bit, repflag;
schar pkkword;
short bitptr, bitmod32, currepeat;
pxlstr endraster; /*:77*/
/*80:*/
short dynf;
long deriv[13];
long bcompsize;
boolean firston;
short flagbyte;
/*:80*/
/*87:*/
unsigned short max2;
pxlstr predpkloc;
short bytelength;
printf("%c ", car);
horesc = pwidth[f][car];
pkwidth = pwidth[f][car];
pkheight = pheight[f][car];
pkheight -= yoffset[f][car];
cxoff = 0;
cyoff = pkheight;
crst = pkpoint[car];
wwid = (pkwidth + 31) / 32 * 4;
fillbytes = wwid - (pkwidth + 7) / 8; /*71:*/
rowzero = nextmemfree;
onesrow = nextmemfree + wwid;
repptr = onesrow + wwid;
bitcounts = repptr + pkheight + 1;
for (i = rowzero; i < onesrow; i++)
repbm[i] = 0;
for (i = onesrow; i <= repptr - 2; i++)
repbm[i] = -1;
j = onesrow + (((unsigned long)(pkwidth + 7)) >> 3);
repbm[j - 1] = power[8] - power[7 - ((pkwidth + 7) & 7)];
for (i = j; i < repptr; i++)
repbm[i] = 0;
i = 0;
j = pkheight;
while (i < j) {
if (equalzo(i * wwid + crst, rowzero))
repbm[repptr + i] = 0;
else if (equalzo(i * wwid + crst, onesrow))
repbm[repptr + i] = 0;
else if (i + 1 == j)
repbm[repptr + i] = 0;
else if (equal(i * wwid + crst, (i + 1) * wwid + crst))
repbm[repptr + i] = 1;
else
repbm[repptr + i] = 0;
i++;
}
i = 0;
while (i < j) {
k = i;
while (repbm[repptr + k] == 1)
k++;
repbm[repptr + i] = k - i;
i = k + 1;
}
repbm[repptr + i] = 0; /*:71*/
/*75:*/
repflag = 0;
bitptr = pkwidth - 1;
currepeat = repptr;
endraster = crst + pkheight * wwid;
curptr = bitcounts;
count = 0;
longind = 0;
test = 0;
do { /*76:*/
bitptr++;
if (bitptr == pkwidth) {
bitmod32 = 0;
bitptr = 0;
if (currepeat > repptr)
crst += fillbytes;
if (repbm[currepeat] > 0) {
repflag = repbm[currepeat];
currepeat += repflag;
crst += wwid * repflag;
}
currepeat++;
}
bitmod32--;
if (bitmod32 == -1) {
bitmod32 = 7;
pkkword = pxlbm[crst];
crst++;
}
if (crst > endraster)
bit = 2;
else if (pkkword < 0)
bit = 1;
else
bit = 0;
pkkword <<= 1; /*:76*/
if (bit == test)
count++;
else {
if (count > 32767) {
longind++;
longtab[longind - 1] = count;
count = -longind - 10000;
}
repbm[curptr] = count;
curptr++;
if (curptr + 1 > maxmemsize)
test = 3;
else {
count = 1;
test = bit;
if (repflag > 0) {
repbm[curptr] = -repflag;
repflag = 0;
curptr++;
}
}
}
} while (test < 2);
repbm[curptr] = 0;
repbm[curptr + 1] = 0; /*:75*/
/*78:*/
if (test < 3) { /*81:*/
for (i = 0; i <= 12; i++)
deriv[i] = 0;
firston = (repbm[bitcounts] == 0);
if (firston)
bitcounts++;
i = bitcounts;
compsize = 0;
while (repbm[i] != 0) { /*79:*/
j = repbm[i];
if (j < -10000)
j = longtab[-j - 10001];
if (j == -1)
compsize++;
else {
if (j < 0) {
compsize++;
j = -j;
}
if (j < 209)
compsize += 2;
else {
k = j - 193;
while (k >= 16) {
k = ((unsigned long)k) >> 4;
compsize += 2;
}
compsize++;
}
if (j < 14)
deriv[j - 1]--;
else if (j < 209)
deriv[(223 - j) / 15 - 1]++;
else {
k = 16;
while (k <= ((unsigned long)(j + 2)) >> 4) {
k <<= 4;
if (k == 0) {
k = 32767;
j += 32767;
}
}
if (j - k <= 192)
deriv[(k - j + 207) / 15 - 1] += 2;
}
}
i++;
}
/*:79*/
bcompsize = compsize;
dynf = 0;
for (i = 1; i <= 13; i++) {
compsize += deriv[i - 1];
if (compsize <= bcompsize) {
bcompsize = compsize;
dynf = i;
}
}
compsize = (bcompsize + 1) / 2;
if (compsize > (pkheight * pkwidth + 7) / 8 ||
pkheight * pkwidth == 0) {
compsize = (pkheight * pkwidth + 7) / 8;
dynf = 14;
}
} else {
dynf = 14;
firston = (repbm[bitcounts] == 0);
compsize = (pkheight * pkwidth + 7) / 8;
}
flagbyte = dynf * 16;
if (firston)
flagbyte += 8;
if (width[f][car] > 16777215L || width[f][car] < 0 ||
horesc < 0 || compsize > 196594L ||
pkwidth > 65535L || pkheight > 65535L ||
cxoff > 32767 || cyoff > 32767 || cxoff < -32768L ||
cyoff < -32768L)
{ /*82:*/
flagbyte += 7;
pkbyte(flagbyte);
compsize += 28;
pkword(compsize);
pkword((long)car);
predpkloc = pkloc + compsize;
pkword(width[f][car]);
pkword((long)horesc);
pkword(0);
pkword(pkwidth);
pkword(pkheight);
pkword(cxoff);
pkword(cyoff);
} /*:82*/
else if (horesc > 255 || pkwidth > 255 ||
pkheight > 255 || cxoff > 127 || cyoff > 127 ||
cxoff < -128 || cyoff < -128 ||
compsize > 1015) {
compsize += 13;
flagbyte += compsize / 65536L + 4;
pkbyte(flagbyte);
/* p2c: bm2font.p, line 824:
* Note: Using % for possibly-negative arguments [317] */
pkhalfword(compsize % 65536L);
pkbyte(car);
predpkloc = pkloc + compsize;
pkthreebytes(width[f][car]);
pkhalfword(horesc);
pkhalfword(pkwidth);
pkhalfword(pkheight);
pkhalfword(cxoff);
pkhalfword(cyoff);
} else {
compsize += 8;
flagbyte += compsize / 256;
pkbyte(flagbyte);
pkbyte(compsize & 255);
pkbyte(car);
predpkloc = pkloc + compsize;
pkthreebytes(width[f][car]);
pkbyte(horesc & 255);
pkbyte(pkwidth);
pkbyte(pkheight);
pkbyte(cxoff);
pkbyte(cyoff);
}
if (dynf != 14) { /*85:*/
bitweight = 16;
max2 = 208 - dynf * 15;
i = bitcounts;
while (repbm[i] != 0) {
j = repbm[i];
if (j < -10000)
j = longtab[-j - 10001];
if (j == -1)
pknyb(15);
else {
if (j < 0) {
pknyb(14);
j = -j;
}
if (j <= dynf)
pknyb(j);
else if (j <= max2) {
j += -dynf - 1;
pknyb((((unsigned long)j) >> 4) + dynf + 1);
pknyb(j & 15);
} else {
j += 15 - max2;
k = 1;
while (k <= ((unsigned long)j) >> 4) {
k <<= 4;
pknyb(0);
}
while (k > 0) {
pknyb(j / k);
j %= k;
/* p2c: bm2font.p, line 839:
* Note: Using % for possibly-negative arguments [317] */
k = ((unsigned long)k) >> 4;
}
}
}
i++;
}
if (bitweight != 16)
pkbyte(outputbyte);
} else /*86:*/
{ /*:86*/
crst = pkpoint[car];
bytelength = (((unsigned long)(pkwidth + 7)) >> 3) - 1;
if ((pkwidth & 7) == 0) {
while (crst < endraster) {
for (i = 0; i <= bytelength; i++)
pkbyte(pxlbm[crst + i]);
crst += wwid;
}
} else {
pkshift = 0;
dshift = pkwidth & 7;
while (crst < endraster) {
if (pkshift == 0) {
for (i = 0; i < bytelength; i++)
pkbyte(pxlbm[crst + i]);
mixbyte = pxlbm[crst + bytelength];
} else {
i = crst;
l = pkwidth + pkshift;
while (l >= 8) {
l -= 8;
restbyte = pxlbm[i];
i++;
pkbyte(mixbyte + (restbyte >> pkshift));
mixbyte = restbyte << (8 - pkshift);
}
if (pkshift < ((pkshift + dshift) & 7))
mixbyte += pxlbm[i] >> pkshift;
}
crst += wwid;
pkshift = (pkshift + dshift) & 7;
}
if (pkshift > 0)
pkbyte(mixbyte);
}
}
/*:85*/
if (predpkloc == pkloc) /*:78*/
return;
printf("Bad predicted character length: character %d\n",
car);
printf("pred: %uloc: %u\n", predpkloc, pkloc);
_Escape(0);
/*84:*/
/*:84*/
/*83:*/
/*:83*/
/*:81*/
} /*:70*/
/*88:*/
/*procedure prepxlfile;
cmd:=concat(font,fontpre[f+1],'.',numtostr(5*truehres),'pxl');
assign(pxlfile,cmd);[$I-]rewrite(pxlfile,1);filestat:=ioresult;
if filestat=3 then begin cmd:=bmname;
cmd:=concat(cmd,fontupc[f+1],'.pxl');assign(pxlfile,cmd);
rewrite(pxlfile,1);filestat:=ioresult;end;
if filestat=0 then fok:=false else fok:=true;
[$I+]if not fok then begin pxlbmi:=0;pxlword(1001);end;end;*/
/*:88*/
/*89:*/
/*procedure restofpxl(fi:integer);var i:integer;ib:pxlstr;begin i:=0;
ib:=0;
for i:=0 to 127 do begin pheight^[fi,i]:=pheight^[fi,i]-yoffset^[fi,i];
yoffset^[fi,i]:=pheight^[fi,i];pxlhword(pwidth^[fi,i]);
pxlhword(pheight^[fi,i]);pxlhword(0);pxlhword(yoffset^[fi,i]);
pxlword(dirpoint[i]);pxlword(width^[fi,i]);end;pxlword(checksum);
pxlword(1000);pxlword(tabdsize[fi]);pxlword((pxlbmi div 4)-515);
pxlword(1001);begin[$I-]blockwrite(pxlfile,pxlbm^[0],pxlbmi);
filestat:=ioresult;
if filestat<>0 then begin writeln('Error occured when writing font ',cmd
,'!');fileproblem;halt;end;[$I+]end;close(pxlfile);
writeln('Font ',cmd,' at ',round(truehres):1,' dots per inch written');
for i:=0 to 128 do dirpoint[i]:=0;for i:=0 to 128 do pkpoint[i]:=0;end;*/
/*:89*/
/*90:*/
Static void fonteject(void)
{
short FORLIM, FORLIM1, FORLIM2;
while (maplines > 0) {
FORLIM = maxx;
for (k = 1; k <= FORLIM; k++) {
i = k - 1;
dirpoint[cref[g]] = pxlbmi / 4;
pkpoint[cref[g]] = pxlbmi;
linepos_ = posbit + i * hres / 8;
pxlinlen = (pwidth[f][cref[g]] + 7) / 8;
zeroline = true;
gi = 0;
FORLIM1 = pheight[f][cref[g]];
for (v = 1; v <= FORLIM1; v++) {
fseek(bitmap, linepos_, SEEK_SET);
j = fread(b1, 1, pxlinlen, bitmap);
FORLIM2 = pxlinlen;
for (lx = 0; lx < FORLIM2; lx++)
b2[lx] = b1[lx];
if (invert) {
FORLIM2 = pxlinlen;
for (lx = 0; lx < FORLIM2; lx++)
b2[lx] = 255 - b1[lx];
}
gi += dv;
if (gi >= lv)
gi -= cv;
if (invbyte == 255) {
FORLIM2 = pxlinlen;
for (lx = 0; lx < FORLIM2; lx++)
b1[lx] = invbyte - b1[lx];
}
lx = 0;
zerorow = true;
FORLIM2 = pxlinlen;
for (j = 0; j < FORLIM2; j++) {
if (b1[j] != 0) {
zerorow = false;
zeroline = false;
}
}
if (zeroline) {
yoffset[f][cref[g]]++;
if (yoffset[f][cref[g]] == pheight[f][cref[g]]) {
yoffset[f][cref[g]]--;
zerorow = false;
zeroline = false;
}
}
cx.i = 0;
if (!zeroline) {
FORLIM2 = pxlinlen;
for (j = 0; j < FORLIM2; j++) {
if (lx > 3) {
lx = 0;
pxlmap(cx.i);
cx.i = 0;
}
cx.b[lx] = b1[j];
lx++;
}
pxlmap(cx.i);
}
linepos_ += (mapwidth + 7) / 8 + zeropads;
}
i += maxx;
g++;
if (g == charpf) { /*91:*/
writepreamble();
for (car = 0; car <= 127; car++) {
if (pkpoint[car] != 0)
shipcharacter();
}
writepostamble();
f++;
g = 0;
/*if f<noffonts then if pxlmod then begin prepxlfile;
if fok then begin write('error occurred when ');
write('allocating pxlfile ');writeln(cmd);fileproblem;halt;end;end;*/
}
/*if pxlmod then restofpxl(f)else*/
/*:91*/
}
maplines -= vres;
posbit += vres * ((mapwidth + 7) / 8 + zeropads);
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL; /*92:*/
if (f >= noffonts) /*if pxlmod then restofpxl(f)else*/
return;
/*:92*/
writepreamble();
for (car = 0; car <= 127; car++) {
if (pkpoint[car] != 0)
shipcharacter();
}
writepostamble();
}
/*:90*/
/*105:*/
main(int argc, Char *argv[])
{
short FORLIM;
Char STR1[256];
uchar FORLIM1;
short FORLIM2, FORLIM3;
uchar FORLIM4;
PASCAL_MAIN(argc, argv);
tfmfile = NULL;
tmpfil = NULL;
pxlfile = NULL;
bitmap = NULL;
texfile = NULL;
power[0] = 1;
for (i = 1; i <= 8; i++)
power[i] = power[i - 1] * 2;
pxlbm = Malloc(sizeof(pxla));
pkbm = Malloc(sizeof(pxla));
repbm = Malloc(sizeof(pxlba));
gkorh = Malloc(sizeof(korbyte));
gkordivp = Malloc(sizeof(korbyte));
spreadvals = Malloc(sizeof(spreadbyte));
width = Malloc(sizeof(dynlong));
height = Malloc(sizeof(dynlong));
yoffset = Malloc(sizeof(dynword));
pwidth = Malloc(sizeof(dynword));
pheight = Malloc(sizeof(dynword));
greymem = Malloc(sizeof(pxla)); /*106:*/
strcpy(cref, "!()+,-./0123456789:;<=>?");
strcat(cref, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
/* p2c: bm2font.p, line 915:
* Note: Possible string truncation in assignment [145] */
strcat(cref, "abcdefghijklmnopqrstuvwxyz");
/* p2c: bm2font.p, line 916:
* Note: Possible string truncation in assignment [145] */
strcpy(fontupc, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
strcpy(fontpre, "abcdefghijklmnopqrstuvwxyz");
truehres = 0.0;
truevres = 0.0;
invert = false;
greypxl = false;
pcxtemp = false;
giftemp = false;
cutgrey = false;
aliasused = false;
xratio = 0;
yratio = 0; /*pxlmod:=false;*/
egastretch = true;
ledprinter = false;
distribute = true;
brightness = 0;
bitspsam = 8;
nowhite = true;
usepxl = 0;
vusepxl = 0;
hrep = 1;
vrep = 1;
valinc = 70.0;
gradint = 70;
newwidth = 0;
newheight = 0;
printf("This is BitMapTOfont, version 1.1c of june 92, via p2c\n");
printf("Converting Bitmap Files to TeX-Fonts\n");
/*assign(logfile,'test.log');rewrite(logfile);close(logfile);*/
/*109:*/
if (P_argc == 1) {
printf("usage is BM2FONT filename and parameters\n");
printf("-f<name of picture for TeX> (std filename)\n");
printf(
"-h<horizontal resolution> (pixel/inch, std 300)\n");
printf(
"-v<vertical resolution> (pixel/inch, std 300)\n");
printf(
"-l<length of mapline> (in bytes, only pure bitmaps)\n");
printf("-e<stretch EGA pictures> (y or n, std y)\n");
printf("-i<inversion of pixels> (y or n, std n)\n");
printf("-g<greypixels in bitmap> (y or n, std n)\n");
/*writeln('-p<write pixel files> (y or n, std n)');*/
printf("-w<let white be light grey> (y or n, std y)\n");
printf("-d<distribute errors> (y or n, std y)\n");
printf("-s<separation of grey dots> (y or n, std n)\n");
printf("-r<repeat each grey pixel> (y or n, std n)\n");
printf("-u<pixels for grey rectangle> (less 8)\n");
printf("-c<vert. pixels for rectangle> (less 8)\n");
printf("-x<bits per sample> (0 < x < 9)\n");
printf(
"-b<reduce halftone colors> (f.e. by 1, less u*c*4, std 0)\n");
printf("-t<gradation value> (in %%, std 70)\n");
printf("-z<area of gradation> (in %%, std 70)\n");
printf("-m<width of picture on paper> (in mm)\n");
printf("-n<height of picture on paper> (in mm)\n");
/*readln(comment);
if length(comment)=0 then goto 9999;j:=ord(comment[0])+1;
if j<=127 then move(comment[0],mem[prefixseg:$80],j);*/
goto _L9999;
}
/*:109*/
/*110:*/
for (j = 1; j < P_argc; j++) {
strcpy(comment, P_argv[j]);
if (comment[0] != '-') {
strcpy(font, comment);
if (strlen(font) < 1 || !strcmp(font, " ")) {
printf("give the name of your bitmap file next time\n");
goto _L9999;
}
} else {
switch (comment[1]) {
case 'h':
case 'H':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%lf", &truehres) == 0);
break;
case 'v':
case 'V':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%lf", &truevres) == 0);
break;
case 'l':
case 'L':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &mapinlen) == 0);
break;
case 'm':
case 'M':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &newwidth) == 0);
break;
case 'n':
case 'N':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &newheight) == 0);
break;
case 'c':
case 'C':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &vusepxl) == 0);
break;
case 'b':
case 'B':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &brightness) == 0);
break;
case 'x':
case 'X':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &bitspsam) == 0);
break;
case 't':
case 'T':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%lf", &valinc) == 0);
break;
case 'z':
case 'Z':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &gradint) == 0);
break;
case 'g':
case 'G':
strdelete((void *)comment, 1, 2);
greypxl = (!strcmp(comment, "y") ||
!strcmp(comment, "Y"));
break;
case 'e':
case 'E':
strdelete((void *)comment, 1, 2);
egastretch = (!strcmp(comment, "n") ||
!strcmp(comment, "N"));
egastretch = !egastretch;
break;
case 'd':
case 'D':
strdelete((void *)comment, 1, 2);
distribute = (!strcmp(comment, "n") ||
!strcmp(comment, "N"));
distribute = !distribute;
break;
case 'f':
case 'F':
strdelete((void *)comment, 1, 2);
strcpy(aliasname, comment);
aliasused = true;
break;
case 's':
case 'S':
strdelete((void *)comment, 1, 2);
ledprinter = (!strcmp(comment, "y") ||
!strcmp(comment, "Y"));
break;
/*'p','P':begin delete(comment,1,2);pxlmod:=(comment='y')or(comment='Y');
end;*/
case 'r':
case 'R':
strdelete((void *)comment, 1, 2);
if (!strcmp(comment, "y")) {
hrep = 2;
vrep = 2;
}
break;
case 'w':
case 'W':
strdelete((void *)comment, 1, 2);
nowhite = (!strcmp(comment, "n") ||
!strcmp(comment, "N"));
nowhite = !nowhite;
break;
case 'i':
case 'I':
strdelete((void *)comment, 1, 2);
invert = (!strcmp(comment, "y") ||
!strcmp(comment, "Y"));
break;
case 'u':
case 'U':
strdelete((void *)comment, 1, 2);
i = (sscanf(comment, "%ld", &usepxl) == 0);
break;
}
}
}
/*:110*/
/*111:*/
if (bitspsam < 1 || bitspsam > 8)
bitspsam = 8;
if (invert) {
invbit = 0;
invbyte = 0;
} else {
invbit = 1;
invbyte = 255;
}
if (usepxl == 0)
usepxl = 2;
if (vusepxl == 0)
vusepxl = usepxl;
if (brightness >= usepxl * vusepxl * 4)
brightness = 0;
if (brightness != 0 && usepxl < 2)
brightness = 0;
if (valinc > 99)
valinc = 99.0;
if (valinc > 0) {
if (gradint == 0)
gradint = 1;
}
if (gradint > 99)
gradint = 99;
if (newheight < 0)
newheight = 0;
if (newwidth < 0)
newwidth = 0;
if (newwidth > 200) {
printf("Sorry, new width set to 200mm\n");
newwidth = 200;
}
if (newheight > 280) {
printf("Sorry, new height set to 280mm\n");
newheight = 280;
}
if (truehres == 0)
truehres = 300.0;
if (truevres == 0) /*:111*/
truevres = truehres;
/*:106*/
/*107:*/
for (j = 0; j <= 25; j++) {
for (i = 0; i <= 128; i++) {
pwidth[j][i] = 0;
width[j][i] = 0;
height[j][i] = 0;
pheight[j][i] = 0;
yoffset[j][i] = 0;
}
}
for (i = 0; i <= 128; i++)
dirpoint[i] = 0;
for (i = 0; i <= 128; i++)
pkpoint[i] = 0;
maxx = 0;
minx = 646;
mapheight = 0; /*:107*/
fok = true;
strcpy(bmname, font);
strcpy(bitmap_NAME, bmname);
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
_SETIO(bitmap != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) { /*112:*/
printf("File %s not found, abort\n", font);
fileproblem();
goto _L9999;
}
i = 1;
j = 0;
strcpy(cmd, " ");
while (i <= strlen(bmname)) {
if (bmname[i - 1] == '.')
j = i;
i++;
}
if (j > 0)
strsub(cmd, bmname, j + 1, strlen(bmname) - j + 1);
if (!strcmp(cmd, "tif") || !strcmp(cmd, "TIF") ||
!strcmp(cmd, "tiff") || !strcmp(cmd, "TIFF"))
tifint();
else {
if (!strcmp(cmd, "pcx") || !strcmp(cmd, "PCX"))
pcxint();
else if (!strcmp(cmd, "lbm") || !strcmp(cmd, "LBM") ||
!strcmp(cmd, "iff") || !strcmp(cmd, "IFF"))
iffint();
else if (!strcmp(cmd, "gif") || !strcmp(cmd, "GIF"))
gifint();
else if (!strcmp(cmd, "bmp") || !strcmp(cmd, "BMP"))
bmpint();
else if (!strcmp(cmd, "img") || !strcmp(cmd, "IMG"))
imgint();
else if (!strcmp(cmd, "cut") || !strcmp(cmd, "CUT"))
cutint();
else
posbit = 0;
}
if (aliasused) {
strcpy(font, aliasname);
strcpy(bmname, aliasname);
}
FORLIM = strlen(bmname);
for (i = 1; i <= FORLIM; i++) {
sprintf(STR1, "%c", bmname[i - 1]);
j = strpos2(fontpre, STR1, 1);
if (j != 0)
bmname[i - 1] = fontupc[j - 1];
}
FORLIM = strlen(font);
for (i = 1; i <= FORLIM; i++) {
sprintf(STR1, "%c", font[i - 1]);
j = strpos2(fontupc, STR1, 1);
if (j != 0)
font[i - 1] = fontpre[j - 1];
}
korrfont();
nameok = true;
FORLIM = strlen(font);
for (i = 1; i <= FORLIM; i++) {
if (isdigit(font[i - 1]))
nameok = false;
}
if (!nameok) {
printf("no digits allowed in name of font\n");
goto _L9999;
}
strcpy(bmname, font);
FORLIM = strlen(bmname);
for (i = 1; i <= FORLIM; i++) { /*:112*/
sprintf(STR1, "%c", bmname[i - 1]);
j = strpos2(fontpre, STR1, 1);
if (j != 0)
bmname[i - 1] = fontupc[j - 1];
}
/*113:*/
if (truehres <= 0 || truehres > 2000)
truehres = 300.0;
if (truevres <= 0 || truevres > 2000)
truevres = 300.0;
whatistrue();
if (hres != (long)floor(truehres + 0.5))
printf("maximum width of characters is %ld pixel\n",
hres);
if (vres != (long)floor(truevres + 0.5))
printf("maximum height of characters is %ld pixel\n",
vres);
if (posbit != 0)
pxlinlen = (halfk)((mapwidth + 7) / 8);
else {
pxlinlen = mapinlen;
mapwidth = pxlinlen * 8;
if (greypxl) /*115:*/
mapwidth /= bitspsam;
if (mapwidth < 1) {
printf("Width not correct!\n");
goto _L9999;
}
mapheight = P_maxpos(bitmap) / mapinlen;
if (P_maxpos(bitmap) % mapinlen > 0) {
printf("Remainder > 0 when dividing size of file by width!\n");
goto _L9999;
}
/* p2c: bm2font.p, line 1032:
* Note: Using % for possibly-negative arguments [317] */
if (greypxl) {
mapdiv = 1.0;
photoinf = 15;
FORLIM1 = bitspsam;
for (cb = 1; cb <= FORLIM1; cb++)
mapdiv *= 2;
mapdiv /= 16;
} /*:115*/
}
if (pxlinlen > 3000) {
printf("File not processable, width > 3000 bytes\n");
goto _L9999;
} /*:113*/
if (newwidth != 0 || newheight != 0)
scaling();
if (greypxl) { /*96:*/
printf("Halftone picture required\n");
pxlinlen = (halfk)
(((unsigned long)(mapwidth * bitspsam + 7)) >> 3);
greypix = mapwidth;
mapwidth *= bitspsam; /*97:*/
sprintf(tmpname, "%s.tmp", font);
strcpy(tmpfil_NAME, tmpname);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("tempfile %s not accessable, abort\n", tmpname);
fileproblem();
goto _L9999;
}
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "wb", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "wb");
_SETIO(tmpfil != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) { /*:97*/
printf("Tempfile for font %s not found, abort\n",
font);
fileproblem();
goto _L9999;
}
/*103:*/
k = 0;
if (usepxl != vusepxl) {
FORLIM = vusepxl;
for (i = 0; i < FORLIM; i++) {
FORLIM2 = usepxl;
for (j = 0; j < FORLIM2; j++) {
k++;
tab[k - 1][0] = i + 1;
tab[k - 1][1] = j + 1;
tab[k - 1]
[2] = i * i * (usepxl - 1) * (usepxl - 1) +
j * j * (vusepxl - 1) * (vusepxl - 1);
}
}
FORLIM = k;
for (i = 1; i <= FORLIM; i++) {
FORLIM2 = k;
for (j = i; j <= FORLIM2; j++) {
if (tab[i - 1][2] > tab[j - 1][2]) {
lx = tab[i - 1][0];
tab[i - 1][0] = tab[j - 1][0];
tab[j - 1][0] = lx;
lx = tab[i - 1][1];
tab[i - 1][1] = tab[j - 1][1];
tab[j - 1][1] = lx;
lx = tab[i - 1][2];
tab[i - 1][2] = tab[j - 1][2];
tab[j - 1][2] = lx;
}
}
}
FORLIM = k;
for (i = 1; i <= FORLIM; i++) {
lx = tab[i - 1][0];
ly = tab[i - 1][1];
ditherm[lx - 1][ly - 1] = i;
}
}
if (usepxl > 7)
usepxl = 7;
if (vusepxl > 7)
vusepxl = 7;
maxcol = 1;
cb = 0;
usecol = usepxl * vusepxl * 4;
FORLIM = bitspsam;
for (k = 1; k <= FORLIM; k++)
maxcol *= 2;
maxcol--;
for (k = 1; k <= 4; k++) {
for (i = 0; i <= 196; i++) {
for (j = 1; j <= 7; j++)
pattern[k - 1][i][j - 1] = 0;
}
}
FORLIM = vusepxl;
for (i = 1; i <= FORLIM; i++) {
FORLIM2 = usepxl;
for (j = 1; j <= FORLIM2; j++) {
if (ditherm[i - 1][j - 1] <= usecol / 4 &&
ditherm[i - 1][j - 1] > 0) {
v = (ditherm[i - 1][j - 1] - 1) * 4 + 1;
for (ccol = 1; ccol <= 4; ccol++) {
if (ccol == 1)
c = 1;
else if (ccol == 2)
c = 3;
else if (ccol == 3)
c = 4;
else
c = 2;
FORLIM3 = usecol;
for (k = v; k <= FORLIM3; k++) {
switch (c) {
case 4:
if (usepxl > 2 || vusepxl > 2)
pattern[0][k]
[j - 1] |= (cb + 2) << (7 - i);
else
pattern[0][k]
[i - 1] |= (cb + 2) << (7 - j);
break;
case 1:
pattern[1][k]
[vusepxl - i] |= (cb + 1) << (j - usepxl + 7);
break;
case 2:
if (usepxl > 2 || vusepxl > 2)
pattern[2][k]
[vusepxl - j] |= (cb + 2) << (7 - i);
else
pattern[2][k]
[vusepxl - i] |= (cb + 2) << (7 - j);
break;
case 3:
pattern[3][k]
[i - 1] |= (cb + 1) << (j - usepxl + 7);
break;
}
}
v++;
}
}
}
}
if (nowhite)
pattern[1][0][usepxl - 1] = 128 >> (usepxl - 1);
usecol -= brightness; /*:103*/
/*[104:]append(logfile);
for k:=0 to usecol do begin for j:=1 to vusepxl do begin for i:=1 to 4
do begin cb:=pattern[i,k,j];write(logfile,cb:4,' ');
for pk:=1 to usepxl do begin if cb>127 then write(logfile,'1')else write
(logfile,'0');cb:=cb shl 1;end;write(logfile,' ');end;
writeln(logfile,'.');end;writeln(logfile,'---- ',k:1,' ----');end;
close(logfile);[:104]*/
greypix -= greypix & 1;
if (ledprinter)
gbufpp = ((long)floor(greypix * (usepxl + 0.5) + 0.5) *
hrep + 7) / 8;
else
gbufpp = (greypix * usepxl * hrep + 7) / 8;
if (gbufpp > 1280) {
printf("Only up to 1280 bytes in one row allowed!\n");
printf("Try again by decreasing param <u> or <r=n>\n");
_Escape(0);
} /*98:*/
printf("Analysing and optimizing the picture\n");
pminval = 255;
pmaxval = 0;
if (cutgrey) {
checksum = mapheight;
pxlinlen = cutlen;
} else
checksum = mapheight;
pl = 0;
fseek(bitmap, posbit, SEEK_SET);
do {
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
colpos = 0;
cutrep = 0;
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++) {
tmpcolor = getcolor();
if (tmpcolor > pmaxval)
pmaxval = tmpcolor;
if (tmpcolor < pminval)
pminval = tmpcolor;
}
checksum--;
if (cutgrey)
pxlinlen = b1[pxlinlen - 1] * 256 + b1[pxlinlen - 2] + 2;
} while (checksum != 0);
if (pminval == pmaxval) {
printf("Only one color (value %d) used by bitmap!\n",
pmaxval);
printf("It makes no sence to generate a picture!\n");
_Escape(0);
} /*:98*/
if (brightness == 0) {
brightness = (long)floor((maxcol - pmaxval + pminval + 1.0) *
usecol / (maxcol + 1) + 0.5);
if (brightness > 0)
printf("Best result may be with parameter -b%ld !?\n",
brightness);
}
printf("Dithering the picture\n");
memset(greymem, 255, 65522L);
pgreymem = 0;
if (cutgrey) {
checksum = mapheight;
pxlinlen = cutlen;
} else
checksum = mapheight;
pl = 0;
fseek(bitmap, posbit, SEEK_SET);
patswitch = 4;
spreadcol = (maxcol + 1.0) / (pmaxval - pminval + 1);
patref = (double)usecol / maxcol; /*99:*/
for (k = 0; k <= 255; k++)
pxllook[k] = k;
if (invert) {
for (k = 0; k <= 255; k++)
pxllook[k] = 255 - k;
}
if (invert) {
FORLIM = pmaxval;
for (k = pminval; k <= FORLIM; k++)
pxllook[pmaxval - k + pminval] =
(long)floor((k - pminval) * spreadcol + 0.5);
invbit = 1;
invbyte = 255;
} else {
FORLIM = pmaxval;
for (k = pminval; k <= FORLIM; k++)
pxllook[k] = (long)floor((k - pminval) * spreadcol + 0.5);
}
FORLIM = maxcol;
for (k = 0; k <= FORLIM; k++)
lutone[k] = (long)floor((maxcol - k) * patref + 0.5);
if (valinc > 0) { /*100:*/
k = pminval;
pk = 0;
while (pk <= gradint && k <= pmaxval) {
pk = (long)floor(pxllook[k] * 100.0 / maxcol + 0.5);
k++;
}
pkn = pxllook[k - 1];
grxzero = pkn;
redval = valinc / 100;
FORLIM = pmaxval;
for (k = pminval; k <= FORLIM; k++) {
/*write(logfile,(pxllook[k]/maxcol):1:5
);*/
grx = pxllook[k];
if (grx <= pkn) {
if (grx > 0)
pxllook[k] =
(long)
floor(0.5 * grx *
(exp(redval * log(grx / grxzero)) +
exp(-redval * log(grx / grxzero))) + 0.5);
/* p2c: bm2font.p, line 1305: Note: Line breaker spent
* 1.4+0.40 seconds, 5000 tries on line 3965 [251] */
}
/*writeln(logfile,' ',(pxllook[k]/maxcol):1:5);*/
} /*close(logfile);;*/
/*:100*/
}
/*append(logfile);*/
FORLIM = maxcol;
for (pk = 0; pk <= FORLIM; pk++)
hktab[pk] = (long)floor((maxcol - pk) * patref * 100 + 0.5) -
(long)(lutone[pk] * 100.0);
cspread = false;
if (usecol - 1 > maxcol) {
pk = usecol;
for (k = maxcol; k >= 0; k--) {
if (invert)
pk = usecol - lutone[pxllook[maxcol - k]];
else
pk = usecol - lutone[pxllook[k]];
while (pk >= k) {
lutone[pk] = lutone[pxllook[k]];
hktab[pk] = (long)floor(lutone[pk] * 100.0 + 0.5) -
(long)floor((usecol - pk) * 100.0 + 0.5);
lutone[pk] -= hktab[pk] / 100;
pk--;
}
}
if (invert) {
FORLIM = usecol;
for (k = 0; k <= FORLIM; k++)
pxllook[k] = lutone[k];
} else {
FORLIM = usecol;
for (k = 0; k <= FORLIM; k++)
pxllook[k] = usecol - lutone[k];
}
maxcol = usecol;
cspread = true;
}
invert = false;
mapdiv = (usecol + 1.0) / 16;
FORLIM = usecol;
for (k = 0; k <= FORLIM; k++)
lutvga[k] = (long)((usecol - k) / mapdiv);
for (pk = -255; pk <= 255; pk++) {
if (cspread)
gkorh[pk + 255] = (long)(pk / 2.0);
else
gkorh[pk + 255] = (long)floor(pk / 2.0 * spreadcol + 0.5);
if (cspread)
gkordivp[pk + 255] = (long)(pk / 2.0);
else
gkordivp[pk + 255] = (long)
(pk / 2.0 * patref + hktab[abs(pk)] / 100.0);
}
for (pk = 0; pk <= 255; pk++) /*:99*/
spreadvals[pk] = (long)floor(pk * patref + 0.5);
do {
pxlinlen = fread(b1, 1, pxlinlen, bitmap);
colpos = 0;
cutrep = 0;
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b4[pk] = getcolor();
if (cspread) {
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b4[pk] = spreadvals[b4[pk]];
}
if (distribute) { /*101:*/
pk = 1;
pkn = 1;
while (pk < greypix) {
pkn++;
greykor = 0;
if (b4[pk] != b4[pkn]) {
greykor = gkorh[b4[pk] - b4[pkn] + 255];
greykor = gkordivp[greykor + 255];
}
if (greykor != 0) {
tmpcolor = lutone[pxllook[b4[pkn]]];
if (abs(tmpcolor + greykor) <= usecol &&
abs(tmpcolor + greykor) >= 0)
b4[pkn] += greykor;
}
pk++;
}
pk = greypix - 1;
pkn = pk;
while (pk > 0) { /*:101*/
pkn--;
greykor = 0;
if (b4[pk] != b4[pkn]) {
greykor = gkorh[b4[pk] - b4[pkn] + 255];
greykor = gkordivp[greykor + 255];
}
if (greykor != 0) {
tmpcolor = lutone[pxllook[b4[pkn]]];
if (abs(tmpcolor + greykor) <= usecol &&
abs(tmpcolor + greykor) >= 0)
b4[pkn] += greykor;
}
pk--;
}
}
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++)
b4[pk] = lutone[pxllook[b4[pk]]];
FORLIM1 = vrep;
for (yrep = 1; yrep <= FORLIM1; yrep++) { /*102:*/
FORLIM = vusepxl;
for (k = 1; k <= FORLIM; k++) {
gbufp = 0;
cb = 0;
pn = 0;
switch (patswitch) {
case 1:
curpat[0] = 2;
curpat[1] = 3;
break;
case 2:
curpat[0] = 4;
curpat[1] = 1;
break;
case 3:
curpat[0] = 3;
curpat[1] = 2;
break;
case 4:
curpat[0] = 1;
curpat[1] = 4;
break;
}
memset(b3, 0, gbufpp);
FORLIM2 = greypix;
for (pk = 0; pk < FORLIM2; pk++) {
FORLIM4 = hrep;
for (xrep = 1; xrep <= FORLIM4; xrep++) {
cb = pattern[curpat[pn] - 1][b4[pk]][k - 1];
dbuf = ((unsigned)gbufp) >> 3;
bufsh = gbufp & 7;
nextbuf = bufsh + usepxl;
switch (bufsh) {
case 0:
b3[dbuf] = cb;
break;
default:
b3[dbuf] |= cb >> bufsh;
if (nextbuf > 8)
b3[dbuf + 1] = cb << (8 - bufsh);
break;
}
gbufp += usepxl;
if (ledprinter) {
if (curpat[pn] == 1 || curpat[pn] == 3)
gbufp++;
}
pn = abs(pn - 1);
}
}
FORLIM2 = gbufpp;
for (pk = 0; pk <= FORLIM2; pk++)
b3[pk] = ~b3[pk];
if (pgreymem + gbufpp > 65522L) {
_SETIO(fwrite(greymem, pgreymem, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
pgreymem = 0;
}
memmove(&greymem[pgreymem], b3, gbufpp);
pgreymem += gbufpp;
}
memset(b3, 255, gbufpp);
if (ledprinter) {
if (patswitch == 2 || patswitch == 4) {
if (pgreymem + gbufpp > 65522L) {
_SETIO(fwrite(greymem, pgreymem, 1, tmpfil) ==
1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(
printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
pgreymem = 0;
}
memmove(&greymem[pgreymem], b3, gbufpp);
pgreymem += gbufpp;
} /*:102*/
}
patswitch++;
if (patswitch > 4)
patswitch = 1;
}
pm = 128;
pb = pl;
FORLIM = greypix;
for (pk = 0; pk < FORLIM; pk++) {
pxlcolor = lutvga[b4[pk]];
pm >>= 1;
if (pm == 0) {
pm = 128;
pb++;
}
}
pl += 80;
if (pl >= 38400L)
pl = 0;
checksum--;
if (cutgrey)
pxlinlen = (halfk)(b1[pxlinlen - 1] * 256 +
b1[pxlinlen - 2] + 2);
} while (checksum != 0);
if (pgreymem != 0) { /*$I-*/
_SETIO(fwrite(greymem, pgreymem, 1, tmpfil) == 1,
FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n",
tmpname) >= 0, FileWriteError);
fileproblem();
_Escape(0);
}
}
posbit = 0;
if (ledprinter)
mapwidth =
(long)floor(greypix * (usepxl + 0.5) + 0.5) * hrep;
else
mapwidth = greypix * usepxl * hrep;
pxlinlen = (mapwidth + 7) / 8;
mapinlen = pxlinlen;
if (ledprinter)
mapheight =
(long)floor(mapheight * (vusepxl + 0.5) + 0.5) * vrep;
else
mapheight *= vusepxl * vrep;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
strcpy(bitmap_NAME, tmpname);
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
} /*114:*/
checksum = mapheight * ((mapwidth + 7) / 8);
mapheight = 0;
freelines = 0;
fseek(bitmap, posbit, SEEK_SET);
while (checksum >= pxlinlen) {
fread(b1, pxlinlen, 1, bitmap);
mapwidth = pxlinlen * 8;
j = pxlinlen - 1;
while (b1[j] == invbyte && j >= 0)
j--;
if (j >= 0) {
i = 0;
while (b1[i] == invbyte && i <= j)
i++;
if (i < minx)
minx = i;
lx = j * 8 + 8;
cb = b1[j];
for (i = 1; i <= 8; i++) {
if ((cb & 1) == invbit) {
cb >>= 1;
lx--;
} else
i = 8;
}
if (lx > maxx)
maxx = lx;
freelines++;
mapheight += freelines;
freelines = 0;
} else if (mapheight == 0)
posbit += pxlinlen;
else
freelines++;
checksum -= pxlinlen;
}
mapwidth = maxx - minx * 8;
zeropads = pxlinlen - (mapwidth + 7) / 8;
maplines = mapheight;
posbit += minx; /*:114*/
/*116:*/
i = (mapwidth + hres - 1) / hres;
j = (mapheight + vres - 1) / vres;
nofchars = i * j;
charpf = 515832L / (vres * ((hres + 31) / 32) * 32);
noffonts = (nofchars + charpf - 1) / charpf;
if (charpf > 76) {
charpf = 76;
noffonts = (nofchars + 75) / 76;
}
if (noffonts > 26) {
printf("more than 26 fonts necessary, try a smaller bitmap\n");
goto _L9999;
}
/*:116*/
/*120:*/
k = 0;
c = 0;
while (mapheight > 0) { /*:120*/
maxx = mapwidth;
while (maxx > 0) {
if (maxx > hres)
pwidth[k][cref[c]] = hres;
else
pwidth[k][cref[c]] = maxx;
if (mapheight > vres)
pheight[k][cref[c]] = vres;
else
pheight[k][cref[c]] = mapheight;
c++;
if (c == charpf) {
k++;
c = 0;
}
maxx -= hres;
}
mapheight -= vres;
}
/*121:*/
FORLIM = noffonts;
for (a = 0; a < FORLIM; a++) { /*:121*/
lh = 17;
bc = cref[0];
ec = 127;
while (pheight[a][ec] == 0) /*122:*/
ec--;
sprintf(cmd, "%s%c.tfm", font, fontpre[a]);
strcpy(tfmfile_NAME, cmd);
if (tfmfile != NULL)
tfmfile = freopen(tfmfile_NAME, "wb", tfmfile);
else
tfmfile = fopen(tfmfile_NAME, "wb");
_SETIO(tfmfile != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 3 || filestat == 5) {
strcpy(cmd, bmname);
sprintf(cmd + strlen(cmd), "%c.tfm", fontupc[a]);
strcpy(tfmfile_NAME, cmd);
if (tfmfile != NULL)
tfmfile = freopen(tfmfile_NAME, "wb", tfmfile);
else
tfmfile = fopen(tfmfile_NAME, "wb");
_SETIO(tfmfile != NULL, FileNotFound);
filestat = P_ioresult;
}
if (filestat == 0)
fok = false;
else
fok = true;
if (fok) {
printf("error occurred when allocating tfmfile ");
puts(cmd);
fileproblem();
goto _L9999;
}
printf("generating tfmfile %s\n", cmd); /*:122*/
if (pheight[a][bc] > pwidth[a][bc])
dsize = (long)floor(pheight[a][bc] / truehres *
72.27 * 65536L * 16 + 0.5);
else
dsize = (long)floor(pwidth[a][bc] / truehres * 72.27 *
65536L * 16 + 0.5);
tabdsize[a] = dsize;
FORLIM2 = ec;
for (k = bc; k <= FORLIM2; k++) {
height[a]
[k] = (long)floor(pheight[a][k] / truevres *
4736286.7227 / dsize * 16777215L + 0.5);
width[a]
[k] = (long)floor(pwidth[a][k] / truehres * 4736286.7227 /
dsize * 16777215L + 0.5);
}
fh = height[a][bc];
fw = width[a][bc];
sh = fh;
sw = fw;
nw = 2;
nh = 2;
FORLIM2 = ec;
for (k = bc; k <= FORLIM2; k++) {
if (height[a][k] != 0 && height[a][k] != fh &&
height[a][k] != sh) {
sh = height[a][k];
nh++;
}
if (width[a][k] != 0 && width[a][k] != fw &&
width[a][k] != sw) {
sw = width[a][k];
nw++;
}
}
if (nh > 3) {
printf("more than 2 heights, should be impossible\n");
goto _L9999;
}
if (nw > 3) {
printf("more than 2 widths, should be impossible\n");
goto _L9999;
}
nd = 2;
ni = 2;
nl = 0;
nk = 0;
ne = 0;
np = 0;
lf = lh + ec - bc + nw + nh + nd + ni + nk + nl + ne +
np + 7;
checksum = 0;
tfmhword(lf);
tfmhword(lh);
tfmhword(bc);
tfmhword(ec);
tfmhword(nw);
tfmhword(nh);
tfmhword(nd);
tfmhword(ni);
tfmhword(nl);
tfmhword(nk);
tfmhword(ne);
tfmhword(np);
tfmword(checksum);
tfmword(dsize);
strcpy(tfmstr, "0Graphic");
tfmstr[0] = '\007';
FORLIM2 = strlen(tfmstr);
for (i = 1; i <= FORLIM2; i++) {
tfmb = tfmstr[i - 1];
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
}
tfmb = 0;
for (i = 1; i <= 32; i++)
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
strcpy(tfmstr, "0Bitmap");
tfmstr[0] = '\006';
FORLIM2 = strlen(tfmstr);
for (i = 1; i <= FORLIM2; i++) {
tfmb = tfmstr[i - 1];
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
}
tfmb = 0;
for (i = 1; i <= 13; i++)
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
FORLIM2 = ec;
for (i = bc; i <= FORLIM2; i++) {
if (width[a][i] == 0) {
tfmb = 0;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
} else if (width[a][i] == fw) {
tfmb = 1;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
} else {
tfmb = 2;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
}
if (height[a][i] == 0) {
tfmb = 0;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
} else if (height[a][i] == fh) {
tfmb = 16;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
} else {
tfmb = 32;
fwrite(&tfmb, sizeof(uchar), 1, tfmfile);
}
tfmhword(0);
}
tfmword(0);
tfmword(fw);
if (nw > 2)
tfmword(sw);
tfmword(0);
tfmword(fh);
if (nh > 2)
tfmword(sh);
tfmword(0);
tfmword(0);
tfmword(0);
tfmword(0);
if (tfmfile != NULL)
fclose(tfmfile);
tfmfile = NULL;
}
/*117:*/
sprintf(cmd, "%s.tex", font);
strcpy(texfile_NAME, cmd);
if (texfile != NULL)
texfile = freopen(texfile_NAME, "w", texfile);
else
texfile = fopen(texfile_NAME, "w");
_SETIO(texfile != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
if (filestat == 5) {
*cmd = '\0';
sprintf(cmd + strlen(cmd), "%s.tex", font);
strcpy(texfile_NAME, cmd);
if (texfile != NULL)
texfile = freopen(texfile_NAME, "w", texfile);
else
texfile = fopen(texfile_NAME, "w");
_SETIO(texfile != NULL, FileNotFound);
filestat = P_ioresult;
if (filestat == 0)
fok = false;
else
fok = true;
}
if (fok) { /*:117*/
printf("%s error occured when allocating TeXfile %s\n",
cmd, cmd);
fileproblem();
goto _L9999;
}
/*118:*/
fprintf(texfile, "\\newbox\\%sbox\n", font);
fprintf(texfile, "\\newdimen\\%swd\n", font);
FORLIM = noffonts;
for (a = 1; a <= FORLIM; a++) {
fprintf(texfile, "\\font\\%s%c=%s%c at ",
font, fontpre[a - 1], font, fontpre[a - 1]);
outfix(tabdsize[a - 1]);
fprintf(texfile, "truept\n");
}
fprintf(texfile, "\\setbox\\%sbox=\\vbox{\\hbox{%%\n",
font);
a = 0;
k = 1;
c = 1;
i = (mapwidth + hres - 1) / hres;
FORLIM = i;
for (b = 1; b <= FORLIM; b++) {
if (a != k) {
fprintf(texfile, "\\%s%c ", font, fontpre[k - 1]);
a = k;
}
putc(cref[c - 1], texfile);
c++;
if (c > charpf) {
k++;
c = 1;
}
}
fprintf(texfile, "}}\n"); /*:118*/
/*119:*/
fprintf(texfile, "\\%swd=\\wd\\%sbox\n", font, font);
fprintf(texfile,
"\\setbox\\%sbox=\\hbox{\\vbox{\\hsize=\\%swd\n",
font, font);
fprintf(texfile,
"\\parskip=0pt\\offinterlineskip\\parindent0pt\n");
v = 1;
k = 1;
c = 1;
FORLIM = j;
for (a = 0; a < FORLIM; a++) {
fprintf(texfile, "\\hbox{\\%s%c ", font, fontpre[k - 1]);
v = k;
FORLIM2 = i;
for (b = 0; b < FORLIM2; b++) {
if (v != k) {
fprintf(texfile, "\\%s%c ", font, fontpre[k - 1]);
v = k;
}
putc(cref[c - 1], texfile);
c++;
if (c > charpf) {
k++;
c = 1;
}
}
if (a < j - 1)
fprintf(texfile, "}\n");
}
fprintf(texfile, "}}}\n");
fprintf(texfile, "\\ifx\\parbox\\undefined\n");
fprintf(texfile, " \\def\\set%s{\\box\\%sbox}\n",
font, font);
fprintf(texfile, "\\else\n");
fprintf(texfile, " \\def\\set%s{\\parbox{\\wd\\%sbox}",
font, font);
fprintf(texfile, "{\\box\\%sbox}}\n", font);
fprintf(texfile, "\\fi\n");
if (texfile != NULL)
fclose(texfile);
texfile = NULL; /*:119*/
printf("TeX Font Metric files written, generating fonts at ");
printf("%ld dpi\n", (long)floor(truehres + 0.5));
maxx = (mapwidth + hres - 1) / hres;
f = 0;
g = 0; /*if pxlmod then prepxlfile else*/
pxlbmi = 4;
if (fok) {
printf("error occurred when allocating pxlfile ");
puts(cmd);
fileproblem();
goto _L9999;
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
fonteject(); /*108:*/
if (pcxtemp)
/* p2c: bm2font.p, line 1305:
* Note: Called procedure Exec [285] */
Exec("rm", "pcxtemp.tmp");
if (giftemp)
/* p2c: bm2font.p, line 1305:
* Note: Called procedure Exec [285] */
Exec("rm", "giftemp.tmp");
if (greypxl)
/* p2c: bm2font.p, line 1305:
* Note: Called procedure Exec [285] */
Exec("rm", tmpname);
printf("input %s.tex into your document", font);
printf(" and set the picture with \\set%s\n", font);
/*:108*/
_L9999:
if (texfile != NULL)
fclose(texfile);
if (bitmap != NULL)
fclose(bitmap);
if (pxlfile != NULL)
fclose(pxlfile);
if (tmpfil != NULL)
fclose(tmpfil);
if (tfmfile != NULL)
fclose(tfmfile);
exit(EXIT_SUCCESS);
} /*:105*/
/* End. */