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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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.SEPARATE, Trait.BORDER_START);
  75. addBorderTrait(area, bpProps, isNotLast,
  76. CommonBorderPaddingBackground.END,
  77. BorderProps.SEPARATE, Trait.BORDER_END);
  78. addBorderTrait(area, bpProps, false,
  79. CommonBorderPaddingBackground.BEFORE,
  80. BorderProps.SEPARATE, Trait.BORDER_BEFORE);
  81. addBorderTrait(area, bpProps, false,
  82. CommonBorderPaddingBackground.AFTER,
  83. BorderProps.SEPARATE, Trait.BORDER_AFTER);
  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 discard, int side, int mode,
  95. Integer trait) {
  96. int borderWidth = bpProps.getBorderWidth(side, discard);
  97. if (borderWidth > 0) {
  98. area.addTrait(trait,
  99. new BorderProps(bpProps.getBorderStyle(side),
  100. borderWidth, bpProps.getBorderColor(side),
  101. 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);
  116. if (bps != null) {
  117. area.addTrait(Trait.BORDER_BEFORE, bps);
  118. }
  119. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.AFTER);
  120. if (bps != null) {
  121. area.addTrait(Trait.BORDER_AFTER, bps);
  122. }
  123. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.START);
  124. if (bps != null) {
  125. area.addTrait(Trait.BORDER_START, bps);
  126. }
  127. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.END);
  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);
  151. if (bps != null && !discardBefore) {
  152. area.addTrait(Trait.BORDER_BEFORE, bps);
  153. }
  154. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.AFTER);
  155. if (bps != null && !discardAfter) {
  156. area.addTrait(Trait.BORDER_AFTER, bps);
  157. }
  158. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.START);
  159. if (bps != null && !discardStart) {
  160. area.addTrait(Trait.BORDER_START, bps);
  161. }
  162. bps = getBorderProps(borderProps, CommonBorderPaddingBackground.END);
  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, int side) {
  242. int width = bordProps.getBorderWidth(side, false);
  243. if (width != 0) {
  244. BorderProps bps;
  245. bps = new BorderProps(bordProps.getBorderStyle(side),
  246. width,
  247. bordProps.getBorderColor(side),
  248. BorderProps.SEPARATE);
  249. return bps;
  250. } else {
  251. return null;
  252. }
  253. }
  254. private static BorderProps getCollapsingBorderProps(BorderInfo borderInfo, boolean outer) {
  255. assert borderInfo != null;
  256. int width = borderInfo.getRetainedWidth();
  257. if (width != 0) {
  258. return new BorderProps(borderInfo.getStyle(), width, borderInfo.getColor(),
  259. (outer ? BorderProps.COLLAPSE_OUTER : BorderProps.COLLAPSE_INNER));
  260. } else {
  261. return null;
  262. }
  263. }
  264. /**
  265. * Add background to an area. This method is mainly used by table-related layout
  266. * managers to add background for column, body or row. Since the area corresponding to
  267. * border-separation must be filled with the table's background, for every cell an
  268. * additional area with the same dimensions is created to hold the background for the
  269. * corresponding column/body/row. An additional shift must then be added to
  270. * background-position-horizontal/vertical to ensure the background images are
  271. * correctly placed. Indeed the placement of images must be made WRT the
  272. * column/body/row and not the cell.
  273. *
  274. * <p>Note: The area's IPD and BPD must be set before calling this method.</p>
  275. *
  276. * <p>TODO the regular
  277. * {@link #addBackground(Area, CommonBorderPaddingBackground, PercentBaseContext)}
  278. * method should be used instead, and a means to retrieve the original area's
  279. * dimensions must be found.</p>
  280. *
  281. * <p>TODO the placement of images in the x- or y-direction will be incorrect if
  282. * background-repeat is set for that direction.</p>
  283. *
  284. * @param area the area to set the traits on
  285. * @param backProps the background properties
  286. * @param context Property evaluation context
  287. * @param ipdShift horizontal shift to affect to the background, in addition to the
  288. * value of the background-position-horizontal property
  289. * @param bpdShift vertical shift to affect to the background, in addition to the
  290. * value of the background-position-vertical property
  291. * @param referenceIPD value to use as a reference for percentage calculation
  292. * @param referenceBPD value to use as a reference for percentage calculation
  293. */
  294. public static void addBackground(Area area,
  295. CommonBorderPaddingBackground backProps,
  296. PercentBaseContext context,
  297. int ipdShift, int bpdShift, int referenceIPD, int referenceBPD) {
  298. if (!backProps.hasBackground()) {
  299. return;
  300. }
  301. Trait.Background back = new Trait.Background();
  302. back.setColor(backProps.backgroundColor);
  303. if (backProps.getImageInfo() != null) {
  304. back.setURL(backProps.backgroundImage);
  305. back.setImageInfo(backProps.getImageInfo());
  306. back.setRepeat(backProps.backgroundRepeat);
  307. if (backProps.backgroundPositionHorizontal != null) {
  308. if (back.getRepeat() == Constants.EN_NOREPEAT
  309. || back.getRepeat() == Constants.EN_REPEATY) {
  310. if (area.getIPD() > 0) {
  311. PercentBaseContext refContext = new SimplePercentBaseContext(context,
  312. LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
  313. (referenceIPD - back.getImageInfo().getSize().getWidthMpt()));
  314. back.setHoriz(ipdShift
  315. + backProps.backgroundPositionHorizontal.getValue(refContext));
  316. } else {
  317. // TODO Area IPD has to be set for this to work
  318. LOG.warn("Horizontal background image positioning ignored"
  319. + " because the IPD was not set on the area."
  320. + " (Yes, it's a bug in FOP)");
  321. }
  322. }
  323. }
  324. if (backProps.backgroundPositionVertical != null) {
  325. if (back.getRepeat() == Constants.EN_NOREPEAT
  326. || back.getRepeat() == Constants.EN_REPEATX) {
  327. if (area.getBPD() > 0) {
  328. PercentBaseContext refContext = new SimplePercentBaseContext(context,
  329. LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
  330. (referenceBPD - back.getImageInfo().getSize().getHeightMpt()));
  331. back.setVertical(bpdShift
  332. + backProps.backgroundPositionVertical.getValue(refContext));
  333. } else {
  334. // TODO Area BPD has to be set for this to work
  335. LOG.warn("Vertical background image positioning ignored"
  336. + " because the BPD was not set on the area."
  337. + " (Yes, it's a bug in FOP)");
  338. }
  339. }
  340. }
  341. }
  342. area.addTrait(Trait.BACKGROUND, back);
  343. }
  344. /**
  345. * Add background to an area.
  346. * Layout managers that create areas with a background can use this to
  347. * add the background to the area.
  348. * Note: The area's IPD and BPD must be set before calling this method.
  349. * @param area the area to set the traits on
  350. * @param backProps the background properties
  351. * @param context Property evaluation context
  352. */
  353. public static void addBackground(Area area,
  354. CommonBorderPaddingBackground backProps,
  355. PercentBaseContext context) {
  356. if (!backProps.hasBackground()) {
  357. return;
  358. }
  359. Trait.Background back = new Trait.Background();
  360. back.setColor(backProps.backgroundColor);
  361. if (backProps.getImageInfo() != null) {
  362. back.setURL(backProps.backgroundImage);
  363. back.setImageInfo(backProps.getImageInfo());
  364. back.setRepeat(backProps.backgroundRepeat);
  365. if (backProps.backgroundPositionHorizontal != null) {
  366. if (back.getRepeat() == Constants.EN_NOREPEAT
  367. || back.getRepeat() == Constants.EN_REPEATY) {
  368. if (area.getIPD() > 0) {
  369. int width = area.getIPD();
  370. width += backProps.getPaddingStart(false, context);
  371. width += backProps.getPaddingEnd(false, context);
  372. int imageWidthMpt = back.getImageInfo().getSize().getWidthMpt();
  373. int lengthBaseValue = width - imageWidthMpt;
  374. SimplePercentBaseContext simplePercentBaseContext
  375. = new SimplePercentBaseContext(context,
  376. LengthBase.IMAGE_BACKGROUND_POSITION_HORIZONTAL,
  377. lengthBaseValue);
  378. int horizontal = backProps.backgroundPositionHorizontal.getValue(
  379. simplePercentBaseContext);
  380. back.setHoriz(horizontal);
  381. } else {
  382. //TODO Area IPD has to be set for this to work
  383. LOG.warn("Horizontal background image positioning ignored"
  384. + " because the IPD was not set on the area."
  385. + " (Yes, it's a bug in FOP)");
  386. }
  387. }
  388. }
  389. if (backProps.backgroundPositionVertical != null) {
  390. if (back.getRepeat() == Constants.EN_NOREPEAT
  391. || back.getRepeat() == Constants.EN_REPEATX) {
  392. if (area.getBPD() > 0) {
  393. int height = area.getBPD();
  394. height += backProps.getPaddingBefore(false, context);
  395. height += backProps.getPaddingAfter(false, context);
  396. int imageHeightMpt = back.getImageInfo().getSize().getHeightMpt();
  397. int lengthBaseValue = height - imageHeightMpt;
  398. SimplePercentBaseContext simplePercentBaseContext
  399. = new SimplePercentBaseContext(context,
  400. LengthBase.IMAGE_BACKGROUND_POSITION_VERTICAL,
  401. lengthBaseValue);
  402. int vertical = backProps.backgroundPositionVertical.getValue(
  403. simplePercentBaseContext);
  404. back.setVertical(vertical);
  405. } else {
  406. //TODO Area BPD has to be set for this to work
  407. LOG.warn("Vertical background image positioning ignored"
  408. + " because the BPD was not set on the area."
  409. + " (Yes, it's a bug in FOP)");
  410. }
  411. }
  412. }
  413. }
  414. area.addTrait(Trait.BACKGROUND, back);
  415. }
  416. /**
  417. * Add space to a block area.
  418. * Layout managers that create block areas can use this to add space
  419. * outside of the border rectangle to the area.
  420. * @param area the area to set the traits on.
  421. * @param bpProps the border, padding and background properties
  422. * @param startIndent the effective start-indent value
  423. * @param endIndent the effective end-indent value
  424. * @param context the context for evaluation of percentages
  425. */
  426. public static void addMargins(Area area,
  427. CommonBorderPaddingBackground bpProps,
  428. int startIndent, int endIndent,
  429. PercentBaseContext context) {
  430. if (startIndent != 0) {
  431. area.addTrait(Trait.START_INDENT, startIndent);
  432. }
  433. int spaceStart = startIndent
  434. - bpProps.getBorderStartWidth(false)
  435. - bpProps.getPaddingStart(false, context);
  436. if (spaceStart != 0) {
  437. area.addTrait(Trait.SPACE_START, spaceStart);
  438. }
  439. if (endIndent != 0) {
  440. area.addTrait(Trait.END_INDENT, endIndent);
  441. }
  442. int spaceEnd = endIndent
  443. - bpProps.getBorderEndWidth(false)
  444. - bpProps.getPaddingEnd(false, context);
  445. if (spaceEnd != 0) {
  446. area.addTrait(Trait.SPACE_END, spaceEnd);
  447. }
  448. }
  449. /**
  450. * Add space to a block area.
  451. * Layout managers that create block areas can use this to add space
  452. * outside of the border rectangle to the area.
  453. * @param area the area to set the traits on.
  454. * @param bpProps the border, padding and background properties
  455. * @param marginProps the margin properties.
  456. * @param context the context for evaluation of percentages
  457. */
  458. public static void addMargins(Area area,
  459. CommonBorderPaddingBackground bpProps,
  460. CommonMarginBlock marginProps,
  461. PercentBaseContext context) {
  462. int startIndent = marginProps.startIndent.getValue(context);
  463. int endIndent = marginProps.endIndent.getValue(context);
  464. addMargins(area, bpProps, startIndent, endIndent, context);
  465. }
  466. /**
  467. * Returns the effective space length of a resolved space specifier based on the adjustment
  468. * value.
  469. * @param adjust the adjustment value
  470. * @param space the space specifier
  471. * @return the effective space length
  472. */
  473. public static int getEffectiveSpace(double adjust, MinOptMax space) {
  474. if (space == null) {
  475. return 0;
  476. } else {
  477. int spaceOpt = space.getOpt();
  478. if (adjust > 0) {
  479. spaceOpt += (int) (adjust * space.getStretch());
  480. } else {
  481. spaceOpt += (int) (adjust * space.getShrink());
  482. }
  483. return spaceOpt;
  484. }
  485. }
  486. /**
  487. * Adds traits for space-before and space-after to an area.
  488. * @param area the target area
  489. * @param adjust the adjustment value
  490. * @param spaceBefore the space-before space specifier
  491. * @param spaceAfter the space-after space specifier
  492. */
  493. public static void addSpaceBeforeAfter(Area area, double adjust, MinOptMax spaceBefore,
  494. MinOptMax spaceAfter) {
  495. addSpaceTrait(area, Trait.SPACE_BEFORE, spaceBefore, adjust);
  496. addSpaceTrait(area, Trait.SPACE_AFTER, spaceAfter, adjust);
  497. }
  498. private static void addSpaceTrait(Area area, Integer spaceTrait,
  499. MinOptMax space, double adjust) {
  500. int effectiveSpace = getEffectiveSpace(adjust, space);
  501. if (effectiveSpace != 0) {
  502. area.addTrait(spaceTrait, effectiveSpace);
  503. }
  504. }
  505. /**
  506. * Sets the traits for breaks on an area.
  507. * @param area the area to set the traits on.
  508. * @param breakBefore the value for break-before
  509. * @param breakAfter the value for break-after
  510. */
  511. public static void addBreaks(Area area, int breakBefore, int breakAfter) {
  512. /* Currently disabled as these traits are never used by the renderers
  513. area.addTrait(Trait.BREAK_AFTER, new Integer(breakAfter));
  514. area.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore));
  515. */
  516. }
  517. /**
  518. * Adds font traits to an area
  519. * @param area the target are
  520. * @param font the font to use
  521. */
  522. public static void addFontTraits(Area area, Font font) {
  523. area.addTrait(Trait.FONT, font.getFontTriplet());
  524. area.addTrait(Trait.FONT_SIZE, font.getFontSize());
  525. }
  526. /**
  527. * Adds the text-decoration traits to the area.
  528. * @param area the area to set the traits on
  529. * @param deco the text decorations
  530. */
  531. public static void addTextDecoration(Area area, CommonTextDecoration deco) {
  532. //TODO Finish text-decoration
  533. if (deco != null) {
  534. if (deco.hasUnderline()) {
  535. area.addTrait(Trait.UNDERLINE, Boolean.TRUE);
  536. area.addTrait(Trait.UNDERLINE_COLOR, deco.getUnderlineColor());
  537. }
  538. if (deco.hasOverline()) {
  539. area.addTrait(Trait.OVERLINE, Boolean.TRUE);
  540. area.addTrait(Trait.OVERLINE_COLOR, deco.getOverlineColor());
  541. }
  542. if (deco.hasLineThrough()) {
  543. area.addTrait(Trait.LINETHROUGH, Boolean.TRUE);
  544. area.addTrait(Trait.LINETHROUGH_COLOR, deco.getLineThroughColor());
  545. }
  546. if (deco.isBlinking()) {
  547. area.addTrait(Trait.BLINK, Boolean.TRUE);
  548. }
  549. }
  550. }
  551. /**
  552. * Sets the structure tree element associated to the given area.
  553. *
  554. * @param area the area to set the traits on
  555. * @param structureTreeElement the element the area is associated to in the document structure
  556. */
  557. public static void addStructureTreeElement(Area area,
  558. StructureTreeElement structureTreeElement) {
  559. if (structureTreeElement != null) {
  560. area.addTrait(Trait.STRUCTURE_TREE_ELEMENT, structureTreeElement);
  561. }
  562. }
  563. /**
  564. * Sets the producer's ID as a trait on the area. This can be used to track back the
  565. * generating FO node.
  566. * @param area the area to set the traits on
  567. * @param id the ID to set
  568. */
  569. public static void setProducerID(Area area, String id) {
  570. if (id != null && id.length() > 0) {
  571. area.addTrait(Trait.PROD_ID, id);
  572. }
  573. }
  574. }