Lines 155-161
Link Here
|
155 |
private final int follow; |
155 |
private final int follow; |
156 |
private AlignmentContext alignmentContext; |
156 |
private AlignmentContext alignmentContext; |
157 |
|
157 |
|
158 |
private List knuthParagraphs; |
158 |
private List<KnuthSequence> knuthParagraphs; |
159 |
|
159 |
|
160 |
private LineLayoutPossibilities lineLayouts; |
160 |
private LineLayoutPossibilities lineLayouts; |
161 |
private LineLayoutPossibilities[] lineLayoutsList; |
161 |
private LineLayoutPossibilities[] lineLayoutsList; |
Lines 400-406
Link Here
|
400 |
// true if this line contains only zero-height, auxiliary boxes |
400 |
// true if this line contains only zero-height, auxiliary boxes |
401 |
// and the actual line width is 0; in this case, the line "collapses" |
401 |
// and the actual line width is 0; in this case, the line "collapses" |
402 |
// i.e. the line area will have bpd = 0 |
402 |
// i.e. the line area will have bpd = 0 |
403 |
boolean bZeroHeightLine = (difference == ipd); |
403 |
boolean isZeroHeightLine = (difference == ipd); |
404 |
|
404 |
|
405 |
// if line-stacking-strategy is "font-height", the line height |
405 |
// if line-stacking-strategy is "font-height", the line height |
406 |
// is not affected by its content |
406 |
// is not affected by its content |
Lines 436-444
Link Here
|
436 |
} |
436 |
} |
437 |
lastAC = ac; |
437 |
lastAC = ac; |
438 |
} |
438 |
} |
439 |
if (bZeroHeightLine |
439 |
if (isZeroHeightLine |
440 |
&& (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) { |
440 |
&& (!element.isAuxiliary() || ac != null && ac.getHeight() > 0)) { |
441 |
bZeroHeightLine = false; |
441 |
isZeroHeightLine = false; |
442 |
} |
442 |
} |
443 |
} |
443 |
} |
444 |
} |
444 |
} |
Lines 450-456
Link Here
|
450 |
|
450 |
|
451 |
constantLineHeight = lineLead + lineFollow; |
451 |
constantLineHeight = lineLead + lineFollow; |
452 |
|
452 |
|
453 |
if (bZeroHeightLine) { |
453 |
if (isZeroHeightLine) { |
454 |
return new LineBreakPosition(thisLLM, |
454 |
return new LineBreakPosition(thisLLM, |
455 |
knuthParagraphs.indexOf(par), |
455 |
knuthParagraphs.indexOf(par), |
456 |
firstElementIndex, lastElementIndex, |
456 |
firstElementIndex, lastElementIndex, |
Lines 580-586
Link Here
|
580 |
//PHASE 1: Create Knuth elements |
580 |
//PHASE 1: Create Knuth elements |
581 |
if (knuthParagraphs == null) { |
581 |
if (knuthParagraphs == null) { |
582 |
// it's the first time this method is called |
582 |
// it's the first time this method is called |
583 |
knuthParagraphs = new ArrayList(); |
583 |
knuthParagraphs = new ArrayList<KnuthSequence>(); |
584 |
|
584 |
|
585 |
// here starts Knuth's algorithm |
585 |
// here starts Knuth's algorithm |
586 |
collectInlineKnuthElements(context); |
586 |
collectInlineKnuthElements(context); |
Lines 612-623
Link Here
|
612 |
LeafPosition restartPosition) { |
612 |
LeafPosition restartPosition) { |
613 |
log.trace("Restarting line breaking from index " + restartPosition.getIndex()); |
613 |
log.trace("Restarting line breaking from index " + restartPosition.getIndex()); |
614 |
int parIndex = restartPosition.getLeafPos(); |
614 |
int parIndex = restartPosition.getLeafPos(); |
615 |
Paragraph paragraph = (Paragraph) knuthParagraphs.get(parIndex); |
615 |
KnuthSequence paragraph = knuthParagraphs.get(parIndex); |
616 |
for (int i = 0; i <= restartPosition.getIndex(); i++) { |
616 |
paragraph.subList(0, restartPosition.getIndex()).clear(); |
617 |
paragraph.remove(0); |
617 |
Iterator<KnuthElement> iter = paragraph.iterator(); |
618 |
} |
618 |
while (iter.hasNext() && !iter.next().isBox()) { |
619 |
Iterator iter = paragraph.iterator(); |
|
|
620 |
while (iter.hasNext() && !((KnuthElement) iter.next()).isBox()) { |
621 |
iter.remove(); |
619 |
iter.remove(); |
622 |
} |
620 |
} |
623 |
if (!iter.hasNext()) { |
621 |
if (!iter.hasNext()) { |
Lines 650-657
Link Here
|
650 |
|
648 |
|
651 |
Paragraph lastPar = null; |
649 |
Paragraph lastPar = null; |
652 |
|
650 |
|
653 |
InlineLevelLayoutManager curLM; |
651 |
InlineLevelLayoutManager curLM = (InlineLevelLayoutManager) getChildLM(); |
654 |
while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) { |
652 |
while (curLM != null) { |
655 |
List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment); |
653 |
List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment); |
656 |
if (inlineElements == null || inlineElements.size() == 0) { |
654 |
if (inlineElements == null || inlineElements.size() == 0) { |
657 |
/* curLM.getNextKnuthElements() returned null or an empty list; |
655 |
/* curLM.getNextKnuthElements() returned null or an empty list; |
Lines 748-754
Link Here
|
748 |
} |
746 |
} |
749 |
} |
747 |
} |
750 |
} // end of loop over returnedList |
748 |
} // end of loop over returnedList |
|
|
749 |
curLM = (InlineLevelLayoutManager) getChildLM(); |
751 |
} |
750 |
} |
|
|
751 |
|
752 |
if (lastPar != null) { |
752 |
if (lastPar != null) { |
753 |
lastPar.endParagraph(); |
753 |
lastPar.endParagraph(); |
754 |
ElementListObserver.observe(lastPar, "line", fobj.getId()); |
754 |
ElementListObserver.observe(lastPar, "line", fobj.getId()); |
Lines 765-777
Link Here
|
765 |
* @param context the layout context |
765 |
* @param context the layout context |
766 |
* @return a list of Knuth elements representing broken lines |
766 |
* @return a list of Knuth elements representing broken lines |
767 |
*/ |
767 |
*/ |
768 |
private List createLineBreaks(int alignment, LayoutContext context) { |
768 |
private List<ListElement> createLineBreaks(int alignment, LayoutContext context) { |
769 |
// find the optimal line breaking points for each paragraph |
769 |
// find the optimal line breaking points for each paragraph |
770 |
Iterator paragraphsIterator = knuthParagraphs.iterator(); |
770 |
Iterator<KnuthSequence> paragraphsIterator = knuthParagraphs.iterator(); |
771 |
lineLayoutsList = new LineLayoutPossibilities[knuthParagraphs.size()]; |
771 |
lineLayoutsList = new LineLayoutPossibilities[knuthParagraphs.size()]; |
772 |
LineLayoutPossibilities llPoss; |
772 |
LineLayoutPossibilities llPoss; |
773 |
for (int i = 0; paragraphsIterator.hasNext(); i++) { |
773 |
for (int i = 0; paragraphsIterator.hasNext(); i++) { |
774 |
KnuthSequence seq = (KnuthSequence) paragraphsIterator.next(); |
774 |
KnuthSequence seq = paragraphsIterator.next(); |
775 |
if (!seq.isInlineSequence()) { |
775 |
if (!seq.isInlineSequence()) { |
776 |
// This set of line layout possibilities does not matter; |
776 |
// This set of line layout possibilities does not matter; |
777 |
// we only need an entry in lineLayoutsList. |
777 |
// we only need an entry in lineLayoutsList. |
Lines 807-813
Link Here
|
807 |
lineHeight.getValue(this), lead, follow, |
807 |
lineHeight.getValue(this), lead, follow, |
808 |
(knuthParagraphs.indexOf(currPar) == 0), |
808 |
(knuthParagraphs.indexOf(currPar) == 0), |
809 |
hyphenationLadderCount.getEnum() == EN_NO_LIMIT |
809 |
hyphenationLadderCount.getEnum() == EN_NO_LIMIT |
810 |
? 0 : hyphenationLadderCount.getValue(), |
810 |
? 0 : hyphenationLadderCount.getValue(), |
811 |
this); |
811 |
this); |
812 |
alg.setConstantLineWidth(ipd); |
812 |
alg.setConstantLineWidth(ipd); |
813 |
boolean canWrap = (wrapOption != EN_NO_WRAP); |
813 |
boolean canWrap = (wrapOption != EN_NO_WRAP); |
Lines 873-884
Link Here
|
873 |
* @param context the layout context |
873 |
* @param context the layout context |
874 |
* @return the newly built element list |
874 |
* @return the newly built element list |
875 |
*/ |
875 |
*/ |
876 |
private List postProcessLineBreaks(int alignment, LayoutContext context) { |
876 |
private List<ListElement> postProcessLineBreaks(int alignment, LayoutContext context) { |
877 |
|
877 |
|
878 |
List<ListElement> returnList = new LinkedList<ListElement>(); |
878 |
List<ListElement> returnList = new LinkedList<ListElement>(); |
879 |
|
879 |
|
880 |
int endIndex = -1; |
880 |
int endIndex = -1; |
881 |
for (int p = 0; p < knuthParagraphs.size(); p++) { |
881 |
for (int p = 0; p < knuthParagraphs.size(); p++) { |
|
|
882 |
|
883 |
KnuthSequence seq = knuthParagraphs.get(p); |
884 |
LineLayoutPossibilities llPoss = lineLayoutsList[p]; |
882 |
// penalty between paragraphs |
885 |
// penalty between paragraphs |
883 |
if (p > 0) { |
886 |
if (p > 0) { |
884 |
Keep keep = getKeepTogether(); |
887 |
Keep keep = getKeepTogether(); |
Lines 889-897
Link Here
|
889 |
context)); |
892 |
context)); |
890 |
} |
893 |
} |
891 |
|
894 |
|
892 |
LineLayoutPossibilities llPoss = lineLayoutsList[p]; |
|
|
893 |
KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(p); |
894 |
|
895 |
if (!seq.isInlineSequence()) { |
895 |
if (!seq.isInlineSequence()) { |
896 |
List<ListElement> targetList = new LinkedList<ListElement>(); |
896 |
List<ListElement> targetList = new LinkedList<ListElement>(); |
897 |
ListIterator listIter = seq.listIterator(); |
897 |
ListIterator listIter = seq.listIterator(); |
Lines 918-927
Link Here
|
918 |
for (int i = 0; |
918 |
for (int i = 0; |
919 |
i < llPoss.getChosenLineCount(); |
919 |
i < llPoss.getChosenLineCount(); |
920 |
i++) { |
920 |
i++) { |
921 |
if (returnList.size() > 0 |
921 |
if (returnList.size() > 0 && i > 0) { |
922 |
&& i > 0 //if i==0 break generated above already |
|
|
923 |
&& i >= fobj.getOrphans() |
924 |
&& i <= llPoss.getChosenLineCount() - fobj.getWidows()) { |
925 |
// penalty allowing a page break between lines |
922 |
// penalty allowing a page break between lines |
926 |
Keep keep = getKeepTogether(); |
923 |
Keep keep = getKeepTogether(); |
927 |
returnList.add(new BreakElement( |
924 |
returnList.add(new BreakElement( |
Lines 1149-1155
Link Here
|
1149 |
|
1146 |
|
1150 |
/** {@inheritDoc} */ |
1147 |
/** {@inheritDoc} */ |
1151 |
public List getChangedKnuthElements(List oldList, int alignment) { |
1148 |
public List getChangedKnuthElements(List oldList, int alignment) { |
1152 |
List returnList = new LinkedList(); |
1149 |
List<KnuthElement> returnList = new LinkedList<KnuthElement>(); |
1153 |
for (int p = 0; p < knuthParagraphs.size(); p++) { |
1150 |
for (int p = 0; p < knuthParagraphs.size(); p++) { |
1154 |
LineLayoutPossibilities llPoss = lineLayoutsList[p]; |
1151 |
LineLayoutPossibilities llPoss = lineLayoutsList[p]; |
1155 |
//log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits()); |
1152 |
//log.debug("demerits of the chosen layout: " + llPoss.getChosenDemerits()); |
Lines 1392-1398
Link Here
|
1392 |
public void addAreas(PositionIterator parentIter, |
1389 |
public void addAreas(PositionIterator parentIter, |
1393 |
LayoutContext context) { |
1390 |
LayoutContext context) { |
1394 |
while (parentIter.hasNext()) { |
1391 |
while (parentIter.hasNext()) { |
1395 |
Position pos = (Position) parentIter.next(); |
1392 |
Position pos = parentIter.next(); |
1396 |
boolean isLastPosition = !parentIter.hasNext(); |
1393 |
boolean isLastPosition = !parentIter.hasNext(); |
1397 |
if (pos instanceof LineBreakPosition) { |
1394 |
if (pos instanceof LineBreakPosition) { |
1398 |
addInlineArea(context, (LineBreakPosition) pos, isLastPosition); |
1395 |
addInlineArea(context, (LineBreakPosition) pos, isLastPosition); |
Lines 1426-1437
Link Here
|
1426 |
(lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast), |
1423 |
(lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast), |
1427 |
lbp.difference, lbp.availableStretch, lbp.availableShrink); |
1424 |
lbp.difference, lbp.availableStretch, lbp.availableShrink); |
1428 |
if (lbp.startIndent != 0) { |
1425 |
if (lbp.startIndent != 0) { |
1429 |
lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent)); |
1426 |
lineArea.addTrait(Trait.START_INDENT, lbp.startIndent); |
1430 |
} |
1427 |
} |
1431 |
lineArea.setBPD(lbp.lineHeight); |
1428 |
lineArea.setBPD(lbp.lineHeight); |
1432 |
lineArea.setIPD(lbp.lineWidth); |
1429 |
lineArea.setIPD(lbp.lineWidth); |
1433 |
lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore)); |
1430 |
lineArea.addTrait(Trait.SPACE_BEFORE, lbp.spaceBefore); |
1434 |
lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter)); |
1431 |
lineArea.addTrait(Trait.SPACE_AFTER, lbp.spaceAfter); |
1435 |
alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline); |
1432 |
alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline); |
1436 |
|
1433 |
|
1437 |
if (seq instanceof Paragraph) { |
1434 |
if (seq instanceof Paragraph) { |