TSFontTableImpl.mesaRef
Font table loader for the Tioga Typesetter
Last changed by Michael Plass, November 17, 1982 11:34 am
Last Edited by: Beach, August 18, 1983 1:11 pm
DIRECTORY
CIFS USING [dontCheck, Error, GetFC, OpenButDontHandleError, read],
File,
Inline,
Rope,
Space,
Tfm,
TSFontTable,
TSTypes;
TSFontTableImpl: CEDAR PROGRAM
IMPORTS CIFS, File, Inline, Rope, Space, Tfm, TSTypes
EXPORTS TSFontTable =
BEGIN OPEN TSTypes, TSFontTable;
BadTfmFile: SIGNAL = CODE;
TwoToTheTenth: INT = 2*2*2*2*2 * 2*2*2*2*2;
TwoToTheTwentieth: INT = TwoToTheTenth*TwoToTheTenth;
RealTwoToTheTwentieth: REAL = TwoToTheTwentieth;
FixedToReal: PROCEDURE [x: Tfm.Fixed] RETURNS [REAL] = TRUSTED
BEGIN
RETURN[Tfm.Long[x]/RealTwoToTheTwentieth];
END;
tfmDir: Rope.ROPE = "/Indigo/Tioga/TFM/";
Load: PUBLIC PROCEDURE [name: Rope.ROPE] RETURNS [f: Ref] = TRUSTED
BEGIN
ENABLE CIFS.Error => TRUSTED {GOTO FileNotFound};
s: NAT = SIZE[Tfm.Word];
tfmName: Rope.ROPE ← name.Concat[".tfm"];
tfmFile: File.Capability;
pages: File.PageCount;
size: Space.PageCount;
space: Space.Handle;
base: LONG POINTER TO UNSPECIFIED;
dir: LONG POINTER TO Tfm.Directory;
IF Rope.Fetch[tfmName]#'/ THEN tfmName ← Rope.Cat[tfmDir, tfmName];
tfmFile ← CIFS.GetFC[CIFS.OpenButDontHandleError[tfmName, CIFS.read + CIFS.dontCheck]];
pages ← File.GetSize[tfmFile];
size ← IF pages<=16 THEN Inline.LowHalf[pages] ELSE ERROR;
space ← Space.Create[size: size, parent: Space.virtualMemory];
Space.Map[space: space, window: [file: tfmFile, base: 1]]; -- first page is 1!
base ← Space.LongPointer[space];
dir ← LOOPHOLE[base];
f ← NEW[TSFontTable.Record];
IF Tfm.ValidDirectory[dir^] THEN
BEGIN OPEN dir^;
hdr: LONG POINTER TO Tfm.Header ← LOOPHOLE[dir + s*6];
pf: LONG POINTER TO Tfm.FInfo ← LOOPHOLE[hdr + s*lh];
pw: LONG POINTER TO Tfm.Width ← LOOPHOLE[pf + s*(ec-bc+1)];
ph: LONG POINTER TO Tfm.Height ← LOOPHOLE[pw + s*nw];
pd: LONG POINTER TO Tfm.Depth ← LOOPHOLE[ph + s*nh];
pi: LONG POINTER TO Tfm.CharIc ← LOOPHOLE[pd + s*nd];
pl: LONG POINTER TO Tfm.LigKern ← LOOPHOLE[pi + s*ni];
pk: LONG POINTER TO Tfm.Kern ← LOOPHOLE[pl + s*nl];
pe: LONG POINTER TO Tfm.Exten ← LOOPHOLE[pk + s*nk];
pp: LONG POINTER TO Tfm.Param ← LOOPHOLE[pe + s*ne];
f.name ← name;
f.headerInfo ← ExtractHeaderInfo[hdr];
f.bc ← Inline.LowByte[bc];
f.ec ← Inline.LowByte[ec];
f.fInfoTable ← ExtractFInfoTable[pf,dir];
f.widthTable ← ExtractDimensions[pw,nw];
f.heightTable ← ExtractDimensions[ph,nh];
f.depthTable ← ExtractDimensions[pd,nd];
f.charIcTable ← ExtractDimensions[pi,ni];
f.ligKernProgram ← ExtractLigKernProgram[pl,nl];
f.kernTable ← ExtractDimensions[pk,nk];
f.extTable ← NIL; -- don't need this for Tioga at this time
f.parameters ← ExtractParameters[pp,np];
END
ELSE {SIGNAL BadTfmFile};
Space.Delete[space];
EXITS FileNotFound => {}
END;
ExtractHeaderInfo: UNSAFE PROCEDURE [p: LONG POINTER TO Tfm.Header]
RETURNS [h: HeaderInfo] = UNCHECKED
BEGIN --
h ← NEW[HeaderInfoRec];
BEGIN OPEN h^;
checkSum ← p.checkSum;
characterCodingScheme ← Rope.FromRefText[Textify[LOOPHOLE[@p^.characterCodingScheme]]];
family ← Rope.FromRefText[Textify[LOOPHOLE[@p^.externalFontIdentifier]]];
designSize ← RealDimn[FixedToReal[p.designSize],pt];
face ← p.extraInfo.parcFaceByte;
END
END;
Textify: UNSAFE PROCEDURE [a: LONG POINTER TO READONLY PACKED ARRAY [0..255] OF CHARACTER]
RETURNS [t: REF TEXT] = UNCHECKED
BEGIN
len:NATLOOPHOLE[a[0],Byte]; -- length is stashed in first byte
t ← NEW[TEXT[len]];
t.length ← len;
FOR i:NAT IN [0..len) DO
t[i] ← a[i+1];
ENDLOOP;
END;
ExtractFInfoTable: UNSAFE PROCEDURE [p: LONG POINTER TO Tfm.FInfo, dir: LONG POINTER TO Tfm.Directory]
RETURNS [FInfoTable] = UNCHECKED
BEGIN OPEN dir^;
f: FInfoTable ← NEW[FInfoTableRec[ec+1]];
nullEntry: FInfoEntry ← [0,0,0,0,none[[]]];
FOR i:NAT IN [0..bc) DO f[i] ← nullEntry ENDLOOP;
FOR i:NAT IN [bc..ec] DO
OPEN p[i-bc];
IF widthIndex >= nw OR
heightIndex >= nh OR
depthIndex >= nd OR
charIcIndex >= ni THEN SIGNAL BadTfmFile;
f[i] ← p[i-bc] ENDLOOP;
RETURN[f]
END;
ExtractDimensions: UNSAFE PROCEDURE [p: LONG POINTER TO Tfm.FixedArray, n:CARDINAL]
RETURNS [d: MetricTable] = UNCHECKED
BEGIN
d ← NEW[MetricTableRec[n]];
FOR i:NAT IN [0..n) DO d[i] ← FixedToReal[p[i]] ENDLOOP
END;
ExtractLigKernProgram: UNSAFE PROCEDURE [p: LONG POINTER TO Tfm.LigKern, n:CARDINAL]
RETURNS [l: LigKernProgram] = UNCHECKED
BEGIN
l ← NEW[LigKernProgramRec[n]];
FOR i:NAT IN [0..n) DO l[i] ← p[i] ENDLOOP
END;
ExtractParameters: UNSAFE PROCEDURE [p: LONG POINTER TO Tfm.Param, n:CARDINAL]
RETURNS [t: ParamTable] = UNCHECKED
BEGIN
i: Tfm.ParamIndex ← FIRST[Tfm.ParamIndex];
t ← NEW[ParamTableRec[n]];
THROUGH [0..n) DO
t[i] ← FixedToReal[p[i]];
i ← SUCC[i];
ENDLOOP;
t.slantNum ← Tfm.Long[p[slant].ValueTimesTwoToTheTwentieth];
t.slantDenom ← TwoToTheTwentieth;
END;
END.
Michael Plass, September 16, 1982 1:38 pm. Removed !h from CIFS filename.
Michael Plass, September 29, 1982 11:08 am. Added TRUSTED to catch phrase in CIFS call.
Michael Plass, November 2, 1982 10:11 am. CEDARized.
Michael Plass, November 17, 1982 11:33 am. Used ENABLE instead of catch phrase for CIFS.