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

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