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.

Area.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.area;
  8. import java.io.Serializable;
  9. import java.util.Map;
  10. import java.util.HashMap;
  11. // If the area appears more than once in the output
  12. // or if the area has external data it is cached
  13. // to keep track of it and to minimize rendered output
  14. // renderers can render the output once and display it
  15. // for every occurence
  16. // this should also extend to all outputs (including PDFGraphics2D)
  17. // and all types of renderers
  18. /**
  19. * Base object for all areas.
  20. */
  21. public class Area implements Serializable {
  22. // stacking directions
  23. /**
  24. * Stacking left to right
  25. */
  26. public static final int LR = 0;
  27. /**
  28. * Stacking right to left
  29. */
  30. public static final int RL = 1;
  31. /**
  32. * Stacking top to bottom
  33. */
  34. public static final int TB = 2;
  35. /**
  36. * Stacking bottom to top
  37. */
  38. public static final int BT = 3;
  39. // orientations for reference areas
  40. /**
  41. * Normal orientation
  42. */
  43. public static final int ORIENT_0 = 0;
  44. /**
  45. * Rotated 90 degrees clockwise
  46. */
  47. public static final int ORIENT_90 = 1;
  48. /**
  49. * Rotate 180 degrees
  50. */
  51. public static final int ORIENT_180 = 2;
  52. /**
  53. * Rotated 270 degrees clockwise
  54. */
  55. public static final int ORIENT_270 = 3;
  56. // area class values
  57. /**
  58. * Normal class
  59. */
  60. public static final int CLASS_NORMAL = 0;
  61. /**
  62. * Fixed position class
  63. */
  64. public static final int CLASS_FIXED = 1;
  65. /**
  66. * Absolute position class
  67. */
  68. public static final int CLASS_ABSOLUTE = 2;
  69. /**
  70. * Before float class
  71. */
  72. public static final int CLASS_BEFORE_FLOAT = 3;
  73. /**
  74. * Footnote class
  75. */
  76. public static final int CLASS_FOOTNOTE = 4;
  77. /**
  78. * Side float class
  79. */
  80. public static final int CLASS_SIDE_FLOAT = 5;
  81. // IMPORTANT: make sure this is the maximum + 1
  82. /**
  83. * Maximum class count
  84. */
  85. public static final int CLASS_MAX = CLASS_SIDE_FLOAT + 1;
  86. private int areaClass = CLASS_NORMAL;
  87. private int ipd;
  88. /**
  89. * Traits for this area stored in a HashMap
  90. */
  91. protected HashMap props = null;
  92. /**
  93. * Get the area class of this area.
  94. *
  95. * @return the area class
  96. */
  97. public int getAreaClass() {
  98. return areaClass;
  99. }
  100. /**
  101. * Set the area class of this area.
  102. *
  103. * @param areaClass the area class
  104. */
  105. public void setAreaClass(int areaClass) {
  106. this.areaClass = areaClass;
  107. }
  108. /**
  109. * Set the inline progression dimension of this area.
  110. *
  111. * @param i the new inline progression dimension
  112. */
  113. public void setIPD(int i) {
  114. ipd = i;
  115. }
  116. /**
  117. * Get the inline progression dimension of this area.
  118. *
  119. * @return the inline progression dimension
  120. */
  121. public int getIPD() {
  122. return ipd;
  123. }
  124. /**
  125. * Add a child to this area.
  126. * The default is to do nothing. Subclasses must override
  127. * to do something if they can have child areas.
  128. *
  129. * @param child the child area to add
  130. */
  131. public void addChild(Area child) {
  132. }
  133. /**
  134. * Add a trait property to this area.
  135. *
  136. * @param prop the Trait to add
  137. */
  138. public void addTrait(Trait prop) {
  139. if (props == null) {
  140. props = new HashMap(20);
  141. }
  142. props.put(prop.propType, prop.data);
  143. }
  144. /**
  145. * Add a trait to this area.
  146. *
  147. * @param traitCode the trait key
  148. * @param prop the value of the trait
  149. */
  150. public void addTrait(Object traitCode, Object prop) {
  151. if (props == null) {
  152. props = new HashMap(20);
  153. }
  154. props.put(traitCode, prop);
  155. }
  156. /**
  157. * Get the map of all traits on this area.
  158. *
  159. * @return the map of traits
  160. */
  161. public Map getTraits() {
  162. return this.props;
  163. }
  164. /**
  165. * Get a trait from this area.
  166. *
  167. * @param oTraitCode the trait key
  168. * @return the trait value
  169. */
  170. public Object getTrait(Object oTraitCode) {
  171. return (props != null ? props.get(oTraitCode) : null);
  172. }
  173. }