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.

FloatLayoutManager.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 java.util.LinkedList;
  20. import java.util.List;
  21. import org.apache.fop.fo.flow.Float;
  22. import org.apache.fop.layoutmgr.FloatContentLayoutManager;
  23. import org.apache.fop.layoutmgr.InlineKnuthSequence;
  24. import org.apache.fop.layoutmgr.KnuthElement;
  25. import org.apache.fop.layoutmgr.KnuthPossPosIter;
  26. import org.apache.fop.layoutmgr.KnuthSequence;
  27. import org.apache.fop.layoutmgr.LayoutContext;
  28. import org.apache.fop.layoutmgr.LayoutManager;
  29. import org.apache.fop.layoutmgr.Position;
  30. import org.apache.fop.layoutmgr.PositionIterator;
  31. import org.apache.fop.layoutmgr.SpaceResolver;
  32. public class FloatLayoutManager extends InlineStackingLayoutManager {
  33. private FloatContentLayoutManager floatContentLM;
  34. private KnuthInlineBox anchor;
  35. private List<KnuthElement> floatContentKnuthElements;
  36. private Float floatContent;
  37. private boolean floatContentAreaAdded;
  38. public FloatLayoutManager(Float node) {
  39. super(node);
  40. floatContent = node;
  41. }
  42. protected LayoutManager getChildLM() {
  43. return null;
  44. }
  45. public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
  46. if (!floatContentAreaAdded && !floatContent.isDisabled()) {
  47. floatContentLM = new FloatContentLayoutManager(floatContent);
  48. floatContentLM.setParent(this);
  49. floatContentLM.initialize();
  50. floatContentKnuthElements = floatContentLM.getNextKnuthElements(context, alignment);
  51. SpaceResolver.resolveElementList(floatContentKnuthElements);
  52. }
  53. // the only knuth element is a zero width and height knuth box
  54. LinkedList knuthElements = new LinkedList();
  55. KnuthSequence seq = new InlineKnuthSequence();
  56. anchor = new KnuthInlineBox(0, null, null, true);
  57. if (!floatContentAreaAdded) {
  58. anchor.setFloatContentLM(floatContentLM);
  59. }
  60. anchor.setPosition(notifyPos(new Position(this)));
  61. seq.add(anchor);
  62. knuthElements.add(seq);
  63. setFinished(true);
  64. return knuthElements;
  65. }
  66. public void addAreas(PositionIterator posIter, LayoutContext context) {
  67. // "Unwrap" the NonLeafPositions stored in posIter
  68. while (posIter.hasNext()) {
  69. posIter.next();
  70. }
  71. }
  72. public void processAreas(LayoutContext context) {
  73. PositionIterator contentPosIter = new KnuthPossPosIter(floatContentKnuthElements, 0,
  74. floatContentKnuthElements.size());
  75. floatContentLM.addAreas(contentPosIter, context);
  76. floatContentAreaAdded = true;
  77. anchor.setFloatContentLM(null);
  78. }
  79. }