From: Simon Pepping Date: Sat, 29 May 2004 09:07:59 +0000 (+0000) Subject: Remove trailing spaces at the end of a paragraph. X-Git-Tag: Root_Temp_KnuthStylePageBreaking~728 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ab2c0a4f56557c613f870405d03968061384451c;p=xmlgraphics-fop.git Remove trailing spaces at the end of a paragraph. Modify the way to deal with BPs which have not been added to vecInlineBreaks. See bug 28706. The code was rewritten w.r.t. the submitted patch. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197652 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java index b32428953..b9dd60ba4 100644 --- a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -244,8 +244,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager { /* If we are not in justified text, we can end the line at * prevBP. */ - vecInlineBreaks.add(bp); if (prevBP == null) { + vecInlineBreaks.add(bp); prevBP = bp; } break; @@ -313,9 +313,15 @@ public class LineLayoutManager extends InlineStackingLayoutManager { if (!bp.isForcedBreak() && vecPossEnd.size() > 0) { prevBP = getBestBP(vecPossEnd); } - // Backup child LM if necessary - if (bp != prevBP && !prevCouldEndLine(prevBP)) { - reset(); + if (bp != prevBP) { + /** Remove BPs after prevBP + if condAllAreSuppressible returns true, + else backup child LM */ + if (condAllAreSuppressible(prevBP)) { + removeAllBP(prevBP); + } else { + reset(); + } } // Don't justify last line in the sequence or if forced line-end @@ -388,27 +394,18 @@ public class LineLayoutManager extends InlineStackingLayoutManager { return true; } - /** Test whether all breakposs in vecInlineBreaks - back to and including prev could end line */ - private boolean prevCouldEndLine(BreakPoss prev) { + /** Return true if we are at the end of this LM, + and BPs after prev have been added to vecInlineBreaks + and all breakposs in vecInlineBreaks + back to and excluding prev are suppressible */ + private boolean condAllAreSuppressible(BreakPoss prev) { if (!isFinished()) { return false; } - ListIterator bpIter = - vecInlineBreaks.listIterator(vecInlineBreaks.size()); - boolean couldEndLine = true; - while (bpIter.hasPrevious()) { - BreakPoss bp = (BreakPoss) bpIter.previous(); - if (bp == prev) { - break; - } else { - couldEndLine = bp.isSuppressible(); - if (!couldEndLine) { - break; - } - } + if (vecInlineBreaks.get(vecInlineBreaks.size() - 1) == prev) { + return false; } - return couldEndLine; + return allAreSuppressible(prev); } /** Test whether all breakposs in vecInlineBreaks