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.2KB

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