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.

WrapperLayoutManager.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.inline;
  19. import org.apache.fop.area.inline.InlineArea;
  20. import org.apache.fop.area.Block;
  21. import org.apache.fop.fo.flow.Wrapper;
  22. import org.apache.fop.layoutmgr.BlockLayoutManager;
  23. import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
  24. import org.apache.fop.layoutmgr.KnuthBox;
  25. import org.apache.fop.layoutmgr.KnuthSequence;
  26. import org.apache.fop.layoutmgr.LayoutContext;
  27. import org.apache.fop.layoutmgr.ListElement;
  28. import org.apache.fop.layoutmgr.PositionIterator;
  29. import org.apache.fop.layoutmgr.TraitSetter;
  30. import java.util.LinkedList;
  31. import java.util.List;
  32. /**
  33. * This is the layout manager for the fo:wrapper formatting object.
  34. */
  35. public class WrapperLayoutManager extends LeafNodeLayoutManager {
  36. /**
  37. * Creates a new LM for fo:wrapper.
  38. * @param node the fo:wrapper
  39. */
  40. public WrapperLayoutManager(Wrapper node) {
  41. super(node);
  42. }
  43. /** {@inheritDoc} */
  44. @Override
  45. public InlineArea get(LayoutContext context) {
  46. // Create a zero-width, zero-height dummy area so this node can
  47. // participate in the ID handling. Otherwise, addId() wouldn't
  48. // be called. The area must also be added to the tree, because
  49. // determination of the X,Y position is done in the renderer.
  50. InlineArea area = new InlineArea();
  51. if (fobj.hasId()) {
  52. TraitSetter.setProducerID(area, fobj.getId());
  53. }
  54. return area;
  55. }
  56. /**
  57. * Overridden to generate a proper {@link ListElement}, if the parent
  58. * requires it (i.e. is a block-container, list-item-body...)
  59. * If the parent is a block, the line LM will take care of properly
  60. * wrapping the sequence in a line box.
  61. * {@inheritDoc}
  62. */
  63. @Override
  64. public List getNextKnuthElements(LayoutContext context, int alignment) {
  65. List returnList = super.getNextKnuthElements(context, alignment);
  66. KnuthSequence seq = (KnuthSequence) returnList.get(0);
  67. ListElement tempElement = (ListElement) seq.get(0);
  68. if (parentLayoutManager instanceof BlockStackingLayoutManager
  69. && !(parentLayoutManager instanceof BlockLayoutManager)) {
  70. // replace inline box with a block box
  71. returnList = new LinkedList();
  72. KnuthBox auxiliaryBox = new KnuthBox(0, tempElement.getPosition(), true);
  73. returnList.add(auxiliaryBox);
  74. } else {
  75. // make sure the inline box is an auxiliary one
  76. seq.set(0, new KnuthInlineBox(0, null, tempElement.getPosition(), true));
  77. }
  78. return returnList;
  79. }
  80. /**
  81. * Add the area for this layout manager.
  82. * This adds the dummy area to the parent, *if* it has an id
  83. * - otherwise it serves no purpose.
  84. * {@inheritDoc}
  85. */
  86. @Override
  87. public void addAreas(PositionIterator posIter, LayoutContext context) {
  88. if (fobj.hasId()) {
  89. addId();
  90. if (parentLayoutManager instanceof BlockStackingLayoutManager
  91. && !(parentLayoutManager instanceof BlockLayoutManager)) {
  92. Block helperBlock = new Block();
  93. TraitSetter.setProducerID(helperBlock, fobj.getId());
  94. parentLayoutManager.addChildArea(helperBlock);
  95. } else {
  96. InlineArea area = getEffectiveArea();
  97. parentLayoutManager.addChildArea(area);
  98. }
  99. }
  100. while (posIter.hasNext()) {
  101. posIter.next();
  102. }
  103. }
  104. /** {@inheritDoc} */
  105. protected void addId() {
  106. getPSLM().addIDToPage(fobj.getId());
  107. }
  108. }