* @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;
int len = 0;
for (int i = firstIndex; i <= lastIndex; i++) {
areaInfo = (AreaInfo) vecAreaInfo.get(i);
if (areaInfo.isSpace) {
// areaInfo stores information about spaces
// add the spaces - except zero-width spaces - to the TextArea
for (int j = areaInfo.iStartIndex; j < areaInfo.iBreakIndex; j++) {
char spaceChar = textArray[j];
if (!CharUtilities.isZeroWidthSpace(spaceChar)) {
textArea.addSpace(spaceChar, 0,
CharUtilities.isAdjustableSpace(spaceChar));
}
}
} else {
// areaInfo stores information about a word fragment
if (wordStartIndex == -1) {
// here starts a new word
wordStartIndex = i;
len = 0;
}
len += areaInfo.iBreakIndex - areaInfo.iStartIndex;
if (i == lastIndex || ((AreaInfo) vecAreaInfo.get(i + 1)).isSpace) {
// here ends a new word
// add a word to the TextArea
if (isLastArea
&& i == lastIndex
&& areaInfo.bHyphenated) {
len++;
}
StringBuffer wordChars = new StringBuffer(len);
int[] letterAdjust = new int[len];
int letter = 0;
for (int j = wordStartIndex; j <= i; j++) {
AreaInfo ai = (AreaInfo) vecAreaInfo.get(j);
int lsCount = ai.iLScount;
wordChars.append(textArray, ai.iStartIndex, ai.iBreakIndex - ai.iStartIndex);
for (int k = 0; k < ai.iBreakIndex - ai.iStartIndex; k++) {
MinOptMax adj = letterAdjustArray[ai.iStartIndex + k];
if (letter > 0) {
letterAdjust[letter] = (adj != null ? adj.opt : 0);
}
if (lsCount > 0) {
letterAdjust[letter] += textArea.getTextLetterSpaceAdjust();
lsCount--;
}
letter++;
}
}
// String wordChars = new String(textArray, wordStartIndex, len);
if (isLastArea
&& i == lastIndex
&& areaInfo.bHyphenated) {
// add the hyphenation character
wordChars.append(foText.getCommonHyphenation().hyphenationCharacter);
}
textArea.addWord(wordChars.toString(), 0, letterAdjust);
wordStartIndex = -1;
}
}
}
TraitSetter.addFontTraits(textArea, font);
textArea.addTrait(Trait.COLOR, foText.getColor());
TraitSetter.addTextDecoration(textArea, foText.getTextDecoration());
return textArea;
}