home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.IMPL / s5.3 < prev    next >
Text File  |  1994-01-25  |  5KB  |  126 lines

  1. @SubSection
  2.     @Tag { constraints }
  3.     @Title { Size constraints and size adjustments }
  4. @Begin
  5. @PP
  6. The galley flushing algorithm needs to know the available width and
  7. height at each receptive symbol.  These symbols may lie within
  8. arbitrarily complex objects, and they may compete with each other for
  9. available space (as body text and footnote targets do), so this
  10. information must be extracted from the tree structure when required.
  11. @PP
  12. For example, consider the object
  13. @ID @Code "5i  @Wide  {  a  /  b  }"
  14. and suppose that the width of @Code { a } is @Eq { 1i, 2i } (@Eq {1i} to
  15. the left of the mark, @Eq { 2i } to the right).  What then is the
  16. available width at {@Code { b }}?  If we let the width of @Code b be
  17. @Eq {l,r}, we must have
  18. @ID @Eq { (1i up l) + (2i up r) <= 5i }
  19. with the @Eq {non up } (i.e. max) operations arising from mark
  20. alignment.  Eliminating them gives
  21. @ID @Eq {
  22. matrix {
  23.     { 1i + 2i ^<= 5i }
  24. mabove    { l  + 2i ^<= 5i }
  25. mabove    { 1i + r  ^<= 5i }
  26. mabove    { l  + r  ^<= 5i }
  27. }
  28. }
  29. and since we assume that @Code a fits into the available space, the
  30. first inequality may be dropped, leaving
  31. @ID @Eq {
  32. matrix {
  33.     { l     ^<= 3i }
  34. mabove    { l + r ^<= 5i }
  35. mabove    { r     ^<= 4i }
  36. }
  37. }
  38. Object @Code b may have width @Eq {l, r} for any @Eq { l } and
  39. @Eq { r } satisfying these inequalities, and no others.
  40. @PP
  41. Here is another example:
  42. @ID @Code "5i  @High  {  a  /2ix  b  }"
  43. Assuming that @Code a has height @Eq {1i,1i}, the height @Eq {l, r} of
  44. @Code b must satisfy
  45. @ID @Eq { 1i + ((1i + l) up 2i) + r <= 5i }
  46. This time the @Eq { non up } operation arises from the mark-to-mark gap
  47. mode, which will widen the @Eq { 2i } gap if necessary to prevent
  48. @Code a and @Code b from overlapping.  This inequality can be rewritten as
  49. @ID @Eq {
  50. matrix {
  51.     { l     ^<= infinity }
  52. mabove    { l + r ^<= 3i       }
  53. mabove    { r     ^<= 2i       }
  54. }
  55. }
  56. In general, Lout is designed so that the available width or height at
  57. any point can be expressed by three inequalities of the form
  58. @ID @Eq {
  59. matrix {
  60.     { l     ^<= x }
  61. mabove    { l + r ^<= y }
  62. mabove    { r     ^<= z }
  63. }
  64. }
  65. where @Eq {x }, @Eq {y} and @Eq {z} may be @Eq { infinity }.  We
  66. abbreviate these three inequalities to @Eq { l, r <= x, y, z }, and we
  67. call @Eq {x, y, z} a {@I{size constraint}}.
  68. @PP
  69. The two examples above showed how to propagate the size constraint
  70. @Eq { infinity, 5i, infinity } for
  71. @Code "a / b" down one level to the child {@Code b}.  Basser Lout
  72. contains a complete set of general rules for all node types, too
  73. complicated to give here.  Instead, we give just one example of how
  74. these rules are derived, using the object
  75. @ID {
  76. @Eq {x sub 1}  @Code "/"  @Eq {x sub 2}  @Code "/"  @Eq {ldots}  @Code
  77. "/"  @Eq {x sub n}
  78. }
  79. where @Eq { x sub j } has width @Eq { l sub j , r sub j } for all @Eq {j}.
  80. @PP
  81. Suppose the whole object has width constraint @OneCol @Eq {X,Y,Z}, and we
  82. require the width constraint of {@Eq { x sub i }}.  Let
  83. @Eq { L = max sub j ` l sub j } and @Eq { R = max sub j ` r sub j },
  84. so that @OneCol @Eq {L, R} is the width of the whole object.  We assume
  85. @Eq {L, R <= X,Y,Z}.  Then @Eq { x sub i } can be enlarged to any size
  86. @Eq { l sub i ` , r sub i } satisfying
  87. @ID @Eq { ( l sub i up L), ( r sub i up R) <= X, Y, Z }
  88. which expands to eight inequalities:
  89. @ID @Eq {
  90. matrix {
  91.          { l sub i           ^<= X }
  92. mabove   { L                 ^<= X }
  93. mabove   { l sub i + r sub i ^<= Y }
  94. mabove   { l sub i + R       ^<= Y }
  95. mabove   { L + r sub i       ^<= Y }
  96. mabove   { L + R             ^<= Y }
  97. mabove   { r sub i           ^<= Z }
  98. mabove   { R                 ^<= Z }
  99. }
  100. }
  101. Three are already known, and slightly rearranging the others gives
  102. @ID @Eq {
  103. matrix {
  104.          { l sub i           ^<= X     }
  105. mabove   { l sub i           ^<= Y - R }
  106. mabove   { l sub i + r sub i ^<= Y     }
  107. mabove   { r sub i           ^<= Z     }
  108. mabove   { r sub i           ^<= Y - L }
  109. }
  110. }
  111. Therefore the width constraint of @Eq { x sub i } is
  112. @ID @Eq { min(X, Y-R), Y, min(Z, Y-L) }
  113. The size constraint of any node can be found by climbing the tree to a
  114. @I WIDE or @I HIGH node where the constraint is trivial, then propagating
  115. it back down to the node, and this is the function of procedure
  116. {@I Constrained} in Basser Lout.
  117. @PP
  118. After some components have been promoted into a target, the sizes stored
  119. in its parent and higher ancestors must be adjusted to reflect the
  120. increased size.  This is done by yet another set of recursive rules,
  121. upward-moving this time, which cease as soon as some ancestor's size
  122. does not change.  These rules are embodied in procedure @I AdjustSize
  123. of Basser Lout.  The adjustment must be done before relinquishing
  124. control to any other galley, but not after every component.
  125. @End @SubSection
  126.