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.

BlockContainer.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.flow;
  19. import org.xml.sax.Locator;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.datatypes.Length;
  22. import org.apache.fop.datatypes.Numeric;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.FObj;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.ValidationException;
  27. import org.apache.fop.fo.properties.BreakPropertySet;
  28. import org.apache.fop.fo.properties.CommonAbsolutePosition;
  29. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  30. import org.apache.fop.fo.properties.CommonMarginBlock;
  31. import org.apache.fop.fo.properties.KeepProperty;
  32. import org.apache.fop.fo.properties.LengthRangeProperty;
  33. /**
  34. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_block-container">
  35. * <code>fo:block-container</code></a> object.
  36. */
  37. public class BlockContainer extends FObj implements BreakPropertySet {
  38. // The value of properties relevant for fo:block-container.
  39. private CommonAbsolutePosition commonAbsolutePosition;
  40. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  41. private CommonMarginBlock commonMarginBlock;
  42. private LengthRangeProperty blockProgressionDimension;
  43. private int breakAfter;
  44. private int breakBefore;
  45. // private ToBeImplementedProperty clip;
  46. private int displayAlign;
  47. private LengthRangeProperty inlineProgressionDimension;
  48. private KeepProperty keepTogether;
  49. private KeepProperty keepWithNext;
  50. private KeepProperty keepWithPrevious;
  51. private int overflow;
  52. private Numeric referenceOrientation;
  53. private int span;
  54. private int writingMode;
  55. // Unused but valid items, commented out for performance:
  56. // private int intrusionDisplace;
  57. // private Numeric zIndex;
  58. // End of property values
  59. /** used for FO validation */
  60. private boolean blockItemFound = false;
  61. /**
  62. * Creates a new BlockContainer instance as a child of
  63. * the given {@link FONode}.
  64. *
  65. * @param parent {@link FONode} that is the parent of this object
  66. */
  67. public BlockContainer(FONode parent) {
  68. super(parent);
  69. }
  70. /** {@inheritDoc} */
  71. public void bind(PropertyList pList) throws FOPException {
  72. super.bind(pList);
  73. commonAbsolutePosition = pList.getAbsolutePositionProps();
  74. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  75. commonMarginBlock = pList.getMarginBlockProps();
  76. blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  77. breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
  78. breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
  79. // clip = pList.get(PR_CLIP);
  80. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  81. inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
  82. keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
  83. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  84. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  85. overflow = pList.get(PR_OVERFLOW).getEnum();
  86. referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric();
  87. span = pList.get(PR_SPAN).getEnum();
  88. writingMode = pList.get(PR_WRITING_MODE).getEnum();
  89. }
  90. /** {@inheritDoc} */
  91. protected void startOfNode() throws FOPException {
  92. super.startOfNode();
  93. getFOEventHandler().startBlockContainer(this);
  94. }
  95. /**
  96. * {@inheritDoc}
  97. * <br>XSL Content Model: marker* (%block;)+
  98. * <br><i><b>BUT</b>: "In addition an fo:block-container that does not generate an
  99. * absolutely positioned area may have a sequence of zero or more
  100. * fo:markers as its initial children."
  101. * The latter refers to block-containers with absolute-position="absolute"
  102. * or absolute-position="fixed".
  103. */
  104. protected void validateChildNode(Locator loc, String nsURI, String localName)
  105. throws ValidationException {
  106. if (FO_URI.equals(nsURI)) {
  107. if ("marker".equals(localName)) {
  108. if (commonAbsolutePosition.absolutePosition == EN_ABSOLUTE
  109. || commonAbsolutePosition.absolutePosition == EN_FIXED) {
  110. getFOValidationEventProducer()
  111. .markerBlockContainerAbsolutePosition(this, locator);
  112. }
  113. if (blockItemFound) {
  114. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  115. }
  116. } else if (!isBlockItem(FO_URI, localName)) {
  117. invalidChildError(loc, FO_URI, localName);
  118. } else {
  119. blockItemFound = true;
  120. }
  121. }
  122. }
  123. /** {@inheritDoc} */
  124. protected void endOfNode() throws FOPException {
  125. if (!blockItemFound) {
  126. missingChildElementError("marker* (%block;)+");
  127. }
  128. getFOEventHandler().endBlockContainer(this);
  129. }
  130. /** @return <code>true</code> (BlockContainer can generate Reference Areas) */
  131. public boolean generatesReferenceAreas() {
  132. return true;
  133. }
  134. /** @return the {@link CommonAbsolutePosition} */
  135. public CommonAbsolutePosition getCommonAbsolutePosition() {
  136. return commonAbsolutePosition;
  137. }
  138. /** @return the {@link CommonMarginBlock} */
  139. public CommonMarginBlock getCommonMarginBlock() {
  140. return commonMarginBlock;
  141. }
  142. /** @return the {@link CommonBorderPaddingBackground} */
  143. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  144. return commonBorderPaddingBackground;
  145. }
  146. /**
  147. * @return the "block-progression-dimension" property.
  148. */
  149. public LengthRangeProperty getBlockProgressionDimension() {
  150. return blockProgressionDimension;
  151. }
  152. /** @return the "display-align" property. */
  153. public int getDisplayAlign() {
  154. return displayAlign;
  155. }
  156. /** @return the "break-after" property. */
  157. public int getBreakAfter() {
  158. return breakAfter;
  159. }
  160. /** @return the "break-before" property. */
  161. public int getBreakBefore() {
  162. return breakBefore;
  163. }
  164. /** @return the "keep-with-next" property. */
  165. public KeepProperty getKeepWithNext() {
  166. return keepWithNext;
  167. }
  168. /** @return the "keep-with-previous" property. */
  169. public KeepProperty getKeepWithPrevious() {
  170. return keepWithPrevious;
  171. }
  172. /** @return the "keep-together" property. */
  173. public KeepProperty getKeepTogether() {
  174. return keepTogether;
  175. }
  176. /** @return the "inline-progression-dimension" property */
  177. public LengthRangeProperty getInlineProgressionDimension() {
  178. return inlineProgressionDimension;
  179. }
  180. /** @return the "overflow" property */
  181. public int getOverflow() {
  182. return overflow;
  183. }
  184. /** @return the "reference-orientation" property */
  185. public int getReferenceOrientation() {
  186. return referenceOrientation.getValue();
  187. }
  188. /** @return the "span" property */
  189. public int getSpan() {
  190. return this.span;
  191. }
  192. /** @return the "writing-mode" property */
  193. public int getWritingMode() {
  194. return writingMode;
  195. }
  196. /** {@inheritDoc} */
  197. public String getLocalName() {
  198. return "block-container";
  199. }
  200. /**
  201. * {@inheritDoc}
  202. * @return {@link org.apache.fop.fo.Constants#FO_BLOCK_CONTAINER}
  203. */
  204. public int getNameId() {
  205. return FO_BLOCK_CONTAINER;
  206. }
  207. }