-- PressFontWriter.mesa
-- Written by Michael Plass on August 16, 1982 10:02 am
-- Last edit by Michael Plass on August 17, 1982 11:06 am

DIRECTORY
 Graphics,
 Real,
 Rope;

PressFontWriter: DEFINITIONS =
BEGIN

ROPE: TYPE = Rope.ROPE;

NewFont: TYPE = REF NewFontRec;

NewFontRec: TYPE;

CharShapeRepresentation: TYPE = {raster, outline, widthsOnly};

WriteError: SIGNAL[writeErrorCode: WriteErrorCode];

WriteErrorCode: TYPE = {cantHappen, inconsistentParameters, wrongFontFormatForThisOperation, fontHasNoCharacters, notImplemented};

Create: PROCEDURE [
 filename: ROPE,
 representation: CharShapeRepresentation,
 family: ROPE,
 face: [0..256) ← 0,
 size: REAL ← 0, -- in meters, or 0 for a scalable font
 rotation: REAL ← 0, -- in degrees
 bc: CHARFIRST[CHAR], -- first character in the font
 ec: CHARLAST[CHAR], -- last character in the font
 xRes, yRes: REAL ← 0 -- In bits per inch. Only used for a raster font.
 ]
RETURNS [newFont: NewFont];

PaintChar: PROCEDURE [newFont: NewFont, char: CHAR, charInfo: CharInfo, paintProc: PaintProc];

CharInfo: TYPE = RECORD [
 widthX, widthY: REAL, -- the width vector
 minX, minY: REAL ← Real.NonTrappingNaN,  -- the lower left corner of the bounding box
 maxX, maxY: REAL ← Real.NonTrappingNaN  -- the upper right corner of the bounding box
 ];
-- All of the above dimensions are relative to the point size of the character (i.e., they are measured in ems), and are measured from the reference point of the character, with y increasing upwards and x increasing to the right. Any unsupplied values for the bounding box will be calculated from the image.

PaintProc: TYPE = PROCEDURE [context: Graphics.Context]; -- A PaintProc gets called to actually draw the character. When drawing a spline font, only the MoveTo, LineTo, CurveTo, and DrawArea commands are allowed. The context is scaled so that one unit equals one em. The paintProc might be called more than once if a bounding box is not supplied.

Close: PUBLIC PROCEDURE [newFont: NewFont]; -- Actually writes the whole mess out.

END.