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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.io.IOException;
  20. import java.io.ObjectInputStream;
  21. import java.util.Locale;
  22. // block areas hold either more block areas or line
  23. // areas can also be used as a block spacer
  24. // a block area may have children positioned by stacking
  25. // or by relative to the parent for floats, tables and lists
  26. // cacheable object
  27. // has id information
  28. /**
  29. * This is the block area class.
  30. * It holds child block areas such as other blocks or lines.
  31. */
  32. public class Block extends BlockParent {
  33. private static final long serialVersionUID = 6843727817993665788L;
  34. /**
  35. * Normally stacked with other blocks.
  36. */
  37. public static final int STACK = 0;
  38. /**
  39. * Placed relative to the flow position.
  40. * This effects the flow placement of stacking normally.
  41. */
  42. public static final int RELATIVE = 1;
  43. /**
  44. * Relative to the block parent but not effecting the stacking
  45. * Used for block-container, tables and lists.
  46. */
  47. public static final int ABSOLUTE = 2;
  48. /**
  49. * Relative to a viewport/page but not effecting the stacking
  50. * Used for block-container.
  51. */
  52. public static final int FIXED = 3;
  53. private int positioning = STACK;
  54. /** if true, allow BPD update */
  55. protected transient boolean allowBPDUpdate;
  56. private Locale locale;
  57. private String location;
  58. public Block() {
  59. allowBPDUpdate = true;
  60. }
  61. private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
  62. ois.defaultReadObject();
  63. }
  64. /**
  65. * Add the block to this block area.
  66. *
  67. * @param block the block area to add
  68. */
  69. public void addBlock(Block block) {
  70. addBlock(block, true);
  71. }
  72. /**
  73. * Add the block to this block area.
  74. *
  75. * @param block the block area to add
  76. * @param autoHeight increase the height of the block.
  77. */
  78. public void addBlock(Block block, boolean autoHeight) {
  79. if (autoHeight && allowBPDUpdate && block.isStacked()) {
  80. bpd += block.getAllocBPD();
  81. }
  82. addChildArea(block);
  83. }
  84. /**
  85. * Add the line area to this block area.
  86. *
  87. * @param line the line area to add
  88. */
  89. public void addLineArea(LineArea line) {
  90. bpd += line.getAllocBPD();
  91. addChildArea(line);
  92. }
  93. /**
  94. * Set the positioning of this area.
  95. *
  96. * @param pos the positioning to use when rendering this area
  97. */
  98. public void setPositioning(int pos) {
  99. positioning = pos;
  100. }
  101. /**
  102. * Get the positioning of this area.
  103. *
  104. * @return the positioning to use when rendering this area
  105. */
  106. public int getPositioning() {
  107. return positioning;
  108. }
  109. /**
  110. * Indicates whether this block is stacked, rather than absolutely positioned.
  111. * @return true if it is stacked
  112. */
  113. public boolean isStacked() {
  114. return (getPositioning() == Block.STACK || getPositioning() == Block.RELATIVE);
  115. }
  116. /**
  117. * @return the start-indent trait
  118. */
  119. public int getStartIndent() {
  120. Integer startIndent = (Integer)getTrait(Trait.START_INDENT);
  121. return (startIndent != null ? startIndent : 0);
  122. }
  123. /**
  124. * @return the end-indent trait
  125. */
  126. public int getEndIndent() {
  127. Integer endIndent = (Integer)getTrait(Trait.END_INDENT);
  128. return (endIndent != null ? endIndent : 0);
  129. }
  130. /**
  131. * Sets the language information coming from the FO that generated this area.
  132. */
  133. public void setLocale(Locale locale) {
  134. this.locale = locale;
  135. }
  136. /**
  137. * Returns the language information for the FO that generated this area.
  138. */
  139. public Locale getLocale() {
  140. return locale;
  141. }
  142. /**
  143. * Sets the location in the source XML of the FO that generated this area.
  144. *
  145. * @param location the line and column location
  146. */
  147. public void setLocation(String location) {
  148. this.location = location;
  149. }
  150. /**
  151. * Returns the location in the source XML of the FO that generated this area.
  152. *
  153. * @return the line and column location, {@code null} if that information is not available
  154. */
  155. public String getLocation() {
  156. return location;
  157. }
  158. // maybe this can be done in the parent?
  159. public int getEffectiveIPD() {
  160. int eIPD = super.getEffectiveIPD();
  161. if (eIPD != 0) {
  162. effectiveIPD = eIPD;
  163. }
  164. return eIPD;
  165. }
  166. // maybe this can be done in the parent?
  167. public void activateEffectiveIPD() {
  168. super.activateEffectiveIPD();
  169. if (effectiveIPD != -1) {
  170. ipd = effectiveIPD;
  171. }
  172. }
  173. }