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.

StaticContentLayoutManager.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. 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. /* $Id$ */
  18. package org.apache.fop.layoutmgr;
  19. import java.util.List;
  20. import org.apache.fop.area.Area;
  21. import org.apache.fop.area.Block;
  22. import org.apache.fop.area.RegionReference;
  23. import org.apache.fop.fo.Constants;
  24. import org.apache.fop.fo.pagination.PageSequence;
  25. import org.apache.fop.fo.pagination.SideRegion;
  26. import org.apache.fop.fo.pagination.StaticContent;
  27. /**
  28. * LayoutManager for an fo:flow object.
  29. * Its parent LM is the PageSequenceLayoutManager.
  30. * This LM is responsible for getting columns of the appropriate size
  31. * and filling them with block-level areas generated by its children.
  32. */
  33. public class StaticContentLayoutManager extends BlockStackingLayoutManager {
  34. private RegionReference targetRegion;
  35. private Block targetBlock;
  36. private SideRegion regionFO;
  37. private int contentAreaIPD;
  38. private int contentAreaBPD = -1;
  39. /**
  40. * Creates a new StaticContentLayoutManager.
  41. * @param pslm PageSequenceLayoutManager this layout manager belongs to
  42. * @param node static-content FO
  43. * @param reg side region to layout into
  44. */
  45. public StaticContentLayoutManager(PageSequenceLayoutManager pslm,
  46. StaticContent node, SideRegion reg) {
  47. super(node);
  48. setParent(pslm);
  49. regionFO = reg;
  50. targetRegion = getCurrentPV().getRegionReference(regionFO.getNameId());
  51. }
  52. /**
  53. * Creates a new StaticContentLayoutManager.
  54. * @param pslm PageSequenceLayoutManager this layout manager belongs to
  55. * @param node static-content FO
  56. * @param block the block to layout into
  57. */
  58. public StaticContentLayoutManager(PageSequenceLayoutManager pslm,
  59. StaticContent node, Block block) {
  60. super(node);
  61. setParent(pslm);
  62. targetBlock = block;
  63. }
  64. /** {@inheritDoc} */
  65. public List getNextKnuthElements(LayoutContext context, int alignment) {
  66. throw new IllegalStateException();
  67. }
  68. /**
  69. * {@inheritDoc}
  70. */
  71. public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
  72. AreaAdditionUtil.addAreas(this, parentIter, layoutContext);
  73. flush();
  74. targetRegion = null;
  75. }
  76. /**
  77. * Add child area to a the correct container, depending on its
  78. * area class. A Flow can fill at most one area container of any class
  79. * at any one time. The actual work is done by BlockStackingLM.
  80. * {@inheritDoc}
  81. */
  82. public void addChildArea(Area childArea) {
  83. if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) {
  84. targetBlock.addBlock((Block)childArea);
  85. } else {
  86. targetRegion.addBlock((Block)childArea);
  87. }
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public Area getParentArea(Area childArea) {
  93. if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) {
  94. return targetBlock;
  95. } else {
  96. return targetRegion;
  97. }
  98. }
  99. /**
  100. * Does the layout for a side region. Called by PageSequenceLayoutManager.
  101. */
  102. public void doLayout() {
  103. int targetIPD = 0;
  104. int targetBPD = 0;
  105. int targetAlign = EN_AUTO;
  106. boolean autoHeight = false;
  107. StaticContentBreaker breaker;
  108. if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) {
  109. targetIPD = targetBlock.getIPD();
  110. targetBPD = targetBlock.getBPD();
  111. if (targetBPD == 0) {
  112. autoHeight = true;
  113. }
  114. targetAlign = EN_BEFORE;
  115. } else {
  116. targetIPD = targetRegion.getIPD();
  117. targetBPD = targetRegion.getBPD();
  118. targetAlign = regionFO.getDisplayAlign();
  119. }
  120. setContentAreaIPD(targetIPD);
  121. setContentAreaBPD(targetBPD);
  122. breaker = new StaticContentBreaker(this, targetIPD, targetAlign);
  123. breaker.doLayout(targetBPD, autoHeight);
  124. if (breaker.isOverflow()) {
  125. if (!autoHeight) {
  126. String page = getPSLM().getCurrentPage().getPageViewport().getPageNumberString();
  127. BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
  128. getStaticContentFO().getUserAgent().getEventBroadcaster());
  129. boolean canRecover = (regionFO.getOverflow() != EN_ERROR_IF_OVERFLOW);
  130. boolean needClip = (regionFO.getOverflow() == Constants.EN_HIDDEN
  131. || regionFO.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW);
  132. eventProducer.staticRegionOverflow(this, regionFO.getName(),
  133. page,
  134. breaker.getOverflowAmount(), needClip, canRecover,
  135. getStaticContentFO().getLocator());
  136. }
  137. }
  138. }
  139. /**
  140. * Convenience method that returns the Static Content node.
  141. * @return the static content node
  142. */
  143. protected StaticContent getStaticContentFO() {
  144. return (StaticContent) fobj;
  145. }
  146. private class StaticContentBreaker extends LocalBreaker {
  147. public StaticContentBreaker(StaticContentLayoutManager lm, int ipd, int displayAlign) {
  148. super(lm, ipd, displayAlign);
  149. }
  150. /** {@inheritDoc} */
  151. protected void observeElementList(List elementList) {
  152. String elementListID = getStaticContentFO().getFlowName();
  153. String pageSequenceID = ((PageSequence) lm.getParent().getFObj()).getId();
  154. if (pageSequenceID != null && pageSequenceID.length() > 0) {
  155. elementListID += "-" + pageSequenceID;
  156. }
  157. ElementListObserver.observe(elementList, "static-content", elementListID);
  158. }
  159. }
  160. /**
  161. * Returns the IPD of the content area
  162. * @return the IPD of the content area
  163. */
  164. public int getContentAreaIPD() {
  165. return contentAreaIPD;
  166. }
  167. /** {@inheritDoc} */
  168. protected void setContentAreaIPD(int contentAreaIPD) {
  169. this.contentAreaIPD = contentAreaIPD;
  170. }
  171. /**
  172. * Returns the BPD of the content area
  173. * @return the BPD of the content area
  174. */
  175. public int getContentAreaBPD() {
  176. return contentAreaBPD;
  177. }
  178. private void setContentAreaBPD(int contentAreaBPD) {
  179. this.contentAreaBPD = contentAreaBPD;
  180. }
  181. /** {@inheritDoc} */
  182. public Keep getKeepTogether() {
  183. return Keep.KEEP_AUTO;
  184. }
  185. /** {@inheritDoc} */
  186. public Keep getKeepWithNext() {
  187. return Keep.KEEP_AUTO;
  188. }
  189. /** {@inheritDoc} */
  190. public Keep getKeepWithPrevious() {
  191. return Keep.KEEP_AUTO;
  192. }
  193. }