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.

InlineParent.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.area.inline;
  19. import org.apache.fop.area.Area;
  20. import java.util.List;
  21. import java.util.ArrayList;
  22. /**
  23. * Inline parent area.
  24. * This is an inline area that can have other inlines as children.
  25. */
  26. public class InlineParent extends InlineArea {
  27. private static final long serialVersionUID = -3047168298770354813L;
  28. /**
  29. * The list of inline areas added to this inline parent.
  30. */
  31. protected List inlines = new ArrayList();
  32. /** Controls whether the IPD is automatically adjusted based on the area's children. */
  33. protected transient boolean autoSize;
  34. /**
  35. * Create a new inline parent to add areas to.
  36. */
  37. public InlineParent() {
  38. }
  39. /**
  40. * Override generic Area method.
  41. *
  42. * @param childArea the child area to add
  43. */
  44. public void addChildArea(Area childArea) {
  45. if (inlines.size() == 0) {
  46. autoSize = (getIPD() == 0);
  47. }
  48. if (childArea instanceof InlineArea) {
  49. InlineArea inlineChildArea = (InlineArea) childArea;
  50. inlines.add(childArea);
  51. // set the parent area for the child area
  52. inlineChildArea.setParentArea(this);
  53. if (autoSize) {
  54. increaseIPD(inlineChildArea.getAllocIPD());
  55. }
  56. }
  57. }
  58. /**
  59. * Get the child areas for this inline parent.
  60. *
  61. * @return the list of child areas
  62. */
  63. public List getChildAreas() {
  64. return inlines;
  65. }
  66. /**
  67. * recursively apply the variation factor to all descendant areas
  68. * @param variationFactor the variation factor that must be applied to adjustments
  69. * @param lineStretch the total stretch of the line
  70. * @param lineShrink the total shrink of the line
  71. * @return true if there is an UnresolvedArea descendant
  72. */
  73. public boolean applyVariationFactor(double variationFactor,
  74. int lineStretch, int lineShrink) {
  75. boolean bUnresolvedAreasPresent = false;
  76. // recursively apply variation factor to descendant areas
  77. for (int i = 0, len = inlines.size(); i < len; i++) {
  78. bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i))
  79. .applyVariationFactor(variationFactor, lineStretch, lineShrink);
  80. }
  81. return bUnresolvedAreasPresent;
  82. }
  83. }