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

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