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

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