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

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