1signature SET_BOX  =
2sig
3  val setNode:   BoxTypes.boxkind -> BoxTypes.glueParam -> BoxTypes.node -> unit
4  val setList:   BoxTypes.boxkind -> BoxTypes.glueParam -> BoxTypes.node list -> unit
5  val setBox:    BoxTypes.boxkind -> BoxTypes.box -> unit
6  val setHList:  BoxTypes.hlist -> unit
7end
8(*----------*)
9
10structure SetBox: SET_BOX  =
11struct
12  open BasicTypes;  open BoxTypes
13  open Distance
14  open OutHigh;  open DviCmd;  open SetNode
15
16  (* Invariant for horizontal stuff:
17     reference point -> end point = reference point + (0, width)
18     Invariant for vertical stuff:
19     upper left corner -> lower left corner
20  *)
21
22  fun setNode kind  _ (Char info)  =  outChar kind info
23  |   setNode HBox  _ (Box  (shift, b))  =
24       ( Down  shift;  setBox HBox b;  Up   shift )
25  |   setNode VBox  _ (Box  (shift, b))  =
26       ( Right shift;  setBox VBox b;  Left shift )
27  |   setNode kind  _ (Rule  dim)        =  outRule kind dim
28  |   setNode kind gp (Glue  glue)       =  outGlue kind gp glue
29  |   setNode kind  _ (Kern  size)       =  outKern kind size
30  |   setNode _     _  _                 =  ()
31
32  and setList kind gp  =  List.app (setNode kind gp)
33
34  and setBox outerKind
35      {kind,  glueParam,  content,  height,  depth,  width}  =
36      let val out  =  setList kind glueParam
37      in  if  outerKind = kind
38              then  out content
39          else if  outerKind = HBox
40              then  ( Up   height;  out content;  Up   depth;  Right width )
41              else  ( Down height;  out content;  Down depth;  Left  width )
42      end
43
44(* With push and pop:
45  and setBox outerKind
46      {kind,  glueParam,  content,  height,  depth,  width}  =
47      let val out  =  setList kind glueParam
48      in  if  outerKind = kind
49              then  out content
50          else if  outerKind = HBox
51              then ( Push ();  Up   height;  out content;  Pop ();  Right width)
52              else ( Down height;  Push ();  out content;  Pop ();  Down depth )
53      end
54*)
55
56  val setHList  =  setBox VBox o BoxPack.boxList
57
58end
59