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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * $Id: Area.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.area;
  52. import java.io.Serializable;
  53. import java.util.Map;
  54. import java.util.HashMap;
  55. // If the area appears more than once in the output
  56. // or if the area has external data it is cached
  57. // to keep track of it and to minimize rendered output
  58. // renderers can render the output once and display it
  59. // for every occurence
  60. // this should also extend to all outputs (including PDFGraphics2D)
  61. // and all types of renderers
  62. /**
  63. * Base object for all areas.
  64. */
  65. public class Area implements Serializable {
  66. // stacking directions
  67. /**
  68. * Stacking left to right
  69. */
  70. public static final int LR = 0;
  71. /**
  72. * Stacking right to left
  73. */
  74. public static final int RL = 1;
  75. /**
  76. * Stacking top to bottom
  77. */
  78. public static final int TB = 2;
  79. /**
  80. * Stacking bottom to top
  81. */
  82. public static final int BT = 3;
  83. // orientations for reference areas
  84. /**
  85. * Normal orientation
  86. */
  87. public static final int ORIENT_0 = 0;
  88. /**
  89. * Rotated 90 degrees clockwise
  90. */
  91. public static final int ORIENT_90 = 1;
  92. /**
  93. * Rotate 180 degrees
  94. */
  95. public static final int ORIENT_180 = 2;
  96. /**
  97. * Rotated 270 degrees clockwise
  98. */
  99. public static final int ORIENT_270 = 3;
  100. // area class values
  101. /**
  102. * Normal class
  103. */
  104. public static final int CLASS_NORMAL = 0;
  105. /**
  106. * Fixed position class
  107. */
  108. public static final int CLASS_FIXED = 1;
  109. /**
  110. * Absolute position class
  111. */
  112. public static final int CLASS_ABSOLUTE = 2;
  113. /**
  114. * Before float class
  115. */
  116. public static final int CLASS_BEFORE_FLOAT = 3;
  117. /**
  118. * Footnote class
  119. */
  120. public static final int CLASS_FOOTNOTE = 4;
  121. /**
  122. * Side float class
  123. */
  124. public static final int CLASS_SIDE_FLOAT = 5;
  125. // IMPORTANT: make sure this is the maximum + 1
  126. /**
  127. * Maximum class count
  128. */
  129. public static final int CLASS_MAX = CLASS_SIDE_FLOAT + 1;
  130. private int areaClass = CLASS_NORMAL;
  131. private int ipd;
  132. /**
  133. * Traits for this area stored in a HashMap
  134. */
  135. protected HashMap props = null;
  136. /**
  137. * Get the area class of this area.
  138. *
  139. * @return the area class
  140. */
  141. public int getAreaClass() {
  142. return areaClass;
  143. }
  144. /**
  145. * Set the area class of this area.
  146. *
  147. * @param areaClass the area class
  148. */
  149. public void setAreaClass(int areaClass) {
  150. this.areaClass = areaClass;
  151. }
  152. /**
  153. * Set the inline progression dimension of this area.
  154. *
  155. * @param i the new inline progression dimension
  156. */
  157. public void setIPD(int i) {
  158. ipd = i;
  159. }
  160. /**
  161. * Get the inline progression dimension of this area.
  162. *
  163. * @return the inline progression dimension
  164. */
  165. public int getIPD() {
  166. return ipd;
  167. }
  168. /**
  169. * Add a child to this area.
  170. * The default is to do nothing. Subclasses must override
  171. * to do something if they can have child areas.
  172. *
  173. * @param child the child area to add
  174. */
  175. public void addChild(Area child) {
  176. }
  177. /**
  178. * Add a trait property to this area.
  179. *
  180. * @param prop the Trait to add
  181. */
  182. public void addTrait(Trait prop) {
  183. if (props == null) {
  184. props = new java.util.HashMap(20);
  185. }
  186. props.put(prop.getPropType(), prop.getData());
  187. }
  188. /**
  189. * Add a trait to this area.
  190. *
  191. * @param traitCode the trait key
  192. * @param prop the value of the trait
  193. */
  194. public void addTrait(Object traitCode, Object prop) {
  195. if (props == null) {
  196. props = new java.util.HashMap(20);
  197. }
  198. props.put(traitCode, prop);
  199. }
  200. /**
  201. * Get the map of all traits on this area.
  202. *
  203. * @return the map of traits
  204. */
  205. public Map getTraits() {
  206. return this.props;
  207. }
  208. /**
  209. * Get a trait from this area.
  210. *
  211. * @param oTraitCode the trait key
  212. * @return the trait value
  213. */
  214. public Object getTrait(Object oTraitCode) {
  215. return (props != null ? props.get(oTraitCode) : null);
  216. }
  217. /**
  218. * Get a trait from this area as an integer.
  219. *
  220. * @param oTraitCode the trait key
  221. * @return the trait value
  222. */
  223. public int getTraitAsInteger(Object oTraitCode) {
  224. final Object obj = getTrait(oTraitCode);
  225. if (obj instanceof Integer) {
  226. return ((Integer)obj).intValue();
  227. } else {
  228. throw new IllegalArgumentException("Trait "
  229. + oTraitCode.getClass().getName()
  230. + " could not be converted to an integer");
  231. }
  232. }
  233. }