Lines 22-27
Link Here
|
22 |
import org.apache.commons.logging.Log; |
22 |
import org.apache.commons.logging.Log; |
23 |
import org.apache.commons.logging.LogFactory; |
23 |
import org.apache.commons.logging.LogFactory; |
24 |
|
24 |
|
|
|
25 |
import org.apache.fop.fo.Constants; |
25 |
import org.apache.fop.fo.FONode; |
26 |
import org.apache.fop.fo.FONode; |
26 |
|
27 |
|
27 |
/** |
28 |
/** |
Lines 448-453
Link Here
|
448 |
|
449 |
|
449 |
if (log.isTraceEnabled()) { |
450 |
if (log.isTraceEnabled()) { |
450 |
log.trace("Looping over " + (par.size() - startIndex) + " elements"); |
451 |
log.trace("Looping over " + (par.size() - startIndex) + " elements"); |
|
|
452 |
log.trace(par); |
451 |
} |
453 |
} |
452 |
|
454 |
|
453 |
KnuthNode lastForced = getNode(0); |
455 |
KnuthNode lastForced = getNode(0); |
Lines 477-487
Link Here
|
477 |
// only if its penalty is not infinite; |
479 |
// only if its penalty is not infinite; |
478 |
// consider all penalties, non-flagged penalties or non-forcing penalties |
480 |
// consider all penalties, non-flagged penalties or non-forcing penalties |
479 |
// according to the value of allowedBreaks |
481 |
// according to the value of allowedBreaks |
480 |
if (((KnuthPenalty) thisElement).getP() < KnuthElement.INFINITE |
482 |
KnuthPenalty p = (KnuthPenalty) thisElement; |
481 |
&& (!(allowedBreaks == NO_FLAGGED_PENALTIES) |
483 |
if (((p.getP() < KnuthElement.INFINITE || p.getBreakClass() != Constants.EN_LINE) |
482 |
|| !(((KnuthPenalty) thisElement).isFlagged())) |
484 |
&& (!(allowedBreaks == NO_FLAGGED_PENALTIES) || !p.isFlagged()) |
483 |
&& (!(allowedBreaks == ONLY_FORCED_BREAKS) |
485 |
&& (!(allowedBreaks == ONLY_FORCED_BREAKS) |
484 |
|| ((KnuthPenalty) thisElement).getP() == -KnuthElement.INFINITE)) { |
486 |
|| p.isForcedBreak()))) { |
485 |
considerLegalBreak(thisElement, i); |
487 |
considerLegalBreak(thisElement, i); |
486 |
} |
488 |
} |
487 |
previousIsBox = false; |
489 |
previousIsBox = false; |
Lines 495-507
Link Here
|
495 |
// were "bad" breaks since the beginning; |
497 |
// were "bad" breaks since the beginning; |
496 |
// if it is not the node we just restarted from, lastDeactivated can |
498 |
// if it is not the node we just restarted from, lastDeactivated can |
497 |
// replace either lastTooShort or lastTooLong |
499 |
// replace either lastTooShort or lastTooLong |
498 |
if (lastDeactivated != null && lastDeactivated != lastForced) { |
500 |
// TODO re-enable and make it work with keep.within-column |
499 |
if (lastDeactivated.adjustRatio > 0) { |
501 |
// if (lastDeactivated != null && lastDeactivated != lastForced) { |
500 |
lastTooShort = lastDeactivated; |
502 |
// if (lastDeactivated.adjustRatio > 0) { |
501 |
} else { |
503 |
// lastTooShort = lastDeactivated; |
502 |
lastTooLong = lastDeactivated; |
504 |
// } else { |
503 |
} |
505 |
// lastTooLong = lastDeactivated; |
504 |
} |
506 |
// } |
|
|
507 |
// } |
505 |
if (lastTooShort == null || lastForced.position == lastTooShort.position) { |
508 |
if (lastTooShort == null || lastForced.position == lastTooShort.position) { |
506 |
if (isPartOverflowRecoveryActivated()) { |
509 |
if (isPartOverflowRecoveryActivated()) { |
507 |
if (this.lastRecovered == null) { |
510 |
if (this.lastRecovered == null) { |
Lines 510-521
Link Here
|
510 |
log.debug("Recovery point: " + lastRecovered); |
513 |
log.debug("Recovery point: " + lastRecovered); |
511 |
} |
514 |
} |
512 |
} |
515 |
} |
513 |
// content would overflow, insert empty line/page and try again |
516 |
KnuthNode node = recoverFromTooLong(lastTooLong); |
514 |
KnuthNode node = createNode( |
|
|
515 |
lastTooLong.previous.position, lastTooLong.previous.line + 1, 1, |
516 |
0, 0, 0, |
517 |
0, 0, 0, |
518 |
0, 0, lastTooLong.previous); |
519 |
lastForced = node; |
517 |
lastForced = node; |
520 |
node.fitRecoveryCounter = lastTooLong.previous.fitRecoveryCounter + 1; |
518 |
node.fitRecoveryCounter = lastTooLong.previous.fitRecoveryCounter + 1; |
521 |
if (log.isDebugEnabled()) { |
519 |
if (log.isDebugEnabled()) { |
Lines 571-576
Link Here
|
571 |
return line; |
569 |
return line; |
572 |
} |
570 |
} |
573 |
|
571 |
|
|
|
572 |
protected KnuthNode recoverFromTooLong(KnuthNode lastTooLong) { |
573 |
// content would overflow, insert empty line/page and try again |
574 |
KnuthNode node = createNode( |
575 |
lastTooLong.previous.position, lastTooLong.previous.line + 1, 1, |
576 |
0, 0, 0, |
577 |
0, 0, 0, |
578 |
0, 0, lastTooLong.previous); |
579 |
return node; |
580 |
} |
581 |
|
574 |
/** |
582 |
/** |
575 |
* This method tries to find the context FO for a position in a KnuthSequence. |
583 |
* This method tries to find the context FO for a position in a KnuthSequence. |
576 |
* @param seq the KnuthSequence to inspect |
584 |
* @param seq the KnuthSequence to inspect |
Lines 689-694
Link Here
|
689 |
lastDeactivated = null; |
697 |
lastDeactivated = null; |
690 |
lastTooLong = null; |
698 |
lastTooLong = null; |
691 |
for (int line = startLine; line < endLine; line++) { |
699 |
for (int line = startLine; line < endLine; line++) { |
|
|
700 |
if (!elementCanEndLine(element, line + 1)) { |
701 |
continue; |
702 |
} |
692 |
for (KnuthNode node = getNode(line); node != null; node = node.next) { |
703 |
for (KnuthNode node = getNode(line); node != null; node = node.next) { |
693 |
if (node.position == elementIdx) { |
704 |
if (node.position == elementIdx) { |
694 |
continue; |
705 |
continue; |
Lines 759-764
Link Here
|
759 |
} |
770 |
} |
760 |
|
771 |
|
761 |
if (r <= -1) { |
772 |
if (r <= -1) { |
|
|
773 |
log.debug("Considering tooLong, demerits=" + demerits); |
762 |
if (lastTooLong == null || demerits < lastTooLong.totalDemerits) { |
774 |
if (lastTooLong == null || demerits < lastTooLong.totalDemerits) { |
763 |
lastTooLong = createNode(elementIdx, line + 1, fitnessClass, |
775 |
lastTooLong = createNode(elementIdx, line + 1, fitnessClass, |
764 |
newWidth, newStretch, newShrink, |
776 |
newWidth, newStretch, newShrink, |
Lines 791-796
Link Here
|
791 |
} |
803 |
} |
792 |
} |
804 |
} |
793 |
|
805 |
|
|
|
806 |
protected boolean elementCanEndLine(KnuthElement element, int line) { |
807 |
return !(element instanceof KnuthPenalty) |
808 |
|| ((KnuthPenalty) element).getP() < KnuthPenalty.INFINITE; |
809 |
} |
810 |
|
794 |
/** |
811 |
/** |
795 |
* Adds new active nodes for breaks at the given element. |
812 |
* Adds new active nodes for breaks at the given element. |
796 |
* @param line number of the previous line; this element will end line number (line+1) |
813 |
* @param line number of the previous line; this element will end line number (line+1) |