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.

FilledArea.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 java.util.List;
  20. import java.util.ListIterator;
  21. import java.util.ArrayList;
  22. import java.util.Iterator;
  23. /**
  24. * Filled area.
  25. * This inline area contains some inline areas.
  26. * When the renderer gets the child areas to render
  27. * the inline areas are repeated to fill the ipd of
  28. * this inline parent.
  29. * This extends InlineParent so that the renderer will render
  30. * this as a normal inline parent.
  31. */
  32. public class FilledArea extends InlineParent {
  33. private static final long serialVersionUID = 8586584705587017474L;
  34. private int unitWidth;
  35. /**
  36. * Create a new filled area.
  37. */
  38. public FilledArea() {
  39. }
  40. /**
  41. * Set the offset of the descendant TextAreas,
  42. * instead of the offset of the FilledArea itself.
  43. *
  44. * @param v the offset
  45. */
  46. /*
  47. public void setOffset(int v) {
  48. setChildOffset(inlines.listIterator(), v);
  49. }
  50. */
  51. private void setChildOffset(ListIterator childrenIterator, int v) {
  52. while (childrenIterator.hasNext()) {
  53. InlineArea child = (InlineArea) childrenIterator.next();
  54. if (child instanceof InlineParent) {
  55. setChildOffset(((InlineParent) child).getChildAreas().listIterator(), v);
  56. } else if (child instanceof org.apache.fop.area.inline.Viewport) {
  57. // nothing
  58. } else {
  59. child.setOffset(v);
  60. }
  61. }
  62. }
  63. /**
  64. * Set the unit width for the areas to fill the full width.
  65. *
  66. * @param width the unit width
  67. */
  68. public void setUnitWidth(int width) {
  69. this.unitWidth = width;
  70. }
  71. /**
  72. * Return the unit width for the areas to fill the full width.
  73. *
  74. * @return the unit width
  75. */
  76. public int getUnitWidth() {
  77. return this.unitWidth;
  78. }
  79. /**
  80. * {@inheritDoc}
  81. */
  82. public int getBPD() {
  83. int bpd = 0;
  84. for (Iterator childAreaIt = getChildAreas().iterator(); childAreaIt.hasNext();) {
  85. InlineArea area = (InlineArea)childAreaIt.next();
  86. if (bpd < area.getBPD()) {
  87. bpd = area.getBPD();
  88. }
  89. }
  90. return bpd;
  91. }
  92. /**
  93. * Get the child areas for this filled area.
  94. * This copies the references of the inline areas so that
  95. * it fills the total width of the area a whole number of times
  96. * for the unit width.
  97. *
  98. * @return the list of child areas copied to fill the width
  99. */
  100. public List getChildAreas() {
  101. int units = (int)(getIPD() / unitWidth);
  102. List newList = new ArrayList();
  103. for (int count = 0; count < units; count++) {
  104. newList.addAll(inlines);
  105. }
  106. return newList;
  107. }
  108. /**
  109. * Recursively apply the variation factor to all descendant areas
  110. * @param variationFactor the variation factor that must be applied to adjustments
  111. * @param lineStretch the total stretch of the line
  112. * @param lineShrink the total shrink of the line
  113. * @return true if there is an UnresolvedArea descendant
  114. */
  115. public boolean applyVariationFactor(double variationFactor,
  116. int lineStretch, int lineShrink) {
  117. setIPD(getIPD() + adjustingInfo.applyVariationFactor(variationFactor));
  118. return false;
  119. }
  120. }