Iterator iter = layouts.iterator();
while (iter.hasNext()) {
GlyphLayout gl = (GlyphLayout)iter.next();
gvl.add(gl.getGlyphVector());
}
GVTGlyphVector gv = new MultiGlyphVector(gvl);
gvs[chunk] = gv;
wordInfos[chunk] = doWordAnalysis(gv, aci, numWords, frc);
aci.first();
BlockInfo bi = (BlockInfo)aci.getAttribute(FLOW_PARAGRAPH);
bi.initLineInfo(frc);
blockInfos[chunk] = bi;
if (prevBotMargin > bi.getTopMargin())
topSkip[chunk] = prevBotMargin;
else
topSkip[chunk] = bi.getTopMargin();
prevBotMargin = bi.getBottomMargin();
numWords += wordInfos[chunk].length;
}
Iterator frIter = flowRects.iterator();
RegionInfo currentRegion = null;
int currWord = 0;
int chunk = 0;
List lineInfos = new LinkedList();
while(frIter.hasNext()) {
currentRegion = (RegionInfo) frIter.next();
FlowRegions fr = new FlowRegions(currentRegion.getShape());
while (chunk < wordInfos.length) {
WordInfo [] chunkInfo = wordInfos[chunk];
BlockInfo bi = blockInfos[chunk];
WordInfo wi = chunkInfo[currWord];
Object flowLine = wi.getFlowLine();
double lh = Math.max(wi.getLineHeight(),bi.getLineHeight());
LineInfo li = new LineInfo(fr, bi, true);
double newY = li.getCurrentY()+topSkip[chunk];
topSkip[chunk] = 0;
if (li.gotoY(newY)) break;
while (!li.addWord(wi)) {
// step down 1/10 of a line height and try again.
newY = li.getCurrentY()+lh*.1;
if (li.gotoY(newY)) break;
}
if (fr.done()) break;
currWord++;
for (;currWord < chunkInfo.length;currWord++) {
wi = chunkInfo[currWord];
if ((wi.getFlowLine() == flowLine) && (li.addWord(wi)))
continue;
// Word didn't fit or we hit end of flowLine elem,
// go to a new line.
li.layout();
lineInfos.add(li);
li = null;
flowLine = wi.getFlowLine();
lh = Math.max(wi.getLineHeight(),bi.getLineHeight());
if (!fr.newLine(lh)) break; // region is done
li = new LineInfo(fr, bi, false);
while (!li.addWord(wi)) {
newY =li.getCurrentY()+lh*.1;
if (li.gotoY(newY)) break;
}
if (fr.done()) break;
}
if (li != null) {
li.setParaEnd(true);
li.layout();
}
if (fr.done()) break;
chunk++;
currWord = 0;
if (bi.isFlowRegionBreak())
break;
if (!fr.newLine(lh)) // Region is done.
break;
}
if (chunk == wordInfos.length)
break;
}
boolean overflow = (chunk < wordInfos.length);
while (chunk < wordInfos.length) {
WordInfo [] chunkInfo = wordInfos[chunk];
while (currWord < chunkInfo.length) {
WordInfo wi = chunkInfo[currWord];
int numGG = wi.getNumGlyphGroups();
for (int gg=0; gg<numGG; gg++) {
GlyphGroupInfo ggi = wi.getGlyphGroup(gg);
GVTGlyphVector gv = ggi.getGlyphVector();
int end = ggi.getEnd();
for (int g=ggi.getStart(); g <= end; g++) {
gv.setGlyphVisible(g, false);
}
}
currWord++;
}
chunk++;