}
return sum;
}
private void generate(ListIterator iter) {
MinOptMax noBreakLength = new MinOptMax();
MinOptMax glue1; //space before break possibility if break occurs
//MinOptMax glue2; //difference between glue 1 and 3 when no break occurs
MinOptMax glue3; //space after break possibility if break occurs
glue1 = sum(firstPartLengths);
glue3 = sum(secondPartLengths);
noBreakLength = sum(noBreakLengths);
//This doesn't produce the right glue2
//glue2 = new MinOptMax(noBreakLength);
//glue2.subtract(glue1);
//glue2.subtract(glue3);
int glue2w = noBreakLength.opt - glue1.opt - glue3.opt;
int glue2stretch = (noBreakLength.max - noBreakLength.opt);
int glue2shrink = (noBreakLength.opt - noBreakLength.min);
glue2stretch -= glue1.max - glue1.opt;
glue2stretch -= glue3.max - glue3.opt;
glue2shrink -= glue1.opt - glue1.min;
glue2shrink -= glue3.opt - glue3.min;
boolean hasPrecedingNonBlock = false;
if (log.isDebugEnabled()) {
log.debug("noBreakLength=" + noBreakLength
+ ", glue1=" + glue1
+ ", glue2=" + glue2w + "+" + glue2stretch + "-" + glue2shrink
+ ", glue3=" + glue3);
}
if (breakPoss != null) {
boolean forcedBreak = breakPoss.isForcedBreak();
if (glue1.isNonZero()) {
iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE,
false, (Position)null, true));
iter.add(new KnuthGlue(glue1.opt, glue1.max - glue1.opt, glue1.opt - glue1.min,
(Position)null, true));
if (forcedBreak) {
//Otherwise, the preceding penalty and glue will be cut off
iter.add(new KnuthBox(0, (Position)null, true));
}
}
iter.add(new KnuthPenalty(breakPoss.getPenaltyWidth(), breakPoss.getPenaltyValue(),
false, breakPoss.getBreakClass(),
new SpaceHandlingBreakPosition(this, breakPoss), false));
if (breakPoss.getPenaltyValue() <= -KnuthPenalty.INFINITE) {
return; //return early. Not necessary (even wrong) to add additional elements
}
if (glue2w != 0 || glue2stretch != 0 || glue2shrink != 0) {
iter.add(new KnuthGlue(glue2w, glue2stretch, glue2shrink,
(Position)null, true));
}
} else {
if (glue1.isNonZero()) {
throw new IllegalStateException("glue1 should be 0 in this case");
}
}
Position pos = null;
if (breakPoss == null) {
pos = new SpaceHandlingPosition(this);
}
if (glue3.isNonZero() || pos != null) {
iter.add(new KnuthBox(0, pos, true));
}
if (glue3.isNonZero()) {
iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE,
false, (Position)null, true));
iter.add(new KnuthGlue(glue3.opt, glue3.max - glue3.opt, glue3.opt - glue3.min,
(Position)null, true));
hasPrecedingNonBlock = true;