Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BlockArea.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. *
  3. * Copyright 2004 The Apache Software Foundation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * Created on 30/01/2004
  18. * $Id$
  19. */
  20. package org.apache.fop.area;
  21. import java.awt.geom.Rectangle2D;
  22. import org.apache.fop.datastructs.Node;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.flow.FoPageSequence;
  25. /**
  26. * @author pbw
  27. * @version $Revision$ $Name$
  28. */
  29. public class BlockArea extends Area {
  30. /**
  31. * @param parent of this node
  32. */
  33. public BlockArea(
  34. FoPageSequence pageSeq,
  35. FONode generatedBy,
  36. Node parent,
  37. Object sync) {
  38. super(pageSeq, generatedBy, parent, sync);
  39. // Setup the allocation-rectangle
  40. allocation = new BlockAllocationRectangle();
  41. }
  42. private BlockAllocationRectangle allocation;
  43. /** The page space allocation for layout of the block */
  44. private Rectangle2D pageSpace = new Rectangle2D.Double();
  45. /** The content space equivalent to the pageSpace */
  46. private Rectangle2D contentSpace = null;
  47. // /**
  48. // * Receives an allocation of page space from area parent
  49. // * @param pageSpace
  50. // */
  51. // public void receivePageSpace(Rectangle2D pageSpace) {
  52. // this.pageSpace = pageSpace;
  53. // }
  54. /**
  55. * An allocation of page space has been requested by the currently active
  56. * child area. <i>N.B.</i> <code>reference-area</code>s must override
  57. * this method to apply an <code>AffineTransform</code> to areas passed
  58. * up and returned.
  59. * <p>The requested space is the whole area required by the child, including
  60. * padding, borders and margins (spaces). The area is allocated from the
  61. * content area of the parent.
  62. * @return
  63. */
  64. public Rectangle2D pageSpaceRequest(AreaRange spaceRange) {
  65. AreaRange request = adjustedRequest(spaceRange);
  66. // Is there a sufficient allocation already available?
  67. if (spaceContains(spaceRange.minima)) {
  68. if (spaceContains(spaceRange.maxima)) {
  69. // Reduce available space and OK the request
  70. // N.B. the space request must take into account the
  71. // space required for footnotes
  72. // If all of the text fits into the available space, then the
  73. // siblings of the line area must be tested to discover whether
  74. // they contain inline items which will go into the same
  75. // line-area. At this point, e.g., footnotes will be found.
  76. } else {
  77. // The available space is sufficient to contain the mimimum
  78. // layout from the child, but insufficient to contain all of it.
  79. // Negotiate available space with the requester
  80. }
  81. } else { // Need more space from above. Page may be full
  82. // Negotiate with parent for more space
  83. }
  84. return null;
  85. }
  86. private boolean spaceContains(Rectangle2D rect) {
  87. return pageSpace.contains(
  88. rect.getMinX(), rect.getMinY(),
  89. rect.getWidth(), rect.getHeight());
  90. }
  91. private AreaRange adjustedRequest(AreaRange request) {
  92. // TODO Adjust the request for padding, borders and margins on this
  93. // block
  94. // For now, do nothing.
  95. return request;
  96. }
  97. /**
  98. * Accepts a laid-out block from an area child
  99. * @param layout
  100. */
  101. public void acceptLayout(Rectangle2D layout) {
  102. }
  103. protected double getStartSpace() {
  104. return getStartIndent() + getStartIntrusion();
  105. }
  106. protected double getEndSpace() {
  107. return getEndIndent() + getEndIntrusion();
  108. }
  109. protected double getStartIndent() {
  110. // Dummy start-indent
  111. return 10.0;
  112. }
  113. protected double getEndIndent() {
  114. // Dummy end-indent
  115. return 10.0;
  116. }
  117. protected double getStartIntrusion() {
  118. // dummy intrusion
  119. return 0.0;
  120. }
  121. protected double getEndIntrusion() {
  122. // dummy intrusion
  123. return 0.0;
  124. }
  125. /**
  126. * @author pbw
  127. * @version $Revision$ $Name$
  128. */
  129. public class BlockAllocationRectangle extends AreaFrame implements
  130. AllocationRectangle, AreaListener {
  131. private PaddingRectangle padding;
  132. private BorderRectangle borders;
  133. private SpacesRectangle spaces;
  134. /**
  135. * @param area
  136. * @param contents
  137. */
  138. public BlockAllocationRectangle() {
  139. // For block-areas, the allocation-area is bounded in the
  140. // block-progression-direction by the border-rectangle, and in the
  141. // inline-progression-direction by the spaces-rectangle.
  142. // See 4.2.3 Geometric Definitions
  143. // The contents of the BlockAllocationRectangle is the ContentRectangle.
  144. // Initally, set up the AreaFrame representing the allocation
  145. // rectangle to co-incide with the content-rectangle.
  146. super(BlockArea.this, BlockArea.this.getContent());
  147. // Now extend the AreaFrame to co-incide with the
  148. // edges of the border rectangle in the BPDir, and with the edges of
  149. // the spaces rectangle in the IPDir.
  150. padding = BlockArea.this.getPadding();
  151. borders = BlockArea.this.getBorders();
  152. spaces = BlockArea.this.getSpaces();
  153. // Register the listener
  154. spaces.registerAreaListener(this);
  155. setAllocationFrame();
  156. }
  157. public void setAllocationFrame() {
  158. // TODO synchronize this
  159. setStart(spaces.getStart() + borders.getStart() + padding.getStart());
  160. setEnd(spaces.getEnd() + borders.getEnd() + padding.getEnd());
  161. setBefore(borders.getBefore() + padding.getBefore());
  162. setAfter(borders.getAfter() + padding.getAfter());
  163. }
  164. public void setDimensions(Rectangle2D geometry) {
  165. setAllocationFrame();
  166. }
  167. }
  168. }