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.

FootnoteBodyLayoutManager.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.fo.flow.FootnoteBody;
  23. /**
  24. * Layout manager for footnote bodies.
  25. */
  26. public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
  27. private List<KnuthElement> knuthElements;
  28. /**
  29. * Creates a new FootnoteBodyLayoutManager.
  30. * @param body the footnote-body element
  31. */
  32. public FootnoteBodyLayoutManager(FootnoteBody body) {
  33. super(body);
  34. }
  35. @Override
  36. public List<KnuthElement> getNextKnuthElements(LayoutContext context, int alignment) {
  37. if (knuthElements == null) {
  38. knuthElements = super.getNextKnuthElements(context, alignment);
  39. }
  40. return knuthElements;
  41. }
  42. /** {@inheritDoc} */
  43. @Override
  44. public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
  45. LayoutManager childLM;
  46. LayoutManager lastLM = null;
  47. LayoutContext lc = LayoutContext.newInstance();
  48. // "unwrap" the NonLeafPositions stored in parentIter
  49. // and put them in a new list;
  50. LinkedList<Position> positionList = new LinkedList<Position>();
  51. Position pos;
  52. while (parentIter.hasNext()) {
  53. pos = parentIter.next();
  54. Position innerPosition;
  55. if (pos instanceof NonLeafPosition) {
  56. innerPosition = pos.getPosition();
  57. if (innerPosition.getLM() == this) {
  58. // pos was created by this LM and was inside a penalty
  59. // allowing or forbidding a page break
  60. // nothing to do
  61. } else {
  62. // innerPosition was created by another LM
  63. positionList.add(innerPosition);
  64. lastLM = innerPosition.getLM();
  65. }
  66. }
  67. }
  68. // the Positions in positionList were inside the elements
  69. // created by the LineLM
  70. PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
  71. while ((childLM = childPosIter.getNextChildLM()) != null) {
  72. // set last area flag
  73. lc.setFlags(LayoutContext.LAST_AREA,
  74. (layoutContext.isLastArea() && childLM == lastLM));
  75. // Add the line areas to Area
  76. childLM.addAreas(childPosIter, lc);
  77. }
  78. }
  79. /** {@inheritDoc} */
  80. @Override
  81. public void addChildArea(Area childArea) {
  82. childArea.setAreaClass(Area.CLASS_FOOTNOTE);
  83. parentLayoutManager.addChildArea(childArea);
  84. }
  85. /** @return the FootnoteBody node */
  86. protected FootnoteBody getFootnodeBodyFO() {
  87. return (FootnoteBody) fobj;
  88. }
  89. /** {@inheritDoc} */
  90. @Override
  91. public Keep getKeepTogether() {
  92. return getParentKeepTogether();
  93. }
  94. /** {@inheritDoc} */
  95. @Override
  96. public Keep getKeepWithNext() {
  97. return Keep.KEEP_AUTO;
  98. }
  99. /** {@inheritDoc} */
  100. @Override
  101. public Keep getKeepWithPrevious() {
  102. return Keep.KEEP_AUTO;
  103. }
  104. @Override
  105. public void reset() {
  106. super.reset();
  107. knuthElements = null;
  108. }
  109. }