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 9.9KB

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