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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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;
  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. pList.getExplicit(PR_WRITING_MODE) != null);
  95. disableColumnBalancing = pList.get(PR_X_DISABLE_COLUMN_BALANCING).getEnum();
  96. }
  97. /** {@inheritDoc} */
  98. public void startOfNode() throws FOPException {
  99. super.startOfNode();
  100. getFOEventHandler().startBlockContainer(this);
  101. }
  102. /**
  103. * {@inheritDoc}
  104. * <br>XSL Content Model: marker* (%block;)+
  105. * <br><i><b>BUT</b>: "In addition an fo:block-container that does not generate an
  106. * absolutely positioned area may have a sequence of zero or more
  107. * fo:markers as its initial children."
  108. * The latter refers to block-containers with absolute-position="absolute"
  109. * or absolute-position="fixed".
  110. */
  111. protected void validateChildNode(Locator loc, String nsURI, String localName)
  112. throws ValidationException {
  113. if (FO_URI.equals(nsURI)) {
  114. if ("marker".equals(localName)) {
  115. if (commonAbsolutePosition.absolutePosition == EN_ABSOLUTE
  116. || commonAbsolutePosition.absolutePosition == EN_FIXED) {
  117. getFOValidationEventProducer()
  118. .markerBlockContainerAbsolutePosition(this, locator);
  119. }
  120. if (blockItemFound) {
  121. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  122. }
  123. } else if (!isBlockItem(FO_URI, localName)) {
  124. invalidChildError(loc, FO_URI, localName);
  125. } else {
  126. blockItemFound = true;
  127. }
  128. }
  129. }
  130. /** {@inheritDoc} */
  131. public void endOfNode() throws FOPException {
  132. if (!blockItemFound) {
  133. missingChildElementError("marker* (%block;)+");
  134. }
  135. getFOEventHandler().endBlockContainer(this);
  136. }
  137. /** @return <code>true</code> (BlockContainer can generate Reference Areas) */
  138. public boolean generatesReferenceAreas() {
  139. return true;
  140. }
  141. /** @return the {@link CommonAbsolutePosition} */
  142. public CommonAbsolutePosition getCommonAbsolutePosition() {
  143. return commonAbsolutePosition;
  144. }
  145. /** @return the {@link CommonMarginBlock} */
  146. public CommonMarginBlock getCommonMarginBlock() {
  147. return commonMarginBlock;
  148. }
  149. /** @return the {@link CommonBorderPaddingBackground} */
  150. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  151. return commonBorderPaddingBackground;
  152. }
  153. /**
  154. * @return the "block-progression-dimension" FO trait.
  155. */
  156. public LengthRangeProperty getBlockProgressionDimension() {
  157. return blockProgressionDimension;
  158. }
  159. /** @return the "display-align" FO trait. */
  160. public int getDisplayAlign() {
  161. return displayAlign;
  162. }
  163. /** @return the "break-after" FO trait. */
  164. public int getBreakAfter() {
  165. return breakAfter;
  166. }
  167. /** @return the "break-before" FO trait. */
  168. public int getBreakBefore() {
  169. return breakBefore;
  170. }
  171. /** @return the "keep-with-next" FO trait. */
  172. public KeepProperty getKeepWithNext() {
  173. return keepWithNext;
  174. }
  175. /** @return the "keep-with-previous" FO trait. */
  176. public KeepProperty getKeepWithPrevious() {
  177. return keepWithPrevious;
  178. }
  179. /** @return the "keep-together" FO trait. */
  180. public KeepProperty getKeepTogether() {
  181. return keepTogether;
  182. }
  183. /** @return the "inline-progression-dimension" FO trait */
  184. public LengthRangeProperty getInlineProgressionDimension() {
  185. return inlineProgressionDimension;
  186. }
  187. /** @return the "overflow" FO trait */
  188. public int getOverflow() {
  189. return overflow;
  190. }
  191. /** @return the "reference-orientation" FO trait */
  192. public int getReferenceOrientation() {
  193. return referenceOrientation.getValue();
  194. }
  195. /** @return the "span" FO trait */
  196. public int getSpan() {
  197. return this.span;
  198. }
  199. /**
  200. * @return the "fox:disable-column-balancing" property, one of
  201. * {@link org.apache.fop.fo.Constants#EN_TRUE},
  202. * {@link org.apache.fop.fo.Constants#EN_FALSE}
  203. */
  204. public int getDisableColumnBalancing() {
  205. return disableColumnBalancing;
  206. }
  207. /**
  208. * Obtain inline progression direction.
  209. * @return the inline progression direction
  210. */
  211. public Direction getInlineProgressionDirection() {
  212. return writingModeTraits.getInlineProgressionDirection();
  213. }
  214. /**
  215. * Obtain block progression direction.
  216. * @return the block progression direction
  217. */
  218. public Direction getBlockProgressionDirection() {
  219. return writingModeTraits.getBlockProgressionDirection();
  220. }
  221. /**
  222. * Obtain column progression direction.
  223. * @return the column progression direction
  224. */
  225. public Direction getColumnProgressionDirection() {
  226. return writingModeTraits.getColumnProgressionDirection();
  227. }
  228. /**
  229. * Obtain row progression direction.
  230. * @return the row progression direction
  231. */
  232. public Direction getRowProgressionDirection() {
  233. return writingModeTraits.getRowProgressionDirection();
  234. }
  235. /**
  236. * Obtain (baseline) shift direction.
  237. * @return the (baseline) shift direction
  238. */
  239. public Direction getShiftDirection() {
  240. return writingModeTraits.getShiftDirection();
  241. }
  242. /**
  243. * Obtain writing mode.
  244. * @return the writing mode
  245. */
  246. public WritingMode getWritingMode() {
  247. return writingModeTraits.getWritingMode();
  248. }
  249. /**
  250. * Obtain writing mode explicit indicator.
  251. * @return the writing mode explicit indicator
  252. */
  253. public boolean getExplicitWritingMode() {
  254. return writingModeTraits.getExplicitWritingMode();
  255. }
  256. /** {@inheritDoc} */
  257. public String getLocalName() {
  258. return "block-container";
  259. }
  260. /**
  261. * {@inheritDoc}
  262. * @return {@link org.apache.fop.fo.Constants#FO_BLOCK_CONTAINER}
  263. */
  264. public int getNameId() {
  265. return FO_BLOCK_CONTAINER;
  266. }
  267. @Override
  268. protected boolean isBidiBoundary(boolean propagate) {
  269. return getExplicitWritingMode();
  270. }
  271. }