home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
beehive
/
utilitys
/
kwikfont.arc
/
KWIKFONT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1990-12-26
|
14KB
|
528 lines
{$C-}
program KwikFont;
{version 1.80 copyright 1988 by Sam Bellotto Jr. October 29, 1988}
type letrec =record
width :integer;
pass1 :array[1..32] of byte;
pass2 :array[1..32] of byte;
pass3 :array[1..32] of byte;
pass4 :array[1..32] of byte;
end;
str80 =string[80];
str14 =string[14];
const ht01 =#27#65#1; {line height to 01/72}
ht08 =#27#65#8; {line height to 08/72}
ht12 =#27#65#12; {line height to 12/72}
ht216 =#27#51#1; {line height to 01/216}
d60 =#27#42#0; {60 dots per inch}
d80 =#27#42#4; {80 dots per inch}
d90 =#27#42#6; {90 dots per inch}
dot =#128; {one col bit-mapped dot}
spc =#0; {one col bit-mapped space}
exp =6; {6 dots per 10 pitch char}
nrm =8; {8 dots per 10 pitch char}
con =9; {9 dots per 10 pitch char}
lmpre =#27#108; {left margin set prefix}
clesc =#23; {clear to end of screen}
pset =#27#64; {reset printer}
var fontfile :file of letrec;
textfile :text;
recvar :array[1..80] of letrec;
j,runs,
hits,dl,
cw :integer;
skp :real;
dum :char;
prepln :string[5];
dpi :string[3];
filvar,
fname :str14;
line :array[1..23] of str80;
asc,fmf,
nlq,pbp :boolean;
procedure AllCaps(var afn:str14);
var i :integer;
begin
for i:=1 to length(afn) do
if afn[i] in['a'..'z']
then afn[i]:=upcase(afn[i])
end;
procedure EstabRuns;
var ext :str14;
c,p :integer;
begin
nlq:=false;
ext:=copy(fname,length(fname)-1,2);
val(ext,p,c);
case p of
12:begin
runs:=2;
nlq:=true
end;
16:runs:=2;
24:runs:=3;
32:runs:=4;
else runs:=0
end
end;
procedure PrintOut;
var f,i,p,r,
w,loop,
tab :integer;
ctr,flr,
ind,uln :boolean;
procedure CalcWidth(var oneln:str80);
begin
w:=0;
dpi:=d80;
dl:=nrm*cw;
ctr:=false;
flr:=false;
ind:=false;
uln:=false;
repeat
if oneln[1]=';' then
begin
case oneln[2] of
'c','C':ctr:=true; {centered}
'r','R':flr:=true; {flush right}
'u','U':uln:=true; {underline}
't','T':begin {indented}
ind:=true;
delete(oneln,1,2);
val(copy(oneln,1,2),i,p);
if p<>0 then i:=0
end;
'x','X':begin {expanded}
dpi:=d60;
dl:=exp*cw
end;
'd','D':begin {condensed}
dpi:=d90;
dl:=con*cw
end
end;
oneln:=copy(oneln,3,length(oneln)-2);
if length(oneln)=0 then oneln:=' '
end
until oneln[1]<>';';
for p:=1 to length(oneln) do
begin
w:=w+1; {interletter space}
r:=ord(oneln[p])-32;
{$I-} seek(fontfile,r); {$I+}
if ioresult<>0 then
begin
gotoxy(47,1);clreol;
write('** PROGRAM ABORTED **');
gotoxy(1,3);
writeln(^G,'++ ',filvar,' NOT ASCII ++');
halt
end;
read(fontfile,recvar[p]);
with recvar[p] do w:=w+width
end;
if ind then tab:=(dl div cw)*i else
if ctr then tab:=(dl-w) div 2 else
if flr then tab:=dl-w else tab:=0;
w:=w+tab;
prepln:=dpi+chr(w mod 256)+chr(w div 256)
end;
procedure SetTab;
var s :integer;
begin
if tab>0 then
begin
for s:=1 to tab do
write(lst,spc)
end
end;
procedure ChangeFonts;
var ok :boolean;
procedure CallErr(msg:str80);
begin
gotoxy(47,1);write('** ERROR ** ');
gotoxy(1,3);
writeln(^G,fname,msg);
write('Change to: ');
read(fname);
gotoxy(1,3);write(clesc);
gotoxy(47,1);write('Printing ... ')
end;
begin
fname:=copy(line[f],2,length(line[f])-1);
repeat
ok:=true;
AllCaps(fname);
if fname='PICA' then
begin
asc:=true;
writeln(lst);
write(lst,ht12)
end else begin
if asc then
begin
asc:=false;
write(lst,ht08)
end;
EstabRuns;
close(fontfile);
if runs=0 then
begin
ok:=false;
CallErr(' is illegal!')
end;
if ok then
begin
assign(fontfile,fname);
{$I-} reset(fontfile); {$I+}
if ioresult<>0 then
begin
ok:=false;
CallErr(' doesn''t exist!')
end
end
end
until ok;
gotoxy(65,1);clreol;
write(fname)
end;
procedure RunOneLine;
begin
CalcWidth(line[f]);
for loop:=1 to hits do
begin
write(lst,prepln);
SetTab;
for p:=1 to length(line[f]) do
begin
with recvar[p] do
begin
for i:=1 to width do
write(lst,chr(pass1[i]));
write(lst,spc) {interletter space}
end
end;
if hits>1 then write(lst,#13)
end;
if nlq then writeln(lst,ht216) {down 1/216 inch space}
else begin
writeln(lst);
skp:=skp+1
end;
for loop:=1 to hits do
begin
write(lst,prepln);
SetTab;
for p:=1 to length(line[f]) do
begin
with recvar[p] do
begin
for i:=1 to width do
write(lst,chr(pass2[i]));
write(lst,spc) {interletter space}
end
end;
if hits>1 then write(lst,#13)
end;
if nlq then writeln(lst,ht12)
else writeln(lst,ht08);
skp:=skp+1;
if runs>2 then
begin
for loop:=1 to hits do
begin
write(lst,prepln);
SetTab;
for p:=1 to length(line[f]) do
begin
with recvar[p] do
begin
for i:=1 to width do
write(lst,chr(pass3[i]));
write(lst,spc) {interletter space}
end
end;
if hits>1 then write(lst,#13)
end;
writeln(lst);
skp:=skp+1;
if runs=4 then
begin
for loop:=1 to hits do
begin
write(lst,prepln);
SetTab;
for p:=1 to length(line[f]) do
begin
with recvar[p] do
begin
for i:=1 to width do
write(lst,chr(pass4[i]));
write(lst,spc) {interletter space}
end
end;
if hits>1 then write(lst,#13)
end;
writeln(lst);
skp:=skp+1
end
end;
if f<j then
begin
writeln(lst,ht01); {down 1/72 inch space}
if uln then
begin
write(lst,prepln);
SetTab;
for i:=1 to w do
write(lst,dot);
writeln(lst);
writeln(lst,ht01)
end;
write(lst,ht08) {set line height}
end
end;
procedure PrintPica(var oneln:str80);
var x,t :integer;
begin
t:=0;
repeat
if oneln[1]=';' then
begin
case oneln[2] of
't','T':begin
delete(oneln,1,2);
val(copy(oneln,1,2),t,x);
if x<>0 then t:=0
end;
'c','C':t:=(cw-length(oneln)) div 2;
'r','R':t:=(cw-length(oneln));
end;
oneln:=copy(oneln,3,length(oneln)-2)
end
until oneln[1]<>';';
if t>0 then
for x:=1 to t do write(lst,' ');
writeln(lst,oneln);
skp:=skp+1.5
end;
procedure InsLine;
begin
gotoxy(47,1);write(^G,'Waiting .... ');
gotoxy(1,3);
write('Insert: ');
read(line[f]);
if length(line[f])=0
then line[f]:=' '; {fill null line}
gotoxy(1,3);clreol;
gotoxy(47,1);write('Printing ... ')
end;
begin
f:=0;
if not asc then write(lst,ht08); {set line height}
repeat
repeat
f:=f+1;
if (line[f]=';p') or (line[f]=';P') then
begin
write(lst,#12); {forced page break}
skp:=0
end else begin
if (copy(line[f],1,2)=';M')
or (copy(line[f],1,2)=';m')
or (copy(line[f],1,2)=';W')
or (copy(line[f],1,2)=';w')
then begin
val(copy(line[f],3,2),i,p);
if p=0 then
begin
if (copy(line[f],2,1))
in['M','m'] then
write(lst,lmpre,chr(i)); {set left margin}
if (copy(line[f],2,1))
in['W','w'] then cw:=i {set page width}
end
end else begin
if line[f][1]='.' then
ChangeFonts
else begin
if (line[f]=';i') or (line[f]=';I') then
InsLine;
if asc then PrintPica(line[f])
else RunOneLine
end
end
end
until (skp>77) or (f=j);
if skp>77 then
begin
if pbp then
begin
gotoxy(47,1);write('Pausing .... ');
gotoxy(1,3);
write('Ready? ');
read(kbd,dum);
gotoxy(1,3);clreol;
gotoxy(47,1);write('Printing ... ')
end;
if fmf then write(lst,#12); {conditional form feed}
skp:=0
end
until f=j
end;
procedure OutPutJob;
var h :char;
c :integer;
procedure FromTerminal;
var y :integer;
ans :char;
begin
repeat
gotoxy(1,3);
write(clesc);
j:=0;y:=3;
repeat
j:=j+1;
gotoxy(1,y);
if y=21 then write(^G,'LAST LINE> ')
else write('> ');
read(line[j]);
y:=y+1;
until (length(line[j])=0) or (y=22);
if length(line[j])=0
then line[j]:=' '; {fill null line}
gotoxy(1,y+1);
write('OK to print? ');
read(kbd,ans)
until ans in['Y','y',#13];
gotoxy(1,3);
write(clesc);
gotoxy(47,1);
write('Printing ... ');
PrintOut
end;
procedure FromDisk;
begin
assign(textfile,filvar);
{$I-} reset(textfile); {$I+}
if ioresult<>0 then FromTerminal
else begin
gotoxy(1,3);
write(clesc);
gotoxy(47,1);
write('Printing ... ');
while not eof(textfile) do
begin
j:=0;
repeat
j:=j+1;
readln(textfile,line[j]);
if length(line[j])=0
then line[j]:=' '; {fill null lines}
until (j=22) or eof(textfile);
PrintOut
end
end
end;
begin
cw:=80;
skp:=0;
gotoxy(1,1);write('KwikFont 1.80 (c) 1988 by Sam Bellotto Jr.');
gotoxy(65,1);write(fname);
gotoxy(1,3);
write('Strikes? ':21);
read(kbd,h);
val(h,hits,c);
if (c<>0) or not (hits in[1..6])
then hits:=1;
write(hits);
gotoxy(1,4);
write('Use form feeds? ':21);
read(kbd,dum);
if dum in['Y','y'] then fmf:=true
else begin
fmf:=false;
dum:='N'
end;
write(upcase(dum));
gotoxy(1,5);
write('Pause between pages? ':21);
read(kbd,dum);
if dum in ['Y','y'] then pbp:=true
else begin
pbp:=false;
dum:='N'
end;
write(upcase(dum));
gotoxy(1,6);
write('Disk file? ':21);
read(filvar);
if length(filvar)=0 then FromTerminal
else begin
AllCaps(filvar);
FromDisk
end
end;
procedure ErrMess(msg:str80);
begin
writeln(^G);
writeln(msg);
halt
end;
procedure CallDos;
var d:integer;
begin
d:=bdos($19);
bdos($0E,d)
end;
begin {main}
CallDos;
asc:=false;
if length(paramstr(1))=0 then
begin
fname:='PICA';
asc:=true;
write(lst,ht12)
end else begin
fname:=paramstr(1);
EstabRuns;
if runs=0 then
ErrMess('++ ILLEGAL FILE ++');
assign(fontfile,fname);
{$I-} reset(fontfile); {$I+}
if ioresult<>0 then
ErrMess('++ FILE DOES NOT EXIST ++')
end;
clrscr;
OutPutJob;
writeln(lst,pset); {reset printer}
gotoxy(47,1);
write(^G,'*** Finished ');
delay(3000);
clrscr
end.