選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BodyRegion.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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;
  19. import java.util.List;
  20. import org.apache.fop.fo.pagination.RegionBody;
  21. /**
  22. * This class is a container for the areas that may be generated by
  23. * an fo:region-body. It extends the RegionReference that is used
  24. * directly by the other region classes.
  25. * See fo:region-body definition in the XSL Rec for more information.
  26. */
  27. public class BodyRegion extends RegionReference {
  28. private BeforeFloat beforeFloat; // optional
  29. private MainReference mainReference; // mandatory
  30. private Footnote footnote; // optional
  31. private int columnGap;
  32. private int columnCount;
  33. /**
  34. * Constructor which can read traits directly
  35. * from an fo:region-body formatting object.
  36. * @param rb the region-body FO node
  37. * @param parent the parent region viewport
  38. */
  39. public BodyRegion(RegionBody rb, RegionViewport parent) {
  40. this(rb.getNameId(), rb.getRegionName(), parent, rb.getColumnCount(), rb.getColumnGap());
  41. }
  42. /**
  43. * Constructor which can read traits directly
  44. * from an fo:region-body formatting object.
  45. * @param regionClass the region class (as returned by Region.getNameId())
  46. * @param regionName the name of the region (as returned by Region.getRegionName())
  47. * @param parent the parent region viewport
  48. * @param columnCount the number of columns
  49. * @param columnGap the gap between columns
  50. */
  51. public BodyRegion(int regionClass, String regionName, RegionViewport parent,
  52. int columnCount, int columnGap) {
  53. super(regionClass, regionName, parent);
  54. this.columnCount = columnCount;
  55. this.columnGap = columnGap;
  56. mainReference = new MainReference(this);
  57. }
  58. /**
  59. * Get the number of columns when not spanning
  60. *
  61. * @return the number of columns
  62. */
  63. public int getColumnCount() {
  64. return this.columnCount;
  65. }
  66. /** @return the column-gap value */
  67. public int getColumnGap() {
  68. return this.columnGap;
  69. }
  70. /**
  71. * Get the main reference area.
  72. *
  73. * @return the main reference area
  74. */
  75. public MainReference getMainReference() {
  76. return mainReference;
  77. }
  78. /**
  79. * indicates whether the main reference area has any child areas added to it
  80. *
  81. * @return whether the main reference area has any child areas added to it
  82. */
  83. public boolean isEmpty() {
  84. return (mainReference == null || mainReference.isEmpty())
  85. && (footnote == null || footnote.isEmpty())
  86. && (beforeFloat == null || beforeFloat.isEmpty());
  87. }
  88. /**
  89. * Get the before float area.
  90. *
  91. * @return the before float area
  92. */
  93. public BeforeFloat getBeforeFloat() {
  94. if (beforeFloat == null) {
  95. beforeFloat = new BeforeFloat();
  96. }
  97. return beforeFloat;
  98. }
  99. /**
  100. * Get the footnote area.
  101. *
  102. * @return the footnote area
  103. */
  104. public Footnote getFootnote() {
  105. if (footnote == null) {
  106. footnote = new Footnote();
  107. }
  108. return footnote;
  109. }
  110. /**
  111. * @return the available BPD in the main reference area after the previous span reference
  112. * areas are subtracted.
  113. */
  114. public int getRemainingBPD() {
  115. int usedBPD = 0;
  116. List spans = getMainReference().getSpans();
  117. int previousSpanCount = spans.size() - 1;
  118. for (int i = 0; i < previousSpanCount; i++) {
  119. usedBPD += ((Span)spans.get(i)).getHeight();
  120. }
  121. return getBPD() - usedBPD;
  122. }
  123. /**
  124. * Clone this object.
  125. *
  126. * @return a shallow copy of this object
  127. */
  128. public Object clone() {
  129. BodyRegion br = new BodyRegion(getRegionClass(), getRegionName(), regionViewport,
  130. getColumnCount(), getColumnGap());
  131. br.setCTM(getCTM());
  132. br.setIPD(getIPD());
  133. br.beforeFloat = beforeFloat;
  134. br.mainReference = mainReference;
  135. br.footnote = footnote;
  136. return br;
  137. }
  138. }