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.6KB

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