View | Details | Raw Unified | Return to bug 37579
Collapse All | Expand All

(-)src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (+35 lines)
Lines 21-26 Link Here
21
21
22
import java.util.List;
22
import java.util.List;
23
import java.util.ListIterator;
23
import java.util.ListIterator;
24
import java.util.LinkedList;
24
25
25
import org.apache.commons.logging.Log;
26
import org.apache.commons.logging.Log;
26
import org.apache.commons.logging.LogFactory;
27
import org.apache.commons.logging.LogFactory;
Lines 33-38 Link Here
33
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
34
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
34
import org.apache.fop.layoutmgr.ElementListUtils;
35
import org.apache.fop.layoutmgr.ElementListUtils;
35
import org.apache.fop.layoutmgr.KnuthBox;
36
import org.apache.fop.layoutmgr.KnuthBox;
37
import org.apache.fop.layoutmgr.KnuthBlockBox;
36
import org.apache.fop.layoutmgr.KnuthElement;
38
import org.apache.fop.layoutmgr.KnuthElement;
37
import org.apache.fop.layoutmgr.KnuthPenalty;
39
import org.apache.fop.layoutmgr.KnuthPenalty;
38
import org.apache.fop.layoutmgr.MinOptMaxUtil;
40
import org.apache.fop.layoutmgr.MinOptMaxUtil;
Lines 101-106 Link Here
101
        private int penaltyLength;
103
        private int penaltyLength;
102
        /** Value of the penalty ending this step, 0 if the step does not end on a penalty. */
104
        /** Value of the penalty ending this step, 0 if the step does not end on a penalty. */
103
        private int penaltyValue;
105
        private int penaltyValue;
106
        /** list of footnotes for this step */
107
        private List footnoteList;
104
        /**
108
        /**
105
         * One of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
109
         * One of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
106
         * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
110
         * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
Lines 130-135 Link Here
130
            this.totalLength   = other.totalLength;
134
            this.totalLength   = other.totalLength;
131
            this.penaltyLength = other.penaltyLength;
135
            this.penaltyLength = other.penaltyLength;
132
            this.penaltyValue  = other.penaltyValue;
136
            this.penaltyValue  = other.penaltyValue;
137
            this.footnoteList  = other.footnoteList;
133
            this.condBeforeContentLength = other.condBeforeContentLength;
138
            this.condBeforeContentLength = other.condBeforeContentLength;
134
            this.breakClass    = other.breakClass;
139
            this.breakClass    = other.breakClass;
135
        }
140
        }
Lines 293-298 Link Here
293
        afterNextStep.penaltyValue = 0;
298
        afterNextStep.penaltyValue = 0;
294
        afterNextStep.condBeforeContentLength = 0;
299
        afterNextStep.condBeforeContentLength = 0;
295
        afterNextStep.breakClass = Constants.EN_AUTO;
300
        afterNextStep.breakClass = Constants.EN_AUTO;
301
        afterNextStep.footnoteList = null;
296
        boolean breakFound = false;
302
        boolean breakFound = false;
297
        boolean prevIsBox = false;
303
        boolean prevIsBox = false;
298
        boolean boxFound = false;
304
        boolean boxFound = false;
Lines 322-327 Link Here
322
                }
328
                }
323
                prevIsBox = false;
329
                prevIsBox = false;
324
            } else {
330
            } else {
331
                if (el instanceof KnuthBlockBox
332
                        && ((KnuthBlockBox)el).hasAnchors()) {
333
                    if (afterNextStep.footnoteList == null) {
334
                        afterNextStep.footnoteList = new LinkedList();
335
                    }
336
                    afterNextStep.footnoteList.addAll(
337
                            ((KnuthBlockBox)el).getFootnoteBodyLMs());
338
                }
325
                prevIsBox = true;
339
                prevIsBox = true;
326
                boxFound = true;
340
                boxFound = true;
327
                afterNextStep.contentLength += el.getW();
341
                afterNextStep.contentLength += el.getW();
Lines 555-560 Link Here
555
        }
569
        }
556
    }
570
    }
557
571
572
    /**
573
     * Return the list of FootnoteBodyLMs for the 
574
     * next step.
575
     * 
576
     * @return  the list of footnotes
577
     */
578
    List getFootnoteList() {
579
        return this.nextStep.footnoteList;
580
    }
581
582
    /**
583
     * Return <code>true</code> if the next step has 
584
     * associated footnotes.
585
     * 
586
     * @return  true if there are associated footnotes
587
     */
588
    boolean hasFootnotes() {
589
        return this.nextStep.footnoteList != null 
590
                && !this.nextStep.footnoteList.isEmpty();
591
    }
592
558
    /** {@inheritDoc} */
593
    /** {@inheritDoc} */
559
    public String toString() {
594
    public String toString() {
560
        return "Cell " + (pgu.getRowIndex() + 1) + "." + (pgu.getColIndex() + 1);
595
        return "Cell " + (pgu.getRowIndex() + 1) + "." + (pgu.getColIndex() + 1);
(-)src/java/org/apache/fop/layoutmgr/table/TableStepper.java (-1 / +12 lines)
Lines 33-38 Link Here
33
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
33
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
34
import org.apache.fop.layoutmgr.BreakElement;
34
import org.apache.fop.layoutmgr.BreakElement;
35
import org.apache.fop.layoutmgr.KeepUtil;
35
import org.apache.fop.layoutmgr.KeepUtil;
36
import org.apache.fop.layoutmgr.KnuthBlockBox;
36
import org.apache.fop.layoutmgr.KnuthBox;
37
import org.apache.fop.layoutmgr.KnuthBox;
37
import org.apache.fop.layoutmgr.KnuthElement;
38
import org.apache.fop.layoutmgr.KnuthElement;
38
import org.apache.fop.layoutmgr.KnuthGlue;
39
import org.apache.fop.layoutmgr.KnuthGlue;
Lines 199-210 Link Here
199
                }
200
                }
200
            }
201
            }
201
202
203
            LinkedList footnoteList = new LinkedList();
202
            //Put all involved grid units into a list
204
            //Put all involved grid units into a list
203
            List cellParts = new java.util.ArrayList(columnCount);
205
            List cellParts = new java.util.ArrayList(columnCount);
204
            for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
206
            for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
205
                ActiveCell activeCell = (ActiveCell) iter.next();
207
                ActiveCell activeCell = (ActiveCell) iter.next();
206
                CellPart part = activeCell.createCellPart();
208
                CellPart part = activeCell.createCellPart();
207
                cellParts.add(part);
209
                cellParts.add(part);
210
                if (activeCell.hasFootnotes()) {
211
                    footnoteList.addAll(
212
                            activeCell.getFootnoteList());
213
                }
208
            }
214
            }
209
215
210
            //Create elements for step
216
            //Create elements for step
Lines 217-224 Link Here
217
                tcpos.setFlag(TableContentPosition.FIRST_IN_ROWGROUP, true);
223
                tcpos.setFlag(TableContentPosition.FIRST_IN_ROWGROUP, true);
218
            }
224
            }
219
            lastTCPos = tcpos;
225
            lastTCPos = tcpos;
220
            returnList.add(new KnuthBox(boxLen, tcpos, false));
221
226
227
            if (footnoteList.isEmpty()) {
228
                returnList.add(new KnuthBox(boxLen, tcpos, false));
229
            } else {
230
                returnList.add(new KnuthBlockBox(boxLen, footnoteList, tcpos, false));
231
            }
232
222
            int effPenaltyLen = Math.max(0, penaltyOrGlueLen);
233
            int effPenaltyLen = Math.max(0, penaltyOrGlueLen);
223
            TableHFPenaltyPosition penaltyPos = new TableHFPenaltyPosition(getTableLM());
234
            TableHFPenaltyPosition penaltyPos = new TableHFPenaltyPosition(getTableLM());
224
            if (bodyType == TableRowIterator.BODY) {
235
            if (bodyType == TableRowIterator.BODY) {
(-)src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java (-15 / +41 lines)
Lines 40-50 Link Here
40
import org.apache.fop.layoutmgr.ElementListUtils;
40
import org.apache.fop.layoutmgr.ElementListUtils;
41
import org.apache.fop.layoutmgr.KeepUtil;
41
import org.apache.fop.layoutmgr.KeepUtil;
42
import org.apache.fop.layoutmgr.KnuthBox;
42
import org.apache.fop.layoutmgr.KnuthBox;
43
import org.apache.fop.layoutmgr.KnuthBlockBox;
43
import org.apache.fop.layoutmgr.KnuthElement;
44
import org.apache.fop.layoutmgr.KnuthElement;
44
import org.apache.fop.layoutmgr.KnuthPenalty;
45
import org.apache.fop.layoutmgr.KnuthPenalty;
45
import org.apache.fop.layoutmgr.KnuthPossPosIter;
46
import org.apache.fop.layoutmgr.KnuthPossPosIter;
46
import org.apache.fop.layoutmgr.LayoutContext;
47
import org.apache.fop.layoutmgr.LayoutContext;
47
import org.apache.fop.layoutmgr.LayoutManager;
48
import org.apache.fop.layoutmgr.LayoutManager;
49
import org.apache.fop.layoutmgr.ListElement;
48
import org.apache.fop.layoutmgr.NonLeafPosition;
50
import org.apache.fop.layoutmgr.NonLeafPosition;
49
import org.apache.fop.layoutmgr.Position;
51
import org.apache.fop.layoutmgr.Position;
50
import org.apache.fop.layoutmgr.PositionIterator;
52
import org.apache.fop.layoutmgr.PositionIterator;
Lines 264-274 Link Here
264
    private LinkedList getCombinedKnuthElementsForListItem(LinkedList labelElements,
266
    private LinkedList getCombinedKnuthElementsForListItem(LinkedList labelElements,
265
                                                           LinkedList bodyElements,
267
                                                           LinkedList bodyElements,
266
                                                           LayoutContext context) {
268
                                                           LayoutContext context) {
267
        //Copy elements to array lists to improve element access performance
269
        //Copy elements to arrays to improve element access performance
268
        List[] elementLists = {new ArrayList(labelElements),
270
        ListElement[][] elementLists = new ListElement[2][];
269
                               new ArrayList(bodyElements)};
271
        elementLists[0] = (ListElement[])labelElements.toArray(new ListElement[1]);
270
        int[] fullHeights = {ElementListUtils.calcContentLength(elementLists[0]),
272
        elementLists[1] = (ListElement[])bodyElements.toArray(new ListElement[1]);
271
                ElementListUtils.calcContentLength(elementLists[1])};
273
        
274
        int[] fullHeights = {
275
                ElementListUtils.calcContentLength(labelElements),
276
                ElementListUtils.calcContentLength(bodyElements)};
272
        int[] partialHeights = {0, 0};
277
        int[] partialHeights = {0, 0};
273
        int[] start = {-1, -1};
278
        int[] start = {-1, -1};
274
        int[] end = {-1, -1};
279
        int[] end = {-1, -1};
Lines 282-291 Link Here
282
        while ((step = getNextStep(elementLists, start, end, partialHeights))
287
        while ((step = getNextStep(elementLists, start, end, partialHeights))
283
               > 0) {
288
               > 0) {
284
            
289
            
285
            if (end[0] + 1 == elementLists[0].size()) {
290
            if (end[0] + 1 == elementLists[0].length) {
286
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnLabel);
291
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnLabel);
287
            }
292
            }
288
            if (end[1] + 1 == elementLists[1].size()) {
293
            if (end[1] + 1 == elementLists[1].length) {
289
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnBody);
294
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnBody);
290
            }
295
            }
291
296
Lines 297-308 Link Here
297
            //Additional penalty height from penalties in the source lists
302
            //Additional penalty height from penalties in the source lists
298
            int additionalPenaltyHeight = 0;
303
            int additionalPenaltyHeight = 0;
299
            int stepPenalty = 0;
304
            int stepPenalty = 0;
300
            KnuthElement endEl = (KnuthElement)elementLists[0].get(end[0]);
305
            KnuthElement endEl = (KnuthElement)elementLists[0][end[0]];
301
            if (endEl instanceof KnuthPenalty) {
306
            if (endEl instanceof KnuthPenalty) {
302
                additionalPenaltyHeight = endEl.getW();
307
                additionalPenaltyHeight = endEl.getW();
303
                stepPenalty = Math.max(stepPenalty, endEl.getP());
308
                stepPenalty = Math.max(stepPenalty, endEl.getP());
304
            }
309
            }
305
            endEl = (KnuthElement)elementLists[1].get(end[1]);
310
            endEl = (KnuthElement)elementLists[1][end[1]];
306
            if (endEl instanceof KnuthPenalty) {
311
            if (endEl instanceof KnuthPenalty) {
307
                additionalPenaltyHeight = Math.max(
312
                additionalPenaltyHeight = Math.max(
308
                        additionalPenaltyHeight, endEl.getW());
313
                        additionalPenaltyHeight, endEl.getW());
Lines 312-322 Link Here
312
            int boxHeight = step - addedBoxHeight - penaltyHeight;
317
            int boxHeight = step - addedBoxHeight - penaltyHeight;
313
            penaltyHeight += additionalPenaltyHeight; //Add AFTER calculating boxHeight!
318
            penaltyHeight += additionalPenaltyHeight; //Add AFTER calculating boxHeight!
314
319
320
            // collect footnote information
321
            LinkedList footnoteList = null;
322
            ListElement el;
323
            for (int i = 0; i < elementLists.length; i ++) {
324
                for (int j = start[i]; j <= end[i]; j ++) {
325
                    el = elementLists[i][j];
326
                    if (el instanceof KnuthBlockBox
327
                            && ((KnuthBlockBox) el).hasAnchors()) {
328
                        if (footnoteList == null) {
329
                            footnoteList = new LinkedList();
330
                        }
331
                        footnoteList.addAll(
332
                                ((KnuthBlockBox) el).getFootnoteBodyLMs());
333
                    }
334
                }
335
            }
336
315
            // add the new elements
337
            // add the new elements
316
            addedBoxHeight += boxHeight;
338
            addedBoxHeight += boxHeight;
317
            ListItemPosition stepPosition = new ListItemPosition(this, 
339
            ListItemPosition stepPosition = new ListItemPosition(this,
318
                    start[0], end[0], start[1], end[1]);
340
                    start[0], end[0], start[1], end[1]);
319
            returnList.add(new KnuthBox(boxHeight, stepPosition, false));
341
            if (footnoteList == null) {
342
                returnList.add(new KnuthBox(boxHeight, stepPosition, false));
343
            } else {
344
                returnList.add(new KnuthBlockBox(boxHeight, footnoteList, stepPosition, false));
345
            }
320
            if (addedBoxHeight < totalHeight) {
346
            if (addedBoxHeight < totalHeight) {
321
                int strength = BlockLevelLayoutManager.KEEP_AUTO;
347
                int strength = BlockLevelLayoutManager.KEEP_AUTO;
322
                strength = Math.max(strength, keepWithNextActive);
348
                strength = Math.max(strength, keepWithNextActive);
Lines 332-338 Link Here
332
        return returnList;
358
        return returnList;
333
    }
359
    }
334
360
335
    private int getNextStep(List[] elementLists, int[] start, int[] end, int[] partialHeights) {
361
    private int getNextStep(ListElement[][] elementLists, int[] start, int[] end, int[] partialHeights) {
336
        // backup of partial heights
362
        // backup of partial heights
337
        int[] backupHeights = {partialHeights[0], partialHeights[1]};
363
        int[] backupHeights = {partialHeights[0], partialHeights[1]};
338
364
Lines 343-351 Link Here
343
        // get next possible sequence for label and body
369
        // get next possible sequence for label and body
344
        int seqCount = 0;
370
        int seqCount = 0;
345
        for (int i = 0; i < start.length; i++) {
371
        for (int i = 0; i < start.length; i++) {
346
            while (end[i] + 1 < elementLists[i].size()) {
372
            while (end[i] + 1 < elementLists[i].length) {
347
                end[i]++;
373
                end[i]++;
348
                KnuthElement el = (KnuthElement)elementLists[i].get(end[i]);
374
                KnuthElement el = (KnuthElement)elementLists[i][end[i]];
349
                if (el.isPenalty()) {
375
                if (el.isPenalty()) {
350
                    if (el.getP() < KnuthElement.INFINITE) {
376
                    if (el.getP() < KnuthElement.INFINITE) {
351
                        //First legal break point
377
                        //First legal break point
Lines 353-359 Link Here
353
                    }
379
                    }
354
                } else if (el.isGlue()) {
380
                } else if (el.isGlue()) {
355
                    if (end[i] > 0) {
381
                    if (end[i] > 0) {
356
                        KnuthElement prev = (KnuthElement)elementLists[i].get(end[i] - 1);
382
                        KnuthElement prev = (KnuthElement)elementLists[i][end[i] - 1];
357
                        if (prev.isBox()) {
383
                        if (prev.isBox()) {
358
                            //Second legal break point
384
                            //Second legal break point
359
                            break;
385
                            break;
(-)src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java (-1 / +19 lines)
Lines 23-34 Link Here
23
23
24
import org.apache.fop.area.Area;
24
import org.apache.fop.area.Area;
25
import org.apache.fop.fo.flow.FootnoteBody;
25
import org.apache.fop.fo.flow.FootnoteBody;
26
import org.apache.fop.layoutmgr.inline.FootnoteLayoutManager;
26
27
27
/**
28
/**
28
 * Layout manager for footnote bodies.
29
 * Layout manager for footnote bodies.
29
 */
30
 */
30
public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
31
public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {
31
32
33
    private FootnoteLayoutManager footnoteLM;
34
32
    /**
35
    /**
33
     * Creates a new FootnoteBodyLayoutManager.
36
     * Creates a new FootnoteBodyLayoutManager.
34
     * @param body the footnote-body element
37
     * @param body the footnote-body element
Lines 37-42 Link Here
37
        super(body);
40
        super(body);
38
    }
41
    }
39
42
43
    public void setParent(LayoutManager lm) {
44
        super.setParent(lm);
45
        if (footnoteLM == null) {
46
            assert (lm instanceof FootnoteLayoutManager);
47
            footnoteLM = (FootnoteLayoutManager) lm;
48
        }
49
    }
50
40
    /** {@inheritDoc} */
51
    /** {@inheritDoc} */
41
    public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
52
    public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
42
        LayoutManager childLM = null;
53
        LayoutManager childLM = null;
Lines 105-109 Link Here
105
    public int getKeepWithPreviousStrength() {
116
    public int getKeepWithPreviousStrength() {
106
        return KEEP_AUTO;
117
        return KEEP_AUTO;
107
    }
118
    }
108
    
119
120
    /**
121
     * {@inheritDoc}
122
     * <i>Note: overridden to always return the associated FootnoteLM</i>
123
     */
124
    public LayoutManager getParent() {
125
        return footnoteLM;
126
    }
109
}
127
}

Return to bug 37579