* @return the new text area
*/
protected TextArea createTextArea(MinOptMax width, int adjust,
LayoutContext context, int spaceDiff,
int firstIndex, int lastIndex, boolean isLastArea) {
TextArea textArea;
if (context.getIPDAdjust() == 0.0) {
// create just a TextArea
textArea = new TextArea();
} else {
// justified area: create a TextArea with extra info
// about potential adjustments
textArea = new TextArea(width.max - width.opt,
width.opt - width.min,
adjust);
}
textArea.setIPD(width.opt + adjust);
textArea.setBPD(font.getAscender() - font.getDescender());
textArea.setBaselineOffset(font.getAscender());
if (textArea.getBPD() == alignmentContext.getHeight()) {
textArea.setOffset(0);
} else {
textArea.setOffset(alignmentContext.getOffset());
}
// set the text of the TextArea, split into words and spaces
int wordStartIndex = -1;
AreaInfo areaInfo;
for (int i = firstIndex; i <= lastIndex; i ++) {
areaInfo = (AreaInfo) vecAreaInfo.get(i);
if (areaInfo.iWScount > 0) {
// areaInfo stores information about a space
// add a space to the TextArea
char spaceChar = textArray[areaInfo.iStartIndex];
textArea.addSpace(spaceChar, 0,
CharUtilities.isAdjustableSpace(spaceChar));
} else {
// areaInfo stores information about a word fragment
if (wordStartIndex == -1) {
// here starts a new word
wordStartIndex = areaInfo.iStartIndex;
}
if (i == lastIndex || ((AreaInfo) vecAreaInfo.get(i + 1)).iWScount > 0) {
// here ends a new word
// add a word to the TextArea
String wordChars = new String(textArray, wordStartIndex, areaInfo.iBreakIndex - wordStartIndex);
if (isLastArea
&& i == lastIndex
&& areaInfo.bHyphenated) {
// add the hyphenation character
wordChars += foText.getCommonHyphenation().hyphenationCharacter;
}
textArea.addWord(wordChars, 0);
wordStartIndex = -1;
}
}
}
textArea.addTrait(Trait.FONT_NAME, font.getFontName());
textArea.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
textArea.addTrait(Trait.COLOR, foText.getColor());
TraitSetter.addTextDecoration(textArea, foText.getTextDecoration());
return textArea;
}