From b37680209557f4dece0b25f5a4bf1594ab72194e Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 18 Apr 2014 19:34:46 +0000 Subject: [PATCH] By default, only the first child of a multi-switch should be laid out Patch by Seifeddine Dridi, applied with minor modifications git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_WhitespaceManagement@1588548 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/MultiSwitchLayoutManager.java | 19 +++-- .../fop/layoutmgr/PageBreakingAlgorithm.java | 8 +-- .../WhitespaceManagementPenalty.java | 4 +- .../standard-testcases/multi-switch_basic.xml | 61 ++++++++++++++++ ...ulti-switch_best-fit_forced_page_break.xml | 67 ++++++++++++++++++ .../multi-switch_best-fit_padding.xml | 70 +++++++++++++++++++ 6 files changed, 212 insertions(+), 17 deletions(-) create mode 100644 test/layoutengine/standard-testcases/multi-switch_basic.xml create mode 100644 test/layoutengine/standard-testcases/multi-switch_best-fit_forced_page_break.xml create mode 100644 test/layoutengine/standard-testcases/multi-switch_best-fit_padding.xml diff --git a/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java b/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java index 7c810754a..2aff34e14 100644 --- a/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java @@ -64,18 +64,15 @@ public class MultiSwitchLayoutManager extends BlockStackingLayoutManager { private class DefaultKnuthListGenerator implements KnuthElementsGenerator { public List getKnuthElement(LayoutContext context, int alignment) { - List knuthList = new LinkedList(); - LayoutManager childLM; - while ((childLM = getChildLM()) != null) { - if (!childLM.isFinished()) { - LayoutContext childLC = makeChildLayoutContext(context); - List childElements = childLM.getNextKnuthElements(childLC, alignment); - if (childElements != null) { - List newList = new LinkedList(); - wrapPositionElements(childElements, newList); - knuthList.addAll(newList); - } + LayoutManager childLM = getChildLM(); + while (!childLM.isFinished()) { + LayoutContext childLC = makeChildLayoutContext(context); + List childElements = childLM.getNextKnuthElements(childLC, alignment); + if (childElements != null) { + List newList = new LinkedList(); + wrapPositionElements(childElements, newList); + knuthList.addAll(newList); } } return knuthList; diff --git a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java index 64757854e..8b8cc4982 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java @@ -1026,10 +1026,10 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { KnuthPageNode pageNode = (KnuthPageNode) bestActiveNode; KnuthPageNode previousPageNode = ((KnuthPageNode) pageNode.previous); for (Variant var : previousPageNode.pendingVariants) { - WhitespaceManagementPenalty penalty = var.getBestFitPenalty(); - int penaltyIndex = this.par.indexOf(penalty); - // Make sure penalty is inside the range of the current page node - if (penaltyIndex <= pageNode.position) { + WhitespaceManagementPenalty penalty = var.getWhitespaceManagementPenalty(); + // A WMPenalty should not be activated more than once. The reason is simply + // because a dynamic content cannot occupy multiple pages at the same time. + if (!penalty.hasActiveVariant()) { penalty.setActiveVariant(var); } } diff --git a/src/java/org/apache/fop/layoutmgr/WhitespaceManagementPenalty.java b/src/java/org/apache/fop/layoutmgr/WhitespaceManagementPenalty.java index 967df2d6a..20c83d205 100644 --- a/src/java/org/apache/fop/layoutmgr/WhitespaceManagementPenalty.java +++ b/src/java/org/apache/fop/layoutmgr/WhitespaceManagementPenalty.java @@ -46,7 +46,7 @@ public class WhitespaceManagementPenalty extends KnuthPenalty { return new KnuthPenalty(width, 0, false, null, false); } - public WhitespaceManagementPenalty getBestFitPenalty() { + public WhitespaceManagementPenalty getWhitespaceManagementPenalty() { return WhitespaceManagementPenalty.this; } @@ -69,7 +69,7 @@ public class WhitespaceManagementPenalty extends KnuthPenalty { whitespaceManagementPosition.setKnuthList(bestVariant.knuthList); } - public boolean isActivated() { + public boolean hasActiveVariant() { return whitespaceManagementPosition.getKnuthList() != null; } diff --git a/test/layoutengine/standard-testcases/multi-switch_basic.xml b/test/layoutengine/standard-testcases/multi-switch_basic.xml new file mode 100644 index 000000000..8f00d4179 --- /dev/null +++ b/test/layoutengine/standard-testcases/multi-switch_basic.xml @@ -0,0 +1,61 @@ + + + + + +

+ Test standard fo:multi-switch. +

+
+ + + + + + + + + + Block 1 + + + MS1 multi-case + + + Block 2 + + + MS2 multi-case 1 + + + MS2 multi-case 2 + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/multi-switch_best-fit_forced_page_break.xml b/test/layoutengine/standard-testcases/multi-switch_best-fit_forced_page_break.xml new file mode 100644 index 000000000..6b47dcf32 --- /dev/null +++ b/test/layoutengine/standard-testcases/multi-switch_best-fit_forced_page_break.xml @@ -0,0 +1,67 @@ + + + + + +

+ Test forced page breaks. +

+
+ + + + + + + + + + + Block 1 page 1 + + + MS1 Variant 1 + + + + + + MS2 Variant 1 + + + + Block 2 page 3 + + + MS3 Variant 1 + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/multi-switch_best-fit_padding.xml b/test/layoutengine/standard-testcases/multi-switch_best-fit_padding.xml new file mode 100644 index 000000000..5f11ce57d --- /dev/null +++ b/test/layoutengine/standard-testcases/multi-switch_best-fit_padding.xml @@ -0,0 +1,70 @@ + + + + + +

+ Test padding properties. +

+
+ + + + + + + + + + + + MS1 Variant 1 + + + + + MS2 Variant 1 + + + + + + MS3 Variant 1 + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5