TSArtworkImpl.mesa
Michael Plass, December 8, 1982 3:22 pm
DIRECTORY
Rope,
TextNode,
TSArtwork,
TSGraphic,
TSObject,
TSOps,
TSOutput,
TSTranslate,
TSTranslatePrivate,
TSTypes;
TSArtworkImpl: CEDAR MONITOR
IMPORTS Rope, TSObject, TSOps, TSOutput, TSTranslate, TSTranslatePrivate
EXPORTS TSArtwork = {
OPEN TSTypes;
ObjectFromBranchProc: TYPE = TSArtwork.ObjectFromBranchProc;
ROPE: TYPE = Rope.ROPE;
ARec: TYPE = RECORD [
artworkClassName: ROPE,
objectFromBranchProc: ObjectFromBranchProc
];
AList: LIST OF ARec ← NIL;
Register: PUBLIC ENTRY PROCEDURE [
artworkClassName: Rope.ROPE,
objectFromBranchProc: ObjectFromBranchProc
] = {ENABLE UNWIND => NULL;
AList ← CONS[[artworkClassName, objectFromBranchProc], AList];
};
Lookup: PUBLIC ENTRY PROCEDURE [artworkClassName: ROPE]
RETURNS [ObjectFromBranchProc] = {ENABLE UNWIND => NULL;
FOR a: LIST OF ARec ← AList, a.rest UNTIL a=NIL DO
IF a.first.artworkClassName.Equal[artworkClassName] THEN RETURN[a.first.objectFromBranchProc];
ENDLOOP;
RETURN[CreateTypesetObject];
};
CreateTypesetObject: PUBLIC ObjectFromBranchProc = {
object ← NEW[TSGraphic.ObjectRec];
object.paintProc ← TypesetObjectPaint;
object.layoutProc ← TypesetObjectLayout;
object.data ← NEW[TypesetObjectRec ← [node: node]];
};
TypesetObjectRec: TYPE = RECORD [
node: TextNode.Ref,
vlist: TSObject.ItemList
];
TypesetObjectLayout: TSGraphic.LayoutProc = TRUSTED {
data: REF TypesetObjectRec ← NARROW[self.data];
box: TSObject.Box;
data.vlist ← TSTranslate.TreeToVlist[data.node].galley;
TSTranslatePrivate.InitializeStateForNewNode[
data.vlist.listWriter,
NARROW[data.vlist.listWriter.writerData]
];
IF NumberOfBoxesIn[data.vlist] = 1 THEN {
box ← FirstBoxOf[data.vlist];
WITH b: box SELECT FROM
list => box ← TSOps.Package[b.items.CreateReader[], right,
[zeroDimn, nilDimn, nilDimn, nilDimn]];
ENDCASE;
}
ELSE {
data.vlist ← TSOps.InsertLeading[data.vlist];
box ← TSOps.Package[data.vlist.CreateReader[], down,
[zeroDimn, nilDimn, zeroDimn, nilDimn]];
};
extent ← box.extent;
};
TypesetObjectPaint: TSGraphic.PaintProc = {
data: REF TypesetObjectRec ← NARROW[self.data];
box: TSObject.Box ← TSOps.Package[data.vlist.CreateReader[], down, extent];
TSOutput.BoxOut[NARROW[context], originX, originY, box^];
};
NumberOfBoxesIn: PROCEDURE [list: TSObject.ItemList] RETURNS [numberOfBoxes: INT ← 0] = {
listReader: TSObject.ListReader ← list.CreateReader[];
UNTIL listReader.End[] DO
IF listReader.CurrentTag[] = exception AND ISTYPE[listReader.CurrentItem[], TSObject.Box]
THEN numberOfBoxes ← numberOfBoxes + 1;
listReader.Next[];
ENDLOOP;
listReader.DestroyReader[];
};
FirstBoxOf: PROCEDURE [list: TSObject.ItemList] RETURNS [box: TSObject.Box ← NIL] = {
listReader: TSObject.ListReader ← list.CreateReader[];
UNTIL listReader.End[] OR box#NIL DO
IF listReader.CurrentTag[] = exception AND ISTYPE[listReader.CurrentItem[], TSObject.Box]
THEN box ← NARROW[listReader.CurrentItem[]];
listReader.Next[];
ENDLOOP;
listReader.DestroyReader[];
};
}.
Michael Plass, September 15, 1982 9:45 am. ENABLE UNWIND => NULL.
Michael Plass, December 8, 1982 3:22 pm. Changed TypesetObjectLayout to return dimensions instead of flexes.