AlbiteFont font;
HyphenatedTextRegion lastHyphenatedWord;
boolean startsNewParagraph;
TextParser parser = ip.parser;
int wordPixelWidth; //word width in pixels
Vector wordsOnThisLine = new Vector(20); //RegionTexts
boolean firstWord;
int posX = 0;
int posY = 0;
Vector regionsTemp;
if (images.isEmpty()) {
//text mode
regionsTemp = new Vector(300);
parser.position = end = start = ip.position;
parser.length = ip.length;
bufferSize = buffer.length;
style = ip.style;
center = ip.center;
lastHyphenatedWord = ip.lastHyphenatedWord;
startsNewParagraph = ip.startsNewParagraph;
} else {
//image mode
ImageRegion ri = (ImageRegion) images.firstElement();
images.removeElementAt(0);
imageRegion = ri;
regionsTemp = new Vector(40);
posY = 0;
bufferSize = ri.altTextBufferPosition + ri.altTextBufferLength;
parser.position = end = start = ri.altTextBufferPosition;
parser.length = 0;
style = ITALIC;
center = true;
lastHyphenatedWord = null;
startsNewParagraph = true;
}
/*
* Setup font & color, based on style value from previous page.
*/
font = chooseFont(fontPlain, fontItalic, style);
color = chooseTextColor(style);
boolean lastLine = false;
boolean firstLine = true;
boolean lineBreak = false;
page:
while (true) {
/*
* There is no more space for new lines,
* so the page is done.
*/
if (posY >= height - fontHeight) {
break;
}
/*
* Check if it is the last line of the page
*/
if (posY >= height - (fontHeightX2)) {
lastLine = true;
}
/*
* NB: posX & posY are in pixels, pos is in chars.
*/
posX = 0;
firstWord = true;
/*
* Clear the cache that will hold all the elements on the line
*/
wordsOnThisLine.removeAllElements();
/*
* Indent the line, if it starts a new paragraph.
*/
if (startsNewParagraph) {
posX = fontIndent;
}
line:
while (true) {
/*
* Parse on
*/
if (!parser.parseNext(buffer, bufferSize)) {
//#ifdef DEBUG_PARSER
//# AlbiteMIDlet.LOGGER.log("parser done");
//#endif
/* No more chars to read */