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 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 1999-2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.area.inline;
  18. import org.apache.fop.area.Area;
  19. import java.util.List;
  20. import java.util.ArrayList;
  21. /**
  22. * Inline parent area.
  23. * This is an inline area that can have other inlines as children.
  24. */
  25. public class InlineParent extends InlineArea {
  26. /**
  27. * The list of inline areas added to this inline parent.
  28. */
  29. protected List inlines = new ArrayList();
  30. /** Controls whether the IPD is automatically adjusted based on the area's children. */
  31. protected transient boolean autoSize;
  32. /**
  33. * Create a new inline parent to add areas to.
  34. */
  35. public InlineParent() {
  36. }
  37. /**
  38. * Override generic Area method.
  39. *
  40. * @param childArea the child area to add
  41. */
  42. public void addChildArea(Area childArea) {
  43. if (inlines.size() == 0) {
  44. autoSize = (getIPD() == 0);
  45. }
  46. if (childArea instanceof InlineArea) {
  47. inlines.add(childArea);
  48. if (autoSize) {
  49. increaseIPD(((InlineArea) childArea).getAllocIPD());
  50. }
  51. }
  52. }
  53. /**
  54. * Get the child areas for this inline parent.
  55. *
  56. * @return the list of child areas
  57. */
  58. public List getChildAreas() {
  59. return inlines;
  60. }
  61. /**
  62. * recursively apply the variation factor to all descendant areas
  63. * @param variationFactor the variation factor that must be applied to adjustments
  64. * @param lineStretch the total stretch of the line
  65. * @param lineShrink the total shrink of the line
  66. * @return true if there is an UnresolvedArea descendant
  67. */
  68. public boolean applyVariationFactor(double variationFactor,
  69. int lineStretch, int lineShrink) {
  70. boolean bUnresolvedAreasPresent = false;
  71. // recursively apply variation factor to descendant areas
  72. for (int i = 0, len = inlines.size(); i < len; i++) {
  73. bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i))
  74. .applyVariationFactor(variationFactor, lineStretch, lineShrink);
  75. }
  76. return bUnresolvedAreasPresent;
  77. }
  78. }