-- file: LaurelHardcopyDefs.mesa
-- edited by Brotz, March 7, 1983 4:00 PM
-- edited by Levin, January 16, 1981 11:02 AM

DIRECTORY
lsD: FROM "LaurelStateDefs" USING [StateSegment],
MailParseDefs USING [ParseHandle],
vmD: FROM "VirtualMgrDefs" USING [CharIndex];

LaurelHardcopyDefs: DEFINITIONS
IMPORTS MailParseDefs =

BEGIN

-- entity list commands:
showCharactersShortCom: Byte = 0B;
fontCom: Byte = 160B;
setXCom: Byte = 356B;
setYCom: Byte = 357B;
showCharactersCom: Byte = 360B;
setSpaceXCom: Byte = 364B;
showRectangleCom: Byte = 376B;

Byte: TYPE = [0 .. 377B];
Mica: TYPE = CARDINAL;
inch: Mica = 2540;
magicNonPrintingWidth: CARDINAL = 100000B;
postColonSpacing: Mica = inch / 8;

EntityTrailer: TYPE = MACHINE DEPENDENT RECORD
[entityType: Byte,
fontSet: Byte,
beginByteHigh,
beginByteLow,
byteLengthHigh,
byteLengthLow,
ye,
xe,
left,
bottom,
width,
height,
entityLength: CARDINAL];

PartDirectoryEntry: TYPE = MACHINE DEPENDENT RECORD
[partType,
recordStart,
nRecords,
entityListPadding: CARDINAL];

DocumentDirectoryHeader: TYPE = MACHINE DEPENDENT RECORD
[generalPassword,
nRecordsInFile,
nParts,
partDirectoryStartRecord,
nRecordsInPartDirectory,
obsoleteBackPointer,
unused1,
unused2,
firstCopy,
lastCopy: CARDINAL];

FontDirectoryEntry: TYPE = MACHINE DEPENDENT RECORD
[entryLength: CARDINAL,
fontSet: Byte,
fontNumber: Byte,
m: Byte,
n: Byte,
familyName: FontName,
face,
source: Byte,
size,
rotation: CARDINAL];

FontDirectoryRec: TYPE = RECORD
[entry: ARRAY FontNumber OF FontDirectoryEntry,
endMarker: CARDINAL];
FontDirectory: TYPE = POINTER TO FontDirectoryRec;

FontName: TYPE = PACKED ARRAY [0 .. 20) OF CHARACTER;

FontFace: TYPE = [0 .. 2*3*3);
-- FontFace encoded as follows:
-- medium weight, regular slope is 0.
-- for bold weight add 2.
-- for italic slope add 1.

normalFontFace: FontFace = 0;
boldFontFace: FontFace = 2;
italicFontFace: FontFace = 1;

maxNFonts: CARDINAL = 10;
FontNumber: TYPE = [0 .. maxNFonts);



-- Type definitions for reading Fonts.widths.

Ix: TYPE = MACHINE DEPENDENT RECORD
[type: [0 .. 17B),
length: [0 .. 7777B]];

Ixn: TYPE = MACHINE DEPENDENT RECORD
[ix: Ix,
code: CARDINAL,
name: FontName];

Stdix: TYPE = MACHINE DEPENDENT RECORD
[ix: Ix,
code,
face: Byte,
bc,
ec: CHARACTER,
size: CARDINAL,
rotation: INTEGER,
x1,
location,
x2,
length: CARDINAL]; -- position in file

WidthSegment: TYPE = MACHINE DEPENDENT RECORD
[fBBox,
fBBoy,
fBBdx,
fBBdy: CARDINAL,
xWidthFixed,
yWidthFixed: BOOLEAN,
xxx: [0 .. 37777B]];

WidthTableArray: TYPE = ARRAY FontNumber OF CharWidthArray;
WidthTable: TYPE = POINTER TO WidthTableArray;
CharWidthArray: TYPE = ARRAY CHARACTER[0C .. 177C] OF Mica;

-- Type definitions for compiled hardcopy forms.

HardcopyFormTable: TYPE = POINTER TO HardcopyFormTableRec;
HardcopyFormTableRec: TYPE = RECORD
[nForms: CARDINAL,
formTable: ARRAY [0 .. 0) OF HardcopyFormTableElement];

HardcopyFormTableElement: TYPE = RECORD
[name: STRING,
segment: lsD.StateSegment];

HardcopyFormRec: TYPE = RECORD
[top: Mica,
bottom: Mica,
left: Mica,
right: Mica,
nFields: CARDINAL,
lineLeading: Mica,
startOnNewPage: BOOLEAN,
fieldTable: FieldTableRelPtr,
options: OptionRelPtr,
rows: RowRelPtr];
HardcopyForm: TYPE = BASE POINTER TO HardcopyFormRec;

FieldTableRelPtr: TYPE = HardcopyForm RELATIVE FieldTable;
FieldTableNIL: FieldTableRelPtr = LOOPHOLE[0];
FieldTable: TYPE = POINTER TO FieldTableArray;
FieldTableArray: TYPE = ARRAY [0 .. 0) OF HardcopyRelativeString;

HardcopyRelativeString: TYPE = HardcopyForm RELATIVE STRING;
HardcopyRelativeStringNIL: HardcopyRelativeString = LOOPHOLE[0];

OptionRelPtr: TYPE = HardcopyForm RELATIVE Option;
OptionNIL: OptionRelPtr = LOOPHOLE[0];
Option: TYPE = POINTER TO OptionRec;
OptionRec: TYPE = RECORD
[x: Mica,
y: Mica,
font: FontNumber,
onFirstPage: BOOLEAN,
nextOption: OptionRelPtr,
vp: SELECT option: OptionType FROM
heading =>
[fieldName: HardcopyRelativeString,
right: Mica,
start: vmD.CharIndex, -- state variable used during processing.
end: vmD.CharIndex], -- state variable used during processing.
caption => [text: HardcopyRelativeString],
pageNumber => NULL,
ENDCASE];

OptionType: TYPE = {heading, caption, pageNumber};

RowRelPtr: TYPE = HardcopyForm RELATIVE Row;
RowNIL: RowRelPtr = LOOPHOLE[0];
Row: TYPE = POINTER TO RowRec;
RowRec: TYPE = RECORD
[rowLeading: Mica,
verticalTab: Mica,
lineLeading: Mica,
nextRow: RowRelPtr,
columns: ColumnRelPtr];

ColumnRelPtr: TYPE = HardcopyForm RELATIVE Column;
ColumnNIL: ColumnRelPtr = LOOPHOLE[0];
Column: TYPE = POINTER TO ColumnRec;
ColumnRec: TYPE = RECORD
[left: Mica,
right: Mica,
font: FontNumber,
justify: BOOLEAN,
start: CARDINAL, -- state variable used during processing.
end: CARDINAL, -- state variable used during processing.
nextColumn: ColumnRelPtr,
cv: SELECT columnType: ColumnType FROM
field =>
[fieldFont: FontNumber,
fieldNameAbove: BOOLEAN,
colonAfterFieldName: BOOLEAN,
textLeft: Mica,
fv: SELECT fieldType: FieldType FROM
specific =>
[fieldIndex: CARDINAL,
aliasFieldIndex: CARDINAL,
required: BOOLEAN,
suppress: BOOLEAN,
printFieldName: BOOLEAN,
breakOnComma: BOOLEAN],
other =>
[fieldLeading: Mica,
newField: BOOLEAN], -- state variable used during processing.
ENDCASE],
caption => [text: HardcopyRelativeString],
body => NULL,
everything => NULL,
ENDCASE];

ColumnType: TYPE = {field, caption, body, everything};
FieldType: TYPE = {specific, other};

LineSegmentTable: TYPE = ARRAY [0 .. 12] OF RECORD [index: CARDINAL, x: Mica];



-- ******************** --
-- Procedures --
-- ******************** --


FontCode: TYPE = {ok, profileBadFont, badFontsWidths, fontNotInFontsWidths};


FontError: ERROR [code: FontCode];
-- May be raised by IncludeHardcopyFont or InstallHardcopy.


InitHardcopyFonts: PROCEDURE;
-- Initializes the font directory for hardcopy. This must be called first of all hardcopy
-- installation procedures.


IncludeHardcopyFont: PROCEDURE
[fontNumber: FontNumber, name: STRING, points: CARDINAL, face: FontFace];
-- Reads name-points-face and makes it font number fontNumber. May be called an
-- arbitrary number of times between InitHardcopyFonts and InstallHardcopy. May raise
-- FontError.


ParseFont: PROCEDURE [line: STRING];
-- Reads a font name from line and calls IncludeHardcopyFont with the parsed font. May
-- raise FontError.


ParseHardcopyForm: PROCEDURE [pH: MailParseDefs.ParseHandle];
-- Parses the next field body read from Laurel.profile and creates a relocatable segment for it.
-- May raise MailParse.ParseError.


InstallHardcopy: PROCEDURE;
-- Must be called after Profile is read. Insures that appropriate fonts and forms are loaded,
-- supplying default fonts and forms if necessary. Writes out hardcopy font width tables,
-- font directory and forms to Laurel.state. This procedure must be called last of all
-- hardcopy installation procedures. May raise FontError.


CheckForAbort: PROCEDURE;
-- Checks keystream for cancel character (DEL or CANCEL). Raises AbortHardcopy error if
-- cancel character is seen. Flushes any other characters.


-- Press file procedures --


InitPressPage: PROCEDURE;
-- Initializes state variables.


FinishPressPage: PROCEDURE;
-- Completes the current page part by pushing out the entity list onto the pressStream and
-- by adding a new entry to the part directory.


FinishPressFile: PROCEDURE [chunk: CARDINAL];
-- Completes the press file by pushing out the font directory, the part directory, and the
-- document directory.


PrintPressString: PROCEDURE [string: STRING, justify: BOOLEAN, x, y: Mica,
segTable: POINTER TO LineSegmentTable];
-- Puts string into the press file entity list and data list.


SetCurrentPressFont: PROCEDURE [font: FontNumber];
-- Sets font in the press file entity list.


FindPrinter: PROCEDURE RETURNS [found: BOOLEAN];
-- Locates printer to which press file will be sent.


SendPressFile: PROCEDURE;
-- Uses EFTP to send the current press file to the current hardcopy host.


TimeToSend: PROCEDURE RETURNS [BOOLEAN];
-- Returns TRUE iff press file exceeds maximum length.


OpenPressStreams: PROCEDURE;
-- Opens files and streams used during press file construction.


ClosePressStreams: PROCEDURE;
-- Closes files and streams used during press file construction.


AbortHardcopy: ERROR;

widthTable: WidthTable; -- exported by IntHardcopyCom.

HardcopyAbortCode: TYPE = {no, laurel, user};

aborted: HardcopyAbortCode; -- exported by IntHardcopyCom.


-- Diablo HyType printer definitions.


xPerInch: CARDINAL = 60;
yPerInch: CARDINAL = 48;
micasPerDiabloX: CARDINAL = inch / xPerInch;
micasPerDiabloY: CARDINAL = inch / yPerInch;
elevenInchesInMicas: CARDINAL = inch * 11;
pwiIn: POINTER TO UNSPECIFIED = LOOPHOLE[177030B];
pwiOut: POINTER TO UNSPECIFIED = LOOPHOLE[177016B];
wiPaper: UNSPECIFIED = 100000B;
wiReset: UNSPECIFIED = 40000B;
wiCheck: UNSPECIFIED = 40000B;
wiOnline: UNSPECIFIED = 20000B;
wiRibbon: UNSPECIFIED = 20000B;
wiDaisy: UNSPECIFIED = 10000B;
wiCarriage: UNSPECIFIED = 4000B;
wiReady: UNSPECIFIED = 2000B;
wiAllReady: UNSPECIFIED = 116000B;
wiNil: UNSPECIFIED = 0B;
wMaxStrobe: UNSPECIFIED = 1024;
wAbsMaxStrobe: UNSPECIFIED = 13777B; -- signed magnitude -1023 --


-- Diablo HyType printer procedures.


NewDiabloPage: PROCEDURE [firstPage: BOOLEAN];


FinishDiabloPage: PROCEDURE;


PrintDiabloString: PROCEDURE [string: STRING, fontNumber: CARDINAL, x, y: Mica,
segTable: POINTER TO LineSegmentTable];


END. -- of LaurelHardcopyDefs --