Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MainReference.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.ArrayList;
  20. import java.util.List;
  21. import org.apache.fop.traits.WritingModeTraitsGetter;
  22. /**
  23. * The main-reference-area generated by an fo:region-body
  24. * This object holds one or more span-reference-areas (block-areas
  25. * stacked in the block progression direction)
  26. * See fo:region-body definition in the XSL Rec for more information.
  27. */
  28. public class MainReference extends Area {
  29. private static final long serialVersionUID = 7635126485620012448L;
  30. private BodyRegion parent;
  31. private List<Span> spanAreas = new java.util.ArrayList<Span>();
  32. private boolean isEmpty = true;
  33. /**
  34. * Constructor
  35. *
  36. * @param parent the body region this reference area is placed in.
  37. */
  38. public MainReference(BodyRegion parent) {
  39. this.parent = parent;
  40. addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  41. }
  42. /**
  43. * Add a span area to this area.
  44. *
  45. * @param spanAll whether to make a single-column span
  46. * @return the created span area.
  47. */
  48. public Span createSpan(boolean spanAll) {
  49. if (spanAreas.size() > 0 && getCurrentSpan().isEmpty()) {
  50. //Remove the current one if it is empty
  51. spanAreas.remove(spanAreas.size() - 1);
  52. }
  53. Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
  54. getColumnGap(), parent.getContentIPD());
  55. spanAreas.add(newSpan);
  56. return getCurrentSpan();
  57. }
  58. /**
  59. * Get the span areas from this area.
  60. *
  61. * @return the list of span areas
  62. */
  63. public List<Span> getSpans() {
  64. return spanAreas;
  65. }
  66. /**
  67. * Do not use. Used to handle special page-master for last page: transfer the content
  68. * that had already been added to a normal page to this main reference for the last
  69. * page. TODO this is hacky.
  70. *
  71. * @param spans content already laid out
  72. */
  73. public void setSpans(List<Span> spans) {
  74. spanAreas = new ArrayList<Span>(spans);
  75. }
  76. /**
  77. * Get the span area currently being filled (i.e., the last span created).
  78. * @return the active span.
  79. */
  80. public Span getCurrentSpan() {
  81. return spanAreas.get(spanAreas.size() - 1);
  82. }
  83. /**
  84. * Indicates whether any child areas have been added to this reference area.
  85. *
  86. * This is achieved by looping through each span.
  87. * @return true if no child areas have been added yet.
  88. */
  89. public boolean isEmpty() {
  90. if (isEmpty && spanAreas != null) {
  91. for (Span spanArea : spanAreas) {
  92. if (!spanArea.isEmpty()) {
  93. isEmpty = false;
  94. break;
  95. }
  96. }
  97. }
  98. return isEmpty;
  99. }
  100. /** @return the number of columns */
  101. public int getColumnCount() {
  102. return parent.getColumnCount();
  103. }
  104. /** @return the column gap in millipoints */
  105. public int getColumnGap() {
  106. return parent.getColumnGap();
  107. }
  108. /**
  109. * Sets the writing mode traits for the spans of this main
  110. * reference area.
  111. * @param wmtg a WM traits getter
  112. */
  113. public void setWritingModeTraits(WritingModeTraitsGetter wmtg) {
  114. for (Span s : getSpans()) {
  115. s.setWritingModeTraits(wmtg);
  116. }
  117. }
  118. }