You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Block.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.area;
  19. import java.util.Locale;
  20. // block areas hold either more block areas or line
  21. // areas can also be used as a block spacer
  22. // a block area may have children positioned by stacking
  23. // or by relative to the parent for floats, tables and lists
  24. // cacheable object
  25. // has id information
  26. /**
  27. * This is the block area class.
  28. * It holds child block areas such as other blocks or lines.
  29. */
  30. public class Block extends BlockParent {
  31. private static final long serialVersionUID = 6843727817993665788L;
  32. /**
  33. * Normally stacked with other blocks.
  34. */
  35. public static final int STACK = 0;
  36. /**
  37. * Placed relative to the flow position.
  38. * This effects the flow placement of stacking normally.
  39. */
  40. public static final int RELATIVE = 1;
  41. /**
  42. * Relative to the block parent but not effecting the stacking
  43. * Used for block-container, tables and lists.
  44. */
  45. public static final int ABSOLUTE = 2;
  46. /**
  47. * Relative to a viewport/page but not effecting the stacking
  48. * Used for block-container.
  49. */
  50. public static final int FIXED = 3;
  51. private int positioning = STACK;
  52. /** if true, allow BPD update */
  53. protected transient boolean allowBPDUpdate = true;
  54. private Locale locale;
  55. private String location;
  56. /**
  57. * Add the block to this block area.
  58. *
  59. * @param block the block area to add
  60. */
  61. public void addBlock(Block block) {
  62. addBlock(block, true);
  63. }
  64. /**
  65. * Add the block to this block area.
  66. *
  67. * @param block the block area to add
  68. * @param autoHeight increase the height of the block.
  69. */
  70. public void addBlock(Block block, boolean autoHeight) {
  71. if (autoHeight && allowBPDUpdate && block.isStacked()) {
  72. bpd += block.getAllocBPD();
  73. }
  74. addChildArea(block);
  75. }
  76. /**
  77. * Add the line area to this block area.
  78. *
  79. * @param line the line area to add
  80. */
  81. public void addLineArea(LineArea line) {
  82. bpd += line.getAllocBPD();
  83. addChildArea(line);
  84. }
  85. /**
  86. * Set the positioning of this area.
  87. *
  88. * @param pos the positioning to use when rendering this area
  89. */
  90. public void setPositioning(int pos) {
  91. positioning = pos;
  92. }
  93. /**
  94. * Get the positioning of this area.
  95. *
  96. * @return the positioning to use when rendering this area
  97. */
  98. public int getPositioning() {
  99. return positioning;
  100. }
  101. /**
  102. * Indicates whether this block is stacked, rather than absolutely positioned.
  103. * @return true if it is stacked
  104. */
  105. public boolean isStacked() {
  106. return (getPositioning() == Block.STACK || getPositioning() == Block.RELATIVE);
  107. }
  108. /**
  109. * @return the start-indent trait
  110. */
  111. public int getStartIndent() {
  112. Integer startIndent = (Integer)getTrait(Trait.START_INDENT);
  113. return (startIndent != null ? startIndent : 0);
  114. }
  115. /**
  116. * @return the end-indent trait
  117. */
  118. public int getEndIndent() {
  119. Integer endIndent = (Integer)getTrait(Trait.END_INDENT);
  120. return (endIndent != null ? endIndent : 0);
  121. }
  122. /**
  123. * Sets the language information coming from the FO that generated this area.
  124. */
  125. public void setLocale(Locale locale) {
  126. this.locale = locale;
  127. }
  128. /**
  129. * Returns the language information for the FO that generated this area.
  130. */
  131. public Locale getLocale() {
  132. return locale;
  133. }
  134. /**
  135. * Sets the location in the source XML of the FO that generated this area.
  136. *
  137. * @location the line and column location
  138. */
  139. public void setLocation(String location) {
  140. this.location = location;
  141. }
  142. /**
  143. * Returns the location in the source XML of the FO that generated this area.
  144. *
  145. * @return the line and column location, {@code null} if that information is not available
  146. */
  147. public String getLocation() {
  148. return location;
  149. }
  150. }