From 1b4f4bca2eeff6d23ebe29c676e50eccf898c15d Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 10 Feb 2005 15:54:03 +0000 Subject: [PATCH] Rearranged the process a bit to better show the different phases. Helped me to better understand what's going on there. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198414 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/LineLayoutManager.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java index a6b514d8f..8acbc244b 100644 --- a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -394,15 +394,15 @@ public class LineLayoutManager extends InlineStackingLayoutManager { } prevBP = null; - // here starts Knuth's algorithm - KnuthElement thisElement = null; - LinkedList returnedList = null; - LineBreakPosition lbp = null; - + //PHASE 1: Create Knuth elements + if (knuthParagraphs == null) { // it's the first time this method is called knuthParagraphs = new ArrayList(); - breakpoints = new ArrayList(); + + // here starts Knuth's algorithm + KnuthElement thisElement = null; + LinkedList returnedList = null; // convert all the text in a sequence of paragraphs made // of KnuthBox, KnuthGlue and KnuthPenalty objects @@ -490,14 +490,23 @@ public class LineLayoutManager extends InlineStackingLayoutManager { } } knuthPar.endParagraph(); + } else { + // this method has been called before + // all line breaks are already calculated + } - // emergency patch - if (knuthParagraphs.size() == 0) { - setFinished(true); - return null; - } + // return finished when there's no content + if (knuthParagraphs.size() == 0) { + setFinished(true); + return null; + } + //PHASE 2: Create line breaks + + LineBreakPosition lbp = null; + if (breakpoints == null) { // find the optimal line breaking points for each paragraph + breakpoints = new ArrayList(); ListIterator paragraphsIterator = knuthParagraphs.listIterator(knuthParagraphs.size()); Paragraph currPar = null; @@ -505,11 +514,10 @@ public class LineLayoutManager extends InlineStackingLayoutManager { currPar = (Paragraph) paragraphsIterator.previous(); findBreakingPoints(currPar, context.getStackLimit().opt); } - } else { - // this method has been called before - // all line breaks are already calculated } + //PHASE 3: Return lines + // get a break point from the list lbp = (LineBreakPosition) breakpoints.get(iReturnedLBP ++); if (iReturnedLBP == breakpoints.size()) { @@ -1364,9 +1372,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager { } while ((LineBreakPosition) breakpoints.get(iReturnedLBP) != (LineBreakPosition) resetPos) { - iReturnedLBP --; + iReturnedLBP--; } - iReturnedLBP ++; + iReturnedLBP++; } } -- 2.39.5