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.

StaticContentLayoutManager.java 7.4KB

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