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 4.6KB

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