// when starting a line
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), true));
spaceElements.add(new KnuthPenalty(0, KnuthElement.INFINITE,
false, new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt, ai.ipdArea.max - ai.ipdArea.opt,
ai.ipdArea.opt - ai.ipdArea.min, mainPosition, false));
} else {
// the space does not need to stretch or shrink, and must be
// preserved when starting a line
spaceElements.add(new KnuthInlineBox(ai.ipdArea.opt, null,
mainPosition, true));
}
} else {
if (textArray[ai.iStartIndex] != CharUtilities.SPACE
|| foText.getWhitespaceTreatment() == Constants.EN_PRESERVE) {
// a breaking space that needs to be preserved
switch (alignment) {
case EN_CENTER:
// centered text:
// if the second element is chosen as a line break these elements
// add a constant amount of stretch at the end of a line and at the
// beginning of the next one, otherwise they don't add any stretch
spaceElements.add(new KnuthGlue(lineEndBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements
.add(new KnuthPenalty(
0,
0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
- (lineStartBAP + lineEndBAP), -6
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0, KnuthElement.INFINITE,
false, new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt + lineStartBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
mainPosition, false));
break;
case EN_START: // fall through
case EN_END:
// left- or right-aligned text:
// if the second element is chosen as a line break these elements
// add a constant amount of stretch at the end of a line, otherwise
// they don't add any stretch
spaceElements.add(new KnuthGlue(lineEndBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
- (lineStartBAP + lineEndBAP), -3
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt + lineStartBAP, 0, 0,
mainPosition, false));
break;
case EN_JUSTIFY:
// justified text:
// the stretch and shrink depends on the space width
spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
- (lineStartBAP + lineEndBAP), ai.ipdArea.max
- ai.ipdArea.opt, ai.ipdArea.opt - ai.ipdArea.min,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP + ai.ipdArea.opt, 0, 0,
mainPosition, false));
break;
default:
// last line justified, the other lines unjustified:
// use only the space stretch
spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
- (lineStartBAP + lineEndBAP), ai.ipdArea.max
- ai.ipdArea.opt, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP + ai.ipdArea.opt, 0, 0,
mainPosition, false));
}
} else {
// a (possible block) of breaking spaces
switch (alignment) {
case EN_CENTER:
// centered text:
// if the second element is chosen as a line break these elements
// add a constant amount of stretch at the end of a line and at the
// beginning of the next one, otherwise they don't add any stretch
spaceElements.add(new KnuthGlue(lineEndBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements
.add(new KnuthPenalty(
0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt
- (lineStartBAP + lineEndBAP), -6
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0, KnuthElement.INFINITE,
false, new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
break;
case EN_START: // fall through
case EN_END:
// left- or right-aligned text:
// if the second element is chosen as a line break these elements
// add a constant amount of stretch at the end of a line, otherwise
// they don't add any stretch
if (lineStartBAP != 0 || lineEndBAP != 0) {
spaceElements.add(new KnuthGlue(lineEndBAP,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt
- (lineStartBAP + lineEndBAP), -3
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP, 0, 0,
new LeafPosition(this, -1), false));
} else {
spaceElements.add(new KnuthGlue(0,
3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt, -3
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
mainPosition, false));
}
break;
case EN_JUSTIFY:
// justified text:
// the stretch and shrink depends on the space width
if (lineStartBAP != 0 || lineEndBAP != 0) {
spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
ai.ipdArea.opt - (lineStartBAP + lineEndBAP),
ai.ipdArea.max - ai.ipdArea.opt,
ai.ipdArea.opt - ai.ipdArea.min,
mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP, 0, 0,
new LeafPosition(this, -1), false));
} else {
spaceElements.add(new KnuthGlue(ai.ipdArea.opt,
ai.ipdArea.max - ai.ipdArea.opt,
ai.ipdArea.opt - ai.ipdArea.min,
mainPosition, false));
}
break;
default:
// last line justified, the other lines unjustified:
// use only the space stretch
if (lineStartBAP != 0 || lineEndBAP != 0) {
spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(
ai.ipdArea.opt - (lineStartBAP + lineEndBAP),
ai.ipdArea.max - ai.ipdArea.opt,
0, mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false, new LeafPosition(
this, -1), false));
spaceElements.add(new KnuthGlue(lineStartBAP, 0, 0,
new LeafPosition(this, -1), false));
} else {
spaceElements.add(new KnuthGlue(ai.ipdArea.opt,
ai.ipdArea.max - ai.ipdArea.opt, 0,
mainPosition, false));
}
}
}