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.

MainReference.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 java.util.Iterator;
  21. /**
  22. * The main-reference-area generated by an fo:region-body
  23. * This object holds one or more span-reference-areas (block-areas
  24. * stacked in the block progression direction)
  25. * See fo:region-body definition in the XSL Rec for more information.
  26. */
  27. public class MainReference extends Area {
  28. private BodyRegion parent;
  29. private List spanAreas = new java.util.ArrayList();
  30. private boolean isEmpty = true;
  31. /**
  32. * Constructor
  33. *
  34. * @param parent the body region this reference area is placed in.
  35. */
  36. public MainReference(BodyRegion parent) {
  37. this.parent = parent;
  38. addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  39. }
  40. /**
  41. * Add a span area to this area.
  42. *
  43. * @param spanAll whether to make a single-column span
  44. * @return the created span area.
  45. */
  46. public Span createSpan(boolean spanAll) {
  47. if (spanAreas.size() > 0 && getCurrentSpan().isEmpty()) {
  48. //Remove the current one if it is empty
  49. spanAreas.remove(spanAreas.size() - 1);
  50. }
  51. RegionViewport rv = parent.getRegionViewport();
  52. int ipdWidth = (int) parent.getIPD()
  53. - rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
  54. Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
  55. getColumnGap(), ipdWidth);
  56. spanAreas.add(newSpan);
  57. return getCurrentSpan();
  58. }
  59. /**
  60. * Get the span areas from this area.
  61. *
  62. * @return the list of span areas
  63. */
  64. public List getSpans() {
  65. return spanAreas;
  66. }
  67. /**
  68. * Get the span area currently being filled (i.e., the last span created).
  69. * @return the active span.
  70. */
  71. public Span getCurrentSpan() {
  72. return (Span) spanAreas.get(spanAreas.size() - 1);
  73. }
  74. /**
  75. * Indicates whether any child areas have been added to this reference area.
  76. *
  77. * This is achieved by looping through each span.
  78. * @return true if no child areas have been added yet.
  79. */
  80. public boolean isEmpty() {
  81. if (isEmpty) {
  82. boolean nonEmptyFound = false;
  83. if (spanAreas != null) {
  84. for (Iterator spaniter = spanAreas.iterator(); spaniter.hasNext();) {
  85. Span spanArea = (Span) spaniter.next();
  86. nonEmptyFound |= !spanArea.isEmpty();
  87. }
  88. }
  89. isEmpty = !nonEmptyFound;
  90. }
  91. return isEmpty;
  92. }
  93. /** @return the number of columns */
  94. public int getColumnCount() {
  95. return parent.getColumnCount();
  96. }
  97. /** @return the column gap in millipoints */
  98. public int getColumnGap() {
  99. return parent.getColumnGap();
  100. }
  101. }