From 6d07774192bb641251bd72b7ea68f012f20e2d88 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Mon, 12 May 2008 12:30:42 +0000 Subject: Replaced hack in TableStepper to get the steps' penalty values with a more proper implementation. Allows in the same time to avoid skimming, at each step, through the active cells' LinkedLists of elements, which may have a negative impact on performance git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@655489 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/layoutmgr/table/ActiveCell.java | 16 ++++++++++++++-- .../org/apache/fop/layoutmgr/table/TableStepper.java | 11 ++--------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java b/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java index 70e2b2330..feb4b67ac 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java +++ b/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java @@ -99,6 +99,8 @@ class ActiveCell { private int totalLength; /** Length of the penalty ending this step, if any. */ private int penaltyLength; + /** Value of the penalty ending this step, 0 if the step does not end on a penalty. */ + private int penaltyValue; /** * One of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN}, * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE}, @@ -127,6 +129,7 @@ class ActiveCell { this.contentLength = other.contentLength; this.totalLength = other.totalLength; this.penaltyLength = other.penaltyLength; + this.penaltyValue = other.penaltyValue; this.condBeforeContentLength = other.condBeforeContentLength; this.breakClass = other.breakClass; } @@ -287,6 +290,7 @@ class ActiveCell { private void gotoNextLegalBreak() { afterNextStep.penaltyLength = 0; + afterNextStep.penaltyValue = 0; afterNextStep.condBeforeContentLength = 0; afterNextStep.breakClass = Constants.EN_AUTO; boolean breakFound = false; @@ -299,8 +303,9 @@ class ActiveCell { if (el.getP() < KnuthElement.INFINITE) { // First legal break point breakFound = true; - afterNextStep.penaltyLength = el.getW(); KnuthPenalty p = (KnuthPenalty) el; + afterNextStep.penaltyLength = p.getW(); + afterNextStep.penaltyValue = p.getP(); if (p.isForcedBreak()) { afterNextStep.breakClass = p.getBreakClass(); } @@ -542,7 +547,14 @@ class ActiveCell { return keepWithNextStrength; } - + int getPenaltyValue() { + if (includedInLastStep()) { + return nextStep.penaltyValue; + } else { + return previousStep.penaltyValue; + } + } + /** {@inheritDoc} */ public String toString() { return "Cell " + (pgu.getRowIndex() + 1) + "." + (pgu.getColIndex() + 1); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java index 2d3c990f8..f514844ac 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java @@ -200,20 +200,11 @@ public class TableStepper { } //Put all involved grid units into a list - int stepPenalty = 0; List cellParts = new java.util.ArrayList(columnCount); for (Iterator iter = activeCells.iterator(); iter.hasNext();) { ActiveCell activeCell = (ActiveCell) iter.next(); CellPart part = activeCell.createCellPart(); cellParts.add(part); - - //Record highest penalty value of part - if (part.end >= 0) { - KnuthElement endEl = (KnuthElement)part.pgu.getElements().get(part.end); - if (endEl instanceof KnuthPenalty) { - stepPenalty = Math.max(stepPenalty, endEl.getP()); - } - } } //Create elements for step @@ -242,9 +233,11 @@ public class TableStepper { } int strength = BlockLevelLayoutManager.KEEP_AUTO; + int stepPenalty = 0; for (Iterator iter = activeCells.iterator(); iter.hasNext();) { ActiveCell activeCell = (ActiveCell) iter.next(); strength = Math.max(strength, activeCell.getKeepWithNextStrength()); + stepPenalty = Math.max(stepPenalty, activeCell.getPenaltyValue()); } if (!rowFinished) { strength = Math.max(strength, rowGroup[activeRowIndex].getKeepTogetherStrength()); -- cgit v1.2.3