BoxTreeImpl.mesa
Mcisaac, July 20, 1987 6:25:45 pm PDT
Implementation for Displaying Mathematical Expressions
DIRECTORY
BoxTree,
InternalExpr,
ImagerFont;

BoxTreeImpl: CEDAR PROGRAM
~ BEGIN
Type Definitions
EXPR: TYPE ~ InternalExpr.EXPR;
BoxTreeRep: TYPE ~
RECORD [
boundBox: ImagerBox.Box ← [0,0,0,0], -- size of bounding box
offset: Vector.VEC ←[0,0], -- offset from origin of parent box
subBoxes: LIST OF BoxTree.BOXTREE ← NIL, -- list of boxes bound by this box
parentBox: BoxTree.BOXTREE ← NIL, -- parent bounding box
style: BoxTree.STYLE,
value: EXPR, -- value of this box
expression: EXPR -- pointer to expression bound by this box
];
Display & Formatting
Format: PUBLIC PROC[box: BoxTree] ~ {
local declarations
subExprBoxes: LIST OF BOX;
myBox, tempBox: BOX;
WITH box.value SELECT FROM
atm: atomic => {
AtomicFormat[atm, size]
};
fn: function => {
box.subBoxes ← GetFormat[fn]; -- get format rule
-- recursively format subexpressions
FOR l: LIST OF BoxTreeRep.subBoxes ← box.subBoxes, l.rest DO
Format[l.first]
ENDLOOP;
-- size boxes
box.boundBox ← BoundingBox[box.subBoxes];
-- compose layout
LayOutBoxes[box.subBoxes];
};
ENDCASE => ERROR;
};
GetFormat: PROC [expr: function EXPR] RETURNS [LIST OF BoxTree.BOXTREE] ~ {
lookup expression in data base and return a list of boxes for it
dummy routine for now
boxlist : BOX.subBoxes;
xi : INT ← 1;
boxlist ← MakeBox[expr.name, [0,0]];
FOR l: LIST OF EXPR ← expr.subExprs, l.next DO
{
xi ← xi + 1;
boxlist ← CONS[MakeBox[l.first, [xi,0]], boxlist]
};
ENDLOOP;
};
MakeBox: PROC [exp: EXPR, offset: Vector.VEC RETURNS [BoxTree.BOXTREE] ~ {
NEW[BoxTreeRep ← [offset: offset, value: exp, expression: exp]]
};
BoundingBox: PROC [boxes: LIST OF BoxTree.BOXTREE] RETURNS [ImagerBox.Box] ~ {
compute least greatest bounding box for list of boxes
biggestBox: ImagerBox.Box ← [0, 0, 0, 0];
FOR l: LIST OF BoxTree.BOXTREE ← boxes, l.next DO
biggestBox ← ImagerBox.BoundingBox[BiggestBox, l.first]
ENDLOOP;
RETURN [biggestBox]
};
LayOutBoxes: PROC [boxes: LIST OF BoxTree.BOXTREE] ~ {
-- compose layout of list of boxes using the relative offsets
};
Paint: PUBLIC PROC [boxTree: BOXTREE, context: Imager.Context, selections: LIST OF Selection];
paints a boxed expression in the imager space given by context
END.