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.

Block.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 java.awt.Color;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.Length;
  23. import org.apache.fop.datatypes.Numeric;
  24. import org.apache.fop.fo.CharIterator;
  25. import org.apache.fop.fo.FONode;
  26. import org.apache.fop.fo.FObjMixed;
  27. import org.apache.fop.fo.NullCharIterator;
  28. import org.apache.fop.fo.PropertyList;
  29. import org.apache.fop.fo.ValidationException;
  30. import org.apache.fop.fo.properties.BreakPropertySet;
  31. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  32. import org.apache.fop.fo.properties.CommonFont;
  33. import org.apache.fop.fo.properties.CommonHyphenation;
  34. import org.apache.fop.fo.properties.CommonMarginBlock;
  35. import org.apache.fop.fo.properties.CommonRelativePosition;
  36. import org.apache.fop.fo.properties.KeepProperty;
  37. import org.apache.fop.fo.properties.SpaceProperty;
  38. import org.apache.fop.fo.properties.StructurePointerPropertySet;
  39. /**
  40. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_block">
  41. * <code>fo:block object</code></a>.
  42. */
  43. public class Block extends FObjMixed implements BreakPropertySet, StructurePointerPropertySet {
  44. // used for FO validation
  45. private boolean blockOrInlineItemFound = false;
  46. private boolean initialPropertySetFound = false;
  47. // The value of properties relevant for fo:block.
  48. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  49. private CommonFont commonFont;
  50. private CommonHyphenation commonHyphenation;
  51. private CommonMarginBlock commonMarginBlock;
  52. private CommonRelativePosition commonRelativePosition;
  53. private int breakAfter;
  54. private int breakBefore;
  55. private Color color;
  56. private int hyphenationKeep;
  57. private Numeric hyphenationLadderCount;
  58. private int intrusionDisplace;
  59. private KeepProperty keepTogether;
  60. private KeepProperty keepWithNext;
  61. private KeepProperty keepWithPrevious;
  62. private Length lastLineEndIndent;
  63. private int linefeedTreatment;
  64. private SpaceProperty lineHeight;
  65. private int lineHeightShiftAdjustment;
  66. private int lineStackingStrategy;
  67. private Numeric orphans;
  68. private String ptr; //used for accessibility
  69. private int whiteSpaceTreatment;
  70. private int span;
  71. private int textAlign;
  72. private int textAlignLast;
  73. private Length textIndent;
  74. private int whiteSpaceCollapse;
  75. private Numeric widows;
  76. private int wrapOption;
  77. private int disableColumnBalancing;
  78. // Unused but valid items, commented out for performance:
  79. // private CommonAccessibility commonAccessibility;
  80. // private CommonAural commonAural;
  81. // private Length textDepth;
  82. // private Length textAltitude;
  83. // private int visibility;
  84. // End of property values
  85. /**
  86. * Base constructor
  87. *
  88. * @param parent FONode that is the parent of this object
  89. *
  90. */
  91. public Block(FONode parent) {
  92. super(parent);
  93. }
  94. /** {@inheritDoc} */
  95. public void bind(PropertyList pList) throws FOPException {
  96. super.bind(pList);
  97. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  98. commonFont = pList.getFontProps();
  99. commonHyphenation = pList.getHyphenationProps();
  100. commonMarginBlock = pList.getMarginBlockProps();
  101. commonRelativePosition = pList.getRelativePositionProps();
  102. breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
  103. breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
  104. color = pList.get(PR_COLOR).getColor(getUserAgent());
  105. hyphenationKeep = pList.get(PR_HYPHENATION_KEEP).getEnum();
  106. hyphenationLadderCount = pList.get(PR_HYPHENATION_LADDER_COUNT).getNumeric();
  107. intrusionDisplace = pList.get(PR_INTRUSION_DISPLACE).getEnum();
  108. keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
  109. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  110. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  111. lastLineEndIndent = pList.get(PR_LAST_LINE_END_INDENT).getLength();
  112. linefeedTreatment = pList.get(PR_LINEFEED_TREATMENT).getEnum();
  113. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  114. lineHeightShiftAdjustment = pList.get(PR_LINE_HEIGHT_SHIFT_ADJUSTMENT).getEnum();
  115. lineStackingStrategy = pList.get(PR_LINE_STACKING_STRATEGY).getEnum();
  116. orphans = pList.get(PR_ORPHANS).getNumeric();
  117. ptr = pList.get(PR_X_PTR).getString(); //used for accessibility
  118. whiteSpaceTreatment = pList.get(PR_WHITE_SPACE_TREATMENT).getEnum();
  119. span = pList.get(PR_SPAN).getEnum();
  120. textAlign = pList.get(PR_TEXT_ALIGN).getEnum();
  121. textAlignLast = pList.get(PR_TEXT_ALIGN_LAST).getEnum();
  122. textIndent = pList.get(PR_TEXT_INDENT).getLength();
  123. whiteSpaceCollapse = pList.get(PR_WHITE_SPACE_COLLAPSE).getEnum();
  124. widows = pList.get(PR_WIDOWS).getNumeric();
  125. wrapOption = pList.get(PR_WRAP_OPTION).getEnum();
  126. disableColumnBalancing = pList.get(PR_X_DISABLE_COLUMN_BALANCING).getEnum();
  127. }
  128. /** {@inheritDoc} */
  129. protected void startOfNode() throws FOPException {
  130. super.startOfNode();
  131. getFOEventHandler().startBlock(this);
  132. }
  133. /** {@inheritDoc} */
  134. protected void endOfNode() throws FOPException {
  135. super.endOfNode();
  136. getFOEventHandler().endBlock(this);
  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 {@link CommonFont} */
  148. public CommonFont getCommonFont() {
  149. return commonFont;
  150. }
  151. /** @return the {@link CommonHyphenation} */
  152. public CommonHyphenation getCommonHyphenation() {
  153. return commonHyphenation;
  154. }
  155. /** @return the "break-after" property. */
  156. public int getBreakAfter() {
  157. return breakAfter;
  158. }
  159. /** {@inheritDoc} */
  160. public String getPtr() {
  161. return ptr;
  162. }
  163. /** @return the "break-before" property. */
  164. public int getBreakBefore() {
  165. return breakBefore;
  166. }
  167. /** @return the "hyphenation-ladder-count" property. */
  168. public Numeric getHyphenationLadderCount() {
  169. return hyphenationLadderCount;
  170. }
  171. /** @return the "keep-with-next" property. */
  172. public KeepProperty getKeepWithNext() {
  173. return keepWithNext;
  174. }
  175. /** @return the "keep-with-previous" property. */
  176. public KeepProperty getKeepWithPrevious() {
  177. return keepWithPrevious;
  178. }
  179. /** @return the "keep-together" property. */
  180. public KeepProperty getKeepTogether() {
  181. return keepTogether;
  182. }
  183. /** @return the "orphans" property. */
  184. public int getOrphans() {
  185. return orphans.getValue();
  186. }
  187. /** @return the "widows" property. */
  188. public int getWidows() {
  189. return widows.getValue();
  190. }
  191. /** @return the "line-stacking-strategy" property. */
  192. public int getLineStackingStrategy() {
  193. return lineStackingStrategy;
  194. }
  195. /** @return the "color" property */
  196. public Color getColor() {
  197. return color;
  198. }
  199. /** @return the "line-height" property */
  200. public SpaceProperty getLineHeight() {
  201. return lineHeight;
  202. }
  203. /** @return the "span" property */
  204. public int getSpan() {
  205. return this.span;
  206. }
  207. /** @return the "text-align" property */
  208. public int getTextAlign() {
  209. return textAlign;
  210. }
  211. /** @return the "text-align-last" property */
  212. public int getTextAlignLast() {
  213. return textAlignLast;
  214. }
  215. /** @return the "text-indent" property */
  216. public Length getTextIndent() {
  217. return textIndent;
  218. }
  219. /** @return the "last-line-end-indent" property */
  220. public Length getLastLineEndIndent() {
  221. return lastLineEndIndent;
  222. }
  223. /** @return the "wrap-option" property */
  224. public int getWrapOption() {
  225. return wrapOption;
  226. }
  227. /**
  228. * {@inheritDoc}
  229. * <br>XSL Content Model: marker* initial-property-set? (#PCDATA|%inline;|%block;)*
  230. * <br><i>Additionally: "An fo:bidi-override that is a descendant of an fo:leader
  231. * or of the fo:inline child of an fo:footnote may not have block-level
  232. * children, unless it has a nearer ancestor that is an
  233. * fo:inline-container."</i>
  234. */
  235. protected void validateChildNode(Locator loc, String nsURI, String localName)
  236. throws ValidationException {
  237. if (FO_URI.equals(nsURI)) {
  238. if ("marker".equals(localName)) {
  239. if (blockOrInlineItemFound || initialPropertySetFound) {
  240. nodesOutOfOrderError(loc, "fo:marker",
  241. "initial-property-set? (#PCDATA|%inline;|%block;)");
  242. }
  243. } else if ("initial-property-set".equals(localName)) {
  244. if (initialPropertySetFound) {
  245. tooManyNodesError(loc, "fo:initial-property-set");
  246. } else if (blockOrInlineItemFound) {
  247. nodesOutOfOrderError(loc, "fo:initial-property-set",
  248. "(#PCDATA|%inline;|%block;)");
  249. } else {
  250. initialPropertySetFound = true;
  251. }
  252. } else if (isBlockOrInlineItem(nsURI, localName)) {
  253. blockOrInlineItemFound = true;
  254. } else {
  255. invalidChildError(loc, nsURI, localName);
  256. }
  257. }
  258. }
  259. /** @return the "linefeed-treatment" property */
  260. public int getLinefeedTreatment() {
  261. return linefeedTreatment;
  262. }
  263. /** @return the "white-space-treatment" property */
  264. public int getWhitespaceTreatment() {
  265. return whiteSpaceTreatment;
  266. }
  267. /** @return the "white-space-collapse" property */
  268. public int getWhitespaceCollapse() {
  269. return whiteSpaceCollapse;
  270. }
  271. /** @return the {@link CommonRelativePosition} */
  272. public CommonRelativePosition getCommonRelativePosition() {
  273. return this.commonRelativePosition;
  274. }
  275. /** @return the "hyphenation-keep" property */
  276. public int getHyphenationKeep() {
  277. return this.hyphenationKeep;
  278. }
  279. /** @return the "intrusion-displace" property */
  280. public int getIntrusionDisplace() {
  281. return this.intrusionDisplace;
  282. }
  283. /** @return the "line-height-shift-adjustment" property */
  284. public int getLineHeightShiftAdjustment() {
  285. return this.lineHeightShiftAdjustment;
  286. }
  287. /**
  288. * @return the "fox:disable-column-balancing" property, one of
  289. * {@link org.apache.fop.fo.Constants#EN_TRUE},
  290. * {@link org.apache.fop.fo.Constants#EN_FALSE}
  291. */
  292. public int getDisableColumnBalancing() {
  293. return disableColumnBalancing;
  294. }
  295. /** {@inheritDoc} */
  296. public CharIterator charIterator() {
  297. return NullCharIterator.getInstance();
  298. }
  299. /** {@inheritDoc} */
  300. public String getLocalName() {
  301. return "block";
  302. }
  303. /**
  304. * {@inheritDoc}
  305. * @return {@link org.apache.fop.fo.Constants#FO_BLOCK}
  306. */
  307. public int getNameId() {
  308. return FO_BLOCK;
  309. }
  310. }