Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

BlockArea.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $Id$
  2. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  3. * For details on use and redistribution please refer to the
  4. * LICENSE file included with these sources.
  5. */
  6. package org.apache.fop.layout;
  7. // FOP
  8. import org.apache.fop.render.Renderer;
  9. import org.apache.fop.fo.flow.*;
  10. import org.apache.fop.fo.*;
  11. import org.apache.fop.apps.*;
  12. import org.apache.fop.fo.properties.*;
  13. // Java
  14. import java.util.Vector;
  15. import java.util.Enumeration;
  16. import org.apache.fop.messaging.MessageHandler;
  17. /**
  18. * This class represents a Block Area.
  19. * A block area is made up of a sequence of Line Areas.
  20. *
  21. * This class is used to organise the sequence of line areas as
  22. * inline areas are added to this block it creates and ands line areas
  23. * to hold the inline areas.
  24. * This uses the line-height and line-stacking-strategy to work
  25. * out how to stack the lines.
  26. */
  27. public class BlockArea extends Area {
  28. /* relative to area container */
  29. protected int startIndent;
  30. protected int endIndent;
  31. /* first line startIndent modifier */
  32. protected int textIndent;
  33. protected int lineHeight;
  34. protected int halfLeading;
  35. /* text-align of all but the last line */
  36. protected int align;
  37. /* text-align of the last line */
  38. protected int alignLastLine;
  39. protected LineArea currentLineArea;
  40. protected LinkSet currentLinkSet;
  41. /* have any line areas been used? */
  42. protected boolean hasLines = false;
  43. /*hyphenation*/
  44. protected HyphenationProps hyphProps;
  45. protected Vector pendingFootnotes = null;
  46. public BlockArea(FontState fontState, int allocationWidth,
  47. int maxHeight, int startIndent, int endIndent,
  48. int textIndent, int align, int alignLastLine, int lineHeight) {
  49. super(fontState, allocationWidth, maxHeight);
  50. this.startIndent = startIndent;
  51. this.endIndent = endIndent;
  52. this.textIndent = textIndent;
  53. this.contentRectangleWidth =
  54. allocationWidth - startIndent - endIndent;
  55. this.align = align;
  56. this.alignLastLine = alignLastLine;
  57. this.lineHeight = lineHeight;
  58. if (fontState != null)
  59. this.halfLeading = (lineHeight - fontState.getFontSize()) / 2;
  60. }
  61. public void render(Renderer renderer) {
  62. renderer.renderBlockArea(this);
  63. }
  64. /**
  65. * Add a Line Area to this block area.
  66. * Used internally to add a completed line area to this block area
  67. * when either a new line area is created or this block area is
  68. * completed.
  69. *
  70. * @param la the LineArea to add
  71. */
  72. protected void addLineArea(LineArea la) {
  73. if (!la.isEmpty()) {
  74. la.verticalAlign();
  75. this.addDisplaySpace(this.halfLeading);
  76. int size = la.getHeight();
  77. this.addChild(la);
  78. this.increaseHeight(size);
  79. this.addDisplaySpace(this.halfLeading);
  80. }
  81. // add pending footnotes
  82. if (pendingFootnotes != null) {
  83. for (Enumeration e = pendingFootnotes.elements();
  84. e.hasMoreElements();) {
  85. FootnoteBody fb = (FootnoteBody) e.nextElement();
  86. Page page = getPage();
  87. if (!Footnote.layoutFootnote(page, fb, this)) {
  88. page.addPendingFootnote(fb);
  89. }
  90. }
  91. pendingFootnotes = null;
  92. }
  93. }
  94. /**
  95. * Get the current line area in this block area.
  96. * This is used to get the current line area for adding
  97. * inline objects to.
  98. * This will return null if there is not enough room left
  99. * in the block area to accomodate the line area.
  100. *
  101. * @return the line area to be used to add inlie objects
  102. */
  103. public LineArea getCurrentLineArea() {
  104. if (currentHeight + this.currentLineArea.getHeight() > maxHeight) {
  105. return null;
  106. }
  107. this.currentLineArea.changeHyphenation(hyphProps);
  108. this.hasLines = true;
  109. return this.currentLineArea;
  110. }
  111. /**
  112. * Create a new line area to add inline objects.
  113. * This should be called after getting the current line area
  114. * and discovering that the inline object will not fit inside the current
  115. * line. This method will create a new line area to place the inline
  116. * object into.
  117. * This will return null if the new line cannot fit into the block area.
  118. *
  119. * @return the new current line area, which will be empty.
  120. */
  121. public LineArea createNextLineArea() {
  122. if (this.hasLines) {
  123. this.currentLineArea.align(this.align);
  124. this.addLineArea(this.currentLineArea);
  125. }
  126. this.currentLineArea =
  127. new LineArea(fontState, lineHeight, halfLeading,
  128. allocationWidth, startIndent, endIndent, currentLineArea);
  129. this.currentLineArea.changeHyphenation(hyphProps);
  130. if (currentHeight + lineHeight > maxHeight) {
  131. return null;
  132. }
  133. return this.currentLineArea;
  134. }
  135. public void setupLinkSet(LinkSet ls) {
  136. if (ls != null) {
  137. this.currentLinkSet = ls;
  138. ls.setYOffset(currentHeight);
  139. }
  140. }
  141. /**
  142. * Notify this block that the area has completed layout.
  143. * Indicates the the block has been fully laid out, this will
  144. * add (if any) the current line area.
  145. */
  146. public void end() {
  147. if (this.hasLines) {
  148. this.currentLineArea.addPending();
  149. this.currentLineArea.align(this.alignLastLine);
  150. this.addLineArea(this.currentLineArea);
  151. }
  152. }
  153. public void start() {
  154. currentLineArea = new LineArea(fontState, lineHeight, halfLeading,
  155. allocationWidth, startIndent + textIndent, endIndent, null);
  156. }
  157. public int getEndIndent() {
  158. return endIndent;
  159. }
  160. // KL: I think we should just return startIndent here!
  161. public int getStartIndent() {
  162. //return startIndent + paddingLeft + borderWidthLeft;
  163. return startIndent ;
  164. }
  165. public void setIndents(int startIndent, int endIndent) {
  166. this.startIndent = startIndent;
  167. this.endIndent = endIndent;
  168. this.contentRectangleWidth =
  169. allocationWidth - startIndent - endIndent;
  170. }
  171. public int spaceLeft() {
  172. return maxHeight - currentHeight;
  173. }
  174. public int getHalfLeading() {
  175. return halfLeading;
  176. }
  177. public void setHyphenation(HyphenationProps hyphProps) {
  178. this.hyphProps = hyphProps;
  179. }
  180. public void addFootnote(FootnoteBody fb) {
  181. if (pendingFootnotes == null) {
  182. pendingFootnotes = new Vector();
  183. }
  184. pendingFootnotes.addElement(fb);
  185. }
  186. }