Return-Path: Delivered-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Received: (qmail 68289 invoked from network); 6 Jul 2007 06:35:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Jul 2007 06:35:06 -0000 Received: (qmail 78446 invoked by uid 500); 6 Jul 2007 13:35:06 -0000 Delivered-To: apmail-xmlgraphics-fop-commits-archive@xmlgraphics.apache.org Received: (qmail 78344 invoked by uid 500); 6 Jul 2007 13:35:05 -0000 Mailing-List: contact fop-commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: fop-dev@xmlgraphics.apache.org Delivered-To: mailing list fop-commits@xmlgraphics.apache.org Received: (qmail 78333 invoked by uid 99); 6 Jul 2007 13:35:05 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jul 2007 06:35:05 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jul 2007 06:35:02 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 29B0D1A981A; Fri, 6 Jul 2007 06:34:42 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r553876 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java Date: Fri, 06 Jul 2007 13:34:42 -0000 To: fop-commits@xmlgraphics.apache.org From: vhennebert@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070706133442.29B0D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vhennebert Date: Fri Jul 6 06:34:41 2007 New Revision: 553876 URL: http://svn.apache.org/viewvc?view=rev&rev=553876 Log: Move the getNextStep method into ActiveCell Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java?view=diff&rev=553876&r1=553875&r2=553876 ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java Fri Jul 6 06:34:41 2007 @@ -62,8 +62,11 @@ private int paddingBefore; private int paddingAfter; private boolean keepWithNextSignal; + private int lastPenaltyLength; + private TableLayoutManager tableLM; - ActiveCell(PrimaryGridUnit pgu, EffRow row, int rowIndex) { + ActiveCell(PrimaryGridUnit pgu, EffRow row, int rowIndex, EffRow[] rowGroup, TableLayoutManager tableLM) { + this.tableLM = tableLM; this.pgu = pgu; boolean makeBoxForWholeRow = false; if (row.getExplicitHeight().min > 0) { @@ -106,6 +109,14 @@ width = 0; startRow = rowIndex; keepWithNextSignal = false; + computeBaseWidth(rowGroup); + } + + private void computeBaseWidth(EffRow[] rowGroup) { + baseWidth = 0; + for (int prevRow = 0; prevRow < startRow; prevRow++) { + baseWidth += rowGroup[prevRow].getHeight().opt; + } } private boolean endsOnRow(int rowIndex) { @@ -135,6 +146,47 @@ void backupWidth() { backupWidth = width; } + + int getNextStep() { + lastPenaltyLength = 0; + while (end + 1 < elementList.size()) { + end++; + KnuthElement el = (KnuthElement)elementList.get(end); + if (el.isPenalty()) { + if (el.getP() < KnuthElement.INFINITE) { + //First legal break point + lastPenaltyLength = el.getW(); + break; + } + } else if (el.isGlue()) { + if (end > 0) { + KnuthElement prev = (KnuthElement)elementList.get(end - 1); + if (prev.isBox()) { + //Second legal break point + break; + } + } + width += el.getW(); + } else { + width += el.getW(); + } + } + if (end < start) { +// if (log.isTraceEnabled()) { +// log.trace("column " + (i + 1) + ": (end=" + end + ") < (start=" + start +// + ") => resetting width to backupWidth"); +// } + width = backupWidth; + return 0; + } else { + return baseWidth + width + borderBefore + borderAfter + paddingBefore + + paddingAfter + 2 * tableLM.getHalfBorderSeparationBPD(); + } + } + + int getLastPenaltyLength() { + return lastPenaltyLength; + } } /** Logger **/ private static Log log = LogFactory.getLog(TableStepper.class); @@ -219,7 +271,7 @@ GridUnit gu = getActiveGridUnit(column); EffRow row = getActiveRow(); if (gu != null && !gu.isEmpty() && gu.isPrimary()) { - activeCells.add(new ActiveCell((PrimaryGridUnit) gu, row, activeRowIndex)); + activeCells.add(new ActiveCell((PrimaryGridUnit) gu, row, activeRowIndex, rowGroup, getTableLM())); } } @@ -423,80 +475,23 @@ goToNextRowIfCurrentFinished(); //Get next possible sequence for each cell + //Determine smallest possible step + int minStep = Integer.MAX_VALUE; boolean stepFound = false; for (Iterator iter = activeCells.iterator(); iter.hasNext();) { ActiveCell activeCell = (ActiveCell) iter.next(); - while (activeCell.end + 1 < activeCell.elementList.size()) { - activeCell.end++; - KnuthElement el = (KnuthElement)activeCell.elementList.get(activeCell.end); - if (el.isPenalty()) { - this.lastMaxPenaltyLength = Math.max(this.lastMaxPenaltyLength, el.getW()); - if (el.getP() <= -KnuthElement.INFINITE) { - log.debug("FORCED break encountered!"); - break; - } else if (el.getP() < KnuthElement.INFINITE) { - //First legal break point - break; - } - } else if (el.isGlue()) { - if (activeCell.end > 0) { - KnuthElement prev = (KnuthElement)activeCell.elementList.get(activeCell.end - 1); - if (prev.isBox()) { - //Second legal break point - break; - } - } - activeCell.width += el.getW(); - } else { - activeCell.width += el.getW(); - } - } - if (activeCell.end < activeCell.start) { -// if (log.isTraceEnabled()) { -// log.trace("column " + (i + 1) + ": (end=" + activeCell.end + ") < (start=" + activeCell.start -// + ") => resetting width to backupWidth"); -// } - activeCell.width = activeCell.backupWidth; - } else { + int nextStep = activeCell.getNextStep(); + if (nextStep > 0) { stepFound = true; + minStep = Math.min(minStep, nextStep); + lastMaxPenaltyLength = Math.max(lastMaxPenaltyLength, activeCell + .getLastPenaltyLength()); } - //log.debug("part " + activeCell.start + "-" + activeCell.end + " " + activeCell.width); -// if (log.isTraceEnabled()) { -// log.trace("column " + (i+1) + ": borders before=" + activeCell.borderBefore + " after=" + activeCell.borderAfter); -// log.trace("column " + (i+1) + ": padding before=" + activeCell.paddingBefore + " after=" + activeCell.paddingAfter); -// } } if (!stepFound) { return -1; } - //Determine smallest possible step - int minStep = Integer.MAX_VALUE; - StringBuffer sb = new StringBuffer(); - for (Iterator iter = activeCells.iterator(); iter.hasNext();) { - ActiveCell activeCell = (ActiveCell) iter.next(); - activeCell.baseWidth = 0; - for (int prevRow = 0; prevRow < activeCell.startRow; prevRow++) { - activeCell.baseWidth += rowGroup[prevRow].getHeight().opt; - } - activeCell.baseWidth += 2 * getTableLM().getHalfBorderSeparationBPD(); - activeCell.baseWidth += activeCell.borderBefore + activeCell.borderAfter; - activeCell.baseWidth += activeCell.paddingBefore + activeCell.paddingAfter; - if (activeCell.end >= activeCell.start) { - int len = activeCell.baseWidth + activeCell.width; - sb.append(len + " "); - minStep = Math.min(len, minStep); - } - } - if (log.isDebugEnabled()) { - log.debug("candidate steps: " + sb); - } - - //Check for constellations that would result in overlapping borders - /* - for (int i = 0; i < columnCount; i++) { - - }*/ //Reset bigger-than-minimum sequences //See http://people.apache.org/~jeremias/fop/NextStepAlgoNotes.pdf @@ -504,18 +499,13 @@ skippedStep = false; for (Iterator iter = activeCells.iterator(); iter.hasNext();) { ActiveCell activeCell = (ActiveCell) iter.next(); - int len = activeCell.baseWidth + activeCell.width; + int len = activeCell.baseWidth + activeCell.width + activeCell.borderBefore + activeCell.borderAfter + activeCell.paddingBefore + + activeCell.paddingAfter + 2 * getTableLM().getHalfBorderSeparationBPD(); if (len > minStep) { activeCell.width = activeCell.backupWidth; activeCell.end = activeCell.start - 1; - if (activeCell.baseWidth + activeCell.width > minStep) { -// if (log.isDebugEnabled()) { -// log.debug("column " -// + (i + 1) -// + ": minStep vs. border/padding increase conflict: basewidth + width = " -// + activeCell.baseWidth + " + " + activeCell.width + " = " -// + (activeCell.baseWidth + activeCell.width)); -// } + if (activeCell.baseWidth + activeCell.borderBefore + activeCell.borderAfter + activeCell.paddingBefore + + activeCell.paddingAfter + 2 * getTableLM().getHalfBorderSeparationBPD() + activeCell.width > minStep) { if (activeRowIndex == 0) { log.debug(" First row. Skip this step."); skippedStep = true; @@ -529,17 +519,6 @@ } } } -// if (log.isDebugEnabled()) { -// /*StringBuffer*/ sb = new StringBuffer("[col nb: start-end(width)] "); -// for (int i = 0; i < columnCount; i++) { -// if (end[i] >= start[i]) { -// sb.append(i + ": " + start[i] + "-" + end[i] + "(" + widths[i] + "), "); -// } else { -// sb.append(i + ": skip, "); -// } -// } -// log.debug(sb.toString()); -// } return minStep; } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org