home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
text
/
jemtex-2.00.lha
/
JemTeX
/
sources
/
jis2mf.pas
< prev
Wrap
Pascal/Delphi Source File
|
1993-12-21
|
33KB
|
940 lines
{$A-,B-,D-,E-,F-,I+,L-,N-,O-,R-,S-,V-}
{Compile with Turbo-Pascal 5.0}
Program JIS2MF(Input,Output);
{
This program generates METAFONT code from a Bitmaps file JIS24
Author: Francois Jalbert
'
Date: November 1990
Version: 1.0
Date: April 1991
Version: 2.00
Modifications: - Added four kanjis.
- Fixed incorrect VGA resolution.
- Command line parameter now supported.
- Added automatic mode.
- Added batch mode.
- Updated and improved run-time messages.
- Long triangles added by Mr. Masatoshi Watanabe. Fantastic!
- Fixed and proportional parameters added.
- Standard and dictionary parameters added.
- JIS24 now accessed through low-level I/O channel for speed.
Error Levels: 0 - Normal termination.
1 - Error.
2 - All fonts generated (batch).
}
Const
{Number of Bitmaps in JIS24}
BitmapMax=7806;
{Size of each square Bitmap}
SizeMax=24;
SizeMax1=25;
{DOS Record Size}
RecSize=72; {SizeMax*SizeMax/8}
{Parameter flag}
Flag1='/'; {DOS style}
Flag2='-'; {UNIX style}
{Parameter keywords}
FixedX1:String[10]='FIXEDWIDTH';
FixedX2:String[6]='FIXEDX';
FixedX3:String[19]='NOPROPORTIONALWIDTH';
FixedX4:String[15]='NOPROPORTIONALX';
NoFixedX1:String[12]='NOFIXEDWIDTH';
NoFixedX2:String[8]='NOFIXEDX';
NoFixedX3:String[17]='PROPORTIONALWIDTH';
NoFixedX4:String[13]='PROPORTIONALX';
FixedY1:String[11]='FIXEDHEIGHT';
FixedY2:String[6]='FIXEDY';
FixedY3:String[20]='NOPROPORTIONALHEIGHT';
FixedY4:String[15]='NOPROPORTIONALY';
NoFixedY1:String[13]='NOFIXEDHEIGHT';
NoFixedY2:String[8]='NOFIXEDY';
NoFixedY3:String[18]='PROPORTIONALHEIGHT';
NoFixedY4:String[13]='PROPORTIONALY';
Standard1:String[8]='STANDARD';
NoStandard1:String[10]='DICTIONARY';
Batch1:String[5]='BATCH';
Type
InFileType=File; {Low-level I/O channel}
OutFileType=Text;
BitmapRange=1..BitmapMax;
Bitmap0Range=0..BitmapMax;
SizeRange=1..SizeMax;
Size0Range=0..SizeMax1;
{Buffer for the Bitmap Data}
ColumnType=Record Data1,Data2,Data3:Byte End;
BufferType=Array [SizeRange] Of ColumnType;
{The Bitmap array is defined larger to simplify the forthcoming code}
BitmapType=Array [Size0Range,Size0Range] Of Boolean;
BitmapsType=Record
Bitmap:BitmapType;
XMin,XMax,YMin,YMax:Size0Range
End;
{Run time parameters}
RunTimeType=Record
FileName:String;
{Batch mode}
Batch:Boolean;
{Automatic mode for JemTeX fonts only}
Automatic:Boolean;
{Fixed or proportional fonts}
FixedX,FixedY:Boolean;
{Standard or dictionary fonts}
Standard:Boolean
End;
Var
{JIS24 and METAFONT file names}
InFile:InFileType;
OutFile:OutFileType;
{Current METAFONT character number}
Number:Integer;
{Run time parameters}
RunTime:RunTimeType;
{-------------------------------- GetParameters ------------------------------}
Procedure SimpleQuery(Title,ChoiceA,ChoiceB:String; Var Answer:Boolean);
Var
JChar:Char;
Valid:Boolean;
Begin
Repeat
Valid:=True;
Writeln(Title+':');
Writeln(' a) '+ChoiceA);
Writeln(' b) '+ChoiceB);
Write('Your choice? ');
Readln(JChar);
JChar:=UpCase(JChar);
If JChar='A' Then Answer:=True
Else
If JChar='B' Then Answer:=False
Else
Begin Valid:=False; Write(Chr(7)) End
Until Valid;
Writeln
End;
Procedure GetMode(Var RunTime:RunTimeType);
{Determines if the desired font is a JemTeX font}
Begin
With RunTime Do
Begin
Automatic:=False;
If UpCase(FileName[1])='K' Then
If UpCase(FileName[2])='A' Then
If UpCase(FileName[3])='N' Then
If UpCase(FileName[4])='J' Then
If UpCase(FileName[5])='I' Then
If ('A'<=UpCase(FileName[6])) And (UpCase(FileName[6])<='H') Then
If ('A'<=UpCase(FileName[7])) And (UpCase(FileName[7])<='H') Then
If Length(FileName)=7 Then
If UpCase(FileName[6])<='G' Then Automatic:=True
Else
If UpCase(FileName[7])<='E' Then Automatic:=True
End
End;
Procedure EchoParameters(Var RunTime:RunTimeType);
{Echoes the current parameters}
Begin
With RunTime Do
Begin
Write('Font='+FileName);
If FixedX Then Write(' Fixed Width')
Else Write(' Prop. Width');
If FixedY Then Write(' Fixed Height')
Else Write(' Prop. Height');
If Standard Then Write(' Standard')
Else Write(' Dictionary');
If Automatic Then Write(' Automatic')
Else Write(' Manual');
If Batch Then Write(' Batch');
Writeln('.')
End
End;
Procedure Manual(Var RunTime:RunTimeType);
{Get parameters from user}
Begin
With RunTime Do
Begin
Write('METAFONT file name? ');
Readln(FileName);
Writeln;
SimpleQuery('Fixed or proportional font width','Fixed','Proportional',FixedX);
SimpleQuery('Fixed or proportional font height','Fixed','Proportional',FixedY);
SimpleQuery('Standard or dictionary font','Standard','Dictionary',Standard);
{Batch mode intrinsically isn't manual}
Batch:=False
End
End;
Procedure FindBefore(Var FileName:String);
{No check for before kanjiaa}
Begin
If FileName[7]='a' Then
Begin
FileName[7]:='h';
FileName[6]:=Pred(FileName[6])
End
Else
FileName[7]:=Pred(FileName[7])
End;
Procedure FindAfter(Var FileName:String);
{No check for above kanjihe}
Begin
If FileName[7]='h' Then
Begin
FileName[7]:='a';
FileName[6]:=Succ(FileName[6])
End
Else
FileName[7]:=Succ(FileName[7])
End;
Procedure ScanMF(Var FileName:String);
{Scans backwards for the last JemTeX font generated}
{Looks first for a .TFM and then for an .MF}
{If no more fonts to generate, stops with error level 2}
Var
TestFile:Text;
Found:Boolean;
Begin
FileName:='kanjihf';
Repeat
FindBefore(FileName);
Assign(TestFile,FileName+'.tfm');
{$I-}Reset(TestFile);{$I+}
{IOResult must be immediately used once only}
Found:=(IOResult=0);
If Not Found Then
Begin
Assign(TestFile,FileName+'.mf');
{$I-}Reset(TestFile);{$I+}
{IOResult must be immediately used once only}
Found:=(IOResult=0)
End;
Until Found Or (FileName='kanjiaa');
If Found Then
Begin
Close(TestFile);
If FileName='kanjihe' Then
Begin
Writeln(Chr(7)+'All JemTeX fonts generated!');
Halt(2)
End
Else FindAfter(FileName)
End
End;
Procedure Automate(Var RunTime:RunTimeType);
{Get parameters from command line}
{Finds the next font to be generated if in batch mode}
Var
ParamIndex,Index:Integer;
Param:String;
Begin
With RunTime Do
Begin
{Defaults}
FileName:='kanjiaa';
FixedX:=False;
FixedY:=False;
Standard:=True;
Batch:=False;
{Scan command line parameters}
For ParamIndex:=1 To ParamCount Do
Begin
Param:=ParamStr(ParamIndex);
If (Param[1]=Flag1) Or (Param[1]=Flag2) Then
{Not a font name}
Begin
{Delete 1 char at the 1st position}
Delete(Param,1,1);
{Convert to upper case}
For Index:=1 To Length(Param) Do
Param[Index]:=UpCase(Param[Index]);
{Scan known keywords}
If (Param=FixedX1) Or (Param=FixedX2) Or (Param=FixedX3) Or
(Param=FixedX4) Then FixedX:=True
Else
If (Param=NoFixedX1) Or (Param=NoFixedX2) Or (Param=NoFixedX3) Or
(Param=NoFixedX4) Then FixedX:=False
Else
If (Param=FixedY1) Or (Param=FixedY2) Or (Param=FixedY3) Or
(Param=FixedY4) Then FixedY:=True
Else
If (Param=NoFixedY1) Or (Param=NoFixedY2) Or (Param=NoFixedY3) Or
(Param=NoFixedY4) Then FixedY:=False
Else
If Param=Standard1 Then Standard:=True
Else
If Param=NoStandard1 Then Standard:=False
Else
If Param=Batch1 Then Batch:=True
Else
{Unknown keyword}
Begin
Writeln(Chr(7)+'Invalid comman