From 1f5a254a57c081e092d8ff009a28e5975be71618 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Tue, 29 Mar 2016 11:17:23 +0000 Subject: [PATCH] FOP-2596: NPE with changing ipd git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1736999 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/layoutmgr/AbstractBreaker.java | 27 +++++--- .../flow_changing-ipd_last-page_11.xml | 62 +++++++++++++++++++ 2 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 fop/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_11.xml diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java index d0594ce8a..cc598ff88 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java @@ -464,15 +464,7 @@ public abstract class AbstractBreaker { if (onLastPageAndIPDChanges && visitedBefore && this.originalRestartAtLM == null) { optimalBreak = null; } - - int positionIndex = (optimalBreak != null) ? optimalBreak.position : start; - KnuthElement elementAtBreak = alg.getElement(positionIndex); - if (elementAtBreak.getPosition() == null) { - elementAtBreak = alg.getElement(0); - } - positionAtBreak = elementAtBreak.getPosition(); - /* Retrieve the original position wrapped into this space position */ - positionAtBreak = positionAtBreak.getPosition(); + int positionIndex = findPositionIndex(optimalBreak, alg, start); if (ipdChangesOnNextPage || (positionAtBreak != null && positionAtBreak.getIndex() > -1)) { firstElementsForRestart = Collections.EMPTY_LIST; if (ipdChangesOnNextPage) { @@ -542,6 +534,23 @@ public abstract class AbstractBreaker { return restartAtLM; } + private int findPositionIndex(KnuthNode optimalBreak, PageBreakingAlgorithm alg, int start) { + int positionIndex = (optimalBreak != null) ? optimalBreak.position : start; + for (int i = positionIndex; i < alg.par.size(); i++) { + KnuthElement elementAtBreak = alg.getElement(i); + if (elementAtBreak.getPosition() == null) { + elementAtBreak = alg.getElement(0); + } + positionAtBreak = elementAtBreak.getPosition(); + /* Retrieve the original position wrapped into this space position */ + positionAtBreak = positionAtBreak.getPosition(); + if (positionAtBreak != null) { + return i; + } + } + return positionIndex; + } + /** * Returns {@code true} if the given position or one of its descendants * corresponds to a non-restartable LM. diff --git a/fop/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_11.xml b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_11.xml new file mode 100644 index 000000000..e4941542e --- /dev/null +++ b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_last-page_11.xml @@ -0,0 +1,62 @@ + + + + + +

+ This test checks that the definition of a special page-master for the last page with a + different width that the previous "rest" page causes FOP to redo the line breaking layout. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + test + + + + + + + + + + +
-- 2.39.5