Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FootnoteBodyLayoutManager.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.setFromFootnote(true);
  77. childLM.addAreas(childPosIter, lc);
  78. }
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public void addChildArea(Area childArea) {
  83. childArea.setAreaClass(Area.CLASS_FOOTNOTE);
  84. childArea.setFromFootnote(true);
  85. parentLayoutManager.addChildArea(childArea);
  86. }
  87. /** @return the FootnoteBody node */
  88. protected FootnoteBody getFootnodeBodyFO() {
  89. return (FootnoteBody) fobj;
  90. }
  91. /** {@inheritDoc} */
  92. @Override
  93. public Keep getKeepTogether() {
  94. return getParentKeepTogether();
  95. }
  96. /** {@inheritDoc} */
  97. @Override
  98. public Keep getKeepWithNext() {
  99. return Keep.KEEP_AUTO;
  100. }
  101. /** {@inheritDoc} */
  102. @Override
  103. public Keep getKeepWithPrevious() {
  104. return Keep.KEEP_AUTO;
  105. }
  106. @Override
  107. public void reset() {
  108. super.reset();
  109. knuthElements = null;
  110. }
  111. }