-- FontWidthDefs.mesa
-- Written by Joe Maleson
-- Last changed by Doug Wyatt, September 29, 1980 1:42 PM

-- calculate font widths

DIRECTORY
StreamDefs USING [StreamHandle, StreamIndex];

FontWidthDefs: DEFINITIONS =
BEGIN

UpperCase: PROCEDURE [s: STRING];
Upper
: PROCEDURE [c: CHARACTER] RETURNS[CHARACTER];

fwReadIndex
: PROCEDURE[s: StreamDefs.StreamHandle] RETURNS[POINTER TO FontWidthDefs.Index];

EncodeFace: PUBLIC PROCEDURE [weight,slope,expansion: CHARACTER] RETURNS [INTEGER];

LookupFontName: PROCEDURE [s: StreamDefs.StreamHandle,famstr: STRING,face,siz,rot: INTEGER,bufx,bufy: POINTER TO ARRAY [0..256) OF INTEGER,boundbox: POINTER TO ARRAY [0..4) OF INTEGER] RETURNS[BOOLEAN];

CalculateWidths: PROCEDURE [best: POINTER TO widths FontWidthDefs.Index,s: StreamDefs.StreamHandle,siz,rot: CARDINAL,boundbox: POINTER TO ARRAY[0..4) OF INTEGER,bufx,bufy: POINTER TO ARRAY[0..256) OF INTEGER];

Byte: TYPE = [0..377B];

IndexHeader: TYPE = RECORD
[ Type: [0..15],
Length: [0..4095]
];

IndexType: TYPE = {end,name,splines,chars,widths};

RawIndex: TYPE = MACHINE DEPENDENT RECORD
[
hdr: IndexHeader,
variantPart: SELECT COMPUTED IndexType FROM
end=> NULL,
name=>
[
Code: CARDINAL,
textLen: Byte,firstChar: CHARACTER,
textBody: PACKED ARRAY [0..17) OF CHARACTER
],
splines,widths =>
[
fam: Byte,
face: Byte,
bc: Byte,-- First char number
ec: Byte,-- and last
siz: CARDINAL,-- Font size (10 micron units)
rotation: CARDINAL,-- Rotation (anti clockwise)
sa: ARRAY[0..2) OF CARDINAL,--Starting address of data part
len: ARRAY[0..2) OF CARDINAL--Length of data part
],
chars =>
[
fam: Byte,
face: Byte,
bc: Byte,-- First char number
ec: Byte,-- and last
siz: CARDINAL,-- Font size (10 micron units)
rotation: CARDINAL,-- Rotation (anti clockwise)
sa: ARRAY[0..2) OF CARDINAL,--Starting address of data part
len: ARRAY[0..2) OF CARDINAL,--Length of data part
resolutionx: CARDINAL,-- 10*(number of bits/inch)
resolutiony: CARDINAL-- ditto
],
ENDCASE
];


Index: TYPE = RECORD
[body: SELECT type: IndexType FROM
end => NULL,
name =>
[
Code: CARDINAL,
Name: STRING
],
splines,widths =>
[fam,face,bc,ec: Byte,
siz,rotation: CARDINAL,
sa: StreamDefs.StreamIndex,
len: LONG CARDINAL
],
chars =>
[fam,face,bc,ec: Byte,
siz,rotation: CARDINAL,
sa: StreamDefs.StreamIndex,
len: LONG CARDINAL,
resolutionx,resolutiony: CARDINAL
],
ENDCASE
];

--RawIndexHeader types
IndexTypeEnd: CARDINAL = 0;
IndexTypeName: CARDINAL = 1;
IndexTypeSplines: CARDINAL = 2;
IndexTypeChars: CARDINAL = 3;
IndexTypeWidths: CARDINAL = 4;

--IndexHeader lengths
IndexLEnd: CARDINAL = 1;
IndexLName: CARDINAL = 11;
IndexLSplines: CARDINAL = 9;
IndexLChars: CARDINAL = 11;
IndexLWidths: CARDINAL = 9;
IndexLMax: CARDINAL = 11;

-- W I D T H segment definitions

WTB: TYPE = MACHINE DEPENDENT RECORD
[
--Width Table Block
XL: CARDINAL,--X offset
YB: CARDINAL,--Y offset
XW: CARDINAL,-- width
YH: CARDINAL,-- height
XWidthFixed: BOOLEAN,
YWidthFixed: BOOLEAN,
spare14:[0..37777B]
];

-- S P L I N E segment definitions

--SplineWidth: RECORD
-- [
//Block describing spline widths
--
WX word 2//X width - FP
--
WY word 2//Y width - FP
--
XL word 2//X left - FP
--
YB word 2//Y bottom - FP
--
XR word 2//X right - FP
--
YT word 2//Y top - FP
--
]

--Codes in the height entry for a char that indicate something else
HNonExCode: INTEGER = -1;
HSplineCode: INTEGER = -2;

--DL Types (for Spline File)
DSplineFontMoveTo: INTEGER = 1;
DSplineFontDrawTo: INTEGER = 2;
DSplineFontDrawCurve: INTEGER = 3;

DSplineFontNewObject: INTEGER = -1;
DSplineFontEndObjects: INTEGER = -2;


-- C H A R segment definitions (scan-converted chars)

CharWidth: TYPE = RECORD
[
--Block describing char widths
WX: LONG CARDINAL,--X width - DP
WY: LONG CARDINAL,--Y width - DP
XL: CARDINAL,--X left (offset) integer
YB: CARDINAL,--Y bottom (offset) integer
W: CARDINAL,--Width (integer)
H: CARDINAL--Height (integer) or special code
];

FHEAD: TYPE = RECORD
[
--Font header, scan converted
hw: [0..63],--Height in words
ns: [0..1023]--width in scan lines
];


--Misc.
Convert: TYPE = RECORD
[ Monotone: BOOLEAN,
--True if input to conversion is monotone
SplineOk: BOOLEAN,--True if output can be spline (too big)
BBGood: BOOLEAN,--True if bounding box will be correct
PressFontPart: BOOLEAN,--True if scan converting a press font part
Len: CARDINAL--(if so, this is the length)
];

END.