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.

LocalBreaker.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.fo.FObj;
  22. import org.apache.fop.layoutmgr.PageBreakingAlgorithm.PageBreakingLayoutListener;
  23. import org.apache.fop.layoutmgr.inline.TextLayoutManager;
  24. public abstract class LocalBreaker extends AbstractBreaker {
  25. protected BlockStackingLayoutManager lm;
  26. private int displayAlign;
  27. private int ipd;
  28. private int overflow;
  29. private boolean repeatedHeader;
  30. private boolean isDescendantOfTableFooter;
  31. private boolean repeatedFooter;
  32. public void setRepeatedFooter(boolean repeatedFooter) {
  33. this.repeatedFooter = repeatedFooter;
  34. }
  35. public void setDescendantOfTableFooter(boolean isDescendantOfTableFooter) {
  36. this.isDescendantOfTableFooter = isDescendantOfTableFooter;
  37. }
  38. public LocalBreaker(BlockStackingLayoutManager lm, int ipd, int displayAlign) {
  39. this.lm = lm;
  40. this.ipd = ipd;
  41. this.displayAlign = displayAlign;
  42. }
  43. public void setRepeatedHeader(boolean repeatedHeader) {
  44. this.repeatedHeader = repeatedHeader;
  45. }
  46. /** {@inheritDoc} */
  47. protected boolean isPartOverflowRecoveryActivated() {
  48. // For side regions, this must be disabled because of wanted overflow.
  49. return false;
  50. }
  51. public boolean isOverflow() {
  52. return (this.overflow != 0);
  53. }
  54. public int getOverflowAmount() {
  55. return this.overflow;
  56. }
  57. /** {@inheritDoc} */
  58. protected PageBreakingLayoutListener createLayoutListener() {
  59. return new PageBreakingLayoutListener() {
  60. public void notifyOverflow(int part, int amount, FObj obj) {
  61. if (LocalBreaker.this.overflow == 0) {
  62. LocalBreaker.this.overflow = amount;
  63. }
  64. }
  65. };
  66. }
  67. protected LayoutManager getTopLevelLM() {
  68. return lm;
  69. }
  70. protected LayoutContext createLayoutContext() {
  71. LayoutContext lc = super.createLayoutContext();
  72. lc.setRefIPD(ipd);
  73. return lc;
  74. }
  75. protected List getNextKnuthElements(LayoutContext context, int alignment) {
  76. LayoutManager curLM; // currently active LM
  77. List returnList = new LinkedList();
  78. while ((curLM = lm.getChildLM()) != null) {
  79. LayoutContext childLC = LayoutContext.newInstance();
  80. childLC.setStackLimitBP(context.getStackLimitBP());
  81. childLC.setRefIPD(context.getRefIPD());
  82. childLC.setWritingMode(context.getWritingMode());
  83. List returnedList = null;
  84. // The following is a HACK! Ignore leading and trailing white space
  85. boolean ignore = curLM instanceof TextLayoutManager;
  86. if (!curLM.isFinished()) {
  87. returnedList = curLM.getNextKnuthElements(childLC, alignment);
  88. }
  89. if (returnedList != null && !ignore) {
  90. lm.wrapPositionElements(returnedList, returnList);
  91. }
  92. }
  93. SpaceResolver.resolveElementList(returnList);
  94. lm.setFinished(true);
  95. return returnList;
  96. }
  97. protected int getCurrentDisplayAlign() {
  98. return displayAlign;
  99. }
  100. protected boolean hasMoreContent() {
  101. return !lm.isFinished();
  102. }
  103. protected void addAreas(PositionIterator posIter, LayoutContext context) {
  104. if (isDescendantOfTableFooter) {
  105. if (repeatedHeader) {
  106. context.setTreatAsArtifact(true);
  107. }
  108. } else {
  109. if (repeatedFooter) {
  110. context.setTreatAsArtifact(true);
  111. }
  112. }
  113. AreaAdditionUtil.addAreas(lm, posIter, context);
  114. }
  115. protected void doPhase3(PageBreakingAlgorithm alg, int partCount, BlockSequence originalList,
  116. BlockSequence effectiveList) {
  117. if (partCount > 1) {
  118. PageBreakPosition pos = alg.getPageBreaks().getFirst();
  119. int firstPartLength = ElementListUtils.calcContentLength(effectiveList,
  120. effectiveList.ignoreAtStart, pos.getLeafPos());
  121. overflow += alg.totalWidth - firstPartLength;
  122. }
  123. // Rendering all parts (not just the first) at once for the case where the parts that
  124. // overflow should be visible.
  125. alg.removeAllPageBreaks();
  126. // Directly add areas after finding the breaks
  127. this.addAreas(alg, 1, originalList, effectiveList);
  128. }
  129. protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) {
  130. // nop for static content
  131. }
  132. protected LayoutManager getCurrentChildLM() {
  133. return null; // TODO NYI
  134. }
  135. }