xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vhenneb...@apache.org
Subject svn commit: r816718 [7/11] - in /xmlgraphics/fop/branches/Temp_Accessibility: ./ examples/fo/advanced/ hyph/ lib/ src/codegen/unicode/java/org/apache/fop/hyphenation/ src/codegen/unicode/java/org/apache/fop/text/linebreak/ src/codegen/unicode/java/org/...
Date Fri, 18 Sep 2009 17:10:52 GMT
Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -20,6 +20,7 @@
 package org.apache.fop.layoutmgr.inline;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
@@ -36,6 +37,7 @@
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.properties.CommonHyphenation;
+import org.apache.fop.fo.properties.KeepProperty;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
@@ -46,7 +48,7 @@
 import org.apache.fop.layoutmgr.BreakingAlgorithm;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.InlineKnuthSequence;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
@@ -115,8 +117,8 @@
      * inline break positions.
      */
     private static class LineBreakPosition extends LeafPosition {
-        private int iParIndex; // index of the Paragraph this Position refers to
-        private int iStartIndex; //index of the first element this Position refers to
+        private int parIndex; // index of the Paragraph this Position refers to
+        private int startIndex; //index of the first element this Position refers to
         private int availableShrink;
         private int availableStretch;
         private int difference;
@@ -129,16 +131,16 @@
         private int spaceAfter;
         private int baseline;
 
-        LineBreakPosition(LayoutManager lm, int index, int iStartIndex, int iBreakIndex,
+        LineBreakPosition(LayoutManager lm, int index, int startIndex, int breakIndex,
                           int shrink, int stretch, int diff,
                           double ipdA, double adjust, int ind,
                           int lh, int lw, int sb, int sa, int bl) {
-            super(lm, iBreakIndex);
+            super(lm, breakIndex);
             availableShrink = shrink;
             availableStretch = stretch;
             difference = diff;
-            iParIndex = index;
-            this.iStartIndex = iStartIndex;
+            parIndex = index;
+            this.startIndex = startIndex;
             ipdAdjust = ipdA;
             dAdjust = adjust;
             startIndent = ind;
@@ -166,18 +168,18 @@
     private Length lineHeight;
     private int lead;
     private int follow;
-    private AlignmentContext alignmentContext = null;
+    private AlignmentContext alignmentContext;
 
-    private List knuthParagraphs = null;
-    private int iReturnedLBP = 0;
-
-    //     parameters of Knuth's algorithm:
-    // penalty value for flagged penalties
-    private int flaggedPenalty = 50;
+    private List knuthParagraphs;
 
     private LineLayoutPossibilities lineLayouts;
     private List lineLayoutsList;
-    private int iLineWidth = 0;
+    private int ipd = 0;
+    /**
+     * When layout must be re-started due to a change of IPD, there is no need
+     * to perform hyphenation on the remaining Knuth sequence once again.
+     */
+    private boolean hyphenationPerformed;
 
     /**
      * this constant is used to create elements when text-align is center:
@@ -237,7 +239,7 @@
             } else {
                 lineFiller = new MinOptMax(lastLineEndIndent,
                                             lastLineEndIndent,
-                                            layoutManager.iLineWidth);
+                                            layoutManager.ipd);
             }
 
             // add auxiliary elements at the beginning of the paragraph
@@ -318,11 +320,9 @@
         private int activePossibility;
         private int addedPositions;
         private int textIndent;
-        private int fillerMinWidth;
         private int lineHeight;
         private int lead;
         private int follow;
-        private int maxDiff;
         private static final double MAX_DEMERITS = 10e6;
 
         public LineBreakingAlgorithm (int pageAlign,
@@ -333,22 +333,17 @@
             super(textAlign, textAlignLast, first, false, maxFlagCount);
             pageAlignment = pageAlign;
             textIndent = indent;
-            fillerMinWidth = fillerWidth;
             lineHeight = lh;
             lead = ld;
             follow = fl;
             thisLLM = llm;
             activePossibility = -1;
-            maxDiff = fobj.getWidows() >= fobj.getOrphans()
-                    ? fobj.getWidows()
-                    : fobj.getOrphans();
         }
 
         public void updateData1(int lineCount, double demerits) {
             lineLayouts.addPossibility(lineCount, demerits);
-            if (super.log.isTraceEnabled()) {
-                super.log.trace(
-                        "Layout possibility in " + lineCount + " lines; break at position:");
+            if (log.isTraceEnabled()) {
+                log.trace("Layout possibility in " + lineCount + " lines; break at position:");
             }
         }
 
@@ -362,7 +357,7 @@
             int textAlign = (bestActiveNode.line < total) ? alignment : alignmentLast;
             indent += (textAlign == Constants.EN_CENTER)
                       ? difference / 2 : (textAlign == Constants.EN_END) ? difference : 0;
-            indent += (bestActiveNode.line == 1 && bFirst && isFirstInBlock) ? textIndent : 0;
+            indent += (bestActiveNode.line == 1 && indentFirstPart && isFirstInBlock) ? textIndent : 0;
             double ratio = (textAlign == Constants.EN_JUSTIFY
                 || difference < 0 && -difference <= bestActiveNode.availableShrink)
                         ? bestActiveNode.adjustRatio : 0;
@@ -429,7 +424,7 @@
             // true if this line contains only zero-height, auxiliary boxes
             // and the actual line width is 0; in this case, the line "collapses"
             // i.e. the line area will have bpd = 0
-            boolean bZeroHeightLine = (difference == iLineWidth);
+            boolean bZeroHeightLine = (difference == ipd);
 
             // if line-stacking-strategy is "font-height", the line height
             // is not affected by its content
@@ -485,7 +480,7 @@
                                              firstElementIndex, lastElementIndex,
                                              availableShrink, availableStretch,
                                              difference, ratio, 0, indent,
-                                             0, iLineWidth, 0, 0, 0);
+                                             0, ipd, 0, 0, 0);
             } else {
                 return new LineBreakPosition(thisLLM,
                                              knuthParagraphs.indexOf(par),
@@ -493,18 +488,11 @@
                                              availableShrink, availableStretch,
                                              difference, ratio, 0, indent,
                                              lineLead + lineFollow,
-                                             iLineWidth, spaceBefore, spaceAfter,
+                                             ipd, spaceBefore, spaceAfter,
                                              lineLead);
             }
         }
 
-        public int findBreakingPoints(Paragraph par, /*int lineWidth,*/
-                                      double threshold, boolean force,
-                                      int allowedBreaks) {
-            return super.findBreakingPoints(par, /*lineWidth,*/
-                    threshold, force, allowedBreaks);
-        }
-
         protected int filterActiveNodes() {
             KnuthNode bestActiveNode = null;
 
@@ -577,13 +565,10 @@
         FontInfo fi = fobj.getFOEventHandler().getFontInfo();
         FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi);
         Font fs = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
-        alignmentContext
-          = new AlignmentContext(fs, lineHeight.getValue(this), context.getWritingMode());
+        alignmentContext = new AlignmentContext(fs, lineHeight.getValue(this),
+                context.getWritingMode());
         context.setAlignmentContext(alignmentContext);
-        // Get a break from currently active child LM
-        // Set up constraints for inline level managers
-
-        clearPrevIPD();
+        ipd = context.getRefIPD();
 
         //PHASE 1: Create Knuth elements
         if (knuthParagraphs == null) {
@@ -605,34 +590,33 @@
 
         //PHASE 2: Create line breaks
         return createLineBreaks(context.getBPAlignment(), context);
-        /*
-        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;
-            while (paragraphsIterator.hasPrevious()) {
-                currPar = (Paragraph) paragraphsIterator.previous();
-                findBreakingPoints(currPar, context.getStackLimit().opt);
-            }
-        }*/
+    }
 
-        //PHASE 3: Return lines
+    public List getNextKnuthElements(LayoutContext context, int alignment,
+            LeafPosition restartPosition) {
+        log.trace("Restarting line breaking from index " + restartPosition.getIndex());
+        int parIndex = restartPosition.getLeafPos();
+        Paragraph paragraph = (Paragraph) knuthParagraphs.get(parIndex);
+        for (int i = 0; i <= restartPosition.getIndex(); i++) {
+            paragraph.remove(0);
+        }
+        Iterator iter = paragraph.iterator();
+        while (iter.hasNext() && !((KnuthElement) iter.next()).isBox()) {
+            iter.remove();
+        }
+        if (!iter.hasNext()) {
+            knuthParagraphs.remove(parIndex);
+        }
 
-        /*
-        // get a break point from the list
-        lbp = (LineBreakPosition) breakpoints.get(iReturnedLBP ++);
-        if (iReturnedLBP == breakpoints.size()) {
+        // return finished when there's no content
+        if (knuthParagraphs.size() == 0) {
             setFinished(true);
+            return null;
         }
 
-        BreakPoss curLineBP = new BreakPoss(lbp);
-        curLineBP.setFlag(BreakPoss.ISLAST, isFinished());
-        curLineBP.setStackingSize(new MinOptMax(lbp.lineHeight));
-        return curLineBP;
-        */
+        ipd = context.getRefIPD();
+        //PHASE 2: Create line breaks
+        return createLineBreaks(context.getBPAlignment(), context);
     }
 
     /**
@@ -642,22 +626,18 @@
     private void collectInlineKnuthElements(LayoutContext context) {
         LayoutContext inlineLC = new LayoutContext(context);
 
-        InlineLevelLayoutManager curLM;
-        List returnedList = null;
-        iLineWidth = context.getStackLimitIP().opt;
-
         // convert all the text in a sequence of paragraphs made
         // of KnuthBox, KnuthGlue and KnuthPenalty objects
-        boolean bPrevWasKnuthBox = false;
+        boolean previousIsBox = false;
 
         StringBuffer trace = new StringBuffer("LineLM:");
 
         Paragraph lastPar = null;
 
+        InlineLevelLayoutManager curLM;
         while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) {
-            returnedList = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
-            if (returnedList == null
-                    || returnedList.size() == 0) {
+            List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
+            if (inlineElements == null || inlineElements.size() == 0) {
                 /* curLM.getNextKnuthElements() returned null or an empty list;
                  * this can happen if there is nothing more to layout,
                  * so just iterate once more to see if there are other children */
@@ -665,7 +645,7 @@
             }
 
             if (lastPar != null) {
-                KnuthSequence firstSeq = (KnuthSequence) returnedList.get(0);
+                KnuthSequence firstSeq = (KnuthSequence) inlineElements.get(0);
 
                 // finish last paragraph before a new block sequence
                 if (!firstSeq.isInlineSequence()) {
@@ -675,7 +655,7 @@
                     if (log.isTraceEnabled()) {
                         trace.append(" ]");
                     }
-                    bPrevWasKnuthBox = false;
+                    previousIsBox = false;
                 }
 
                 // does the first element of the first paragraph add to an existing word?
@@ -683,27 +663,24 @@
                     KnuthElement thisElement;
                     thisElement = (KnuthElement) firstSeq.get(0);
                     if (thisElement.isBox() && !thisElement.isAuxiliary()
-                            && bPrevWasKnuthBox) {
+                            && previousIsBox) {
                         lastPar.addALetterSpace();
                     }
                 }
             }
 
             // loop over the KnuthSequences (and single KnuthElements) in returnedList
-            ListIterator iter = returnedList.listIterator();
+            ListIterator iter = inlineElements.listIterator();
             while (iter.hasNext()) {
                 KnuthSequence sequence = (KnuthSequence) iter.next();
                 // the sequence contains inline Knuth elements
                 if (sequence.isInlineSequence()) {
                     // look at the last element
                     ListElement lastElement = sequence.getLast();
-                    if (lastElement == null) {
-                        throw new NullPointerException(
-                        "Sequence was empty! lastElement is null");
-                    }
-                    bPrevWasKnuthBox = lastElement.isBox()
-                                        && !((KnuthElement) lastElement).isAuxiliary()
-                                        && ((KnuthElement) lastElement).getW() != 0;
+                    assert lastElement != null;
+                    previousIsBox = lastElement.isBox()
+                            && !((KnuthElement) lastElement).isAuxiliary()
+                            && ((KnuthElement) lastElement).getW() != 0;
 
                     // if last paragraph is open, add the new elements to the paragraph
                     // else this is the last paragraph
@@ -728,8 +705,7 @@
 
                     // finish last paragraph if it was closed with a linefeed
                     if (lastElement.isPenalty()
-                            && ((KnuthPenalty) lastElement).getP()
-                            == -KnuthPenalty.INFINITE) {
+                            && ((KnuthPenalty) lastElement).getP() == -KnuthPenalty.INFINITE) {
                         // a penalty item whose value is -inf
                         // represents a preserved linefeed,
                         // which forces a line break
@@ -737,7 +713,7 @@
                         if (!lastPar.containsBox()) {
                             //only a forced linefeed on this line
                             //-> compensate with an auxiliary glue
-                            lastPar.add(new KnuthGlue(iLineWidth, 0, iLineWidth, null, true));
+                            lastPar.add(new KnuthGlue(ipd, 0, ipd, null, true));
                         }
                         lastPar.endParagraph();
                         ElementListObserver.observe(lastPar, "line", null);
@@ -745,7 +721,7 @@
                         if (log.isTraceEnabled()) {
                             trace.append(" ]");
                         }
-                        bPrevWasKnuthBox = false;
+                        previousIsBox = false;
                     }
                 } else { // the sequence is a block sequence
                     // the positions will be wrapped with this LM in postProcessLineBreaks
@@ -767,144 +743,14 @@
     }
 
     /**
-     * Find a set of breaking points.
-     * This method is called only once by getNextBreakPoss, and it
-     * subsequently calls the other findBreakingPoints() method with
-     * different parameters, until a set of breaking points is found.
-     *
-     * @param par       the list of elements that must be parted
-     *                  into lines
-     * @param lineWidth the desired length ot the lines
-     */
-    /*
-    private void findBreakingPoints(Paragraph par, int lineWidth) {
-        // maximum adjustment ratio permitted
-        float maxAdjustment = 1;
-
-        // first try
-        if (!findBreakingPoints(par, lineWidth, maxAdjustment, false)) {
-            // the first try failed, now try something different
-            log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment);
-            if (hyphenationProperties.hyphenate == Constants.EN_TRUE) {
-                // consider every hyphenation point as a legal break
-                findHyphenationPoints(par);
-            } else {
-                // try with a higher threshold
-                maxAdjustment = 5;
-            }
-
-            if (!findBreakingPoints(par, lineWidth, maxAdjustment, false)) {
-                // the second try failed too, try with a huge threshold;
-                // if this fails too, use a different algorithm
-                log.debug("No set of breaking points found with maxAdjustment = " + maxAdjustment
-                          + (hyphenationProperties.hyphenate == Constants.EN_TRUE ? " and hyphenation" : ""));
-                maxAdjustment = 20;
-                if (!findBreakingPoints(par, lineWidth, maxAdjustment, true)) {
-                    log.debug("No set of breaking points found, using first-fit algorithm");
-                }
-            }
-        }
-    }
-
-    private boolean findBreakingPoints(Paragraph par, int lineWidth,
-            double threshold, boolean force) {
-        KnuthParagraph knuthPara = new KnuthParagraph(par);
-        int lines = knuthPara.findBreakPoints(lineWidth, threshold, force);
-        if (lines == 0) {
-            return false;
-        }
-
-        for (int i = lines-1; i >= 0; i--) {
-            int line = i+1;
-            if (log.isTraceEnabled()) {
-                log.trace("Making line from " + knuthPara.getStart(i) + " to " +
-                           knuthPara.getEnd(i));
-            }
-            // compute indent and adjustment ratio, according to
-            // the value of text-align and text-align-last
-
-            int difference = knuthPara.getDifference(i);
-            if (line == lines) {
-                difference += par.lineFillerWidth;
-            }
-            int textAlign = (line < lines)
-                ? textAlignment : textAlignmentLast;
-            int indent = (textAlign == EN_CENTER)
-                ? difference / 2
-                : (textAlign == EN_END) ? difference : 0;
-            indent += (line == 1 && knuthParagraphs.indexOf(par) == 0)
-                ? textIndent.getValue(this) : 0;
-            double ratio = (textAlign == EN_JUSTIFY)
-                ? knuthPara.getAdjustRatio(i) : 0;
-
-            int start = knuthPara.getStart(i);
-            int end = knuthPara.getEnd(i);
-            makeLineBreakPosition(par, start, end, 0, ratio, indent);
-        }
-        return true;
-    }
-
-    private void makeLineBreakPosition(Paragraph par,
-                                       int firstElementIndex, int lastElementIndex,
-                                       int insertIndex, double ratio, int indent) {
-        // line height calculation
-
-        int halfLeading = (lineHeight - lead - follow) / 2;
-        // height above the main baseline
-        int lineLead = lead + halfLeading;
-        // maximum size of top and bottom alignment
-        int lineFollow = follow + halfLeading;
-
-        ListIterator inlineIterator
-            = par.listIterator(firstElementIndex);
-        for (int j = firstElementIndex;
-             j <= lastElementIndex;
-             j++) {
-            KnuthElement element = (KnuthElement) inlineIterator.next();
-            if (element.isBox()) {
-                KnuthInlineBox box = (KnuthInlineBox)element;
-                if (box.getLead() > lineLead) {
-                    lineLead = box.getLead();
-                }
-                if (box.getTotal() > lineFollow) {
-                    lineFollow = box.getTotal();
-                }
-                if (box.getMiddle() > lineLead + middleShift) {
-                    lineLead += box.getMiddle()
-                                - lineLead - middleShift;
-                }
-                if (box.getMiddle() > middlefollow - middleShift) {
-                    middlefollow += box.getMiddle()
-                                    - middlefollow + middleShift;
-                }
-            }
-        }
-
-        if (lineFollow - lineLead > middlefollow) {
-                    middlefollow = lineFollow - lineLead;
-        }
-
-        breakpoints.add(insertIndex,
-                        new LineBreakPosition(this,
-                                              knuthParagraphs.indexOf(par),
-                                              lastElementIndex ,
-                                              ratio, 0, indent,
-                                              lineLead + middlefollow,
-                                              lineLead));
-    }*/
-
-
-    /**
      * Phase 2 of Knuth algorithm: find optimal break points.
      * @param alignment alignment in BP direction of the paragraph
      * @param context the layout context
      * @return a list of Knuth elements representing broken lines
      */
     private List createLineBreaks(int alignment, LayoutContext context) {
-
         // find the optimal line breaking points for each paragraph
-        ListIterator paragraphsIterator
-            = knuthParagraphs.listIterator(knuthParagraphs.size());
+        ListIterator paragraphsIterator = knuthParagraphs.listIterator(knuthParagraphs.size());
         lineLayoutsList = new ArrayList(knuthParagraphs.size());
         LineLayoutPossibilities llPoss;
         while (paragraphsIterator.hasPrevious()) {
@@ -946,7 +792,8 @@
                                         this);
 
         if (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
-                && fobj.getWrapOption() != EN_NO_WRAP) {
+                && fobj.getWrapOption() != EN_NO_WRAP && !hyphenationPerformed) {
+            hyphenationPerformed = true;
             findHyphenationPoints(currPar);
         }
 
@@ -957,7 +804,7 @@
         } else {
             allowedBreaks = BreakingAlgorithm.NO_FLAGGED_PENALTIES;
         }
-        alg.setConstantLineWidth(iLineWidth);
+        alg.setConstantLineWidth(ipd);
         iBPcount = alg.findBreakingPoints(currPar,
                                           maxAdjustment, false, allowedBreaks);
         if (iBPcount == 0 || alignment == EN_JUSTIFY) {
@@ -1013,26 +860,26 @@
                     alg.resetAlgorithm();
                     lineLayouts.savePossibilities(true);
                     // try with shorter lines
-                    int savedLineWidth = iLineWidth;
-                    iLineWidth = (int) (iLineWidth * 0.95);
+                    int savedLineWidth = ipd;
+                    ipd = (int) (ipd * 0.95);
                     iBPcount = alg.findBreakingPoints(currPar,
-                             maxAdjustment, true, allowedBreaks);
+                            maxAdjustment, true, allowedBreaks);
                     // use normal lines, when possible
                     lineLayouts.restorePossibilities();
-                    iLineWidth = savedLineWidth;
+                    ipd = savedLineWidth;
                 }
                 if (!lineLayouts.canUseLessLines()) {
                     alg.resetAlgorithm();
                     lineLayouts.savePossibilities(true);
                     // try with longer lines
-                    int savedLineWidth = iLineWidth;
-                    iLineWidth = (int) (iLineWidth * 1.05);
-                    alg.setConstantLineWidth(iLineWidth);
+                    int savedLineWidth = ipd;
+                    ipd = (int) (ipd * 1.05);
+                    alg.setConstantLineWidth(ipd);
                     iBPcount = alg.findBreakingPoints(currPar,
                             maxAdjustment, true, allowedBreaks);
                     // use normal lines, when possible
                     lineLayouts.restorePossibilities();
-                    iLineWidth = savedLineWidth;
+                    ipd = savedLineWidth;
                 }
                 //log.debug("LLM.getNextKnuthElements> now, layouts with more lines? " + lineLayouts.canUseMoreLines());
                 //log.debug("                          now, layouts with fewer lines? " + lineLayouts.canUseLessLines());
@@ -1051,15 +898,16 @@
 
         List returnList = new LinkedList();
 
+        int endIndex = -1;
         for (int p = 0; p < knuthParagraphs.size(); p++) {
             // penalty between paragraphs
             if (p > 0) {
-                int strength = getKeepTogetherStrength();
-                int penalty = KeepUtil.getPenaltyForKeep(strength);
-                if (penalty < KnuthElement.INFINITE) {
-                    returnList.add(new BreakElement(
-                            new Position(this), penalty, context));
-                }
+                Keep keep = getKeepTogether();
+                returnList.add(new BreakElement(
+                            new Position(this),
+                            keep.getPenalty(),
+                            keep.getContext(),
+                            context));
             }
 
             LineLayoutPossibilities llPoss;
@@ -1088,7 +936,6 @@
             } else {
                 /* "normal" vertical alignment: create a sequence whose boxes
                    represent effective lines, and contain LineBreakPositions */
-                Position returnPosition = new LeafPosition(this, p);
                 int startIndex = 0;
                 for (int i = 0;
                         i < llPoss.getChosenLineCount();
@@ -1098,15 +945,14 @@
                             && i >= fobj.getOrphans()
                             && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
                         // penalty allowing a page break between lines
-                        int strength = getKeepTogetherStrength();
-                        int penalty = KeepUtil.getPenaltyForKeep(strength);
-                        if (penalty < KnuthElement.INFINITE) {
-                            returnList.add(new BreakElement(
-                                    returnPosition, penalty, context));
-                        }
+                        Keep keep = getKeepTogether();
+                        returnList.add(new BreakElement(
+                                new LeafPosition(this, p, endIndex),
+                                    keep.getPenalty(),
+                                    keep.getContext(),
+                                    context));
                     }
-                    int endIndex
-                      = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
+                    endIndex = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
                     // create a list of the FootnoteBodyLM handling footnotes
                     // whose citations are in this line
                     List footnoteList = new LinkedList();
@@ -1114,15 +960,14 @@
                     while (elementIterator.nextIndex() <= endIndex) {
                         KnuthElement element = (KnuthElement) elementIterator.next();
                         if (element instanceof KnuthInlineBox
-                            && ((KnuthInlineBox) element).isAnchor()) {
+                                && ((KnuthInlineBox) element).isAnchor()) {
                             footnoteList.add(((KnuthInlineBox) element).getFootnoteBodyLM());
                         } else if (element instanceof KnuthBlockBox) {
                             footnoteList.addAll(((KnuthBlockBox) element).getFootnoteBodyLMs());
                         }
                     }
                     startIndex = endIndex + 1;
-                    LineBreakPosition lbp
-                      = (LineBreakPosition) llPoss.getChosenPosition(i);
+                    LineBreakPosition lbp = (LineBreakPosition) llPoss.getChosenPosition(i);
                     returnList.add(new KnuthBlockBox
                                    (lbp.lineHeight + lbp.spaceBefore + lbp.spaceAfter,
                                     footnoteList, lbp, false));
@@ -1283,28 +1128,43 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        return ((BlockLevelLayoutManager) getParent()).getKeepTogetherStrength();
+    public KeepProperty getKeepTogetherProperty() {
+        return ((BlockLevelLayoutManager) getParent()).getKeepTogetherProperty();
+    }
+
+    /** {@inheritDoc} */
+    public KeepProperty getKeepWithPreviousProperty() {
+        return ((BlockLevelLayoutManager) getParent()).getKeepWithPreviousProperty();
+    }
+
+    /** {@inheritDoc} */
+    public KeepProperty getKeepWithNextProperty() {
+        return ((BlockLevelLayoutManager) getParent()).getKeepWithNextProperty();
+    }
+
+    /** {@inheritDoc} */
+    public Keep getKeepTogether() {
+        return ((BlockLevelLayoutManager) getParent()).getKeepTogether();
     }
 
     /** {@inheritDoc} */
     public boolean mustKeepWithPrevious() {
-        return getKeepWithPreviousStrength() > KEEP_AUTO;
+        return !getKeepWithPrevious().isAuto();
     }
 
     /** {@inheritDoc} */
     public boolean mustKeepWithNext() {
-        return getKeepWithNextStrength() > KEEP_AUTO;
+        return !getKeepWithNext().isAuto();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
     }
 
     /** {@inheritDoc} */
@@ -1409,6 +1269,7 @@
                 break;
             }
             //TODO Something's not right here. See block_hyphenation_linefeed_preserve.xml
+            //for more info: see also https://issues.apache.org/bugzilla/show_bug.cgi?id=38264
 
             // collect word fragments, ignoring auxiliary elements;
             // each word fragment was created by a different TextLM
@@ -1580,7 +1441,7 @@
             Position pos = (Position) parentIter.next();
             boolean isLastPosition = !parentIter.hasNext();
             if (pos instanceof LineBreakPosition) {
-                addInlineArea(context, pos, isLastPosition);
+                addInlineArea(context, (LineBreakPosition) pos, isLastPosition);
             } else if ((pos instanceof NonLeafPosition) && pos.generatesAreas()) {
                 addBlockArea(context, pos, isLastPosition);
             } else {
@@ -1600,147 +1461,129 @@
      * @param pos the position for which the line is generated
      * @param isLastPosition true if this is the last position of this LM
      */
-    private void addInlineArea(LayoutContext context, Position pos, boolean isLastPosition) {
-            ListIterator seqIterator = null;
-            KnuthElement tempElement = null;
-            // the TLM which created the last KnuthElement in this line
-            LayoutManager lastLM = null;
-
-            LineBreakPosition lbp = (LineBreakPosition) pos;
-            int iCurrParIndex;
-            iCurrParIndex = lbp.iParIndex;
-            KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex);
-            int iStartElement = lbp.iStartIndex;
-            int iEndElement = lbp.getLeafPos();
-
-            LineArea lineArea
-              = new LineArea((lbp.getLeafPos() < seq.size() - 1
-                              ? textAlignment : textAlignmentLast),
-                              lbp.difference, lbp.availableStretch, lbp.availableShrink);
-            if (lbp.startIndent != 0) {
-                lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
-            }
-            lineArea.setBPD(lbp.lineHeight);
-            lineArea.setIPD(lbp.lineWidth);
-            lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
-            lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
-            alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
-
-            if (seq instanceof Paragraph) {
-                Paragraph currPar = (Paragraph) seq;
-                // ignore the first elements added by the LineLayoutManager
-                iStartElement += (iStartElement == 0) ? currPar.ignoreAtStart : 0;
-
-                // if this is the last line area that for this paragraph,
-                // ignore the last elements added by the LineLayoutManager and
-                // subtract the last-line-end-indent from the area ipd
-                if (iEndElement == (currPar.size() - 1)) {
-                    iEndElement -= currPar.ignoreAtEnd;
-                    lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
-                }
+    private void addInlineArea(LayoutContext context, LineBreakPosition lbp,
+            boolean isLastPosition) {
+        // the TLM which created the last KnuthElement in this line
+        LayoutManager lastLM = null;
+
+        KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(lbp.parIndex);
+        int startElementIndex = lbp.startIndex;
+        int endElementIndex = lbp.getLeafPos();
+
+        LineArea lineArea = new LineArea(
+                (lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
+                lbp.difference, lbp.availableStretch, lbp.availableShrink);
+        if (lbp.startIndent != 0) {
+            lineArea.addTrait(Trait.START_INDENT, new Integer(lbp.startIndent));
+        }
+        lineArea.setBPD(lbp.lineHeight);
+        lineArea.setIPD(lbp.lineWidth);
+        lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
+        lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
+        alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);
+
+        if (seq instanceof Paragraph) {
+            Paragraph currPar = (Paragraph) seq;
+            // ignore the first elements added by the LineLayoutManager
+            startElementIndex += (startElementIndex == 0) ? currPar.ignoreAtStart : 0;
+
+            // if this is the last line area that for this paragraph,
+            // ignore the last elements added by the LineLayoutManager and
+            // subtract the last-line-end-indent from the area ipd
+            if (endElementIndex == (currPar.size() - 1)) {
+                endElementIndex -= currPar.ignoreAtEnd;
+                lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
             }
+        }
 
-            // Remove trailing spaces if allowed so
-            if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+        // Remove trailing spaces if allowed so
+        if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
                 || whiteSpaceTreament == EN_IGNORE
                 || whiteSpaceTreament == EN_IGNORE_IF_BEFORE_LINEFEED) {
-                // ignore the last element in the line if it is a KnuthGlue object
-                seqIterator = seq.listIterator(iEndElement);
-                tempElement = (KnuthElement) seqIterator.next();
-                if (tempElement.isGlue()) {
-                    iEndElement--;
-                    // this returns the same KnuthElement
-                    seqIterator.previous();
-                    if (seqIterator.hasPrevious()) {
-                        tempElement = (KnuthElement) seqIterator.previous();
-                    } else {
-                        tempElement = null;
-                    }
-                }
-                if (tempElement != null) {
-                    lastLM = tempElement.getLayoutManager();
+            // ignore the last element in the line if it is a KnuthGlue object
+            ListIterator seqIterator = seq.listIterator(endElementIndex);
+            KnuthElement lastElement = (KnuthElement) seqIterator.next();
+            lastLM = lastElement.getLayoutManager();
+            if (lastElement.isGlue()) {
+                endElementIndex--;
+                // this returns the same KnuthElement
+                seqIterator.previous();
+                if (seqIterator.hasPrevious()) {
+                    lastLM = ((KnuthElement) seqIterator.previous()).getLayoutManager();
                 }
             }
+        }
 
-            // Remove leading spaces if allowed so
-            if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+        // Remove leading spaces if allowed so
+        if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
                 || whiteSpaceTreament == EN_IGNORE
                 || whiteSpaceTreament == EN_IGNORE_IF_AFTER_LINEFEED) {
-                // ignore KnuthGlue and KnuthPenalty objects
-                // at the beginning of the line
-                seqIterator = seq.listIterator(iStartElement);
-                tempElement = (KnuthElement) seqIterator.next();
-                while (!tempElement.isBox() && seqIterator.hasNext()) {
-                    tempElement = (KnuthElement) seqIterator.next();
-                    iStartElement++;
-                }
-            }
-            // Add the inline areas to lineArea
-            PositionIterator inlinePosIter
-              = new KnuthPossPosIter(seq, iStartElement, iEndElement + 1);
-
-            iStartElement = lbp.getLeafPos() + 1;
-            if (iStartElement == seq.size()) {
-                // advance to next paragraph
-                iStartElement = 0;
-            }
-
-            LayoutContext lc = new LayoutContext(0);
-            lc.setAlignmentContext(alignmentContext);
-            lc.setSpaceAdjust(lbp.dAdjust);
-            lc.setIPDAdjust(lbp.ipdAdjust);
-            lc.setLeadingSpace(new SpaceSpecifier(true));
+            // ignore KnuthGlue and KnuthPenalty objects
+            // at the beginning of the line
+            ListIterator seqIterator = seq.listIterator(startElementIndex);
+            while (seqIterator.hasNext() && !((KnuthElement) seqIterator.next()).isBox()) {
+                startElementIndex++;
+            }
+        }
+        // Add the inline areas to lineArea
+        PositionIterator inlinePosIter = new KnuthPossPosIter(seq, startElementIndex,
+                endElementIndex + 1);
+
+        LayoutContext lc = new LayoutContext(0);
+        lc.setAlignmentContext(alignmentContext);
+        lc.setSpaceAdjust(lbp.dAdjust);
+        lc.setIPDAdjust(lbp.ipdAdjust);
+        lc.setLeadingSpace(new SpaceSpecifier(true));
+        lc.setTrailingSpace(new SpaceSpecifier(false));
+        lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+
+        /*
+         * extension (not in the XSL FO recommendation): if the left and right margins
+         * have been optimized, recompute indents and / or adjust ratio, according
+         * to the paragraph horizontal alignment
+         */
+        if (false && textAlignment == EN_JUSTIFY) {
+            // re-compute space adjust ratio
+            int updatedDifference = context.getRefIPD()
+            - lbp.lineWidth + lbp.difference;
+            double updatedRatio = 0.0;
+            if (updatedDifference > 0) {
+                updatedRatio = (float) updatedDifference / lbp.availableStretch;
+            } else if (updatedDifference < 0) {
+                updatedRatio = (float) updatedDifference / lbp.availableShrink;
+            }
+            lc.setIPDAdjust(updatedRatio);
+            //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
+            //log.debug("              old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
+        } else if (false && textAlignment == EN_CENTER) {
+            // re-compute indent
+            int updatedIndent = lbp.startIndent
+            + (context.getRefIPD() - lbp.lineWidth) / 2;
+            lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
+        } else if (false && textAlignment == EN_END) {
+            // re-compute indent
+            int updatedIndent = lbp.startIndent
+            + (context.getRefIPD() - lbp.lineWidth);
+            lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
+        }
+
+        setCurrentArea(lineArea);
+        setChildContext(lc);
+        LayoutManager childLM;
+        while ((childLM = inlinePosIter.getNextChildLM()) != null) {
+            lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
+            childLM.addAreas(inlinePosIter, lc);
+            lc.setLeadingSpace(lc.getTrailingSpace());
             lc.setTrailingSpace(new SpaceSpecifier(false));
-            lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+        }
 
-            /*
-             * extension (not in the XSL FO recommendation): if the left and right margins
-             * have been optimized, recompute indents and / or adjust ratio, according
-             * to the paragraph horizontal alignment
-             */
-            if (false && textAlignment == EN_JUSTIFY) {
-                // re-compute space adjust ratio
-                int updatedDifference = context.getStackLimitIP().opt
-                                        - lbp.lineWidth + lbp.difference;
-                double updatedRatio = 0.0;
-                if (updatedDifference > 0) {
-                    updatedRatio = (float) updatedDifference / lbp.availableStretch;
-                } else if (updatedDifference < 0) {
-                    updatedRatio = (float) updatedDifference / lbp.availableShrink;
-                }
-                lc.setIPDAdjust(updatedRatio);
-                //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
-                //log.debug("              old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
-            } else if (false && textAlignment == EN_CENTER) {
-                // re-compute indent
-                int updatedIndent = lbp.startIndent
-                                    + (context.getStackLimitIP().opt - lbp.lineWidth) / 2;
-                lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
-            } else if (false && textAlignment == EN_END) {
-                // re-compute indent
-                int updatedIndent = lbp.startIndent
-                                    + (context.getStackLimitIP().opt - lbp.lineWidth);
-                lineArea.addTrait(Trait.START_INDENT, new Integer(updatedIndent));
-            }
-
-            setCurrentArea(lineArea);
-            setChildContext(lc);
-            LayoutManager childLM;
-            while ((childLM = inlinePosIter.getNextChildLM()) != null) {
-                lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
-                childLM.addAreas(inlinePosIter, lc);
-                lc.setLeadingSpace(lc.getTrailingSpace());
-                lc.setTrailingSpace(new SpaceSpecifier(false));
-            }
-
-            // when can this be null?
-            // if display-align is distribute, add space after
-            if (context.getSpaceAfter() > 0
-                    && (!context.isLastArea() || !isLastPosition)) {
-                lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
-            }
-            lineArea.finalise();
-            parentLM.addChildArea(lineArea);
+        // if display-align is distribute, add space after
+        if (context.getSpaceAfter() > 0
+                && (!context.isLastArea() || !isLastPosition)) {
+            lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
+        }
+        lineArea.finalise();
+        parentLM.addChildArea(lineArea);
     }
 
     /**
@@ -1783,7 +1626,7 @@
             // set last area flag
             blocklc.setFlags(LayoutContext.LAST_AREA,
                              (context.isLastArea() && childLM == lastLM));
-            blocklc.setStackLimitsFrom(context);
+            blocklc.setStackLimitBP(context.getStackLimitBP());
             // Add the line areas to Area
             childLM.addAreas(childPosIter, blocklc);
             blocklc.setLeadingSpace(blocklc.getTrailingSpace());
@@ -1824,5 +1667,11 @@
     public boolean getGeneratesLineArea() {
         return true;
     }
+
+    /** {@inheritDoc} */
+    public boolean isRestartable() {
+        return true;
+    }
+
 }
 

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -29,10 +29,10 @@
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
 import org.apache.fop.fo.flow.ListBlock;
+import org.apache.fop.fo.properties.KeepProperty;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
 import org.apache.fop.layoutmgr.ConditionalElementListener;
 import org.apache.fop.layoutmgr.ElementListUtils;
-import org.apache.fop.layoutmgr.KeepUtil;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.NonLeafPosition;
@@ -279,21 +279,18 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
-                getListBlockFO().getKeepTogether());
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
+    public KeepProperty getKeepTogetherProperty() {
+        return getListBlockFO().getKeepTogether();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getListBlockFO().getKeepWithNext());
+    public KeepProperty getKeepWithPreviousProperty() {
+        return getListBlockFO().getKeepWithPrevious();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getListBlockFO().getKeepWithPrevious());
+    public KeepProperty getKeepWithNextProperty() {
+        return getListBlockFO().getKeepWithNext();
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -28,8 +28,9 @@
 import org.apache.fop.fo.flow.AbstractListItemPart;
 import org.apache.fop.fo.flow.ListItemBody;
 import org.apache.fop.fo.flow.ListItemLabel;
+import org.apache.fop.fo.properties.KeepProperty;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.NonLeafPosition;
@@ -221,20 +222,18 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(getPartFO().getKeepTogether());
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
+    public KeepProperty getKeepTogetherProperty() {
+        return getPartFO().getKeepTogether();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -32,13 +32,13 @@
 import org.apache.fop.fo.flow.ListItem;
 import org.apache.fop.fo.flow.ListItemBody;
 import org.apache.fop.fo.flow.ListItemLabel;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
+import org.apache.fop.fo.properties.KeepProperty;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
 import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ConditionalElementListener;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.ElementListUtils;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
@@ -83,8 +83,8 @@
     private MinOptMax effSpaceBefore;
     private MinOptMax effSpaceAfter;
 
-    private int keepWithNextPendingOnLabel;
-    private int keepWithNextPendingOnBody;
+    private Keep keepWithNextPendingOnLabel;
+    private Keep keepWithNextPendingOnBody;
 
     private int listItemHeight;
 
@@ -254,8 +254,8 @@
 
         context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel);
         context.updateKeepWithNextPending(this.keepWithNextPendingOnBody);
-        context.updateKeepWithNextPending(getKeepWithNextStrength());
-        context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
+        context.updateKeepWithNextPending(getKeepWithNext());
+        context.updateKeepWithPreviousPending(getKeepWithPrevious());
 
         setFinished(true);
         resetSpaces();
@@ -276,16 +276,16 @@
         int totalHeight = Math.max(fullHeights[0], fullHeights[1]);
         int step;
         int addedBoxHeight = 0;
-        int keepWithNextActive = BlockLevelLayoutManager.KEEP_AUTO;
+        Keep keepWithNextActive = Keep.KEEP_AUTO;
 
         LinkedList returnList = new LinkedList();
         while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {
 
             if (end[0] + 1 == elementLists[0].size()) {
-                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnLabel);
+                keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnLabel);
             }
             if (end[1] + 1 == elementLists[1].size()) {
-                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnBody);
+                keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnBody);
             }
 
             // compute penalty height and box height
@@ -339,14 +339,13 @@
             }
 
             if (addedBoxHeight < totalHeight) {
-                int strength = BlockLevelLayoutManager.KEEP_AUTO;
-                strength = Math.max(strength, keepWithNextActive);
-                strength = Math.max(strength, getKeepTogetherStrength());
+                Keep keep = keepWithNextActive.compare(getKeepTogether());
                 int p = stepPenalty;
                 if (p > -KnuthElement.INFINITE) {
-                    p = Math.max(p, KeepUtil.getPenaltyForKeep(strength));
+                    p = Math.max(p, keep.getPenalty());
                 }
-                returnList.add(new BreakElement(stepPosition, penaltyHeight, p, -1, context));
+                returnList.add(new BreakElement(stepPosition, penaltyHeight, p, keep.getContext(),
+                        context));
             }
         }
 
@@ -644,21 +643,18 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
-                getListItemFO().getKeepTogether());
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
+    public KeepProperty getKeepTogetherProperty() {
+        return getListItemFO().getKeepTogether();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getListItemFO().getKeepWithNext());
+    public KeepProperty getKeepWithPreviousProperty() {
+        return getListItemFO().getKeepWithPrevious();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getListItemFO().getKeepWithPrevious());
+    public KeepProperty getKeepWithNextProperty() {
+        return getListItemFO().getKeepWithNext();
     }
 
     /** {@inheritDoc} */
@@ -706,6 +702,13 @@
         }
     }
 
+    /** {@inheritDoc} */
+    public void reset() {
+        super.reset();
+        label.reset();
+        body.reset();
+    }
+
 
 }
 

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java Fri Sep 18 17:10:42 2009
@@ -19,19 +19,21 @@
 
 package org.apache.fop.layoutmgr.table;
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.flow.table.ConditionalBorder;
 import org.apache.fop.fo.flow.table.EffRow;
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.ElementListUtils;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
@@ -73,7 +75,7 @@
     /** True if the next CellPart that will be created will be the last one for this cell. */
     private boolean lastCellPart;
 
-    private int keepWithNextStrength;
+    private Keep keepWithNext;
 
     private int spanIndex = 0;
 
@@ -133,7 +135,12 @@
             this.totalLength   = other.totalLength;
             this.penaltyLength = other.penaltyLength;
             this.penaltyValue  = other.penaltyValue;
-            this.footnoteList  = other.footnoteList;
+            if (other.footnoteList != null) {
+                if (this.footnoteList == null) {
+                    this.footnoteList = new ArrayList();
+                }
+                this.footnoteList.addAll(other.footnoteList);
+            }
             this.condBeforeContentLength = other.condBeforeContentLength;
             this.breakClass    = other.breakClass;
         }
@@ -211,7 +218,7 @@
         includedLength = -1;  // Avoid troubles with cells having content of zero length
         totalLength = previousRowsLength + ElementListUtils.calcContentLength(elementList);
         endRowIndex = rowIndex + pgu.getCell().getNumberRowsSpanned() - 1;
-        keepWithNextStrength = BlockLevelLayoutManager.KEEP_AUTO;
+        keepWithNext = Keep.KEEP_AUTO;
         remainingLength = totalLength - previousRowsLength;
 
         afterNextStep = new Step(previousRowsLength);
@@ -297,7 +304,9 @@
         afterNextStep.penaltyValue = 0;
         afterNextStep.condBeforeContentLength = 0;
         afterNextStep.breakClass = Constants.EN_AUTO;
-        afterNextStep.footnoteList = null;
+        if (afterNextStep.footnoteList != null) {
+            afterNextStep.footnoteList.clear();
+        }
         boolean breakFound = false;
         boolean prevIsBox = false;
         boolean boxFound = false;
@@ -305,7 +314,11 @@
             KnuthElement el = (KnuthElement) knuthIter.next();
             if (el.isPenalty()) {
                 prevIsBox = false;
-                if (el.getP() < KnuthElement.INFINITE) {
+                if (el.getP() < KnuthElement.INFINITE
+                        || ((KnuthPenalty) el).getBreakClass() == Constants.EN_PAGE) {
+                    // TODO too much is being done in that test, only to handle
+                    // keep.within-column properly.
+
                     // First legal break point
                     breakFound = true;
                     KnuthPenalty p = (KnuthPenalty) el;
@@ -524,7 +537,7 @@
      */
     CellPart createCellPart() {
         if (nextStep.end + 1 == elementList.size()) {
-            keepWithNextStrength = pgu.getKeepWithNextStrength();
+            keepWithNext = pgu.getKeepWithNext();
             // TODO if keep-with-next is set on the row, must every cell of the row
             // contribute some content from children blocks?
             // see http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-dev/200802.mbox/
@@ -563,11 +576,12 @@
     void addFootnotes(List footnoteList) {
         if (includedInLastStep() && nextStep.footnoteList != null) {
             footnoteList.addAll(nextStep.footnoteList);
+            nextStep.footnoteList.clear();
         }
     }
 
-    int getKeepWithNextStrength() {
-        return keepWithNextStrength;
+    Keep getKeepWithNext() {
+        return keepWithNext;
     }
 
     int getPenaltyValue() {

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -60,8 +60,8 @@
         LinkedList returnList = new LinkedList();
         createElementsForRowGroup(context, alignment, bodyType, returnList);
 
-        context.updateKeepWithPreviousPending(rowGroup[0].getKeepWithPreviousStrength());
-        context.updateKeepWithNextPending(rowGroup[rowGroup.length - 1].getKeepWithNextStrength());
+        context.updateKeepWithPreviousPending(rowGroup[0].getKeepWithPrevious());
+        context.updateKeepWithNextPending(rowGroup[rowGroup.length - 1].getKeepWithNext());
 
         int breakBefore = Constants.EN_AUTO;
         TableRow firstRow = rowGroup[0].getTableRow();

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -23,6 +23,7 @@
 import org.apache.fop.area.Block;
 import org.apache.fop.fo.flow.table.TableAndCaption;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.PositionIterator;
 
@@ -201,19 +202,8 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KEEP_AUTO;
-        /* TODO Complete me!
-        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
-                getTableAndCaptionFO().getKeepTogether());
-        */
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
-    }
-
-    /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
         /* TODO Complete me!
         return KeepUtil.getCombinedBlockLevelKeepStrength(
                 getTableAndCaptionFO().getKeepWithNext());
@@ -221,12 +211,12 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
         /* TODO Complete me!
         return KeepUtil.getCombinedBlockLevelKeepStrength(
                 getTableAndCaptionFO().getKeepWithPrevious());
         */
     }
 
-}
\ No newline at end of file
+}

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCaptionLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCaptionLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCaptionLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCaptionLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -23,6 +23,7 @@
 import org.apache.fop.area.Block;
 import org.apache.fop.fo.flow.table.TableCaption;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.PositionIterator;
 
@@ -197,21 +198,8 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KEEP_AUTO;
-        /* TODO Complete me!
-        strength = Math.max(strength, KeepUtil.getKeepStrength(
-                getTableCaptionFO().getKeepTogether().getWithinPage()));
-        strength = Math.max(strength, KeepUtil.getKeepStrength(
-                getTableCaptionFO().getKeepTogether().getWithinColumn()));
-        */
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
-    }
-
-    /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
         /* TODO Complete me!
         return KeepUtil.getCombinedBlockLevelKeepStrength(
                 getTableCaptionFO().getKeepWithNext());
@@ -219,8 +207,8 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KEEP_AUTO;
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
         /* TODO Complete me!
         return KeepUtil.getCombinedBlockLevelKeepStrength(
                 getTableCaptionFO().getKeepWithPrevious());

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.Trait;
@@ -31,21 +32,23 @@
 import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.Table;
-import org.apache.fop.fo.flow.table.TablePart;
 import org.apache.fop.fo.flow.table.TableCell;
 import org.apache.fop.fo.flow.table.TableColumn;
+import org.apache.fop.fo.flow.table.TablePart;
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
 import org.apache.fop.layoutmgr.AreaAdditionUtil;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.ElementListUtils;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.SpaceResolver;
@@ -138,9 +141,9 @@
         List contentList = new LinkedList();
         List returnList = new LinkedList();
 
-        BlockLevelLayoutManager curLM; // currently active LM
-        BlockLevelLayoutManager prevLM = null; // previously active LM
-        while ((curLM = (BlockLevelLayoutManager) getChildLM()) != null) {
+        LayoutManager curLM; // currently active LM
+        LayoutManager prevLM = null; // previously active LM
+        while ((curLM = getChildLM()) != null) {
             LayoutContext childLC = new LayoutContext(0);
             // curLM is a ?
             childLC.setStackLimitBP(MinOptMax.subtract(context
@@ -153,11 +156,12 @@
                 log.debug("child LM signals pending keep with next");
             }
             if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
-                primaryGridUnit.setKeepWithPreviousStrength(childLC.getKeepWithPreviousPending());
+                primaryGridUnit.setKeepWithPrevious(childLC.getKeepWithPreviousPending());
                 childLC.clearKeepWithPreviousPending();
             }
 
-            if (prevLM != null) {
+            if (prevLM != null
+                    && !ElementListUtils.endsWithForcedBreak(contentList)) {
                 // there is a block handled by prevLM
                 // before the one handled by curLM
                 addInBetweenBreak(contentList, context, childLC);
@@ -174,7 +178,7 @@
             }
             prevLM = curLM;
         }
-        primaryGridUnit.setKeepWithNextStrength(context.getKeepWithNextPending());
+        primaryGridUnit.setKeepWithNext(context.getKeepWithNextPending());
 
         returnedList = new LinkedList();
         if (!contentList.isEmpty()) {
@@ -195,7 +199,7 @@
         }
         final KnuthElement lastItem = (KnuthElement) ListUtil
                 .getLast(returnList);
-        if (((KnuthElement) lastItem).isForcedBreak()) {
+        if (lastItem.isForcedBreak()) {
             KnuthPenalty p = (KnuthPenalty) lastItem;
             primaryGridUnit.setBreakAfter(p.getBreakClass());
             p.setP(0);
@@ -556,26 +560,23 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KEEP_AUTO;
+    public Keep getKeepTogether() {
+        Keep keep = Keep.KEEP_AUTO;
         if (primaryGridUnit.getRow() != null) {
-            strength = Math.max(strength, KeepUtil.getKeepStrength(
-                    primaryGridUnit.getRow().getKeepTogether().getWithinPage()));
-            strength = Math.max(strength, KeepUtil.getKeepStrength(
-                    primaryGridUnit.getRow().getKeepTogether().getWithinColumn()));
+            keep = Keep.getKeep(primaryGridUnit.getRow().getKeepTogether());
         }
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
+        keep = keep.compare(getParentKeepTogether());
+        return keep;
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-next!)
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-next!)
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-previous!)
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-previous!)
     }
 
     // --------- Property Resolution related functions --------- //

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -35,10 +35,9 @@
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TablePart;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ElementListUtils;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
@@ -213,13 +212,13 @@
         context.clearKeepsPending();
         context.setBreakBefore(Constants.EN_AUTO);
         context.setBreakAfter(Constants.EN_AUTO);
-        int keepWithPrevious = BlockLevelLayoutManager.KEEP_AUTO;
+        Keep keepWithPrevious = Keep.KEEP_AUTO;
         int breakBefore = Constants.EN_AUTO;
         if (rowGroup != null) {
             RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup,
                     stepper);
             List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
-            keepWithPrevious = Math.max(keepWithPrevious, context.getKeepWithPreviousPending());
+            keepWithPrevious = keepWithPrevious.compare(context.getKeepWithPreviousPending());
             breakBefore = context.getBreakBefore();
             int breakBetween = context.getBreakAfter();
             returnList.addAll(nextRowGroupElems);
@@ -228,7 +227,7 @@
 
                 //Note previous pending keep-with-next and clear the strength
                 //(as the layout context is reused)
-                int keepWithNextPending = context.getKeepWithNextPending();
+                Keep keepWithNextPending = context.getKeepWithNextPending();
                 context.clearKeepWithNextPending();
 
                 //Get elements for next row group
@@ -246,17 +245,17 @@
                  */
 
                 //Determine keep constraints
-                int penaltyStrength = BlockLevelLayoutManager.KEEP_AUTO;
-                penaltyStrength = Math.max(penaltyStrength, keepWithNextPending);
-                penaltyStrength = Math.max(penaltyStrength, context.getKeepWithPreviousPending());
+                Keep keep = keepWithNextPending.compare(context.getKeepWithPreviousPending());
                 context.clearKeepWithPreviousPending();
-                penaltyStrength = Math.max(penaltyStrength, getTableLM().getKeepTogetherStrength());
-                int penaltyValue = KeepUtil.getPenaltyForKeep(penaltyStrength);
+                keep = keep.compare(getTableLM().getKeepTogether());
+                int penaltyValue = keep.getPenalty();
+                int breakClass = keep.getContext();
 
                 breakBetween = BreakUtil.compareBreakClasses(breakBetween,
                         context.getBreakBefore());
                 if (breakBetween != Constants.EN_AUTO) {
                     penaltyValue = -KnuthElement.INFINITE;
+                    breakClass = breakBetween;
                 }
                 BreakElement breakElement;
                 ListIterator elemIter = returnList.listIterator(returnList.size());
@@ -267,7 +266,7 @@
                     breakElement = (BreakElement) elem;
                 }
                 breakElement.setPenaltyValue(penaltyValue);
-                breakElement.setBreakClass(breakBetween);
+                breakElement.setBreakClass(breakClass);
                 returnList.addAll(nextRowGroupElems);
                 breakBetween = context.getBreakAfter();
             }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java Fri Sep 18 17:10:42 2009
@@ -35,11 +35,11 @@
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TableColumn;
+import org.apache.fop.fo.properties.KeepProperty;
 import org.apache.fop.layoutmgr.BlockLevelEventProducer;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
 import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ConditionalElementListener;
-import org.apache.fop.layoutmgr.KeepUtil;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.LayoutContext;
@@ -256,10 +256,10 @@
         log.debug(contentKnuthElements);
         wrapPositionElements(contentKnuthElements, returnList);
 
-        context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
+        context.updateKeepWithPreviousPending(getKeepWithPrevious());
         context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
 
-        context.updateKeepWithNextPending(getKeepWithNextStrength());
+        context.updateKeepWithNextPending(getKeepWithNext());
         context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
 
         if (getTable().isSeparateBorderModel()) {
@@ -448,20 +448,18 @@
     }
 
     /** {@inheritDoc} */
-    public int getKeepTogetherStrength() {
-        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepTogether());
-        strength = Math.max(strength, getParentKeepTogetherStrength());
-        return strength;
+    public KeepProperty getKeepTogetherProperty() {
+        return getTable().getKeepTogether();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithNextStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepWithNext());
+    public KeepProperty getKeepWithPreviousProperty() {
+        return getTable().getKeepWithPrevious();
     }
 
     /** {@inheritDoc} */
-    public int getKeepWithPreviousStrength() {
-        return KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepWithPrevious());
+    public KeepProperty getKeepWithNextProperty() {
+        return getTable().getKeepWithNext();
     }
 
     // --------- Property Resolution related functions --------- //

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableStepper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableStepper.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableStepper.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/layoutmgr/table/TableStepper.java Fri Sep 18 17:10:42 2009
@@ -30,12 +30,10 @@
 import org.apache.fop.fo.flow.table.EffRow;
 import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BreakElement;
-import org.apache.fop.layoutmgr.KeepUtil;
+import org.apache.fop.layoutmgr.Keep;
 import org.apache.fop.layoutmgr.KnuthBlockBox;
 import org.apache.fop.layoutmgr.KnuthBox;
-import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
@@ -241,40 +239,38 @@
                 }
             }
 
-            int strength = BlockLevelLayoutManager.KEEP_AUTO;
+            Keep keep = Keep.KEEP_AUTO;
             int stepPenalty = 0;
             for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
                 ActiveCell activeCell = (ActiveCell) iter.next();
-                strength = Math.max(strength, activeCell.getKeepWithNextStrength());
+                keep = keep.compare(activeCell.getKeepWithNext());
                 stepPenalty = Math.max(stepPenalty, activeCell.getPenaltyValue());
             }
             if (!rowFinished) {
-                strength = Math.max(strength, rowGroup[activeRowIndex].getKeepTogetherStrength());
+                keep = keep.compare(rowGroup[activeRowIndex].getKeepTogether());
                 //The above call doesn't take the penalty from the table into account, so...
-                strength = Math.max(strength, getTableLM().getKeepTogetherStrength());
+                keep = keep.compare(getTableLM().getKeepTogether());
             } else if (activeRowIndex < rowGroup.length - 1) {
-                strength = Math.max(strength,
-                        rowGroup[activeRowIndex].getKeepWithNextStrength());
-                strength = Math.max(strength,
-                        rowGroup[activeRowIndex + 1].getKeepWithPreviousStrength());
+                keep = keep.compare(rowGroup[activeRowIndex].getKeepWithNext());
+                keep = keep.compare(rowGroup[activeRowIndex + 1].getKeepWithPrevious());
                 nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
                         rowGroup[activeRowIndex].getBreakAfter());
                 nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
                         rowGroup[activeRowIndex + 1].getBreakBefore());
             }
-            int p = KeepUtil.getPenaltyForKeep(strength);
+            int p = keep.getPenalty();
             if (rowHeightSmallerThanFirstStep) {
                 rowHeightSmallerThanFirstStep = false;
                 p = KnuthPenalty.INFINITE;
             }
-            if (p > -KnuthElement.INFINITE) {
-                p = Math.max(p, stepPenalty);
-            }
+            p = Math.max(p, stepPenalty);
+            int breakClass = keep.getContext();
             if (nextBreakClass != Constants.EN_AUTO) {
                 log.trace("Forced break encountered");
                 p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in XSL 1.0)
+                breakClass = nextBreakClass;
             }
-            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, nextBreakClass, context));
+            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, breakClass, context));
             if (penaltyOrGlueLen < 0) {
                 returnList.add(new KnuthGlue(-penaltyOrGlueLen, 0, 0, new Position(null), true));
             }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFColor.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFColor.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFColor.java Fri Sep 18 17:10:42 2009
@@ -541,13 +541,8 @@
         return (new byte[0]);
     }
 
-    /**
-     * Check for equality of color with another object.
-     *
-     * @param obj the object to compare
-     * @return true if colors are equal
-     */
-    public boolean equals(Object obj) {
+    /** {@inheritDoc} */
+    protected boolean contentEquals(PDFObject obj) {
         if (!(obj instanceof PDFColor)) {
             return false;
         }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFDocument.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFDocument.java Fri Sep 18 17:10:42 2009
@@ -526,8 +526,8 @@
 
     private Object findPDFObject(List list, PDFObject compare) {
         for (Iterator iter = list.iterator(); iter.hasNext();) {
-            Object obj = iter.next();
-            if (compare.equals(obj)) {
+            PDFObject obj = (PDFObject) iter.next();
+            if (compare.contentEquals(obj)) {
                 return obj;
             }
         }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFactory.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFactory.java Fri Sep 18 17:10:42 2009
@@ -174,22 +174,24 @@
      * PDFDocument later using addObject().
      *
      * @param resources resources object to use
-     * @param pageWidth width of the page in points
-     * @param pageHeight height of the page in points
      * @param pageIndex index of the page (zero-based)
+     * @param mediaBox the MediaBox area
+     * @param cropBox the CropBox area
+     * @param bleedBox the BleedBox area
+     * @param trimBox the TrimBox area
      * @param currentPageParentKey the integer key in the structural parent tree
      *
      * @return the created /Page object
      */
-    public PDFPage makePage(PDFResources resources,
-                            int pageWidth, int pageHeight, int pageIndex,
+    public PDFPage makePage(PDFResources resources, int pageIndex,
+                            Rectangle2D mediaBox, Rectangle2D cropBox,
+                            Rectangle2D bleedBox, Rectangle2D trimBox,
                             int currentPageParentKey) {
         /*
          * create a PDFPage with the next object number, the given
          * resources, contents and dimensions
          */
-        PDFPage page = new PDFPage(resources,                       // old numPages
-                                   pageWidth, pageHeight, pageIndex);
+        PDFPage page = new PDFPage(resources, pageIndex, mediaBox, cropBox, bleedBox, trimBox);
         if (currentPageParentKey > -1) {
             //Accessibility is enabled
             page.setStructParents(currentPageParentKey);
@@ -217,7 +219,8 @@
      */
     public PDFPage makePage(PDFResources resources,
                             int pageWidth, int pageHeight, int pageIndex) {
-        return makePage(resources, pageWidth, pageHeight, pageIndex, -1);
+        Rectangle2D mediaBox = new Rectangle2D.Double(0, 0, pageWidth, pageHeight);
+        return makePage(resources, pageIndex, mediaBox, mediaBox, mediaBox, mediaBox, -1);
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFileSpec.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFileSpec.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFileSpec.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFileSpec.java Fri Sep 18 17:10:42 2009
@@ -63,13 +63,8 @@
      * endobj
      */
 
-    /**
-     * Check if this equals another object.
-     *
-     * @param obj the object to compare
-     * @return true if this equals other object
-     */
-    public boolean equals(Object obj) {
+    /** {@inheritDoc} */
+    protected boolean contentEquals(PDFObject obj) {
         if (this == obj) {
             return true;
         }

Modified: xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFunction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFunction.java?rev=816718&r1=816717&r2=816718&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFunction.java (original)
+++ xmlgraphics/fop/branches/Temp_Accessibility/src/java/org/apache/fop/pdf/PDFFunction.java Fri Sep 18 17:10:42 2009
@@ -696,15 +696,8 @@
 
     }
 
-    /**
-     * Check if this function is equal to another object.
-     * This is used to find if a particular function already exists
-     * in a document.
-     *
-     * @param obj the obj to compare
-     * @return true if the functions are equal
-     */
-    public boolean equals(Object obj) {
+    /** {@inheritDoc} */
+    protected boolean contentEquals(PDFObject obj) {
         if (obj == null) {
             return false;
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message