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

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