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.

TextLayoutManager.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * $Id: TextLayoutManager.java,v 1.21 2003/03/05 20:38:26 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.layoutmgr;
  52. import java.util.ArrayList;
  53. import org.apache.fop.fo.TextInfo;
  54. import org.apache.fop.traits.SpaceVal;
  55. import org.apache.fop.area.Trait;
  56. import org.apache.fop.area.inline.InlineArea;
  57. import org.apache.fop.area.inline.Word;
  58. import org.apache.fop.area.inline.Space;
  59. import org.apache.fop.util.CharUtilities;
  60. import org.apache.fop.traits.MinOptMax;
  61. /**
  62. * LayoutManager for text (a sequence of characters) which generates one
  63. * or more inline areas.
  64. */
  65. public class TextLayoutManager extends AbstractLayoutManager {
  66. /**
  67. * Store information about each potential word area.
  68. * Index of character which ends the area, IPD of area, including
  69. * any word-space and letter-space.
  70. * Number of word-spaces?
  71. */
  72. private class AreaInfo {
  73. private short iStartIndex;
  74. private short iBreakIndex;
  75. private short iWScount;
  76. private MinOptMax ipdArea;
  77. public AreaInfo(short iSIndex, short iBIndex, short iWS,
  78. MinOptMax ipd) {
  79. iStartIndex = iSIndex;
  80. iBreakIndex = iBIndex;
  81. iWScount = iWS;
  82. ipdArea = ipd;
  83. }
  84. }
  85. // Hold all possible breaks for the text in this LM's FO.
  86. private ArrayList vecAreaInfo;
  87. /** Non-space characters on which we can end a line. */
  88. private static final String BREAK_CHARS = "-/" ;
  89. private char[] chars;
  90. private TextInfo textInfo;
  91. private static final char NEWLINE = '\n';
  92. private static final char SPACE = '\u0020'; // Normal space
  93. private static final char NBSPACE = '\u00A0'; // Non-breaking space
  94. private static final char LINEBREAK = '\u2028';
  95. private static final char ZERO_WIDTH_SPACE = '\u200B';
  96. // byte order mark
  97. private static final char ZERO_WIDTH_NOBREAK_SPACE = '\uFEFF';
  98. /** Start index of first character in this parent Area */
  99. private short iAreaStart = 0;
  100. /** Start index of next "word" */
  101. private short iNextStart = 0;
  102. /** Size since last makeArea call, except for last break */
  103. private MinOptMax ipdTotal;
  104. /** Size including last break possibility returned */
  105. // private MinOptMax nextIPD = new MinOptMax(0);
  106. /** size of a space character (U+0020) glyph in current font */
  107. private int spaceCharIPD;
  108. /** size of the hyphen character glyph in current font */
  109. private int hyphIPD;
  110. /** 1/2 of word-spacing value */
  111. private SpaceVal halfWS;
  112. /** Number of space characters after previous possible break position. */
  113. private int iNbSpacesPending;
  114. /**
  115. * Create a Text layout manager.
  116. *
  117. * @param chars the characters
  118. * @param textInfo the text information for doing layout
  119. */
  120. public TextLayoutManager(char[] chars, TextInfo textInfo) {
  121. this.chars = chars;
  122. this.textInfo = textInfo;
  123. this.vecAreaInfo = new java.util.ArrayList();
  124. // With CID fonts, space isn't neccesary currentFontState.width(32)
  125. spaceCharIPD = CharUtilities.getCharWidth(' ', textInfo.fs);
  126. // Use hyphenationChar property
  127. hyphIPD = CharUtilities.getCharWidth('-', textInfo.fs);
  128. // Make half-space: <space> on either side of a word-space)
  129. SpaceVal ws = textInfo.wordSpacing;
  130. halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5),
  131. ws.isConditional(), ws.isForcing(), ws.getPrecedence());
  132. }
  133. /**
  134. * Text always generates inline areas.
  135. *
  136. * @return true
  137. */
  138. public boolean generatesInlineAreas() {
  139. return true;
  140. }
  141. /**
  142. * Get the word characters between two positions.
  143. * This is used when doing hyphenation or other word manipulations.
  144. *
  145. * @param sbChars the string buffer to put the chars into
  146. * @param bp1 the start position
  147. * @param bp2 the end position
  148. */
  149. public void getWordChars(StringBuffer sbChars, Position bp1,
  150. Position bp2) {
  151. LeafPosition endPos = (LeafPosition) bp2;
  152. AreaInfo ai =
  153. (AreaInfo) vecAreaInfo.get(endPos.getLeafPos());
  154. // Skip all leading spaces for hyphenation
  155. int i;
  156. for (i = ai.iStartIndex;
  157. i < ai.iBreakIndex && CharUtilities.isAnySpace(chars[i]) == true;
  158. i++) {
  159. //nop
  160. }
  161. sbChars.append(new String(chars, i, ai.iBreakIndex - i));
  162. }
  163. /**
  164. * Return value indicating whether the next area to be generated could
  165. * start a new line. This should only be called in the "START" condition
  166. * if a previous inline BP couldn't end the line.
  167. * Return true if the first character is a potential linebreak character.
  168. *
  169. * @param context the layout context for determining a break
  170. * @return true if can break before this text
  171. */
  172. public boolean canBreakBefore(LayoutContext context) {
  173. char c = chars[iNextStart];
  174. return ((c == NEWLINE)
  175. || (textInfo.bWrap && (CharUtilities.isSpace(c)
  176. || BREAK_CHARS.indexOf(c) >= 0)));
  177. }
  178. /**
  179. * Reset position for returning next BreakPossibility.
  180. *
  181. * @param prevPos the position to reset to
  182. */
  183. public void resetPosition(Position prevPos) {
  184. if (prevPos != null) {
  185. // ASSERT (prevPos.getLM() == this)
  186. if (prevPos.getLM() != this) {
  187. getLogger().error(
  188. "TextLayoutManager.resetPosition: " + "LM mismatch!!!");
  189. }
  190. LeafPosition tbp = (LeafPosition) prevPos;
  191. AreaInfo ai =
  192. (AreaInfo) vecAreaInfo.get(tbp.getLeafPos());
  193. if (ai.iBreakIndex != iNextStart) {
  194. iNextStart = ai.iBreakIndex;
  195. vecAreaInfo.ensureCapacity(tbp.getLeafPos() + 1);
  196. // TODO: reset or recalculate total IPD = sum of all word IPD
  197. // up to the break position
  198. ipdTotal = ai.ipdArea;
  199. setFinished(false);
  200. }
  201. } else {
  202. // Reset to beginning!
  203. vecAreaInfo.clear();
  204. iNextStart = 0;
  205. setFinished(false);
  206. }
  207. }
  208. // TODO: see if we can use normal getNextBreakPoss for this with
  209. // extra hyphenation information in LayoutContext
  210. private boolean getHyphenIPD(HyphContext hc, MinOptMax hyphIPD) {
  211. // Skip leading word-space before calculating count?
  212. boolean bCanHyphenate = true;
  213. int iStopIndex = iNextStart + hc.getNextHyphPoint();
  214. if (chars.length < iStopIndex || textInfo.bCanHyphenate == false) {
  215. iStopIndex = chars.length;
  216. bCanHyphenate = false;
  217. }
  218. hc.updateOffset(iStopIndex - iNextStart);
  219. for (; iNextStart < iStopIndex; iNextStart++) {
  220. char c = chars[iNextStart];
  221. hyphIPD.opt += CharUtilities.getCharWidth(c, textInfo.fs);
  222. // letter-space?
  223. }
  224. // Need to include hyphen size too, but don't count it in the
  225. // stored running total, since it would be double counted
  226. // with later hyphenation points
  227. return bCanHyphenate;
  228. }
  229. /**
  230. * Return the next break possibility that fits the constraints.
  231. * @param context An object specifying the flags and input information
  232. * concerning the context of the BreakPoss.
  233. * @return BreakPoss An object containing information about the next
  234. * legal break position or the end of the text run if no break
  235. * was found.
  236. * <p>Assumptions: white-space-treatment and
  237. * linefeed-treatment processing
  238. * are already done, so there are no TAB or RETURN characters remaining.
  239. * white-space-collapse handling is also done
  240. * (but perhaps this shouldn't be true!)
  241. * There may be LINEFEED characters if they weren't converted
  242. * into spaces. A LINEFEED always forces a break.
  243. */
  244. public BreakPoss getNextBreakPoss(LayoutContext context) {
  245. /* On first call in a new Line, the START_AREA
  246. * flag in LC is set.
  247. */
  248. int iFlags = 0;
  249. if (context.startsNewArea()) {
  250. /* This could be first call on this LM, or the first call
  251. * in a new (possible) LineArea.
  252. */
  253. ipdTotal = new MinOptMax(0);
  254. iFlags |= BreakPoss.ISFIRST;
  255. }
  256. /* HANDLE SUPPRESSED LEADING SPACES
  257. * See W3C XSL Rec. 7.16.3.
  258. * Suppress characters whose "suppress-at-line-break" property = "suppress"
  259. * This can only be set on an explicit fo:character object. The default
  260. * behavior is that U+0020 is suppressed; all other character codes are
  261. * retained.
  262. */
  263. if (context.suppressLeadingSpace()) {
  264. for (; iNextStart < chars.length
  265. && chars[iNextStart] == SPACE; iNextStart++) {
  266. }
  267. // If now at end, nothing to compose here!
  268. if (iNextStart >= chars.length) {
  269. setFinished(true);
  270. return null; // Or an "empty" BreakPoss?
  271. }
  272. }
  273. /* Start of this "word", plus any non-suppressed leading space.
  274. * Collapse any remaining word-space with leading space from
  275. * ancestor FOs.
  276. * Add up other leading space which is counted in the word IPD.
  277. */
  278. SpaceSpecifier pendingSpace = new SpaceSpecifier(false);
  279. short iThisStart = iNextStart; // Index of first character counted
  280. MinOptMax spaceIPD = new MinOptMax(0); // Extra IPD from word-spacing
  281. // Sum of glyph IPD of all characters in a word, inc. leading space
  282. int wordIPD = 0;
  283. short iWScount = 0; // Count of word spaces
  284. boolean bSawNonSuppressible = false;
  285. for (; iNextStart < chars.length; iNextStart++) {
  286. char c = chars[iNextStart];
  287. if (CharUtilities.isAnySpace(c) == false) {
  288. break;
  289. }
  290. if (c == SPACE || c == NBSPACE) {
  291. ++iWScount;
  292. // Counted as word-space
  293. if (iNextStart == iThisStart
  294. && (iFlags & BreakPoss.ISFIRST) != 0) {
  295. // If possible, treat as normal inter-word space
  296. if (context.getLeadingSpace().hasSpaces()) {
  297. context.getLeadingSpace().addSpace(halfWS);
  298. } else {
  299. // Doesn't combine with any other leading spaces
  300. // from ancestors
  301. spaceIPD.add(halfWS.getSpace());
  302. }
  303. } else {
  304. pendingSpace.addSpace(halfWS);
  305. spaceIPD.add(pendingSpace.resolve(false));
  306. }
  307. wordIPD += spaceCharIPD; // Space glyph IPD
  308. pendingSpace.clear();
  309. pendingSpace.addSpace(halfWS);
  310. if (c == NBSPACE) {
  311. bSawNonSuppressible = true;
  312. }
  313. } else {
  314. // If we have letter-space, so we apply this to fixed-
  315. // width spaces (which are not word-space) also?
  316. bSawNonSuppressible = true;
  317. spaceIPD.add(pendingSpace.resolve(false));
  318. pendingSpace.clear();
  319. wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
  320. }
  321. }
  322. if (iNextStart < chars.length) {
  323. spaceIPD.add(pendingSpace.resolve(false));
  324. } else {
  325. // This FO ended with spaces. Return the BP
  326. if (!bSawNonSuppressible) {
  327. iFlags |= BreakPoss.ALL_ARE_SUPPRESS_AT_LB;
  328. }
  329. return makeBreakPoss(iThisStart, spaceIPD, wordIPD,
  330. context.getLeadingSpace(), pendingSpace, iFlags,
  331. iWScount);
  332. }
  333. if (context.tryHyphenate()) {
  334. // Get the size of the next syallable
  335. MinOptMax hyphIPD = new MinOptMax(0);
  336. if (getHyphenIPD(context.getHyphContext(), hyphIPD)) {
  337. iFlags |= (BreakPoss.CAN_BREAK_AFTER | BreakPoss.HYPHENATED);
  338. }
  339. wordIPD += hyphIPD.opt;
  340. } else {
  341. // Look for a legal line-break: breakable white-space and certain
  342. // characters such as '-' which can serve as word breaks.
  343. // Don't look for hyphenation points here though
  344. for (; iNextStart < chars.length; iNextStart++) {
  345. char c = chars[iNextStart];
  346. if ((c == NEWLINE) || // Include any breakable white-space as break char
  347. // even if fixed width
  348. (textInfo.bWrap && (CharUtilities.isSpace(c)
  349. || BREAK_CHARS.indexOf(c) >= 0))) {
  350. iFlags |= BreakPoss.CAN_BREAK_AFTER;
  351. if (c != SPACE) {
  352. iNextStart++;
  353. if (c != NEWLINE) {
  354. wordIPD += CharUtilities.getCharWidth(c,
  355. textInfo.fs);
  356. } else {
  357. iFlags |= BreakPoss.FORCE;
  358. }
  359. }
  360. // If all remaining characters would be suppressed at
  361. // line-end, set a flag for parent LM.
  362. int iLastChar;
  363. for (iLastChar = iNextStart;
  364. iLastChar < chars.length
  365. && chars[iLastChar] == SPACE; iLastChar++) {
  366. //nop
  367. }
  368. if (iLastChar == chars.length) {
  369. iFlags |= BreakPoss.REST_ARE_SUPPRESS_AT_LB;
  370. }
  371. return makeBreakPoss(iThisStart, spaceIPD, wordIPD,
  372. context.getLeadingSpace(), null, iFlags,
  373. iWScount);
  374. }
  375. wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
  376. // Note, if a normal non-breaking space, is it stretchable???
  377. // If so, keep a count of these embedded spaces.
  378. }
  379. }
  380. return makeBreakPoss(iThisStart, spaceIPD, wordIPD,
  381. context.getLeadingSpace(), null, iFlags, iWScount);
  382. }
  383. private BreakPoss makeBreakPoss(short iWordStart,
  384. MinOptMax spaceIPD, int wordDim,
  385. SpaceSpecifier leadingSpace, SpaceSpecifier trailingSpace,
  386. int flags, short iWScount) {
  387. MinOptMax ipd = new MinOptMax(wordDim);
  388. ipd.add(spaceIPD);
  389. if (ipdTotal != null) {
  390. ipd.add(ipdTotal); // sum of all words so far in line
  391. }
  392. // Note: break position now stores total size to here
  393. // Position is the index of the info for this word in the vector
  394. vecAreaInfo.add(
  395. new AreaInfo(iWordStart, iNextStart, iWScount, ipd));
  396. BreakPoss bp = new BreakPoss(
  397. new LeafPosition(this, vecAreaInfo.size() - 1));
  398. ipdTotal = ipd;
  399. if ((flags & BreakPoss.HYPHENATED) != 0) {
  400. // Add the hyphen size, but don't change total IPD!
  401. bp.setStackingSize(
  402. MinOptMax.add(ipd, new MinOptMax(hyphIPD)));
  403. } else {
  404. bp.setStackingSize(ipd);
  405. }
  406. // TODO: make this correct (see Keiron's vertical alignment code)
  407. bp.setNonStackingSize(new MinOptMax(textInfo.lineHeight));
  408. /* Set max ascender and descender (offset from baseline),
  409. * used for calculating the bpd of the line area containing
  410. * this text.
  411. */
  412. //bp.setDescender(textInfo.fs.getDescender());
  413. //bp.setAscender(textInfo.fs.getAscender());
  414. if (iNextStart == chars.length) {
  415. flags |= BreakPoss.ISLAST;
  416. setFinished(true);
  417. }
  418. bp.setFlag(flags);
  419. if (trailingSpace != null) {
  420. bp.setTrailingSpace(trailingSpace);
  421. } else {
  422. bp.setTrailingSpace(new SpaceSpecifier(false));
  423. }
  424. if (leadingSpace != null) {
  425. bp.setLeadingSpace(leadingSpace);
  426. } else {
  427. bp.setLeadingSpace(new SpaceSpecifier(false));
  428. }
  429. return bp;
  430. }
  431. /**
  432. * Generate and add areas to parent area.
  433. * This can either generate an area for each "word" and each space, or
  434. * an area containing all text with a parameter controlling the size of
  435. * the word space. The latter is most efficient for PDF generation.
  436. * Set size of each area.
  437. * @param posIter Iterator over Position information returned
  438. * by this LayoutManager.
  439. * @param context LayoutContext for adjustments
  440. */
  441. public void addAreas(PositionIterator posIter, LayoutContext context) {
  442. // Add word areas
  443. AreaInfo ai = null ;
  444. int iStart = -1;
  445. int iWScount = 0;
  446. /* On first area created, add any leading space.
  447. * Calculate word-space stretch value.
  448. */
  449. while (posIter.hasNext()) {
  450. LeafPosition tbpNext = (LeafPosition) posIter.next();
  451. ai = (AreaInfo) vecAreaInfo.get(tbpNext.getLeafPos());
  452. if (iStart == -1) {
  453. iStart = ai.iStartIndex;
  454. }
  455. iWScount += ai.iWScount;
  456. }
  457. if (ai == null) {
  458. return;
  459. }
  460. // Calculate total adjustment
  461. int iAdjust = 0;
  462. double dSpaceAdjust = context.getSpaceAdjust();
  463. if (dSpaceAdjust > 0.0) {
  464. // Stretch by factor
  465. // System.err.println("Potential stretch = " +
  466. // (ai.ipdArea.max - ai.ipdArea.opt));
  467. iAdjust = (int)((double)(ai.ipdArea.max
  468. - ai.ipdArea.opt) * dSpaceAdjust);
  469. } else if (dSpaceAdjust < 0.0) {
  470. // Shrink by factor
  471. // System.err.println("Potential shrink = " +
  472. // (ai.ipdArea.opt - ai.ipdArea.min));
  473. iAdjust = (int)((double)(ai.ipdArea.opt
  474. - ai.ipdArea.min) * dSpaceAdjust);
  475. }
  476. // System.err.println("Text adjustment factor = " + dSpaceAdjust +
  477. // " total=" + iAdjust);
  478. // Make an area containing all characters between start and end.
  479. InlineArea word = null;
  480. int adjust = 0;
  481. // ingnore newline character
  482. if (chars[ai.iBreakIndex - 1] == NEWLINE) {
  483. adjust = 1;
  484. }
  485. String str = new String(chars, iStart, ai.iBreakIndex - iStart - adjust);
  486. if (" ".equals(str)) {
  487. word = new Space();
  488. word.setWidth(ai.ipdArea.opt + iAdjust);
  489. } else {
  490. Word w = createWord(
  491. str,
  492. ai.ipdArea.opt + iAdjust, context.getBaseline());
  493. if (iWScount > 0) {
  494. //getLogger().error("Adjustment per word-space= " +
  495. // iAdjust / iWScount);
  496. w.setWSadjust(iAdjust / iWScount);
  497. }
  498. word = w;
  499. }
  500. if ((chars[iStart] == SPACE || chars[iStart] == NBSPACE)
  501. && context.getLeadingSpace().hasSpaces()) {
  502. context.getLeadingSpace().addSpace(halfWS);
  503. }
  504. // Set LAST flag if done making characters
  505. int iLastChar;
  506. for (iLastChar = ai.iBreakIndex;
  507. iLastChar < chars.length && chars[iLastChar] == SPACE;
  508. iLastChar++) {
  509. //nop
  510. }
  511. context.setFlags(LayoutContext.LAST_AREA,
  512. iLastChar == chars.length);
  513. // Can we have any trailing space? Yes, if last char was a space!
  514. context.setTrailingSpace(new SpaceSpecifier(false));
  515. if (chars[ai.iBreakIndex - 1] == SPACE
  516. || chars[ai.iBreakIndex - 1] == NBSPACE) {
  517. context.getTrailingSpace().addSpace(halfWS);
  518. }
  519. if (word != null) {
  520. parentLM.addChild(word);
  521. }
  522. }
  523. /**
  524. * Create an inline word area.
  525. * This creates a Word and sets up the various attributes.
  526. *
  527. * @param str the string for the word
  528. * @param width the width that the word uses
  529. * @param base the baseline position
  530. * @return the new word area
  531. */
  532. protected Word createWord(String str, int width, int base) {
  533. Word curWordArea = new Word();
  534. curWordArea.setWidth(width);
  535. curWordArea.setHeight(textInfo.fs.getAscender()
  536. - textInfo.fs.getDescender());
  537. curWordArea.setOffset(textInfo.fs.getAscender());
  538. curWordArea.setOffset(base);
  539. curWordArea.setWord(str);
  540. curWordArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
  541. curWordArea.addTrait(Trait.FONT_SIZE,
  542. new Integer(textInfo.fs.getFontSize()));
  543. curWordArea.addTrait(Trait.COLOR, this.textInfo.color);
  544. return curWordArea;
  545. }
  546. }