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

Merged revisions 636407-637074,637076-637118,637120-637790,637792-637856,637858-637992,637994-638047,638049-638307,638309-638315,638318-638936,638938-640888,640890-642905,642907-647402,647404-647536,647538-648983,648985-649005,649007-649013,649015-650549,650551-651301,651303-653536,653538-654452,654454-656285,656287-656523,656525-657519,657521-661579,661581-663481,663483-664691,664693-681285,681287-681290,681292-681298 via svnmerge from https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95 ........ r666635 | jeremias | 2008-06-11 14:18:53 +0200 (Mi, 11 Jun 2008) | 1 line Fixed resolution handling inside AWT preview dialog. ........ r666662 | jeremias | 2008-06-11 15:33:20 +0200 (Mi, 11 Jun 2008) | 1 line Some notes on RTF and print output. ........ r668533 | jeremias | 2008-06-17 09:57:55 +0200 (Di, 17 Jun 2008) | 2 lines Bugzilla #45151: Note on the "compiling" page that Ant 1.7 is required. The README file already points to this page. ........ r668534 | jeremias | 2008-06-17 09:58:40 +0200 (Di, 17 Jun 2008) | 2 lines Update known issues. Remove ApacheConEU logo. ........ r668550 | jeremias | 2008-06-17 10:05:22 +0200 (Di, 17 Jun 2008) | 2 lines Bugzilla #45146: Removed duplicate LICENSE.txt and Notice.txt from the JAR. ........ r668570 | jeremias | 2008-06-17 10:54:07 +0200 (Di, 17 Jun 2008) | 1 line Wrong line number reported in the case of a line overflow. ........ r668641 | jeremias | 2008-06-17 14:59:25 +0200 (Di, 17 Jun 2008) | 1 line Fixed potential NPE. ........ r669118 | jeremias | 2008-06-18 11:02:45 +0200 (Mi, 18 Jun 2008) | 4 lines Bugzilla #44412: Regression fix for empty pages caused by multiple collapsible breaks. No more empty block areas if a break-before occurs on the first child of an FO to match the behaviour of tables and other FO implementations (clarification by XSL WG pending). Added an accessor interface for break-before/-after to avoid long if..else lists in BlockStackingLayoutManager. ........ r669173 | jeremias | 2008-06-18 16:07:27 +0200 (Mi, 18 Jun 2008) | 7 lines Bugzilla #44887: Fixed potential multi-threading problem concerning the use of DecimalFormat. Results from performance measurements in a separate test (operation repeated 100'000 times, exemplary): shared static variable: ~220ms (old choice, problematic!) always create new instance: ~480ms ThreadLocal: ~220ms (new choice) ........ r669478 | jeremias | 2008-06-19 15:03:57 +0200 (Do, 19 Jun 2008) | 4 lines Bugzilla #44412: Improvements after Vincent's feedback: Removal of the somewhat ugly Reference. getBreakBefore() reduced to private visibility. ........ r670551 | jeremias | 2008-06-23 14:54:27 +0200 (Mo, 23 Jun 2008) | 3 lines Use configured source and target resolution for foreign objects in RTF output. Fixed intrinsic size calculation for SVG images when source resolution is not 72 dpi. Fixed calculation of px2mm values in the SVG to G2D converter (used by RTF output). ........ r673750 | adelmelle | 2008-07-03 20:25:01 +0200 (Do, 03 Jul 2008) | 1 line Fix for Bugzilla 45295 (already committed to the trunk with r672010, r672495 and r672496) ........ r674304 | jeremias | 2008-07-06 17:09:10 +0200 (So, 06 Jul 2008) | 18 lines Bugzilla #43606: column-width accepts percent values (proportional-column-width and % working) Table width accepts percent values (100% of the page width as standard) Nested tables are working It is also possible to make nested tables with a higher depth than 3 without causing word to crash Submitted by: Maximilan Aster <maximilian.aster.at.boc-eu.com> Changes to the patch by Jeremias: - Patch simplified (reuse of ColumnSetup from the layoutmgr package) - Percentages and proportional-column-width didn't work properly in my tests -> fixed - Adjustments for FOP code conventions Bugzilla #43824: page-number-citation working but has to be refreshed inside word to show the correct values Submitted by: Maximilan Aster <maximilian.aster.at.boc-eu.com> Changes to the patch by Jeremias: - Adjustments for FOP code conventions ........ r674314 | jeremias | 2008-07-06 18:40:08 +0200 (So, 06 Jul 2008) | 7 lines Bugzilla #43825: leader supports fixed percent values for leader-length, most other properties use-content, leader-pattern-width not implemented Submitted by: Maximilan Aster <maximilian.aster.at.boc-eu.com> Changes to the patch by Jeremias: - Adjustments for FOP code conventions ........ r674317 | jeremias | 2008-07-06 18:44:43 +0200 (So, 06 Jul 2008) | 1 line Doc update after RTF changes. ........ r675106 | jeremias | 2008-07-09 09:03:46 +0200 (Mi, 09 Jul 2008) | 2 lines Bugzilla #45366: Document missing feature. ........ r675150 | jeremias | 2008-07-09 14:56:41 +0200 (Mi, 09 Jul 2008) | 2 lines Bugzilla #39980: Fixed image scaling for RTF output. ........ r675151 | jeremias | 2008-07-09 14:57:06 +0200 (Mi, 09 Jul 2008) | 1 line Removed unused code. ........ r675152 | jeremias | 2008-07-09 14:58:18 +0200 (Mi, 09 Jul 2008) | 1 line Don't generate commands for default values. ........ r675707 | jeremias | 2008-07-10 21:58:27 +0200 (Do, 10 Jul 2008) | 1 line Bugfix: -imagein didn't work because the stylesheet didn't get copied into fop.jar. ........ r680715 | jeremias | 2008-07-29 16:37:10 +0200 (Di, 29 Jul 2008) | 1 line Found a surplus "pop state" which somehow causes a regression (fill color doesn't get properly reset) between 0.94 and 0.95. Shows in Barcode4J's fop-extension-demo.fo. The line has already been there in 0.94 but only shows in 0.95 probably due to an additional save/restore state pair added in PDFRenderer for reference areas after the block-container area refactoring. ........ r680820 | jeremias | 2008-07-29 22:02:14 +0200 (Di, 29 Jul 2008) | 2 lines Bugzilla #41306: The AWT Renderer is really not out-of-order capable. ........ r681284 | jeremias | 2008-07-31 08:47:49 +0200 (Do, 31 Jul 2008) | 1 line Some updates to status.xml (I was not the only one working on the final release). ........ r681290 | jeremias | 2008-07-31 09:44:51 +0200 (Do, 31 Jul 2008) | 2 lines Website updates for the 0.95 release. The projectInfo plug-in of Forrest is not ideal for doing a bugfix release. It's not possible to combine the changes for two releases. ........ r681292 | jeremias | 2008-07-31 09:47:13 +0200 (Do, 31 Jul 2008) | 1 line Disabling the ApacheCon ad for the release build. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@681307 13f79535-47bb-0310-9956-ffa450edef68
16 years ago
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. }