TiogaLineBreak:
CEDAR
DEFINITIONS =
BEGIN
A box is somthing that occupies a fixed amount of space in the line.
Glue is something that occupies a variable amount of space in the line. It has three components: its normal size, the amount by which it should be allowed to grow without a large penalty, and the amount by which it is allowed to shrink. The stretch and shrink have an order of infinity associated with them.
A kerf is a place in the line where a break is possible. It has three major parts, the join, the prebreak, and the postbreak. The join describes the size and flexibility of what is to go into the line if no break occurs at the kerf. If a break does occur at the kerf, the prebreak describes what goes before the break (i.e., at the end of the line), and the postbreak describes what goes at the beginning of the next line. A kerf also has an associated penalty to be charged if the break is taken, and some extra information to allow the positions of the chosen breaks to be communicated back to the client.
Node: TYPE = REF; Offset: TYPE = INT; -- just to compile until integration with TiogaNode
-- Stuff to go into TiogaNode
FlexOrder: TYPE = [0..3];
KerfIndex: TYPE = [0..LAST[CARDINAL]/SIZE[Kerf]-7];
Penalty: TYPE = INTEGER;
Glue:
TYPE =
RECORD [
size: Scaled.Value,
stretch: Scaled.Value, stretchOrder: FlexOrder,
shrink: Scaled.Value, shrinkOrder: FlexOrder
];
ComposingStick: TYPE = REF ComposingStickRec;
ComposingStickRec:
TYPE =
RECORD [
elements: ElementSeq,
kerfs: KerfSeq,
results: BreakSeq
];
ElementSeq: TYPE = REF ElementSeqRec;
ElementSeqRec:
TYPE =
RECORD [
length: NAT,
seq: SEQUENCE maxLength: NAT OF Element
];
OfElement: TYPE = {box, glue, tab, kerf};
Element:
TYPE =
RECORD [
SELECT kind: OfElement
FROM
box => [size: Scaled.Value],
glue => [
stretchOrder, shrinkOrder: FlexOrder,
size, stretch, shrink: Scaled.Value
],
tab => [distanceFromStartOfLine: Scaled.Value],
kerf => [kerfIndex: KerfIndex, offset: Offset],
ENDCASE
];
KerfSeq: TYPE = REF KerfSeqRec;
KerfSeqRec:
TYPE =
RECORD [
length: KerfIndex,
seq: SEQUENCE maxLength: KerfIndex OF Kerf
];
Kerf:
TYPE =
RECORD [
join, prebreak, postbreak: Glue,
penalty: Penalty,
node: Node
];
BreakSeq: TYPE = REF BreakRec;
BreakRec:
TYPE =
RECORD [
length: NAT,
seq: SEQUENCE maxLength: NAT OF Break
];
Break:
TYPE =
RECORD [
node: Node,
offset: Offset,
glueSet: Scaled.Value
];
-- Stuff to stay in TiogaLineBreak:
ObtainScratch: PROCEDURE RETURNS [ComposingStick];
ReleaseScratch: PROCEDURE [composingStick: ComposingStick];
Reset:
PROCEDURE [composingStick: ComposingStick];
Clears the stick, making ready for a new paragraph.
AppendBox: PROCEDURE [composingStick: ComposingStick, size: Scaled.Value];
AppendGlue:
PROCEDURE [
composingStick: ComposingStick,
glue: Glue
];
MakeKerf:
PROCEDURE [
composingStick: ComposingStick,
join, prebreak, postbreak: Glue,
penalty: Penalty,
node: Node
] RETURNS [KerfIndex];
AppendKerf:
PROCEDURE [
composingStick: ComposingStick,
kerfIndex: KerfIndex,
clientIndex: INT
];
ChooseBreaks: PROCEDURE [composingStick: ComposingStick, measure: Scaled.Value ← Scaled.zero, measureProc: MeasureProc ← NIL, measureClientData: REF ← NIL];
MeasureProc:
TYPE =
PROCEDURE [measureClientData:
REF, lineNumber:
INT]
RETURNS [measure: Scaled.Value];
If a MeasureProc is supplied, it overrides the measure parameter. The MeasureProc is called to determine the measure for each line; it may be called multiple times for the same line number, and in any order.
END.