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.

TraitSetter.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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.layoutmgr;
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.apache.fop.accessibility.StructureTreeElement;
  22. import org.apache.fop.area.Area;
  23. import org.apache.fop.area.Trait;
  24. import org.apache.fop.datatypes.LengthBase;
  25. import org.apache.fop.datatypes.PercentBaseContext;
  26. import org.apache.fop.datatypes.SimplePercentBaseContext;
  27. import org.apache.fop.fo.Constants;
  28. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  29. import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
  30. import org.apache.fop.fo.properties.CommonMarginBlock;
  31. import org.apache.fop.fo.properties.CommonTextDecoration;
  32. import org.apache.fop.fonts.Font;
  33. import org.apache.fop.traits.BorderProps;
  34. import org.apache.fop.traits.MinOptMax;
  35. /**
  36. * This is a helper class used for setting common traits on areas.
  37. */
  38. public final class TraitSetter {
  39. private TraitSetter() {
  40. }
  41. /** logger */
  42. private static final Log LOG = LogFactory.getLog(TraitSetter.class);
  43. /**
  44. * Sets border and padding traits on areas.
  45. *
  46. * @param area area to set the traits on
  47. * @param bpProps border and padding properties
  48. * @param isNotFirst True if the area is not the first area
  49. * @param isNotLast True if the area is not the last area
  50. * @param context Property evaluation context
  51. */
  52. public static void setBorderPaddingTraits(Area area,
  53. CommonBorderPaddingBackground bpProps, boolean isNotFirst, boolean isNotLast,
  54. PercentBaseContext context) {
  55. int padding;
  56. padding = bpProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, context);
  57. if (padding > 0) {
  58. area.addTrait(Trait.PADDING_START, padding);
  59. }
  60. padding = bpProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, context);
  61. if (padding > 0) {
  62. area.addTrait(Trait.PADDING_END, padding);
  63. }
  64. padding = bpProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, context);
  65. if (padding > 0) {
  66. area.addTrait(Trait.PADDING_BEFORE, padding);
  67. }
  68. padding = bpProps.getPadding(CommonBorderPaddingBackground.AFTER, false, context);
  69. if (padding > 0) {
  70. area.addTrait(Trait.PADDING_AFTER, padding);
  71. }
  72. addBorderTrait(area, bpProps, isNotFirst,
  73. CommonBorderPaddingBackground.START,
  74. BorderProps.Mode.SEPARATE, Trait.BORDER_START, context);
  75. addBorderTrait(area, bpProps, isNotLast,
  76. CommonBorderPaddingBackground.END,
  77. BorderProps.Mode.SEPARATE, Trait.BORDER_END, context);
  78. addBorderTrait(area, bpProps, false,
  79. CommonBorderPaddingBackground.BEFORE,
  80. BorderProps.Mode.SEPARATE, Trait.BORDER_BEFORE, context);
  81. addBorderTrait(area, bpProps, false,
  82. CommonBorderPaddingBackground.AFTER,
  83. BorderProps.Mode.SEPARATE, Trait.BORDER_AFTER, context);
  84. }
  85. /*
  86. * Sets border traits on an area.
  87. *
  88. * @param area area to set the traits on
  89. * @param bpProps border and padding properties
  90. * @param mode the border paint mode (see BorderProps)
  91. */
  92. private static void addBorderTrait(Area area,
  93. CommonBorderPaddingBackground bpProps,
  94. boolean bDiscard, int iSide, BorderProps.Mode mode,
  95. Integer traitCode, PercentBaseContext context) {
  96. int iBP = bpProps.getBorderWidth(iSide, bDiscard);
  97. int radiusStart = bpProps.getBorderRadiusStart(iSide, bDiscard, context);
  98. int radiusEnd = bpProps.getBorderRadiusEnd(iSide, bDiscard, context);
  99. if (iBP > 0 || radiusStart > 0 || radiusEnd > 0) {
  100. area.addTrait(traitCode, new BorderProps(bpProps.getBorderStyle(iSide), iBP, radiusStart, radiusEnd,
  101. bpProps.getBorderColor(iSide), mode));
  102. }
  103. }
  104. /**
  105. * Add borders to an area. Note: this method also adds unconditional padding. Don't use!
  106. * Layout managers that create areas with borders can use this to
  107. * add the borders to the area.
  108. * @param area the area to set the traits on.
  109. * @param borderProps border properties
  110. * @param context Property evaluation context
  111. * @deprecated Call the other addBorders() method and addPadding separately.
  112. */
  113. public static void addBorders(Area area, CommonBorderPaddingBackground borderProps,
  114. PercentBaseContext context) {
  115. BorderProps bps = getBorderProps(borderProps, CommonBorderPaddingBackground.BEFORE, context);
  116. if (bps != null) {
  117. area.addTrait(Trait.BORDER_BEFORE, bps);
  118. }
  119. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.AFTER, context);
  120. if (bps != null) {
  121. area.addTrait(Trait.BORDER_AFTER, bps);
  122. }
  123. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.START, context);
  124. if (bps != null) {
  125. area.addTrait(Trait.BORDER_START, bps);
  126. }
  127. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.END, context);
  128. if (bps != null) {
  129. area.addTrait(Trait.BORDER_END, bps);
  130. }
  131. addPadding(area, borderProps, context);
  132. }
  133. /**
  134. * Add borders to an area.
  135. * Layout managers that create areas with borders can use this to
  136. * add the borders to the area.
  137. * @param area the area to set the traits on.
  138. * @param borderProps border properties
  139. * @param discardBefore true if the before border should be discarded
  140. * @param discardAfter true if the after border should be discarded
  141. * @param discardStart true if the start border should be discarded
  142. * @param discardEnd true if the end border should be discarded
  143. * @param context Property evaluation context
  144. */
  145. //TODO: remove evaluation context; unused, since border-widths are always absolute lengths
  146. public static void addBorders(Area area, CommonBorderPaddingBackground borderProps,
  147. boolean discardBefore, boolean discardAfter,
  148. boolean discardStart, boolean discardEnd,
  149. PercentBaseContext context) {
  150. BorderProps bps = getBorderProps(borderProps, CommonBorderPaddingBackground.BEFORE, context);
  151. if (bps != null && !discardBefore) {
  152. area.addTrait(Trait.BORDER_BEFORE, bps);
  153. }
  154. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.AFTER, context);
  155. if (bps != null && !discardAfter) {
  156. area.addTrait(Trait.BORDER_AFTER, bps);
  157. }
  158. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.START, context);
  159. if (bps != null && !discardStart) {
  160. area.addTrait(Trait.BORDER_START, bps);
  161. }
  162. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.END, context);
  163. if (bps != null && !discardEnd) {
  164. area.addTrait(Trait.BORDER_END, bps);
  165. }
  166. }
  167. /**
  168. * Add borders to an area for the collapsing border model in tables.
  169. * Layout managers that create areas with borders can use this to
  170. * add the borders to the area.
  171. * @param area the area to set the traits on.
  172. * @param borderBefore the resolved before border
  173. * @param borderAfter the resolved after border
  174. * @param borderStart the resolved start border
  175. * @param borderEnd the resolved end border
  176. * @param outer 4 boolean values indicating if the side represents the
  177. * table's outer border. Order: before, after, start, end
  178. */
  179. public static void addCollapsingBorders(Area area,
  180. BorderInfo borderBefore, BorderInfo borderAfter,
  181. BorderInfo borderStart, BorderInfo borderEnd,
  182. boolean[] outer) {
  183. BorderProps bps = getCollapsingBorderProps(borderBefore, outer[0]);
  184. if (bps != null) {
  185. area.addTrait(Trait.BORDER_BEFORE, bps);
  186. }
  187. bps = getCollapsingBorderProps(borderAfter, outer[1]);
  188. if (bps != null) {
  189. area.addTrait(Trait.BORDER_AFTER, bps);
  190. }
  191. bps = getCollapsingBorderProps(borderStart, outer[2]);
  192. if (bps != null) {
  193. area.addTrait(Trait.BORDER_START, bps);
  194. }
  195. bps = getCollapsingBorderProps(borderEnd, outer[3]);
  196. if (bps != null) {
  197. area.addTrait(Trait.BORDER_END, bps);
  198. }
  199. }
  200. private static void addPadding(Area area, CommonBorderPaddingBackground bordProps,
  201. PercentBaseContext context) {
  202. addPadding(area, bordProps, false, false, false, false, context);
  203. }
  204. /**
  205. * Add padding to an area.
  206. * Layout managers that create areas with padding can use this to
  207. * add the borders to the area.
  208. * @param area the area to set the traits on.
  209. * @param bordProps border and padding properties
  210. * @param discardBefore true if the before padding should be discarded
  211. * @param discardAfter true if the after padding should be discarded
  212. * @param discardStart true if the start padding should be discarded
  213. * @param discardEnd true if the end padding should be discarded
  214. * @param context Property evaluation context
  215. */
  216. public static void addPadding(Area area, CommonBorderPaddingBackground bordProps,
  217. boolean discardBefore, boolean discardAfter,
  218. boolean discardStart, boolean discardEnd,
  219. PercentBaseContext context) {
  220. int padding = bordProps.getPadding(CommonBorderPaddingBackground.BEFORE,
  221. discardBefore, context);
  222. if (padding != 0) {
  223. area.addTrait(Trait.PADDING_BEFORE, padding);
  224. }
  225. padding = bordProps.getPadding(CommonBorderPaddingBackground.AFTER,
  226. discardAfter, context);
  227. if (padding != 0) {
  228. area.addTrait(Trait.PADDING_AFTER, padding);
  229. }
  230. padding = bordProps.getPadding(CommonBorderPaddingBackground.START,
  231. discardStart, context);
  232. if (padding != 0) {
  233. area.addTrait(Trait.PADDING_START, padding);
  234. }
  235. padding = bordProps.getPadding(CommonBorderPaddingBackground.END,
  236. discardEnd, context);
  237. if (padding != 0) {
  238. area.addTrait(Trait.PADDING_END, padding);
  239. }
  240. }
  241. private static BorderProps getBorderProps(CommonBorderPaddingBackground bordProps,
  242. int side, PercentBaseContext context) {
  243. int width = bordProps.getBorderWidth(side, false);
  244. int radiusStart = bordProps.getBorderRadiusStart(side, false, context);
  245. int radiusEnd = bordProps.getBorderRadiusEnd(side, false, context);
  246. if (width != 0 || radiusStart != 0 || radiusEnd != 0) {
  247. return new BorderProps(bordProps.getBorderStyle(side), width, radiusStart, radiusEnd,
  248. bordProps.getBorderColor(side), BorderProps.Mode.SEPARATE);
  249. } else {
  250. return null;
  251. }
  252. }
  253. private static BorderProps getCollapsingBorderProps(BorderInfo borderInfo, boolean outer) {
  254. assert borderInfo != null;
  255. int width = borderInfo.getRetainedWidth();
  256. if (width != 0) {
  257. return BorderProps.makeRectangular(borderInfo.getStyle(), width, borderInfo.getColor(),
  258. (outer ? BorderProps.Mode.COLLAPSE_OUTER : BorderProps.Mode.COLLAPSE_INNER));
  259. } else {
  260. return null;
  261. }
  262. }
  263. /**
  264. * Add background to an area. This method is mainly used by table-related layout
  265. * managers to add background for column, body or row. Since the area corresponding to
  266. * border-separation must be filled with the table's background, for every cell an
  267. * additional area with the same dimensions is created to hold the background for the
  268. * corresponding column/body/row. An additional shift must then be added to
  269. * background-position-horizontal/vertical to ensure the background images are
  270. * correctly placed. Indeed the placement of images must be made WRT the
  271. * column/body/row and not the cell.
  272. *
  273. * <p>Note: The area's IPD and BPD must be set before calling this method.</p>
  274. *
  275. * <p>TODO the regular
  276. * {@link #addBackground(Area, CommonBorderPaddingBackground, PercentBaseContext)}
  277. * method should be used instead, and a means to retrieve the original area's
  278. * dimensions must be found.</p>
  279. *
  280. * <p>TODO the placement of images in the x- or y-direction will be incorrect if
  281. * background-repeat is set for that direction.</p>
  282. *
  283. * @param area the area to set the traits on
  284. * @param backProps the background properties
  285. * @param context Property evaluation context
  286. * @param ipdShift horizontal shift to affect to the background, in addition to the
  287. * value of the background-position-horizontal property
  288. * @param bpdShift vertical shift to affect to the background, in addition to the
  289. * value of the background-position-vertical property
  290. * @param referenceIPD value to use as a reference for percentage calculation
  291. * @param referenceBPD value to use as a reference for percentage calculation
  292. */
  293. public static void addBackground(Area area,
  294. CommonBorderPaddingBackground backProps,
  295. PercentBaseContext context,
  296. int ipdShift, int bpdShift, int referenceIPD, int referenceBPD) {
  297. if (!backProps.hasBackground()) {
  298. return;
  299. }
  300. Trait.Background back = new Trait.Background();
  301. back.setColor(backProps.backgroundColor);
  302. if (backProps.getImageInfo() != null) {
  303. back.setURL(backProps.backgroundImage);
  304. back.setImageInfo(backProps.getImageInfo());
  305. back.setRepeat(backProps.backgroundRepeat);
  306. if (backProps.backgroundPositionHorizontal != null) {
  307. if (back.getRepeat() == Constants.EN_NOREPEAT
  308. || back.getRepeat() == Constants.EN_REPEATY) {
  309. if (area.getIPD() > 0) {
  310. PercentBaseContext refContext = new SimplePercentBaseContext(context,
  311. LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
  312. (referenceIPD - back.getImageInfo().getSize().getWidthMpt()));
  313. back.setHoriz(ipdShift
  314. + backProps.backgroundPositionHorizontal.getValue(refContext));
  315. } else {
  316. // TODO Area IPD has to be set for this to work
  317. LOG.warn("Horizontal background image positioning ignored"
  318. + " because the IPD was not set on the area."
  319. + " (Yes, it's a bug in FOP)");
  320. }
  321. }
  322. }
  323. if (backProps.backgroundPositionVertical != null) {
  324. if (back.getRepeat() == Constants.EN_NOREPEAT
  325. || back.getRepeat() == Constants.EN_REPEATX) {
  326. if (area.getBPD() > 0) {
  327. PercentBaseContext refContext = new SimplePercentBaseContext(context,
  328. LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
  329. (referenceBPD - back.getImageInfo().getSize().getHeightMpt()));
  330. back.setVertical(bpdShift
  331. + backProps.backgroundPositionVertical.getValue(refContext));
  332. } else {
  333. // TODO Area BPD has to be set for this to work
  334. LOG.warn("Vertical background image positioning ignored"
  335. + " because the BPD was not set on the area."
  336. + " (Yes, it's a bug in FOP)");
  337. }
  338. }
  339. }
  340. }
  341. area.addTrait(Trait.BACKGROUND, back);
  342. }
  343. /**
  344. * Add background to an area.
  345. * Layout managers that create areas with a background can use this to
  346. * add the background to the area.
  347. * Note: The area's IPD and BPD must be set before calling this method.
  348. * @param area the area to set the traits on
  349. * @param backProps the background properties
  350. * @param context Property evaluation context
  351. */
  352. public static void addBackground(Area area,
  353. CommonBorderPaddingBackground backProps,
  354. PercentBaseContext context) {
  355. if (!backProps.hasBackground()) {
  356. return;
  357. }
  358. Trait.Background back = new Trait.Background();
  359. back.setColor(backProps.backgroundColor);
  360. if (backProps.getImageInfo() != null) {
  361. back.setURL(backProps.backgroundImage);
  362. back.setImageInfo(backProps.getImageInfo());
  363. back.setRepeat(backProps.backgroundRepeat);
  364. if (backProps.backgroundPositionHorizontal != null) {
  365. if (back.getRepeat() == Constants.EN_NOREPEAT
  366. || back.getRepeat() == Constants.EN_REPEATY) {
  367. if (area.getIPD() > 0) {
  368. int width = area.getIPD();
  369. width += backProps.getPaddingStart(false, context);
  370. width += backProps.getPaddingEnd(false, context);
  371. int imageWidthMpt = back.getImageInfo().getSize().getWidthMpt();
  372. int lengthBaseValue = width - imageWidthMpt;
  373. SimplePercentBaseContext simplePercentBaseContext
  374. = new SimplePercentBaseContext(context,
  375. LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
  376. lengthBaseValue);
  377. int horizontal = backProps.backgroundPositionHorizontal.getValue(
  378. simplePercentBaseContext);
  379. back.setHoriz(horizontal);
  380. } else {
  381. //TODO Area IPD has to be set for this to work
  382. LOG.warn("Horizontal background image positioning ignored"
  383. + " because the IPD was not set on the area."
  384. + " (Yes, it's a bug in FOP)");
  385. }
  386. }
  387. }
  388. if (backProps.backgroundPositionVertical != null) {
  389. if (back.getRepeat() == Constants.EN_NOREPEAT
  390. || back.getRepeat() == Constants.EN_REPEATX) {
  391. if (area.getBPD() > 0) {
  392. int height = area.getBPD();
  393. height += backProps.getPaddingBefore(false, context);
  394. height += backProps.getPaddingAfter(false, context);
  395. int imageHeightMpt = back.getImageInfo().getSize().getHeightMpt();
  396. int lengthBaseValue = height - imageHeightMpt;
  397. SimplePercentBaseContext simplePercentBaseContext
  398. = new SimplePercentBaseContext(context,
  399. LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
  400. lengthBaseValue);
  401. int vertical = backProps.backgroundPositionVertical.getValue(
  402. simplePercentBaseContext);
  403. back.setVertical(vertical);
  404. } else {
  405. //TODO Area BPD has to be set for this to work
  406. LOG.warn("Vertical background image positioning ignored"
  407. + " because the BPD was not set on the area."
  408. + " (Yes, it's a bug in FOP)");
  409. }
  410. }
  411. }
  412. }
  413. area.addTrait(Trait.BACKGROUND, back);
  414. }
  415. /**
  416. * Add space to a block area.
  417. * Layout managers that create block areas can use this to add space
  418. * outside of the border rectangle to the area.
  419. * @param area the area to set the traits on.
  420. * @param bpProps the border, padding and background properties
  421. * @param startIndent the effective start-indent value
  422. * @param endIndent the effective end-indent value
  423. * @param context the context for evaluation of percentages
  424. */
  425. public static void addMargins(Area area,
  426. CommonBorderPaddingBackground bpProps,
  427. int startIndent, int endIndent,
  428. PercentBaseContext context) {
  429. if (startIndent != 0) {
  430. area.addTrait(Trait.START_INDENT, startIndent);
  431. }
  432. int spaceStart = startIndent
  433. - bpProps.getBorderStartWidth(false)
  434. - bpProps.getPaddingStart(false, context);
  435. if (spaceStart != 0) {
  436. area.addTrait(Trait.SPACE_START, spaceStart);
  437. }
  438. if (endIndent != 0) {
  439. area.addTrait(Trait.END_INDENT, endIndent);
  440. }
  441. int spaceEnd = endIndent
  442. - bpProps.getBorderEndWidth(false)
  443. - bpProps.getPaddingEnd(false, context);
  444. if (spaceEnd != 0) {
  445. area.addTrait(Trait.SPACE_END, spaceEnd);
  446. }
  447. }
  448. /**
  449. * Add space to a block area.
  450. * Layout managers that create block areas can use this to add space
  451. * outside of the border rectangle to the area.
  452. * @param area the area to set the traits on.
  453. * @param bpProps the border, padding and background properties
  454. * @param marginProps the margin properties.
  455. * @param context the context for evaluation of percentages
  456. */
  457. public static void addMargins(Area area,
  458. CommonBorderPaddingBackground bpProps,
  459. CommonMarginBlock marginProps,
  460. PercentBaseContext context) {
  461. int startIndent = marginProps.startIndent.getValue(context);
  462. int endIndent = marginProps.endIndent.getValue(context);
  463. addMargins(area, bpProps, startIndent, endIndent, context);
  464. }
  465. /**
  466. * Returns the effective space length of a resolved space specifier based on the adjustment
  467. * value.
  468. * @param adjust the adjustment value
  469. * @param space the space specifier
  470. * @return the effective space length
  471. */
  472. public static int getEffectiveSpace(double adjust, MinOptMax space) {
  473. if (space == null) {
  474. return 0;
  475. } else {
  476. int spaceOpt = space.getOpt();
  477. if (adjust > 0) {
  478. spaceOpt += (int) (adjust * space.getStretch());
  479. } else {
  480. spaceOpt += (int) (adjust * space.getShrink());
  481. }
  482. return spaceOpt;
  483. }
  484. }
  485. /**
  486. * Adds traits for space-before and space-after to an area.
  487. * @param area the target area
  488. * @param adjust the adjustment value
  489. * @param spaceBefore the space-before space specifier
  490. * @param spaceAfter the space-after space specifier
  491. */
  492. public static void addSpaceBeforeAfter(Area area, double adjust, MinOptMax spaceBefore,
  493. MinOptMax spaceAfter) {
  494. addSpaceTrait(area, Trait.SPACE_BEFORE, spaceBefore, adjust);
  495. addSpaceTrait(area, Trait.SPACE_AFTER, spaceAfter, adjust);
  496. }
  497. private static void addSpaceTrait(Area area, Integer spaceTrait,
  498. MinOptMax space, double adjust) {
  499. int effectiveSpace = getEffectiveSpace(adjust, space);
  500. if (effectiveSpace != 0) {
  501. area.addTrait(spaceTrait, effectiveSpace);
  502. }
  503. }
  504. /**
  505. * Sets the traits for breaks on an area.
  506. * @param area the area to set the traits on.
  507. * @param breakBefore the value for break-before
  508. * @param breakAfter the value for break-after
  509. */
  510. public static void addBreaks(Area area, int breakBefore, int breakAfter) {
  511. /* Currently disabled as these traits are never used by the renderers
  512. area.addTrait(Trait.BREAK_AFTER, new Integer(breakAfter));
  513. area.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore));
  514. */
  515. }
  516. /**
  517. * Adds font traits to an area
  518. * @param area the target are
  519. * @param font the font to use
  520. */
  521. public static void addFontTraits(Area area, Font font) {
  522. area.addTrait(Trait.FONT, font.getFontTriplet());
  523. area.addTrait(Trait.FONT_SIZE, font.getFontSize());
  524. }
  525. /**
  526. * Adds the text-decoration traits to the area.
  527. * @param area the area to set the traits on
  528. * @param deco the text decorations
  529. */
  530. public static void addTextDecoration(Area area, CommonTextDecoration deco) {
  531. //TODO Finish text-decoration
  532. if (deco != null) {
  533. if (deco.hasUnderline()) {
  534. area.addTrait(Trait.UNDERLINE, Boolean.TRUE);
  535. area.addTrait(Trait.UNDERLINE_COLOR, deco.getUnderlineColor());
  536. }
  537. if (deco.hasOverline()) {
  538. area.addTrait(Trait.OVERLINE, Boolean.TRUE);
  539. area.addTrait(Trait.OVERLINE_COLOR, deco.getOverlineColor());
  540. }
  541. if (deco.hasLineThrough()) {
  542. area.addTrait(Trait.LINETHROUGH, Boolean.TRUE);
  543. area.addTrait(Trait.LINETHROUGH_COLOR, deco.getLineThroughColor());
  544. }
  545. if (deco.isBlinking()) {
  546. area.addTrait(Trait.BLINK, Boolean.TRUE);
  547. }
  548. }
  549. }
  550. /**
  551. * Sets the structure tree element associated to the given area.
  552. *
  553. * @param area the area to set the traits on
  554. * @param structureTreeElement the element the area is associated to in the document structure
  555. */
  556. public static void addStructureTreeElement(Area area,
  557. StructureTreeElement structureTreeElement) {
  558. if (structureTreeElement != null) {
  559. area.addTrait(Trait.STRUCTURE_TREE_ELEMENT, structureTreeElement);
  560. }
  561. }
  562. /**
  563. * Sets the producer's ID as a trait on the area. This can be used to track back the
  564. * generating FO node.
  565. * @param area the area to set the traits on
  566. * @param id the ID to set
  567. */
  568. public static void setProducerID(Area area, String id) {
  569. if (id != null && id.length() > 0) {
  570. area.addTrait(Trait.PROD_ID, id);
  571. }
  572. }
  573. }