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.

InlineArea.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright 1999-2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.area.inline;
  18. import org.apache.fop.area.Area;
  19. import org.apache.fop.area.LineArea;
  20. import org.apache.fop.area.Trait;
  21. /**
  22. * Inline Area
  23. * This area is for all inline areas that can be placed
  24. * in a line area.
  25. */
  26. public class InlineArea extends Area {
  27. /**
  28. * this class stores information about potential adjustments
  29. * that can be used in order to re-compute adjustments when a
  30. * page-number or a page-number-citation is resolved
  31. */
  32. protected class InlineAdjustingInfo {
  33. /** stretch of the inline area */
  34. protected int availableStretch;
  35. /** shrink of the inline area */
  36. protected int availableShrink;
  37. /** total adjustment (= ipd - width of fixed elements) */
  38. protected int adjustment;
  39. /**
  40. * Constructor
  41. *
  42. * @param stretch the available space for stretching
  43. * @param shrink the available space for shrinking
  44. * @param adj space adjustment type
  45. */
  46. protected InlineAdjustingInfo(int stretch, int shrink, int adj) {
  47. availableStretch = stretch;
  48. availableShrink = shrink;
  49. adjustment = adj;
  50. }
  51. }
  52. /**
  53. * offset position from before edge of parent area
  54. */
  55. protected int offset = 0;
  56. /**
  57. * parent area
  58. * it is needed in order to recompute adjust ratio and indents
  59. * when a page-number or a page-number-citation is resolved
  60. */
  61. private Area parentArea = null;
  62. /**
  63. * ipd variation of child areas: if this area has not already
  64. * been added and cannot notify its parent area, store the variation
  65. * and wait for the parent area to be set
  66. */
  67. private int storedIPDVariation = 0;
  68. /**
  69. * Increase the inline progression dimensions of this area.
  70. * This is used for inline parent areas that contain mulitple child areas.
  71. *
  72. * @param ipd the inline progression to increase by
  73. */
  74. public void increaseIPD(int ipd) {
  75. this.ipd += ipd;
  76. }
  77. /**
  78. * Set the offset of this inline area.
  79. * This is used to set the offset of the inline area
  80. * which is relative to the before edge of the parent area.
  81. *
  82. * @param offset the offset
  83. */
  84. public void setOffset(int offset) {
  85. this.offset = offset;
  86. }
  87. /**
  88. * Get the offset of this inline area.
  89. * This returns the offset of the inline area
  90. * which is relative to the before edge of the parent area.
  91. *
  92. * @return the offset
  93. */
  94. public int getOffset() {
  95. return offset;
  96. }
  97. /**
  98. * @param parentArea The parentArea to set.
  99. */
  100. public void setParentArea(Area parentArea) {
  101. this.parentArea = parentArea;
  102. // notify the parent area about ipd variations
  103. if (storedIPDVariation > 0) {
  104. notifyIPDVariation(storedIPDVariation);
  105. storedIPDVariation = 0;
  106. }
  107. }
  108. /**
  109. * @return Returns the parentArea.
  110. */
  111. public Area getParentArea() {
  112. return parentArea;
  113. }
  114. /**
  115. * Set the parent for the child area.
  116. *
  117. * @see org.apache.fop.area.Area#addChildArea(Area)
  118. */
  119. public void addChildArea(Area childArea) {
  120. super.addChildArea(childArea);
  121. if (childArea instanceof InlineArea) {
  122. ((InlineArea) childArea).setParentArea(this);
  123. }
  124. }
  125. /**
  126. *@return true if the inline area is underlined.
  127. */
  128. public boolean hasUnderline() {
  129. return getBooleanTrait(Trait.UNDERLINE);
  130. }
  131. /** @return true if the inline area is overlined. */
  132. public boolean hasOverline() {
  133. return getBooleanTrait(Trait.OVERLINE);
  134. }
  135. /** @return true if the inline area has a line through. */
  136. public boolean hasLineThrough() {
  137. return getBooleanTrait(Trait.LINETHROUGH);
  138. }
  139. /** @return true if the inline area is blinking. */
  140. public boolean isBlinking() {
  141. return getBooleanTrait(Trait.BLINK);
  142. }
  143. /**
  144. * set the ipd and notify the parent area about the variation;
  145. * this happens when a page-number or a page-number-citation
  146. * is resolved to its actual value
  147. * @param newIPD the new ipd of the area
  148. */
  149. public void updateIPD(int newIPD) {
  150. // default behaviour: do nothing
  151. }
  152. /**
  153. * recursively apply the variation factor to all descendant areas
  154. * @param variationFactor the variation factor that must be applied to adjustments
  155. * @param lineStretch the total stretch of the line
  156. * @param lineShrink the total shrink of the line
  157. * @return true if there is an UnresolvedArea descendant
  158. */
  159. public boolean applyVariationFactor(double variationFactor,
  160. int lineStretch, int lineShrink) {
  161. // default behaviour: simply return false
  162. return false;
  163. }
  164. /**
  165. * notify the parent area about the ipd variation of this area
  166. * or of a descendant area
  167. * @param ipdVariation the difference between new and old ipd
  168. */
  169. protected void notifyIPDVariation(int ipdVariation) {
  170. if (getParentArea() instanceof InlineArea) {
  171. ((InlineArea) getParentArea()).notifyIPDVariation(ipdVariation);
  172. } else if (getParentArea() instanceof LineArea) {
  173. ((LineArea) getParentArea()).handleIPDVariation(ipdVariation);
  174. } else if (getParentArea() == null) {
  175. // parent area not yet set: store the variations
  176. storedIPDVariation += ipdVariation;
  177. }
  178. }
  179. }