Your code:
The following is for formating the text. Put it in a separate script, in order to concentrate on the layout task:
IF PinX exists THENPara.SpLine := -100%;
Para.HorzAlign := 0;
VerticalAlign := 0;
LeftMargin := Char.Size * 0.5;
RightMargin := Char.Size * 0.5;
TopMargin := Char.Size * 0.5;
BottomMargin := Char.Size * 0.5;
Height := TEXTHEIGHT(TheText,Width);
ENDIFThis block means that the first child should follow its parent in both vertical and horizontal direction.
It does not consider the text of the parentIF prop.LeftSibling = 0 THEN
PinX := [P]!PinX + 2 mm;
PinY := [P]!PinY - 7 mm;PinY := [P]!PinY - TEXTHEIGHT([P]!TheText,[P]!Width) - 2 mm;
ENDIF
This block means that all children except the first one, shall follow the first sibling in vertical direction.
PinX is missingIF prop.LeftSibling > 0 THEN
PinY := [L]!PinY;
PinX:= [L]!PinX + [L]!Width + 5mm;ENDIF
This block sets the height of the very first item in the hierarchy.
The height of the children is missingIF
prop.HierarchyDepth = 0 THEN
IF PinX exists THEN
(just a trivial test that applies to any 2D shape)Height := TEXTHEIGHT(TheText,Width)+ 5mm;
(this formula will always work)Height := [MAXDESC](Height) + TEXTHEIGHT(TheText,Width)+ 5mm;
(The formula will only work if the item has children and will overwrite the line above.)ENDIF
What about the width? -->
IF PinX exists THEN
Width := [SUMDESC](Width) + (prop.numdescendents+ 1)*2mm
ENDIF
final script:IF prop.LeftSibling = 0 THEN
PinX := [P]!PinX + 2 mm;
PinY := [P]!PinY - TEXTHEIGHT([P]!TheText,[P]!Width) - 2 mm;
ENDIF
IF prop.LeftSibling > 0 THEN
PinY := [L]!PinY;
PinX:= [L]!PinX + [L]!Width + 2mm;
ENDIF
IF PinX exists THEN
Height := TEXTHEIGHT(TheText,Width)+ 5mm;
Height := [MAXDESC](Height) + TEXTHEIGHT(TheText,Width)+ 5mm;
Width := [SUMDESC](Width) + (prop.numdescendents + 1) * 2mm+5mm;
ENDIF