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.

Region.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.fo.pagination;
  19. import java.awt.Rectangle;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.FODimension;
  23. import org.apache.fop.datatypes.Numeric;
  24. import org.apache.fop.datatypes.PercentBaseContext;
  25. import org.apache.fop.fo.FONode;
  26. import org.apache.fop.fo.FObj;
  27. import org.apache.fop.fo.PropertyList;
  28. import org.apache.fop.fo.ValidationException;
  29. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  30. /**
  31. * This is an abstract base class for pagination regions.
  32. */
  33. public abstract class Region extends FObj {
  34. // The value of properties relevant for fo:region
  35. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  36. // private ToBeImplementedProperty clip
  37. private int displayAlign;
  38. private int overflow;
  39. private String regionName;
  40. private Numeric referenceOrientation;
  41. private int writingMode;
  42. // End of property values
  43. /** the parent {@link SimplePageMaster} */
  44. protected final SimplePageMaster layoutMaster;
  45. /**
  46. * Base constructor
  47. *
  48. * @param parent {@link FONode} that is the parent of this object
  49. */
  50. protected Region(FONode parent) {
  51. super(parent);
  52. layoutMaster = (SimplePageMaster) parent;
  53. }
  54. /** {@inheritDoc} */
  55. public void bind(PropertyList pList) throws FOPException {
  56. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  57. // clip = pList.get(PR_CLIP);
  58. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  59. overflow = pList.get(PR_OVERFLOW).getEnum();
  60. regionName = pList.get(PR_REGION_NAME).getString();
  61. referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric();
  62. writingMode = pList.getWritingMode();
  63. // regions may have name, or default
  64. if (regionName.equals("")) {
  65. regionName = getDefaultRegionName();
  66. } else {
  67. // check that name is OK. Not very pretty.
  68. if (isReserved(getRegionName())
  69. && !getRegionName().equals(getDefaultRegionName())) {
  70. getFOValidationEventProducer().illegalRegionName(this, getName(),
  71. regionName, getLocator());
  72. }
  73. }
  74. //TODO do we need context for getBPPaddingAndBorder() and getIPPaddingAndBorder()?
  75. if ((getCommonBorderPaddingBackground().getBPPaddingAndBorder(false, null) != 0
  76. || getCommonBorderPaddingBackground().getIPPaddingAndBorder(false, null) != 0)) {
  77. getFOValidationEventProducer().nonZeroBorderPaddingOnRegion(this, getName(),
  78. regionName, true, getLocator());
  79. }
  80. }
  81. /**
  82. * {@inheritDoc} String, String)
  83. * <br>XSL Content Model: empty
  84. */
  85. protected void validateChildNode(Locator loc, String nsURI, String localName)
  86. throws ValidationException {
  87. if (FO_URI.equals(nsURI)) {
  88. invalidChildError(loc, nsURI, localName);
  89. }
  90. }
  91. /**
  92. * @param pageRefRect reference dimension of the page area.
  93. * @return the rectangle for the viewport area
  94. */
  95. public abstract Rectangle getViewportRectangle(FODimension pageRefRect);
  96. /**
  97. * Returns the default region name (xsl-region-before, xsl-region-start,
  98. * etc.)
  99. * @return the default region name
  100. */
  101. protected abstract String getDefaultRegionName();
  102. /**
  103. * Checks to see if a given region name is one of the reserved names
  104. *
  105. * @param name a region name to check
  106. * @return true if the name parameter is a reserved region name
  107. */
  108. protected boolean isReserved(String name) {
  109. return (name.equals("xsl-region-before")
  110. || name.equals("xsl-region-start")
  111. || name.equals("xsl-region-end")
  112. || name.equals("xsl-region-after")
  113. || name.equals("xsl-before-float-separator")
  114. || name.equals("xsl-footnote-separator"));
  115. }
  116. /**
  117. * Get the page-width context
  118. * @param lengthBase the lengthBase to use for resolving percentages
  119. * @return context for the width of the page-reference-area
  120. */
  121. protected PercentBaseContext getPageWidthContext(int lengthBase) {
  122. return layoutMaster.getPageWidthContext(lengthBase);
  123. }
  124. /**
  125. * Get the page-width context
  126. * @param lengthBase the lengthBase to use for resolving percentages
  127. * @return context for the width of the page-reference-area
  128. */
  129. protected PercentBaseContext getPageHeightContext(int lengthBase) {
  130. return layoutMaster.getPageHeightContext(lengthBase);
  131. }
  132. /** {@inheritDoc} */
  133. public boolean generatesReferenceAreas() {
  134. return true;
  135. }
  136. /**
  137. * Returns a sibling region for this region.
  138. * @param regionId the Constants ID of the FO representing the region
  139. * @return the requested region
  140. */
  141. protected Region getSiblingRegion(int regionId) {
  142. // Ask parent for region
  143. return layoutMaster.getRegion(regionId);
  144. }
  145. /**
  146. * @return the Background Properties (border and padding are not used here).
  147. */
  148. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  149. return commonBorderPaddingBackground;
  150. }
  151. /** @return the "region-name" property. */
  152. public String getRegionName() {
  153. return regionName;
  154. }
  155. /** @return the "writing-mode" property. */
  156. public int getWritingMode() {
  157. return writingMode;
  158. }
  159. /** @return the "overflow" property. */
  160. public int getOverflow() {
  161. return overflow;
  162. }
  163. /** @return the display-align property. */
  164. public int getDisplayAlign() {
  165. return displayAlign;
  166. }
  167. /** @return the "reference-orientation" property. */
  168. public int getReferenceOrientation() {
  169. return referenceOrientation.getValue();
  170. }
  171. }