Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Block.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 = false;
  48. private boolean initialPropertySetFound = false;
  49. // The value of properties relevant for 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 property 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. protected void startOfNode() throws FOPException {
  132. super.startOfNode();
  133. getFOEventHandler().startBlock(this);
  134. }
  135. /** {@inheritDoc} */
  136. protected void endOfNode() throws FOPException {
  137. super.endOfNode();
  138. getFOEventHandler().endBlock(this);
  139. }
  140. public CommonAccessibility getCommonAccessibility() {
  141. return commonAccessibility;
  142. }
  143. /** @return the {@link CommonMarginBlock} */
  144. public CommonMarginBlock getCommonMarginBlock() {
  145. return commonMarginBlock;
  146. }
  147. /** @return the {@link CommonBorderPaddingBackground} */
  148. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  149. return commonBorderPaddingBackground;
  150. }
  151. /**
  152. * @return the {@link CommonFont} */
  153. public CommonFont getCommonFont() {
  154. return commonFont;
  155. }
  156. /** @return the {@link CommonHyphenation} */
  157. public CommonHyphenation getCommonHyphenation() {
  158. return commonHyphenation;
  159. }
  160. /** @return the "break-after" property. */
  161. public int getBreakAfter() {
  162. return breakAfter;
  163. }
  164. /** @return the "break-before" property. */
  165. public int getBreakBefore() {
  166. return breakBefore;
  167. }
  168. /** @return the "hyphenation-ladder-count" property. */
  169. public Numeric getHyphenationLadderCount() {
  170. return hyphenationLadderCount;
  171. }
  172. /** @return the "keep-with-next" property. */
  173. public KeepProperty getKeepWithNext() {
  174. return keepWithNext;
  175. }
  176. /** @return the "keep-with-previous" property. */
  177. public KeepProperty getKeepWithPrevious() {
  178. return keepWithPrevious;
  179. }
  180. /** @return the "keep-together" property. */
  181. public KeepProperty getKeepTogether() {
  182. return keepTogether;
  183. }
  184. /** @return the "orphans" property. */
  185. public int getOrphans() {
  186. return orphans.getValue();
  187. }
  188. /** @return the "widows" property. */
  189. public int getWidows() {
  190. return widows.getValue();
  191. }
  192. /** @return the "line-stacking-strategy" property. */
  193. public int getLineStackingStrategy() {
  194. return lineStackingStrategy;
  195. }
  196. /** @return the "color" property */
  197. public Color getColor() {
  198. return color;
  199. }
  200. /** @return the "line-height" property */
  201. public SpaceProperty getLineHeight() {
  202. return lineHeight;
  203. }
  204. /** @return the "span" property */
  205. public int getSpan() {
  206. return this.span;
  207. }
  208. /** @return the "text-align" property */
  209. public int getTextAlign() {
  210. return textAlign;
  211. }
  212. /** @return the "text-align-last" property */
  213. public int getTextAlignLast() {
  214. return textAlignLast;
  215. }
  216. /** @return the "text-indent" property */
  217. public Length getTextIndent() {
  218. return textIndent;
  219. }
  220. /** @return the "last-line-end-indent" property */
  221. public Length getLastLineEndIndent() {
  222. return lastLineEndIndent;
  223. }
  224. /** @return the "wrap-option" property */
  225. public int getWrapOption() {
  226. return wrapOption;
  227. }
  228. /**
  229. * {@inheritDoc}
  230. * <br>XSL Content Model: marker* initial-property-set? (#PCDATA|%inline;|%block;)*
  231. * <br><i>Additionally: "An fo:bidi-override that is a descendant of an fo:leader
  232. * or of the fo:inline child of an fo:footnote may not have block-level
  233. * children, unless it has a nearer ancestor that is an
  234. * fo:inline-container."</i>
  235. */
  236. protected void validateChildNode(Locator loc, String nsURI, String localName)
  237. throws ValidationException {
  238. if (FO_URI.equals(nsURI)) {
  239. if ("marker".equals(localName)) {
  240. if (blockOrInlineItemFound || initialPropertySetFound) {
  241. nodesOutOfOrderError(loc, "fo:marker",
  242. "initial-property-set? (#PCDATA|%inline;|%block;)");
  243. }
  244. } else if ("initial-property-set".equals(localName)) {
  245. if (initialPropertySetFound) {
  246. tooManyNodesError(loc, "fo:initial-property-set");
  247. } else if (blockOrInlineItemFound) {
  248. nodesOutOfOrderError(loc, "fo:initial-property-set",
  249. "(#PCDATA|%inline;|%block;)");
  250. } else {
  251. initialPropertySetFound = true;
  252. }
  253. } else if (isBlockOrInlineItem(nsURI, localName)) {
  254. blockOrInlineItemFound = true;
  255. } else {
  256. invalidChildError(loc, nsURI, localName);
  257. }
  258. }
  259. }
  260. /** @return the "linefeed-treatment" property */
  261. public int getLinefeedTreatment() {
  262. return linefeedTreatment;
  263. }
  264. /** @return the "white-space-treatment" property */
  265. public int getWhitespaceTreatment() {
  266. return whiteSpaceTreatment;
  267. }
  268. /** @return the "white-space-collapse" property */
  269. public int getWhitespaceCollapse() {
  270. return whiteSpaceCollapse;
  271. }
  272. /** @return the {@link CommonRelativePosition} */
  273. public CommonRelativePosition getCommonRelativePosition() {
  274. return this.commonRelativePosition;
  275. }
  276. /** @return the "hyphenation-keep" property */
  277. public int getHyphenationKeep() {
  278. return this.hyphenationKeep;
  279. }
  280. /** @return the "intrusion-displace" property */
  281. public int getIntrusionDisplace() {
  282. return this.intrusionDisplace;
  283. }
  284. /** @return the "line-height-shift-adjustment" property */
  285. public int getLineHeightShiftAdjustment() {
  286. return this.lineHeightShiftAdjustment;
  287. }
  288. /**
  289. * @return the "fox:disable-column-balancing" property, one of
  290. * {@link org.apache.fop.fo.Constants#EN_TRUE},
  291. * {@link org.apache.fop.fo.Constants#EN_FALSE}
  292. */
  293. public int getDisableColumnBalancing() {
  294. return disableColumnBalancing;
  295. }
  296. /** {@inheritDoc} */
  297. public CharIterator charIterator() {
  298. return NullCharIterator.getInstance();
  299. }
  300. /** {@inheritDoc} */
  301. public String getLocalName() {
  302. return "block";
  303. }
  304. /**
  305. * {@inheritDoc}
  306. * @return {@link org.apache.fop.fo.Constants#FO_BLOCK}
  307. */
  308. public int getNameId() {
  309. return FO_BLOCK;
  310. }
  311. }