-- TexGlueDefs.Mesa

-- definitions related to glue
-- last written by Doug Wyatt, September 19, 1979  4:49 PM

DIRECTORY
	TexDefs: FROM "TexDefs" USING [Dimn, Penalty];

TexGlueDefs: DEFINITIONS =
BEGIN OPEN TexDefs;

FlexOrder: TYPE = {regular, lowerfill, fill};
FlexVal: TYPE = Dimn;
maxFlexVal: Dimn=LAST[Dimn];
FlexDir: TYPE = {str,shr}; -- flex direction: stretch or shrink

-- stretch or shrink component of glue
Flex: TYPE = RECORD
	[
	order: FlexOrder, -- "order" of stretch/shrinkability
	val: FlexVal
	];
zeroFlex: Flex = [order: regular, val: 0];

FlexPair: TYPE = ARRAY FlexDir OF Flex;
FlexPairPtr: TYPE = POINTER TO FlexPair;
FlexVec: TYPE = ARRAY FlexOrder OF FlexVal;
FlexVecPtr: TYPE = POINTER TO FlexVec;
FlexSums: TYPE = ARRAY FlexDir OF FlexVec;
FlexSumsPtr: TYPE = POINTER TO FlexSums;

ClearFlexSums: PROCEDURE[sums: FlexSumsPtr];
SumFlex: PROCEDURE[glue: GluePtr, sums: FlexSumsPtr];
DominantFlex: PROCEDURE[vec: FlexVecPtr] RETURNS[Flex];

RefCount: TYPE = CARDINAL;
infRefs: RefCount = LAST[CARDINAL]; -- "infinite" reference count

GlueSpec: TYPE = RECORD
	[
	refs: RefCount, -- reference count
	space: Dimn, -- natural width
	flex: FlexPair -- stretchability and shrinkability
	];
GluePtr: TYPE = POINTER TO GlueSpec;

MakeGlue: PROCEDURE RETURNS[GluePtr]; -- allocate and initialize a GlueSpec
AddGlueLink: PROCEDURE[GluePtr]; -- increment reference count
DelGlueLink: PROCEDURE[GluePtr]; -- decrement reference count, free if zero

GlueType: TYPE = {zero, fill, fil, filneg, lowerfill, skip};
CommonGlueType: TYPE = GlueType[zero..lowerfill];
CommonGlue: PROCEDURE[CommonGlueType] RETURNS[GluePtr];

GlueSet: TYPE = RECORD
	[
	dir: FlexDir,
	order: FlexOrder, -- order of flex to which glueset applies
	num: Dimn,
	den: FlexVal
	];
-- the glueset value is a rational number, num/den

zeroGlueSet: GlueSet = [dir: str, order: fill, num: 0, den: 1];

Overfull: SIGNAL[excess: Dimn];

SetGlue: PROCEDURE[dir: FlexDir, delta: Dimn, sums: FlexSumsPtr]
	RETURNS[GlueSet];

GluePenalty: PROCEDURE[GlueSet] RETURNS[Penalty];

FixGlue: PROCEDURE[glue: GluePtr, set: GlueSet] RETURNS[Dimn];

TexGlue: PROGRAM;

END.