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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.apache.fop.apps.FOPException;
  20. import org.apache.fop.datatypes.Numeric;
  21. import org.apache.fop.fo.FONode;
  22. import org.apache.fop.fo.FObj;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. import org.apache.fop.fo.properties.BreakPropertySet;
  26. import org.apache.fop.fo.properties.CommonAbsolutePosition;
  27. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  28. import org.apache.fop.fo.properties.CommonMarginBlock;
  29. import org.apache.fop.fo.properties.KeepProperty;
  30. import org.apache.fop.fo.properties.LengthRangeProperty;
  31. import org.xml.sax.Locator;
  32. /**
  33. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_block-container">
  34. * <code>fo:block-container</code></a> object.
  35. */
  36. public class BlockContainer extends FObj implements BreakPropertySet {
  37. // The value of properties relevant for fo:block-container.
  38. private CommonAbsolutePosition commonAbsolutePosition;
  39. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  40. private CommonMarginBlock commonMarginBlock;
  41. private LengthRangeProperty blockProgressionDimension;
  42. private int breakAfter;
  43. private int breakBefore;
  44. // private ToBeImplementedProperty clip;
  45. private int displayAlign;
  46. private LengthRangeProperty inlineProgressionDimension;
  47. private KeepProperty keepTogether;
  48. private KeepProperty keepWithNext;
  49. private KeepProperty keepWithPrevious;
  50. private int overflow;
  51. private Numeric referenceOrientation;
  52. private int span;
  53. private int disableColumnBalancing;
  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. disableColumnBalancing = pList.get(PR_X_DISABLE_COLUMN_BALANCING).getEnum();
  90. }
  91. /** {@inheritDoc} */
  92. protected void startOfNode() throws FOPException {
  93. super.startOfNode();
  94. getFOEventHandler().startBlockContainer(this);
  95. }
  96. /**
  97. * {@inheritDoc}
  98. * <br>XSL Content Model: marker* (%block;)+
  99. * <br><i><b>BUT</b>: "In addition an fo:block-container that does not generate an
  100. * absolutely positioned area may have a sequence of zero or more
  101. * fo:markers as its initial children."
  102. * The latter refers to block-containers with absolute-position="absolute"
  103. * or absolute-position="fixed".
  104. */
  105. protected void validateChildNode(Locator loc, String nsURI, String localName)
  106. throws ValidationException {
  107. if (FO_URI.equals(nsURI)) {
  108. if ("marker".equals(localName)) {
  109. if (commonAbsolutePosition.absolutePosition == EN_ABSOLUTE
  110. || commonAbsolutePosition.absolutePosition == EN_FIXED) {
  111. getFOValidationEventProducer()
  112. .markerBlockContainerAbsolutePosition(this, locator);
  113. }
  114. if (blockItemFound) {
  115. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  116. }
  117. } else if (!isBlockItem(FO_URI, localName)) {
  118. invalidChildError(loc, FO_URI, localName);
  119. } else {
  120. blockItemFound = true;
  121. }
  122. }
  123. }
  124. /** {@inheritDoc} */
  125. protected void endOfNode() throws FOPException {
  126. if (!blockItemFound) {
  127. missingChildElementError("marker* (%block;)+");
  128. }
  129. getFOEventHandler().endBlockContainer(this);
  130. }
  131. /** @return <code>true</code> (BlockContainer can generate Reference Areas) */
  132. public boolean generatesReferenceAreas() {
  133. return true;
  134. }
  135. /** @return the {@link CommonAbsolutePosition} */
  136. public CommonAbsolutePosition getCommonAbsolutePosition() {
  137. return commonAbsolutePosition;
  138. }
  139. /** @return the {@link CommonMarginBlock} */
  140. public CommonMarginBlock getCommonMarginBlock() {
  141. return commonMarginBlock;
  142. }
  143. /** @return the {@link CommonBorderPaddingBackground} */
  144. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  145. return commonBorderPaddingBackground;
  146. }
  147. /**
  148. * @return the "block-progression-dimension" property.
  149. */
  150. public LengthRangeProperty getBlockProgressionDimension() {
  151. return blockProgressionDimension;
  152. }
  153. /** @return the "display-align" property. */
  154. public int getDisplayAlign() {
  155. return displayAlign;
  156. }
  157. /** @return the "break-after" property. */
  158. public int getBreakAfter() {
  159. return breakAfter;
  160. }
  161. /** @return the "break-before" property. */
  162. public int getBreakBefore() {
  163. return breakBefore;
  164. }
  165. /** @return the "keep-with-next" property. */
  166. public KeepProperty getKeepWithNext() {
  167. return keepWithNext;
  168. }
  169. /** @return the "keep-with-previous" property. */
  170. public KeepProperty getKeepWithPrevious() {
  171. return keepWithPrevious;
  172. }
  173. /** @return the "keep-together" property. */
  174. public KeepProperty getKeepTogether() {
  175. return keepTogether;
  176. }
  177. /** @return the "inline-progression-dimension" property */
  178. public LengthRangeProperty getInlineProgressionDimension() {
  179. return inlineProgressionDimension;
  180. }
  181. /** @return the "overflow" property */
  182. public int getOverflow() {
  183. return overflow;
  184. }
  185. /** @return the "reference-orientation" property */
  186. public int getReferenceOrientation() {
  187. return referenceOrientation.getValue();
  188. }
  189. /** @return the "span" property */
  190. public int getSpan() {
  191. return this.span;
  192. }
  193. /**
  194. * @return the "fox:disable-column-balancing" property, one of
  195. * {@link org.apache.fop.fo.Constants#EN_TRUE},
  196. * {@link org.apache.fop.fo.Constants#EN_FALSE}
  197. */
  198. public int getDisableColumnBalancing() {
  199. return disableColumnBalancing;
  200. }
  201. /** @return the "writing-mode" property */
  202. public int getWritingMode() {
  203. return writingMode;
  204. }
  205. /** {@inheritDoc} */
  206. public String getLocalName() {
  207. return "block-container";
  208. }
  209. /**
  210. * {@inheritDoc}
  211. * @return {@link org.apache.fop.fo.Constants#FO_BLOCK_CONTAINER}
  212. */
  213. public int getNameId() {
  214. return FO_BLOCK_CONTAINER;
  215. }
  216. }