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

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