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

(-)src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java (-6 / +6 lines)
Lines 415-432 Link Here
415
    }
415
    }
416
416
417
    /** {@inheritDoc} */
417
    /** {@inheritDoc} */
418
    public int getKeepTogetherStrength() {
418
    public Keep getKeepTogether() {
419
        return KEEP_AUTO;
419
        return Keep.KEEP_AUTO;
420
    }
420
    }
421
421
422
    /** {@inheritDoc} */
422
    /** {@inheritDoc} */
423
    public int getKeepWithNextStrength() {
423
    public Keep getKeepWithNext() {
424
        return KEEP_AUTO;
424
        return Keep.KEEP_AUTO;
425
    }
425
    }
426
426
427
    /** {@inheritDoc} */
427
    /** {@inheritDoc} */
428
    public int getKeepWithPreviousStrength() {
428
    public Keep getKeepWithPrevious() {
429
        return KEEP_AUTO;
429
        return Keep.KEEP_AUTO;
430
    }
430
    }
431
431
432
}
432
}
(-)src/java/org/apache/fop/layoutmgr/KeepUtil.java (-109 lines)
Lines 1-109 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/* $Id$ */
19
20
package org.apache.fop.layoutmgr;
21
22
import org.apache.fop.fo.Constants;
23
import org.apache.fop.fo.properties.KeepProperty;
24
import org.apache.fop.fo.properties.Property;
25
26
/**
27
 * Utility class for working with keeps.
28
 */
29
public class KeepUtil {
30
31
    /**
32
     * Converts a keep property into an integer value.
33
     * <p>
34
     * Note: The conversion restricts the effectively available integer range by two values.
35
     * Integer.MIN_VALUE is used to represent the value "auto" and
36
     * Integer.MAX_VALUE is used to represebt the value "always".
37
     * @param keep the keep property
38
     * @return the keep value as an integer
39
     */
40
    public static int getKeepStrength(Property keep) {
41
        if (keep.isAuto()) {
42
            return BlockLevelLayoutManager.KEEP_AUTO;
43
        } else if (keep.getEnum() == Constants.EN_ALWAYS) {
44
            return BlockLevelLayoutManager.KEEP_ALWAYS;
45
        } else {
46
            return keep.getNumber().intValue();
47
        }
48
    }
49
50
    /**
51
     * Returns the combined block-level keep strength from a keep property.
52
     * <p>
53
     * Note: This is a temporary method to be used until it is possible to differentiate between
54
     * page and column keeps!
55
     * @param keep the keep property
56
     * @return the combined keep strength
57
     */
58
    public static int getCombinedBlockLevelKeepStrength(KeepProperty keep) {
59
        return Math.max(
60
                getKeepStrength(keep.getWithinPage()),
61
                getKeepStrength(keep.getWithinColumn()));
62
    }
63
64
    /**
65
     * Indicates whether a keep strength indicates a keep constraint.
66
     * @param strength the keep strength
67
     * @return true if the keep is not "auto"
68
     */
69
    public static boolean hasKeep(int strength) {
70
        return strength > BlockLevelLayoutManager.KEEP_AUTO;
71
    }
72
73
    /**
74
     * Returns the penalty value to be used for a certain keep strength.
75
     * <ul>
76
     *   <li>"auto": returns 0</li>
77
     *   <li>"always": returns KnuthElement.INFINITE</li>
78
     *   <li>otherwise: returns KnuthElement.INFINITE - 1</li>
79
     * </ul>
80
     * @param keepStrength the keep strength
81
     * @return the penalty value
82
     */
83
    public static int getPenaltyForKeep(int keepStrength) {
84
        if (keepStrength == BlockLevelLayoutManager.KEEP_AUTO) {
85
            return 0;
86
        }
87
        int penalty = KnuthElement.INFINITE;
88
        if (keepStrength < BlockLevelLayoutManager.KEEP_ALWAYS) {
89
            penalty--;
90
        }
91
        return penalty;
92
    }
93
94
    /**
95
     * Returns a string representation of a keep strength value.
96
     * @param keepStrength the keep strength
97
     * @return the string representation
98
     */
99
    public static String keepStrengthToString(int keepStrength) {
100
        if (keepStrength == BlockLevelLayoutManager.KEEP_AUTO) {
101
            return "auto";
102
        } else if (keepStrength == BlockLevelLayoutManager.KEEP_ALWAYS) {
103
            return "always";
104
        } else {
105
            return Integer.toString(keepStrength);
106
        }
107
    }
108
109
}
(-)src/java/org/apache/fop/layoutmgr/KnuthPenalty.java (+11 lines)
Lines 169-174 Link Here
169
            }
169
            }
170
            sb.append(")");
170
            sb.append(")");
171
        }
171
        }
172
        switch (getBreakClass()) {
173
        case Constants.EN_PAGE:
174
            sb.append(" (page context)");
175
            break;
176
        case Constants.EN_COLUMN:
177
            sb.append(" (column context)");
178
            break;
179
        case Constants.EN_LINE:
180
            sb.append(" (line context)");
181
            break;
182
        }
172
        return sb.toString();
183
        return sb.toString();
173
    }
184
    }
174
185
(-)src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (-19 / +35 lines)
Lines 36-41 Link Here
36
import org.apache.fop.fo.Constants;
36
import org.apache.fop.fo.Constants;
37
import org.apache.fop.fo.flow.Block;
37
import org.apache.fop.fo.flow.Block;
38
import org.apache.fop.fo.properties.CommonHyphenation;
38
import org.apache.fop.fo.properties.CommonHyphenation;
39
import org.apache.fop.fo.properties.KeepProperty;
39
import org.apache.fop.fonts.Font;
40
import org.apache.fop.fonts.Font;
40
import org.apache.fop.fonts.FontInfo;
41
import org.apache.fop.fonts.FontInfo;
41
import org.apache.fop.fonts.FontTriplet;
42
import org.apache.fop.fonts.FontTriplet;
Lines 46-52 Link Here
46
import org.apache.fop.layoutmgr.BreakingAlgorithm;
47
import org.apache.fop.layoutmgr.BreakingAlgorithm;
47
import org.apache.fop.layoutmgr.ElementListObserver;
48
import org.apache.fop.layoutmgr.ElementListObserver;
48
import org.apache.fop.layoutmgr.InlineKnuthSequence;
49
import org.apache.fop.layoutmgr.InlineKnuthSequence;
49
import org.apache.fop.layoutmgr.KeepUtil;
50
import org.apache.fop.layoutmgr.Keep;
50
import org.apache.fop.layoutmgr.KnuthBlockBox;
51
import org.apache.fop.layoutmgr.KnuthBlockBox;
51
import org.apache.fop.layoutmgr.KnuthBox;
52
import org.apache.fop.layoutmgr.KnuthBox;
52
import org.apache.fop.layoutmgr.KnuthElement;
53
import org.apache.fop.layoutmgr.KnuthElement;
Lines 1054-1065 Link Here
1054
        for (int p = 0; p < knuthParagraphs.size(); p++) {
1055
        for (int p = 0; p < knuthParagraphs.size(); p++) {
1055
            // penalty between paragraphs
1056
            // penalty between paragraphs
1056
            if (p > 0) {
1057
            if (p > 0) {
1057
                int strength = getKeepTogetherStrength();
1058
                Keep keep = getKeepTogether();
1058
                int penalty = KeepUtil.getPenaltyForKeep(strength);
1059
                int penalty = keep.getPenalty();
1059
                if (penalty < KnuthElement.INFINITE) {
1060
//                if (penalty < KnuthElement.INFINITE) {
1060
                    returnList.add(new BreakElement(
1061
                    returnList.add(new BreakElement(
1061
                            new Position(this), penalty, context));
1062
                            new Position(this), penalty, keep.getContext(), context));
1062
                }
1063
//                }
1063
            }
1064
            }
1064
1065
1065
            LineLayoutPossibilities llPoss;
1066
            LineLayoutPossibilities llPoss;
Lines 1098-1109 Link Here
1098
                            && i >= fobj.getOrphans()
1099
                            && i >= fobj.getOrphans()
1099
                            && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
1100
                            && i <= llPoss.getChosenLineCount() - fobj.getWidows()) {
1100
                        // penalty allowing a page break between lines
1101
                        // penalty allowing a page break between lines
1101
                        int strength = getKeepTogetherStrength();
1102
                        Keep keep = getKeepTogether();
1102
                        int penalty = KeepUtil.getPenaltyForKeep(strength);
1103
                        int penalty = keep.getPenalty();
1103
                        if (penalty < KnuthElement.INFINITE) {
1104
//                        if (penalty < KnuthElement.INFINITE) {
1104
                            returnList.add(new BreakElement(
1105
                            returnList.add(new BreakElement(
1105
                                    returnPosition, penalty, context));
1106
                                    returnPosition, penalty, keep.getContext(), context));
1106
                        }
1107
//                        }
1107
                    }
1108
                    }
1108
                    int endIndex
1109
                    int endIndex
1109
                      = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
1110
                      = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
Lines 1283-1310 Link Here
1283
    }
1284
    }
1284
1285
1285
    /** {@inheritDoc} */
1286
    /** {@inheritDoc} */
1286
    public int getKeepTogetherStrength() {
1287
    public KeepProperty getKeepTogetherProperty() {
1287
        return ((BlockLevelLayoutManager) getParent()).getKeepTogetherStrength();
1288
        return ((BlockLevelLayoutManager) getParent()).getKeepTogetherProperty();
1288
    }
1289
    }
1289
1290
1290
    /** {@inheritDoc} */
1291
    /** {@inheritDoc} */
1292
    public KeepProperty getKeepWithPreviousProperty() {
1293
        return ((BlockLevelLayoutManager) getParent()).getKeepWithPreviousProperty();
1294
    }
1295
1296
    /** {@inheritDoc} */
1297
    public KeepProperty getKeepWithNextProperty() {
1298
        return ((BlockLevelLayoutManager) getParent()).getKeepWithNextProperty();
1299
    }
1300
1301
    /** {@inheritDoc} */
1302
    public Keep getKeepTogether() {
1303
        return ((BlockLevelLayoutManager) getParent()).getKeepTogether();
1304
    }
1305
1306
    /** {@inheritDoc} */
1291
    public boolean mustKeepWithPrevious() {
1307
    public boolean mustKeepWithPrevious() {
1292
        return getKeepWithPreviousStrength() > KEEP_AUTO;
1308
        return !getKeepWithPrevious().isAuto();
1293
    }
1309
    }
1294
1310
1295
    /** {@inheritDoc} */
1311
    /** {@inheritDoc} */
1296
    public boolean mustKeepWithNext() {
1312
    public boolean mustKeepWithNext() {
1297
        return getKeepWithNextStrength() > KEEP_AUTO;
1313
        return !getKeepWithNext().isAuto();
1298
    }
1314
    }
1299
1315
1300
    /** {@inheritDoc} */
1316
    /** {@inheritDoc} */
1301
    public int getKeepWithNextStrength() {
1317
    public Keep getKeepWithNext() {
1302
        return KEEP_AUTO;
1318
        return Keep.KEEP_AUTO;
1303
    }
1319
    }
1304
1320
1305
    /** {@inheritDoc} */
1321
    /** {@inheritDoc} */
1306
    public int getKeepWithPreviousStrength() {
1322
    public Keep getKeepWithPrevious() {
1307
        return KEEP_AUTO;
1323
        return Keep.KEEP_AUTO;
1308
    }
1324
    }
1309
1325
1310
    /** {@inheritDoc} */
1326
    /** {@inheritDoc} */
(-)src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (-1 / +7 lines)
Lines 399-405 Link Here
399
                ListElement lastBreakElement = effectiveList.getElement(endElementIndex);
399
                ListElement lastBreakElement = effectiveList.getElement(endElementIndex);
400
                if (lastBreakElement.isPenalty()) {
400
                if (lastBreakElement.isPenalty()) {
401
                    KnuthPenalty pen = (KnuthPenalty)lastBreakElement;
401
                    KnuthPenalty pen = (KnuthPenalty)lastBreakElement;
402
                    lastBreakClass = pen.getBreakClass();
402
                    // TODO Handle keep.within-column differently so that break class is
403
                    // automatically set to the right value
404
                    if (pen.getP() >= KnuthPenalty.INFINITE - 1) {
405
                        lastBreakClass = Constants.EN_COLUMN;
406
                    } else {
407
                        lastBreakClass = pen.getBreakClass();
408
                    }
403
                } else {
409
                } else {
404
                    lastBreakClass = Constants.EN_COLUMN;
410
                    lastBreakClass = Constants.EN_COLUMN;
405
                }
411
                }
(-)src/java/org/apache/fop/layoutmgr/BlockLevelLayoutManager.java (-8 / +11 lines)
Lines 19-24 Link Here
19
19
20
package org.apache.fop.layoutmgr;
20
package org.apache.fop.layoutmgr;
21
21
22
import org.apache.fop.fo.properties.KeepProperty;
23
22
/**
24
/**
23
 * The interface for LayoutManagers which generate block areas
25
 * The interface for LayoutManagers which generate block areas
24
 */
26
 */
Lines 35-54 Link Here
35
    /** Adjustment class: adjustment for line height */
37
    /** Adjustment class: adjustment for line height */
36
    int LINE_HEIGHT_ADJUSTMENT = 3;
38
    int LINE_HEIGHT_ADJUSTMENT = 3;
37
39
38
    /** The integer value for "auto" keep strength */
39
    int KEEP_AUTO = Integer.MIN_VALUE;
40
    /** The integer value for "always" keep strength */
41
    int KEEP_ALWAYS = Integer.MAX_VALUE;
42
43
    int negotiateBPDAdjustment(int adj, KnuthElement lastElement);
40
    int negotiateBPDAdjustment(int adj, KnuthElement lastElement);
44
41
45
    void discardSpace(KnuthGlue spaceGlue);
42
    void discardSpace(KnuthGlue spaceGlue);
46
43
44
    KeepProperty getKeepTogetherProperty();
45
46
    KeepProperty getKeepWithPreviousProperty();
47
48
    KeepProperty getKeepWithNextProperty();
49
47
    /**
50
    /**
48
     * Returns the keep-together strength for this element.
51
     * Returns the keep-together strength for this element.
49
     * @return the keep-together strength
52
     * @return the keep-together strength
50
     */
53
     */
51
    int getKeepTogetherStrength();
54
    Keep getKeepTogether();
52
55
53
    /**
56
    /**
54
     * @return true if this element must be kept together
57
     * @return true if this element must be kept together
Lines 59-65 Link Here
59
     * Returns the keep-with-previous strength for this element.
62
     * Returns the keep-with-previous strength for this element.
60
     * @return the keep-with-previous strength
63
     * @return the keep-with-previous strength
61
     */
64
     */
62
    int getKeepWithPreviousStrength();
65
    Keep getKeepWithPrevious();
63
66
64
    /**
67
    /**
65
     * @return true if this element must be kept with the previous element.
68
     * @return true if this element must be kept with the previous element.
Lines 70-76 Link Here
70
     * Returns the keep-with-next strength for this element.
73
     * Returns the keep-with-next strength for this element.
71
     * @return the keep-with-next strength
74
     * @return the keep-with-next strength
72
     */
75
     */
73
    int getKeepWithNextStrength();
76
    Keep getKeepWithNext();
74
77
75
    /**
78
    /**
76
     * @return true if this element must be kept with the next element.
79
     * @return true if this element must be kept with the next element.
(-)src/java/org/apache/fop/layoutmgr/LayoutContext.java (-17 / +16 lines)
Lines 145-152 Link Here
145
    private int breakBefore;
145
    private int breakBefore;
146
    private int breakAfter;
146
    private int breakAfter;
147
147
148
    private int pendingKeepWithNext = BlockLevelLayoutManager.KEEP_AUTO;
148
    private Keep pendingKeepWithNext = Keep.KEEP_AUTO;
149
    private int pendingKeepWithPrevious = BlockLevelLayoutManager.KEEP_AUTO;
149
    private Keep pendingKeepWithPrevious = Keep.KEEP_AUTO;
150
150
151
    private int disableColumnBalancing;
151
    private int disableColumnBalancing;
152
152
Lines 237-243 Link Here
237
     * Returns the strength of a keep-with-next currently pending.
237
     * Returns the strength of a keep-with-next currently pending.
238
     * @return the keep-with-next strength
238
     * @return the keep-with-next strength
239
     */
239
     */
240
    public int getKeepWithNextPending() {
240
    public Keep getKeepWithNextPending() {
241
        return this.pendingKeepWithNext;
241
        return this.pendingKeepWithNext;
242
    }
242
    }
243
243
Lines 245-251 Link Here
245
     * Returns the strength of a keep-with-previous currently pending.
245
     * Returns the strength of a keep-with-previous currently pending.
246
     * @return the keep-with-previous strength
246
     * @return the keep-with-previous strength
247
     */
247
     */
248
    public int getKeepWithPreviousPending() {
248
    public Keep getKeepWithPreviousPending() {
249
        return this.pendingKeepWithPrevious;
249
        return this.pendingKeepWithPrevious;
250
    }
250
    }
251
251
Lines 253-266 Link Here
253
     * Clears any pending keep-with-next strength.
253
     * Clears any pending keep-with-next strength.
254
     */
254
     */
255
    public void clearKeepWithNextPending() {
255
    public void clearKeepWithNextPending() {
256
        this.pendingKeepWithNext = BlockLevelLayoutManager.KEEP_AUTO;
256
        this.pendingKeepWithNext = Keep.KEEP_AUTO;
257
    }
257
    }
258
258
259
    /**
259
    /**
260
     * Clears any pending keep-with-previous strength.
260
     * Clears any pending keep-with-previous strength.
261
     */
261
     */
262
    public void clearKeepWithPreviousPending() {
262
    public void clearKeepWithPreviousPending() {
263
        this.pendingKeepWithPrevious = BlockLevelLayoutManager.KEEP_AUTO;
263
        this.pendingKeepWithPrevious = Keep.KEEP_AUTO;
264
    }
264
    }
265
265
266
    /**
266
    /**
Lines 273-290 Link Here
273
273
274
    /**
274
    /**
275
     * Updates the currently pending keep-with-next strength.
275
     * Updates the currently pending keep-with-next strength.
276
     * @param strength the new strength to consider
276
     * @param keep the new strength to consider
277
     */
277
     */
278
    public void updateKeepWithNextPending(int strength) {
278
    public void updateKeepWithNextPending(Keep keep) {
279
        this.pendingKeepWithNext = Math.max(this.pendingKeepWithNext, strength);
279
        this.pendingKeepWithNext = this.pendingKeepWithNext.compare(keep);
280
    }
280
    }
281
281
282
    /**
282
    /**
283
     * Updates the currently pending keep-with-previous strength.
283
     * Updates the currently pending keep-with-previous strength.
284
     * @param strength the new strength to consider
284
     * @param keep the new strength to consider
285
     */
285
     */
286
    public void updateKeepWithPreviousPending(int strength) {
286
    public void updateKeepWithPreviousPending(Keep keep) {
287
        this.pendingKeepWithPrevious = Math.max(this.pendingKeepWithPrevious, strength);
287
        this.pendingKeepWithPrevious = this.pendingKeepWithPrevious.compare(keep);
288
    }
288
    }
289
289
290
    /**
290
    /**
Lines 292-298 Link Here
292
     * @return true if a keep-with-next constraint is pending
292
     * @return true if a keep-with-next constraint is pending
293
     */
293
     */
294
    public boolean isKeepWithNextPending() {
294
    public boolean isKeepWithNextPending() {
295
        return getKeepWithNextPending() != BlockLevelLayoutManager.KEEP_AUTO;
295
        return !getKeepWithNextPending().isAuto();
296
    }
296
    }
297
297
298
    /**
298
    /**
Lines 300-306 Link Here
300
     * @return true if a keep-with-previous constraint is pending
300
     * @return true if a keep-with-previous constraint is pending
301
     */
301
     */
302
    public boolean isKeepWithPreviousPending() {
302
    public boolean isKeepWithPreviousPending() {
303
        return getKeepWithPreviousPending() != BlockLevelLayoutManager.KEEP_AUTO;
303
        return !getKeepWithPreviousPending().isAuto();
304
    }
304
    }
305
305
306
    public void setLeadingSpace(SpaceSpecifier space) {
306
    public void setLeadingSpace(SpaceSpecifier space) {
Lines 677-685 Link Here
677
        + "\nStarts New Area: \t" + startsNewArea()
677
        + "\nStarts New Area: \t" + startsNewArea()
678
        + "\nIs Last Area: \t" + isLastArea()
678
        + "\nIs Last Area: \t" + isLastArea()
679
        + "\nTry Hyphenate: \t" + tryHyphenate()
679
        + "\nTry Hyphenate: \t" + tryHyphenate()
680
        + "\nKeeps: \t[keep-with-next=" + KeepUtil.keepStrengthToString(getKeepWithNextPending())
680
        + "\nKeeps: \t[keep-with-next=" + getKeepWithNextPending()
681
                + "][keep-with-previous="
681
                + "][keep-with-previous=" + getKeepWithPreviousPending() + "] pending"
682
                + KeepUtil.keepStrengthToString(getKeepWithPreviousPending()) + "] pending"
683
        + "\nBreaks: \tforced [" + (breakBefore != Constants.EN_AUTO ? "break-before" : "") + "]["
682
        + "\nBreaks: \tforced [" + (breakBefore != Constants.EN_AUTO ? "break-before" : "") + "]["
684
        + (breakAfter != Constants.EN_AUTO ? "break-after" : "") + "]";
683
        + (breakAfter != Constants.EN_AUTO ? "break-after" : "") + "]";
685
    }
684
    }
(-)src/java/org/apache/fop/layoutmgr/Keep.java (+132 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3
 * agreements. See the NOTICE file distributed with this work for additional information
4
 * regarding copyright ownership. The ASF licenses this file to You under the Apache
5
 * License, Version 2.0 (the "License"); you may not use this file except in compliance
6
 * with the License. You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software distributed under
11
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12
 * KIND, either express or implied. See the License for the specific language governing
13
 * permissions and limitations under the License.
14
 */
15
16
/* $Id$ */
17
18
package org.apache.fop.layoutmgr;
19
20
import org.apache.fop.fo.Constants;
21
import org.apache.fop.fo.properties.KeepProperty;
22
import org.apache.fop.fo.properties.Property;
23
24
/**
25
 * TODO javadoc
26
 */
27
public class Keep {
28
29
    private static final int STRENGTH_AUTO = Integer.MIN_VALUE;
30
31
    private static final int STRENGTH_ALWAYS = Integer.MAX_VALUE;
32
33
    /** The integer value for "auto" keep strength. */
34
    public static final Keep KEEP_AUTO = new Keep(STRENGTH_AUTO, Constants.EN_AUTO);
35
36
    /** The integer value for "always" keep strength. */
37
    public static final Keep KEEP_ALWAYS = new Keep(STRENGTH_ALWAYS, Constants.EN_LINE);
38
39
    private int strength;
40
41
    private int context;
42
43
    private Keep(int strength, int context) {
44
        this.strength = strength;
45
        this.context = context;
46
    }
47
48
    private static int getKeepStrength(Property keep) {
49
        if (keep.isAuto()) {
50
            return STRENGTH_AUTO;
51
        } else if (keep.getEnum() == Constants.EN_ALWAYS) {
52
            return STRENGTH_ALWAYS;
53
        } else {
54
            return keep.getNumber().intValue();
55
        }
56
    }
57
58
    public static Keep getKeep(KeepProperty keepProperty) {
59
        Keep keep = new Keep(STRENGTH_AUTO, Constants.EN_AUTO);
60
        keep.update(keepProperty.getWithinPage(),   Constants.EN_PAGE);
61
        keep.update(keepProperty.getWithinColumn(), Constants.EN_COLUMN);
62
        keep.update(keepProperty.getWithinLine(),   Constants.EN_LINE);
63
        return keep;
64
    }
65
66
    private void update(Property keep, int context) {
67
        if (!keep.isAuto()) {
68
            this.strength = getKeepStrength(keep);
69
            this.context = context;
70
        }
71
    }
72
73
    public boolean isAuto() {
74
        return strength == STRENGTH_AUTO;
75
    }
76
77
    /**
78
     * Returns the context of this keep.
79
     *
80
     * @return one of {@link Constants#EN_LINE}, {@link Constants#EN_COLUMN} or
81
     * {@link Constants#EN_PAGE}
82
     */
83
    public int getContext() {
84
        return context;
85
    }
86
87
    public int getPenalty() {
88
        if (strength == STRENGTH_AUTO) {
89
            return 0;
90
        } else if (strength == STRENGTH_ALWAYS) {
91
            return KnuthElement.INFINITE;
92
        } else {
93
            return KnuthElement.INFINITE - 1;
94
        }
95
    }
96
97
    private static int getKeepContextPriority(int context) {
98
        switch (context) {
99
        case Constants.EN_LINE:   return 0;
100
        case Constants.EN_COLUMN: return 1;
101
        case Constants.EN_PAGE:   return 2;
102
        case Constants.EN_AUTO:   return 3;
103
        default: throw new IllegalArgumentException();
104
        }
105
    }
106
107
    public Keep compare(Keep other) {
108
        int pThis = getKeepContextPriority(this.context);
109
        int pOther = getKeepContextPriority(other.context);
110
        if (pThis < pOther) {
111
            return this;
112
        } else if (pThis > pOther) {
113
            return other;
114
        } else if (strength >= other.strength) {
115
            return this;
116
        } else {
117
            return other;
118
        }
119
    }
120
121
    /** {@inheritDoc} */
122
    public String toString() {
123
        if (strength == STRENGTH_AUTO) {
124
            return "auto";
125
        } else if (strength == STRENGTH_ALWAYS) {
126
            return "always";
127
        } else {
128
            return Integer.toString(strength);
129
        }
130
    }
131
132
}
0
  + Revision Id
133
  + Revision Id
1
  + native
134
  + native
(-)src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java (-13 / +9 lines)
Lines 37-42 Link Here
37
import org.apache.fop.datatypes.Length;
37
import org.apache.fop.datatypes.Length;
38
import org.apache.fop.fo.flow.BlockContainer;
38
import org.apache.fop.fo.flow.BlockContainer;
39
import org.apache.fop.fo.properties.CommonAbsolutePosition;
39
import org.apache.fop.fo.properties.CommonAbsolutePosition;
40
import org.apache.fop.fo.properties.KeepProperty;
40
import org.apache.fop.traits.MinOptMax;
41
import org.apache.fop.traits.MinOptMax;
41
import org.apache.fop.traits.SpaceVal;
42
import org.apache.fop.traits.SpaceVal;
42
import org.apache.fop.util.ListUtil;
43
import org.apache.fop.util.ListUtil;
Lines 261-267 Link Here
261
262
262
        if (!firstVisibleMarkServed) {
263
        if (!firstVisibleMarkServed) {
263
            addKnuthElementsForSpaceBefore(returnList, alignment);
264
            addKnuthElementsForSpaceBefore(returnList, alignment);
264
            context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
265
            context.updateKeepWithPreviousPending(getKeepWithPrevious());
265
        }
266
        }
266
267
267
        addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
268
        addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
Lines 391-397 Link Here
391
        context.clearPendingMarks();
392
        context.clearPendingMarks();
392
        addKnuthElementsForBreakAfter(returnList, context);
393
        addKnuthElementsForBreakAfter(returnList, context);
393
394
394
        context.updateKeepWithNextPending(getKeepWithNextStrength());
395
        context.updateKeepWithNextPending(getKeepWithNext());
395
396
396
        setFinished(true);
397
        setFinished(true);
397
        return returnList;
398
        return returnList;
Lines 1011-1033 Link Here
1011
    }
1012
    }
1012
1013
1013
    /** {@inheritDoc} */
1014
    /** {@inheritDoc} */
1014
    public int getKeepTogetherStrength() {
1015
    public KeepProperty getKeepTogetherProperty() {
1015
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
1016
        return getBlockContainerFO().getKeepTogether();
1016
                getBlockContainerFO().getKeepTogether());
1017
        strength = Math.max(strength, getParentKeepTogetherStrength());
1018
        return strength;
1019
    }
1017
    }
1020
1018
1021
    /** {@inheritDoc} */
1019
    /** {@inheritDoc} */
1022
    public int getKeepWithNextStrength() {
1020
    public KeepProperty getKeepWithPreviousProperty() {
1023
        return KeepUtil.getCombinedBlockLevelKeepStrength(
1021
        return getBlockContainerFO().getKeepWithPrevious();
1024
                getBlockContainerFO().getKeepWithNext());
1025
    }
1022
    }
1026
1023
1027
    /** {@inheritDoc} */
1024
    /** {@inheritDoc} */
1028
    public int getKeepWithPreviousStrength() {
1025
    public KeepProperty getKeepWithNextProperty() {
1029
        return KeepUtil.getCombinedBlockLevelKeepStrength(
1026
        return getBlockContainerFO().getKeepWithNext();
1030
                getBlockContainerFO().getKeepWithPrevious());
1031
    }
1027
    }
1032
1028
1033
    /**
1029
    /**
(-)src/java/org/apache/fop/layoutmgr/BreakElement.java (-1 / +16 lines)
Lines 41-49 Link Here
41
     * @param context the layout context which contains the pending conditional elements
41
     * @param context the layout context which contains the pending conditional elements
42
     */
42
     */
43
    public BreakElement(Position position, int penaltyValue, LayoutContext context) {
43
    public BreakElement(Position position, int penaltyValue, LayoutContext context) {
44
        this(position, 0, penaltyValue, -1, context);
44
        this(position, penaltyValue, -1, context);
45
    }
45
    }
46
46
47
    public BreakElement(Position position, int penaltyValue, int breakClass, LayoutContext context) {
48
        this(position, 0, penaltyValue, breakClass, context);
49
    }
50
47
    /**
51
    /**
48
     * Constructor for hard breaks.
52
     * Constructor for hard breaks.
49
     *
53
     *
Lines 168-173 Link Here
168
        sb.append("; w:");
172
        sb.append("; w:");
169
        sb.append(penaltyWidth);
173
        sb.append(penaltyWidth);
170
        sb.append("]");
174
        sb.append("]");
175
        switch (getBreakClass()) {
176
        case Constants.EN_PAGE:
177
            sb.append(" (page context)");
178
            break;
179
        case Constants.EN_COLUMN:
180
            sb.append(" (column context)");
181
            break;
182
        case Constants.EN_LINE:
183
            sb.append(" (line context)");
184
            break;
185
        }
171
        return sb.toString();
186
        return sb.toString();
172
    }
187
    }
173
188
(-)src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java (-7 / +7 lines)
Lines 154-160 Link Here
154
            context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
154
            context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
155
            childLC.clearKeepWithNextPending();
155
            childLC.clearKeepWithNextPending();
156
156
157
            context.updateKeepWithNextPending(getKeepWithNextStrength());
157
            context.updateKeepWithNextPending(getKeepWithNext());
158
        }
158
        }
159
159
160
        SpaceResolver.resolveElementList(returnList);
160
        SpaceResolver.resolveElementList(returnList);
Lines 203-220 Link Here
203
    }
203
    }
204
204
205
    /** {@inheritDoc} */
205
    /** {@inheritDoc} */
206
    public int getKeepTogetherStrength() {
206
    public Keep getKeepTogether() {
207
        return KEEP_AUTO;
207
        return Keep.KEEP_AUTO;
208
    }
208
    }
209
209
210
    /** {@inheritDoc} */
210
    /** {@inheritDoc} */
211
    public int getKeepWithNextStrength() {
211
    public Keep getKeepWithNext() {
212
        return KEEP_AUTO;
212
        return Keep.KEEP_AUTO;
213
    }
213
    }
214
214
215
    /** {@inheritDoc} */
215
    /** {@inheritDoc} */
216
    public int getKeepWithPreviousStrength() {
216
    public Keep getKeepWithPrevious() {
217
        return KEEP_AUTO;
217
        return Keep.KEEP_AUTO;
218
    }
218
    }
219
219
220
    /** {@inheritDoc} */
220
    /** {@inheritDoc} */
(-)src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java (-6 / +6 lines)
Lines 92-109 Link Here
92
    }
92
    }
93
93
94
    /** {@inheritDoc} */
94
    /** {@inheritDoc} */
95
    public int getKeepTogetherStrength() {
95
    public Keep getKeepTogether() {
96
        return getParentKeepTogetherStrength();
96
        return getParentKeepTogether();
97
    }
97
    }
98
98
99
    /** {@inheritDoc} */
99
    /** {@inheritDoc} */
100
    public int getKeepWithNextStrength() {
100
    public Keep getKeepWithNext() {
101
        return KEEP_AUTO;
101
        return Keep.KEEP_AUTO;
102
    }
102
    }
103
103
104
    /** {@inheritDoc} */
104
    /** {@inheritDoc} */
105
    public int getKeepWithPreviousStrength() {
105
    public Keep getKeepWithPrevious() {
106
        return KEEP_AUTO;
106
        return Keep.KEEP_AUTO;
107
    }
107
    }
108
108
109
}
109
}
(-)src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java (-9 / +6 lines)
Lines 210-230 Link Here
210
    }
210
    }
211
211
212
    /** {@inheritDoc} */
212
    /** {@inheritDoc} */
213
    public int getKeepTogetherStrength() {
213
    public KeepProperty getKeepTogetherProperty() {
214
        KeepProperty keep = getBlockFO().getKeepTogether();
214
        return getBlockFO().getKeepTogether();
215
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(keep);
216
        strength = Math.max(strength, getParentKeepTogetherStrength());
217
        return strength;
218
    }
215
    }
219
216
220
    /** {@inheritDoc} */
217
    /** {@inheritDoc} */
221
    public int getKeepWithNextStrength() {
218
    public KeepProperty getKeepWithPreviousProperty() {
222
        return KeepUtil.getCombinedBlockLevelKeepStrength(getBlockFO().getKeepWithNext());
219
        return getBlockFO().getKeepWithPrevious();
223
    }
220
    }
224
221
225
    /** {@inheritDoc} */
222
    /** {@inheritDoc} */
226
    public int getKeepWithPreviousStrength() {
223
    public KeepProperty getKeepWithNextProperty() {
227
        return KeepUtil.getCombinedBlockLevelKeepStrength(getBlockFO().getKeepWithPrevious());
224
        return getBlockFO().getKeepWithNext();
228
    }
225
    }
229
226
230
    /** {@inheritDoc} */
227
    /** {@inheritDoc} */
(-)src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (-3 / +65 lines)
Lines 26-31 Link Here
26
26
27
import org.apache.commons.logging.Log;
27
import org.apache.commons.logging.Log;
28
import org.apache.commons.logging.LogFactory;
28
import org.apache.commons.logging.LogFactory;
29
29
import org.apache.fop.fo.Constants;
30
import org.apache.fop.fo.Constants;
30
import org.apache.fop.fo.FObj;
31
import org.apache.fop.fo.FObj;
31
import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
32
import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
Lines 185-190 Link Here
185
        footnoteElementIndex = -1;
186
        footnoteElementIndex = -1;
186
    }
187
    }
187
188
189
    private boolean deferred = false;
190
    private boolean overridePageKeep = false;
191
192
    protected KnuthNode recoverFromTooLong(KnuthNode lastTooLong) {
193
        if (log.isDebugEnabled()) {
194
            log.debug("Recovering from too long: " + lastTooLong);
195
        }
196
        KnuthNode node = lastTooLong.previous;
197
        if (!deferred) {
198
            deferred = true;
199
            while (!pageProvider.startPage(lastTooLong.line - 1)) {
200
                lastTooLong = lastTooLong.previous;
201
            }
202
            node = lastTooLong.previous;
203
            // content would overflow, insert empty line/page and try again
204
            for (int i = 0; i < pageProvider.getColumnCount(lastTooLong.previous.line); i++) {
205
                node = createNode(
206
                        node.position, node.line + 1, 1,
207
                        0, 0, 0,
208
                        0, 0, 0,
209
                        0, 0, node);
210
            }
211
//        } else {
212
//            overridePageKeep = true;
213
        }
214
        return node;
215
    }
216
188
    protected KnuthNode createNode(int position, int line, int fitness,
217
    protected KnuthNode createNode(int position, int line, int fitness,
189
                                   int totalWidth, int totalStretch, int totalShrink,
218
                                   int totalWidth, int totalStretch, int totalShrink,
190
                                   double adjustRatio, int availableShrink, int availableStretch,
219
                                   double adjustRatio, int availableShrink, int availableStretch,
Lines 309-314 Link Here
309
        newFootnotes = false;
338
        newFootnotes = false;
310
    }
339
    }
311
340
341
    protected boolean elementCanEndLine(KnuthElement element, int line) {
342
        if (!(element instanceof KnuthPenalty) || pageProvider == null) {
343
            return true;
344
        } else {
345
            KnuthPenalty p = (KnuthPenalty) element;
346
            if (p.getP() <= 0) {
347
                return true;
348
            } else {
349
                int context = p.getBreakClass();
350
                switch (context) {
351
                case Constants.EN_LINE:
352
                case Constants.EN_COLUMN:
353
                    return p.getP() < KnuthPenalty.INFINITE;
354
                case Constants.EN_PAGE:
355
                    return p.getP() < KnuthPenalty.INFINITE || overridePageKeep
356
                            || !pageProvider.endPage(line - 1);
357
                case Constants.EN_AUTO:
358
                    log.warn("keep is not auto but context is");
359
                    return true;
360
                default:
361
                    if (p.getP() < KnuthPenalty.INFINITE) {
362
                        log.warn("Non recognized keep context:" + context);
363
                        return true;
364
                    } else {
365
                        return false;
366
                    }
367
                }
368
            }
369
        }
370
    }
371
312
    protected int computeDifference(KnuthNode activeNode, KnuthElement element,
372
    protected int computeDifference(KnuthNode activeNode, KnuthElement element,
313
                                    int elementIndex) {
373
                                    int elementIndex) {
314
        KnuthPageNode pageNode = (KnuthPageNode) activeNode;
374
        KnuthPageNode pageNode = (KnuthPageNode) activeNode;
Lines 561-571 Link Here
561
                        splitLength += element.getW();
621
                        splitLength += element.getW();
562
                    } else {
622
                    } else {
563
                        // element is a penalty
623
                        // element is a penalty
564
                        if (element.getP() < KnuthElement.INFINITE) {
624
//                        if (element.getP() < KnuthElement.INFINITE) {
565
                            // end of the sub-sequence
625
                            // end of the sub-sequence
566
                            index = noteListIterator.previousIndex();
626
                            index = noteListIterator.previousIndex();
567
                            break;
627
                            break;
568
                        }
628
//                        }
569
                    }
629
                    }
570
                }
630
                }
571
            }
631
            }
Lines 625-631 Link Here
625
        double f = Math.abs(r);
685
        double f = Math.abs(r);
626
        f = 1 + 100 * f * f * f;
686
        f = 1 + 100 * f * f * f;
627
        if (element.isPenalty() && element.getP() >= 0) {
687
        if (element.isPenalty() && element.getP() >= 0) {
628
            f += element.getP();
688
            if (element.getP() < KnuthPenalty.INFINITE) {
689
                f += element.getP();
690
            }
629
            demerits = f * f;
691
            demerits = f * f;
630
        } else if (element.isPenalty() && !element.isForcedBreak()) {
692
        } else if (element.isPenalty() && !element.isForcedBreak()) {
631
            double penalty = element.getP();
693
            double penalty = element.getP();
(-)src/java/org/apache/fop/layoutmgr/PageProvider.java (+27 lines)
Lines 146-151 Link Here
146
        return this.lastReportedBPD;
146
        return this.lastReportedBPD;
147
    }
147
    }
148
148
149
    // Wish there were a more elegant way to do this in Java
150
    private int[] getColIndexAndColCount(int index) {
151
        int columnCount = 0;
152
        int colIndex = startColumnOfCurrentElementList + index;
153
        int pageIndex = -1;
154
        do {
155
            colIndex -= columnCount;
156
            pageIndex++;
157
            Page page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
158
            columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
159
        } while (colIndex >= columnCount);
160
        return new int[] {colIndex, columnCount};
161
    }
162
163
    boolean startPage(int index) {
164
        return getColIndexAndColCount(index)[0] == 0;
165
    }
166
167
    boolean endPage(int index) {
168
        int[] colIndexAndColCount = getColIndexAndColCount(index);
169
        return colIndexAndColCount[0] == colIndexAndColCount[1] - 1;
170
    }
171
172
    int getColumnCount(int index) {
173
        return getColIndexAndColCount(index)[1];
174
    }
175
149
    /**
176
    /**
150
     * Returns the part index (0<x<partCount) which denotes the first part on the last page
177
     * Returns the part index (0<x<partCount) which denotes the first part on the last page
151
     * generated by the current element list.
178
     * generated by the current element list.
(-)src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java (-10 / +7 lines)
Lines 29-38 Link Here
29
import org.apache.fop.area.Area;
29
import org.apache.fop.area.Area;
30
import org.apache.fop.area.Block;
30
import org.apache.fop.area.Block;
31
import org.apache.fop.fo.flow.ListBlock;
31
import org.apache.fop.fo.flow.ListBlock;
32
import org.apache.fop.fo.properties.KeepProperty;
32
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
33
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
33
import org.apache.fop.layoutmgr.ConditionalElementListener;
34
import org.apache.fop.layoutmgr.ConditionalElementListener;
34
import org.apache.fop.layoutmgr.ElementListUtils;
35
import org.apache.fop.layoutmgr.ElementListUtils;
35
import org.apache.fop.layoutmgr.KeepUtil;
36
import org.apache.fop.layoutmgr.LayoutContext;
36
import org.apache.fop.layoutmgr.LayoutContext;
37
import org.apache.fop.layoutmgr.LayoutManager;
37
import org.apache.fop.layoutmgr.LayoutManager;
38
import org.apache.fop.layoutmgr.NonLeafPosition;
38
import org.apache.fop.layoutmgr.NonLeafPosition;
Lines 279-299 Link Here
279
    }
279
    }
280
280
281
    /** {@inheritDoc} */
281
    /** {@inheritDoc} */
282
    public int getKeepTogetherStrength() {
282
    public KeepProperty getKeepTogetherProperty() {
283
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
283
        return getListBlockFO().getKeepTogether();
284
                getListBlockFO().getKeepTogether());
285
        strength = Math.max(strength, getParentKeepTogetherStrength());
286
        return strength;
287
    }
284
    }
288
285
289
    /** {@inheritDoc} */
286
    /** {@inheritDoc} */
290
    public int getKeepWithNextStrength() {
287
    public KeepProperty getKeepWithPreviousProperty() {
291
        return KeepUtil.getCombinedBlockLevelKeepStrength(getListBlockFO().getKeepWithNext());
288
        return getListBlockFO().getKeepWithPrevious();
292
    }
289
    }
293
290
294
    /** {@inheritDoc} */
291
    /** {@inheritDoc} */
295
    public int getKeepWithPreviousStrength() {
292
    public KeepProperty getKeepWithNextProperty() {
296
        return KeepUtil.getCombinedBlockLevelKeepStrength(getListBlockFO().getKeepWithPrevious());
293
        return getListBlockFO().getKeepWithNext();
297
    }
294
    }
298
295
299
    /** {@inheritDoc} */
296
    /** {@inheritDoc} */
(-)src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java (-23 / +19 lines)
Lines 32-44 Link Here
32
import org.apache.fop.fo.flow.ListItem;
32
import org.apache.fop.fo.flow.ListItem;
33
import org.apache.fop.fo.flow.ListItemBody;
33
import org.apache.fop.fo.flow.ListItemBody;
34
import org.apache.fop.fo.flow.ListItemLabel;
34
import org.apache.fop.fo.flow.ListItemLabel;
35
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
35
import org.apache.fop.fo.properties.KeepProperty;
36
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
36
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
37
import org.apache.fop.layoutmgr.BreakElement;
37
import org.apache.fop.layoutmgr.BreakElement;
38
import org.apache.fop.layoutmgr.ConditionalElementListener;
38
import org.apache.fop.layoutmgr.ConditionalElementListener;
39
import org.apache.fop.layoutmgr.ElementListObserver;
39
import org.apache.fop.layoutmgr.ElementListObserver;
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.Keep;
42
import org.apache.fop.layoutmgr.KnuthBlockBox;
42
import org.apache.fop.layoutmgr.KnuthBlockBox;
43
import org.apache.fop.layoutmgr.KnuthBox;
43
import org.apache.fop.layoutmgr.KnuthBox;
44
import org.apache.fop.layoutmgr.KnuthElement;
44
import org.apache.fop.layoutmgr.KnuthElement;
Lines 83-90 Link Here
83
    private MinOptMax effSpaceBefore;
83
    private MinOptMax effSpaceBefore;
84
    private MinOptMax effSpaceAfter;
84
    private MinOptMax effSpaceAfter;
85
85
86
    private int keepWithNextPendingOnLabel;
86
    private Keep keepWithNextPendingOnLabel;
87
    private int keepWithNextPendingOnBody;
87
    private Keep keepWithNextPendingOnBody;
88
88
89
    private int listItemHeight;
89
    private int listItemHeight;
90
90
Lines 254-261 Link Here
254
254
255
        context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel);
255
        context.updateKeepWithNextPending(this.keepWithNextPendingOnLabel);
256
        context.updateKeepWithNextPending(this.keepWithNextPendingOnBody);
256
        context.updateKeepWithNextPending(this.keepWithNextPendingOnBody);
257
        context.updateKeepWithNextPending(getKeepWithNextStrength());
257
        context.updateKeepWithNextPending(getKeepWithNext());
258
        context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
258
        context.updateKeepWithPreviousPending(getKeepWithPrevious());
259
259
260
        setFinished(true);
260
        setFinished(true);
261
        resetSpaces();
261
        resetSpaces();
Lines 276-291 Link Here
276
        int totalHeight = Math.max(fullHeights[0], fullHeights[1]);
276
        int totalHeight = Math.max(fullHeights[0], fullHeights[1]);
277
        int step;
277
        int step;
278
        int addedBoxHeight = 0;
278
        int addedBoxHeight = 0;
279
        int keepWithNextActive = BlockLevelLayoutManager.KEEP_AUTO;
279
        Keep keepWithNextActive = Keep.KEEP_AUTO;
280
280
281
        LinkedList returnList = new LinkedList();
281
        LinkedList returnList = new LinkedList();
282
        while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {
282
        while ((step = getNextStep(elementLists, start, end, partialHeights)) > 0) {
283
283
284
            if (end[0] + 1 == elementLists[0].size()) {
284
            if (end[0] + 1 == elementLists[0].size()) {
285
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnLabel);
285
                keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnLabel);
286
            }
286
            }
287
            if (end[1] + 1 == elementLists[1].size()) {
287
            if (end[1] + 1 == elementLists[1].size()) {
288
                keepWithNextActive = Math.max(keepWithNextActive, keepWithNextPendingOnBody);
288
                keepWithNextActive = keepWithNextActive.compare(keepWithNextPendingOnBody);
289
            }
289
            }
290
290
291
            // compute penalty height and box height
291
            // compute penalty height and box height
Lines 339-352 Link Here
339
            }
339
            }
340
340
341
            if (addedBoxHeight < totalHeight) {
341
            if (addedBoxHeight < totalHeight) {
342
                int strength = BlockLevelLayoutManager.KEEP_AUTO;
342
                Keep keep = keepWithNextActive.compare(getKeepTogether());
343
                strength = Math.max(strength, keepWithNextActive);
344
                strength = Math.max(strength, getKeepTogetherStrength());
345
                int p = stepPenalty;
343
                int p = stepPenalty;
346
                if (p > -KnuthElement.INFINITE) {
344
                if (p > -KnuthElement.INFINITE) {
347
                    p = Math.max(p, KeepUtil.getPenaltyForKeep(strength));
345
                    p = Math.max(p, keep.getPenalty());
348
                }
346
                }
349
                returnList.add(new BreakElement(stepPosition, penaltyHeight, p, -1, context));
347
                returnList.add(new BreakElement(stepPosition, penaltyHeight, p, keep.getContext(),
348
                        context));
350
            }
349
            }
351
        }
350
        }
352
351
Lines 644-664 Link Here
644
    }
643
    }
645
644
646
    /** {@inheritDoc} */
645
    /** {@inheritDoc} */
647
    public int getKeepTogetherStrength() {
646
    public KeepProperty getKeepTogetherProperty() {
648
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
647
        return getListItemFO().getKeepTogether();
649
                getListItemFO().getKeepTogether());
650
        strength = Math.max(strength, getParentKeepTogetherStrength());
651
        return strength;
652
    }
648
    }
653
649
654
    /** {@inheritDoc} */
650
    /** {@inheritDoc} */
655
    public int getKeepWithNextStrength() {
651
    public KeepProperty getKeepWithPreviousProperty() {
656
        return KeepUtil.getCombinedBlockLevelKeepStrength(getListItemFO().getKeepWithNext());
652
        return getListItemFO().getKeepWithPrevious();
657
    }
653
    }
658
654
659
    /** {@inheritDoc} */
655
    /** {@inheritDoc} */
660
    public int getKeepWithPreviousStrength() {
656
    public KeepProperty getKeepWithNextProperty() {
661
        return KeepUtil.getCombinedBlockLevelKeepStrength(getListItemFO().getKeepWithPrevious());
657
        return getListItemFO().getKeepWithNext();
662
    }
658
    }
663
659
664
    /** {@inheritDoc} */
660
    /** {@inheritDoc} */
(-)src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java (-9 / +8 lines)
Lines 28-35 Link Here
28
import org.apache.fop.fo.flow.AbstractListItemPart;
28
import org.apache.fop.fo.flow.AbstractListItemPart;
29
import org.apache.fop.fo.flow.ListItemBody;
29
import org.apache.fop.fo.flow.ListItemBody;
30
import org.apache.fop.fo.flow.ListItemLabel;
30
import org.apache.fop.fo.flow.ListItemLabel;
31
import org.apache.fop.fo.properties.KeepProperty;
31
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
32
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
32
import org.apache.fop.layoutmgr.KeepUtil;
33
import org.apache.fop.layoutmgr.Keep;
33
import org.apache.fop.layoutmgr.LayoutContext;
34
import org.apache.fop.layoutmgr.LayoutContext;
34
import org.apache.fop.layoutmgr.LayoutManager;
35
import org.apache.fop.layoutmgr.LayoutManager;
35
import org.apache.fop.layoutmgr.NonLeafPosition;
36
import org.apache.fop.layoutmgr.NonLeafPosition;
Lines 221-240 Link Here
221
    }
222
    }
222
223
223
    /** {@inheritDoc} */
224
    /** {@inheritDoc} */
224
    public int getKeepTogetherStrength() {
225
    public KeepProperty getKeepTogetherProperty() {
225
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(getPartFO().getKeepTogether());
226
        return getPartFO().getKeepTogether();
226
        strength = Math.max(strength, getParentKeepTogetherStrength());
227
        return strength;
228
    }
227
    }
229
228
230
    /** {@inheritDoc} */
229
    /** {@inheritDoc} */
231
    public int getKeepWithNextStrength() {
230
    public Keep getKeepWithNext() {
232
        return KEEP_AUTO;
231
        return Keep.KEEP_AUTO;
233
    }
232
    }
234
233
235
    /** {@inheritDoc} */
234
    /** {@inheritDoc} */
236
    public int getKeepWithPreviousStrength() {
235
    public Keep getKeepWithPrevious() {
237
        return KEEP_AUTO;
236
        return Keep.KEEP_AUTO;
238
    }
237
    }
239
238
240
}
239
}
(-)src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (-7 / +12 lines)
Lines 25-37 Link Here
25
25
26
import org.apache.commons.logging.Log;
26
import org.apache.commons.logging.Log;
27
import org.apache.commons.logging.LogFactory;
27
import org.apache.commons.logging.LogFactory;
28
28
import org.apache.fop.fo.Constants;
29
import org.apache.fop.fo.Constants;
29
import org.apache.fop.fo.flow.table.ConditionalBorder;
30
import org.apache.fop.fo.flow.table.ConditionalBorder;
30
import org.apache.fop.fo.flow.table.EffRow;
31
import org.apache.fop.fo.flow.table.EffRow;
31
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
32
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
32
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
33
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
33
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
34
import org.apache.fop.layoutmgr.ElementListUtils;
34
import org.apache.fop.layoutmgr.ElementListUtils;
35
import org.apache.fop.layoutmgr.Keep;
35
import org.apache.fop.layoutmgr.KnuthBlockBox;
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;
Lines 73-79 Link Here
73
    /** True if the next CellPart that will be created will be the last one for this cell. */
74
    /** True if the next CellPart that will be created will be the last one for this cell. */
74
    private boolean lastCellPart;
75
    private boolean lastCellPart;
75
76
76
    private int keepWithNextStrength;
77
    private Keep keepWithNext;
77
78
78
    private int spanIndex = 0;
79
    private int spanIndex = 0;
79
80
Lines 211-217 Link Here
211
        includedLength = -1;  // Avoid troubles with cells having content of zero length
212
        includedLength = -1;  // Avoid troubles with cells having content of zero length
212
        totalLength = previousRowsLength + ElementListUtils.calcContentLength(elementList);
213
        totalLength = previousRowsLength + ElementListUtils.calcContentLength(elementList);
213
        endRowIndex = rowIndex + pgu.getCell().getNumberRowsSpanned() - 1;
214
        endRowIndex = rowIndex + pgu.getCell().getNumberRowsSpanned() - 1;
214
        keepWithNextStrength = BlockLevelLayoutManager.KEEP_AUTO;
215
        keepWithNext = Keep.KEEP_AUTO;
215
        remainingLength = totalLength - previousRowsLength;
216
        remainingLength = totalLength - previousRowsLength;
216
217
217
        afterNextStep = new Step(previousRowsLength);
218
        afterNextStep = new Step(previousRowsLength);
Lines 305-311 Link Here
305
            KnuthElement el = (KnuthElement) knuthIter.next();
306
            KnuthElement el = (KnuthElement) knuthIter.next();
306
            if (el.isPenalty()) {
307
            if (el.isPenalty()) {
307
                prevIsBox = false;
308
                prevIsBox = false;
308
                if (el.getP() < KnuthElement.INFINITE) {
309
                if (el.getP() < KnuthElement.INFINITE
310
                        || ((KnuthPenalty) el).getBreakClass() == Constants.EN_PAGE) {
311
                    // TODO too much is being done in that test, only to handle
312
                    // keep.within-column properly.
313
309
                    // First legal break point
314
                    // First legal break point
310
                    breakFound = true;
315
                    breakFound = true;
311
                    KnuthPenalty p = (KnuthPenalty) el;
316
                    KnuthPenalty p = (KnuthPenalty) el;
Lines 524-530 Link Here
524
     */
529
     */
525
    CellPart createCellPart() {
530
    CellPart createCellPart() {
526
        if (nextStep.end + 1 == elementList.size()) {
531
        if (nextStep.end + 1 == elementList.size()) {
527
            keepWithNextStrength = pgu.getKeepWithNextStrength();
532
            keepWithNext = pgu.getKeepWithNext();
528
            // TODO if keep-with-next is set on the row, must every cell of the row
533
            // TODO if keep-with-next is set on the row, must every cell of the row
529
            // contribute some content from children blocks?
534
            // contribute some content from children blocks?
530
            // see http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-dev/200802.mbox/
535
            // see http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-dev/200802.mbox/
Lines 566-573 Link Here
566
        }
571
        }
567
    }
572
    }
568
573
569
    int getKeepWithNextStrength() {
574
    Keep getKeepWithNext() {
570
        return keepWithNextStrength;
575
        return keepWithNext;
571
    }
576
    }
572
577
573
    int getPenaltyValue() {
578
    int getPenaltyValue() {
(-)src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java (-11 / +10 lines)
Lines 35-44 Link Here
35
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
35
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
36
import org.apache.fop.fo.flow.table.Table;
36
import org.apache.fop.fo.flow.table.Table;
37
import org.apache.fop.fo.flow.table.TablePart;
37
import org.apache.fop.fo.flow.table.TablePart;
38
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
39
import org.apache.fop.layoutmgr.BreakElement;
38
import org.apache.fop.layoutmgr.BreakElement;
40
import org.apache.fop.layoutmgr.ElementListUtils;
39
import org.apache.fop.layoutmgr.ElementListUtils;
41
import org.apache.fop.layoutmgr.KeepUtil;
40
import org.apache.fop.layoutmgr.Keep;
42
import org.apache.fop.layoutmgr.KnuthBox;
41
import org.apache.fop.layoutmgr.KnuthBox;
43
import org.apache.fop.layoutmgr.KnuthElement;
42
import org.apache.fop.layoutmgr.KnuthElement;
44
import org.apache.fop.layoutmgr.KnuthGlue;
43
import org.apache.fop.layoutmgr.KnuthGlue;
Lines 213-225 Link Here
213
        context.clearKeepsPending();
212
        context.clearKeepsPending();
214
        context.setBreakBefore(Constants.EN_AUTO);
213
        context.setBreakBefore(Constants.EN_AUTO);
215
        context.setBreakAfter(Constants.EN_AUTO);
214
        context.setBreakAfter(Constants.EN_AUTO);
216
        int keepWithPrevious = BlockLevelLayoutManager.KEEP_AUTO;
215
        Keep keepWithPrevious = Keep.KEEP_AUTO;
217
        int breakBefore = Constants.EN_AUTO;
216
        int breakBefore = Constants.EN_AUTO;
218
        if (rowGroup != null) {
217
        if (rowGroup != null) {
219
            RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup,
218
            RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup,
220
                    stepper);
219
                    stepper);
221
            List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
220
            List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType);
222
            keepWithPrevious = Math.max(keepWithPrevious, context.getKeepWithPreviousPending());
221
            keepWithPrevious = keepWithPrevious.compare(context.getKeepWithPreviousPending());
223
            breakBefore = context.getBreakBefore();
222
            breakBefore = context.getBreakBefore();
224
            int breakBetween = context.getBreakAfter();
223
            int breakBetween = context.getBreakAfter();
225
            returnList.addAll(nextRowGroupElems);
224
            returnList.addAll(nextRowGroupElems);
Lines 228-234 Link Here
228
227
229
                //Note previous pending keep-with-next and clear the strength
228
                //Note previous pending keep-with-next and clear the strength
230
                //(as the layout context is reused)
229
                //(as the layout context is reused)
231
                int keepWithNextPending = context.getKeepWithNextPending();
230
                Keep keepWithNextPending = context.getKeepWithNextPending();
232
                context.clearKeepWithNextPending();
231
                context.clearKeepWithNextPending();
233
232
234
                //Get elements for next row group
233
                //Get elements for next row group
Lines 246-262 Link Here
246
                 */
245
                 */
247
246
248
                //Determine keep constraints
247
                //Determine keep constraints
249
                int penaltyStrength = BlockLevelLayoutManager.KEEP_AUTO;
248
                Keep keep = keepWithNextPending.compare(context.getKeepWithPreviousPending());
250
                penaltyStrength = Math.max(penaltyStrength, keepWithNextPending);
251
                penaltyStrength = Math.max(penaltyStrength, context.getKeepWithPreviousPending());
252
                context.clearKeepWithPreviousPending();
249
                context.clearKeepWithPreviousPending();
253
                penaltyStrength = Math.max(penaltyStrength, getTableLM().getKeepTogetherStrength());
250
                keep = keep.compare(getTableLM().getKeepTogether());
254
                int penaltyValue = KeepUtil.getPenaltyForKeep(penaltyStrength);
251
                int penaltyValue = keep.getPenalty();
252
                int breakClass = keep.getContext();
255
253
256
                breakBetween = BreakUtil.compareBreakClasses(breakBetween,
254
                breakBetween = BreakUtil.compareBreakClasses(breakBetween,
257
                        context.getBreakBefore());
255
                        context.getBreakBefore());
258
                if (breakBetween != Constants.EN_AUTO) {
256
                if (breakBetween != Constants.EN_AUTO) {
259
                    penaltyValue = -KnuthElement.INFINITE;
257
                    penaltyValue = -KnuthElement.INFINITE;
258
                    breakClass = breakBetween;
260
                }
259
                }
261
                BreakElement breakElement;
260
                BreakElement breakElement;
262
                ListIterator elemIter = returnList.listIterator(returnList.size());
261
                ListIterator elemIter = returnList.listIterator(returnList.size());
Lines 267-273 Link Here
267
                    breakElement = (BreakElement) elem;
266
                    breakElement = (BreakElement) elem;
268
                }
267
                }
269
                breakElement.setPenaltyValue(penaltyValue);
268
                breakElement.setPenaltyValue(penaltyValue);
270
                breakElement.setBreakClass(breakBetween);
269
                breakElement.setBreakClass(breakClass);
271
                returnList.addAll(nextRowGroupElems);
270
                returnList.addAll(nextRowGroupElems);
272
                breakBetween = context.getBreakAfter();
271
                breakBetween = context.getBreakAfter();
273
            }
272
            }
(-)src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java (-2 / +2 lines)
Lines 60-67 Link Here
60
        LinkedList returnList = new LinkedList();
60
        LinkedList returnList = new LinkedList();
61
        createElementsForRowGroup(context, alignment, bodyType, returnList);
61
        createElementsForRowGroup(context, alignment, bodyType, returnList);
62
62
63
        context.updateKeepWithPreviousPending(rowGroup[0].getKeepWithPreviousStrength());
63
        context.updateKeepWithPreviousPending(rowGroup[0].getKeepWithPrevious());
64
        context.updateKeepWithNextPending(rowGroup[rowGroup.length - 1].getKeepWithNextStrength());
64
        context.updateKeepWithNextPending(rowGroup[rowGroup.length - 1].getKeepWithNext());
65
65
66
        int breakBefore = Constants.EN_AUTO;
66
        int breakBefore = Constants.EN_AUTO;
67
        TableRow firstRow = rowGroup[0].getTableRow();
67
        TableRow firstRow = rowGroup[0].getTableRow();
(-)src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java (-11 / +9 lines)
Lines 35-45 Link Here
35
import org.apache.fop.fo.FObj;
35
import org.apache.fop.fo.FObj;
36
import org.apache.fop.fo.flow.table.Table;
36
import org.apache.fop.fo.flow.table.Table;
37
import org.apache.fop.fo.flow.table.TableColumn;
37
import org.apache.fop.fo.flow.table.TableColumn;
38
import org.apache.fop.fo.properties.KeepProperty;
38
import org.apache.fop.layoutmgr.BlockLevelEventProducer;
39
import org.apache.fop.layoutmgr.BlockLevelEventProducer;
39
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
40
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
40
import org.apache.fop.layoutmgr.BreakElement;
41
import org.apache.fop.layoutmgr.BreakElement;
41
import org.apache.fop.layoutmgr.ConditionalElementListener;
42
import org.apache.fop.layoutmgr.ConditionalElementListener;
42
import org.apache.fop.layoutmgr.KeepUtil;
43
import org.apache.fop.layoutmgr.KnuthElement;
43
import org.apache.fop.layoutmgr.KnuthElement;
44
import org.apache.fop.layoutmgr.KnuthGlue;
44
import org.apache.fop.layoutmgr.KnuthGlue;
45
import org.apache.fop.layoutmgr.LayoutContext;
45
import org.apache.fop.layoutmgr.LayoutContext;
Lines 256-265 Link Here
256
        log.debug(contentKnuthElements);
256
        log.debug(contentKnuthElements);
257
        wrapPositionElements(contentKnuthElements, returnList);
257
        wrapPositionElements(contentKnuthElements, returnList);
258
258
259
        context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
259
        context.updateKeepWithPreviousPending(getKeepWithPrevious());
260
        context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
260
        context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
261
261
262
        context.updateKeepWithNextPending(getKeepWithNextStrength());
262
        context.updateKeepWithNextPending(getKeepWithNext());
263
        context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
263
        context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
264
264
265
        if (getTable().isSeparateBorderModel()) {
265
        if (getTable().isSeparateBorderModel()) {
Lines 448-467 Link Here
448
    }
448
    }
449
449
450
    /** {@inheritDoc} */
450
    /** {@inheritDoc} */
451
    public int getKeepTogetherStrength() {
451
    public KeepProperty getKeepTogetherProperty() {
452
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepTogether());
452
        return getTable().getKeepTogether();
453
        strength = Math.max(strength, getParentKeepTogetherStrength());
454
        return strength;
455
    }
453
    }
456
454
457
    /** {@inheritDoc} */
455
    /** {@inheritDoc} */
458
    public int getKeepWithNextStrength() {
456
    public KeepProperty getKeepWithPreviousProperty() {
459
        return KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepWithNext());
457
        return getTable().getKeepWithPrevious();
460
    }
458
    }
461
459
462
    /** {@inheritDoc} */
460
    /** {@inheritDoc} */
463
    public int getKeepWithPreviousStrength() {
461
    public KeepProperty getKeepWithNextProperty() {
464
        return KeepUtil.getCombinedBlockLevelKeepStrength(getTable().getKeepWithPrevious());
462
        return getTable().getKeepWithNext();
465
    }
463
    }
466
464
467
    // --------- Property Resolution related functions --------- //
465
    // --------- Property Resolution related functions --------- //
(-)src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java (-16 / +14 lines)
Lines 24-29 Link Here
24
24
25
import org.apache.commons.logging.Log;
25
import org.apache.commons.logging.Log;
26
import org.apache.commons.logging.LogFactory;
26
import org.apache.commons.logging.LogFactory;
27
27
import org.apache.fop.area.Area;
28
import org.apache.fop.area.Area;
28
import org.apache.fop.area.Block;
29
import org.apache.fop.area.Block;
29
import org.apache.fop.area.Trait;
30
import org.apache.fop.area.Trait;
Lines 31-46 Link Here
31
import org.apache.fop.fo.flow.table.GridUnit;
32
import org.apache.fop.fo.flow.table.GridUnit;
32
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
33
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
33
import org.apache.fop.fo.flow.table.Table;
34
import org.apache.fop.fo.flow.table.Table;
34
import org.apache.fop.fo.flow.table.TablePart;
35
import org.apache.fop.fo.flow.table.TableCell;
35
import org.apache.fop.fo.flow.table.TableCell;
36
import org.apache.fop.fo.flow.table.TableColumn;
36
import org.apache.fop.fo.flow.table.TableColumn;
37
import org.apache.fop.fo.flow.table.TablePart;
37
import org.apache.fop.fo.flow.table.TableRow;
38
import org.apache.fop.fo.flow.table.TableRow;
38
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
39
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
39
import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
40
import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
40
import org.apache.fop.layoutmgr.AreaAdditionUtil;
41
import org.apache.fop.layoutmgr.AreaAdditionUtil;
41
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
42
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
42
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
43
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
43
import org.apache.fop.layoutmgr.KeepUtil;
44
import org.apache.fop.layoutmgr.Keep;
44
import org.apache.fop.layoutmgr.KnuthBox;
45
import org.apache.fop.layoutmgr.KnuthBox;
45
import org.apache.fop.layoutmgr.KnuthElement;
46
import org.apache.fop.layoutmgr.KnuthElement;
46
import org.apache.fop.layoutmgr.KnuthGlue;
47
import org.apache.fop.layoutmgr.KnuthGlue;
Lines 153-159 Link Here
153
                log.debug("child LM signals pending keep with next");
154
                log.debug("child LM signals pending keep with next");
154
            }
155
            }
155
            if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
156
            if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
156
                primaryGridUnit.setKeepWithPreviousStrength(childLC.getKeepWithPreviousPending());
157
                primaryGridUnit.setKeepWithPrevious(childLC.getKeepWithPreviousPending());
157
                childLC.clearKeepWithPreviousPending();
158
                childLC.clearKeepWithPreviousPending();
158
            }
159
            }
159
160
Lines 174-180 Link Here
174
            }
175
            }
175
            prevLM = curLM;
176
            prevLM = curLM;
176
        }
177
        }
177
        primaryGridUnit.setKeepWithNextStrength(context.getKeepWithNextPending());
178
        primaryGridUnit.setKeepWithNext(context.getKeepWithNextPending());
178
179
179
        returnedList = new LinkedList();
180
        returnedList = new LinkedList();
180
        if (!contentList.isEmpty()) {
181
        if (!contentList.isEmpty()) {
Lines 556-581 Link Here
556
    }
557
    }
557
558
558
    /** {@inheritDoc} */
559
    /** {@inheritDoc} */
559
    public int getKeepTogetherStrength() {
560
    public Keep getKeepTogether() {
560
        int strength = KEEP_AUTO;
561
        Keep keep = Keep.KEEP_AUTO;
561
        if (primaryGridUnit.getRow() != null) {
562
        if (primaryGridUnit.getRow() != null) {
562
            strength = Math.max(strength, KeepUtil.getKeepStrength(
563
            keep = Keep.getKeep(primaryGridUnit.getRow().getKeepTogether());
563
                    primaryGridUnit.getRow().getKeepTogether().getWithinPage()));
564
            strength = Math.max(strength, KeepUtil.getKeepStrength(
565
                    primaryGridUnit.getRow().getKeepTogether().getWithinColumn()));
566
        }
564
        }
567
        strength = Math.max(strength, getParentKeepTogetherStrength());
565
        keep = keep.compare(getParentKeepTogether());
568
        return strength;
566
        return keep;
569
    }
567
    }
570
568
571
    /** {@inheritDoc} */
569
    /** {@inheritDoc} */
572
    public int getKeepWithNextStrength() {
570
    public Keep getKeepWithNext() {
573
        return KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-next!)
571
        return Keep.KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-next!)
574
    }
572
    }
575
573
576
    /** {@inheritDoc} */
574
    /** {@inheritDoc} */
577
    public int getKeepWithPreviousStrength() {
575
    public Keep getKeepWithPrevious() {
578
        return KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-previous!)
576
        return Keep.KEEP_AUTO; //TODO FIX ME (table-cell has no keep-with-previous!)
579
    }
577
    }
580
578
581
    // --------- Property Resolution related functions --------- //
579
    // --------- Property Resolution related functions --------- //
(-)src/java/org/apache/fop/layoutmgr/table/TableAndCaptionLayoutManager.java (-15 / +5 lines)
Lines 23-28 Link Here
23
import org.apache.fop.area.Block;
23
import org.apache.fop.area.Block;
24
import org.apache.fop.fo.flow.table.TableAndCaption;
24
import org.apache.fop.fo.flow.table.TableAndCaption;
25
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
25
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
26
import org.apache.fop.layoutmgr.Keep;
26
import org.apache.fop.layoutmgr.LayoutContext;
27
import org.apache.fop.layoutmgr.LayoutContext;
27
import org.apache.fop.layoutmgr.PositionIterator;
28
import org.apache.fop.layoutmgr.PositionIterator;
28
29
Lines 201-228 Link Here
201
    }
202
    }
202
203
203
    /** {@inheritDoc} */
204
    /** {@inheritDoc} */
204
    public int getKeepTogetherStrength() {
205
    public Keep getKeepWithNext() {
205
        int strength = KEEP_AUTO;
206
        return Keep.KEEP_AUTO;
206
        /* TODO Complete me!
207
        /* TODO Complete me!
207
        int strength = KeepUtil.getCombinedBlockLevelKeepStrength(
208
                getTableAndCaptionFO().getKeepTogether());
209
        */
210
        strength = Math.max(strength, getParentKeepTogetherStrength());
211
        return strength;
212
    }
213
214
    /** {@inheritDoc} */
215
    public int getKeepWithNextStrength() {
216
        return KEEP_AUTO;
217
        /* TODO Complete me!
218
        return KeepUtil.getCombinedBlockLevelKeepStrength(
208
        return KeepUtil.getCombinedBlockLevelKeepStrength(
219
                getTableAndCaptionFO().getKeepWithNext());
209
                getTableAndCaptionFO().getKeepWithNext());
220
        */
210
        */
221
    }
211
    }
222
212
223
    /** {@inheritDoc} */
213
    /** {@inheritDoc} */
224
    public int getKeepWithPreviousStrength() {
214
    public Keep getKeepWithPrevious() {
225
        return KEEP_AUTO;
215
        return Keep.KEEP_AUTO;
226
        /* TODO Complete me!
216
        /* TODO Complete me!
227
        return KeepUtil.getCombinedBlockLevelKeepStrength(
217
        return KeepUtil.getCombinedBlockLevelKeepStrength(
228
                getTableAndCaptionFO().getKeepWithPrevious());
218
                getTableAndCaptionFO().getKeepWithPrevious());
(-)src/java/org/apache/fop/layoutmgr/table/TableStepper.java (-16 / +12 lines)
Lines 30-41 Link Here
30
import org.apache.fop.fo.flow.table.EffRow;
30
import org.apache.fop.fo.flow.table.EffRow;
31
import org.apache.fop.fo.flow.table.GridUnit;
31
import org.apache.fop.fo.flow.table.GridUnit;
32
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
32
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
33
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
34
import org.apache.fop.layoutmgr.BreakElement;
33
import org.apache.fop.layoutmgr.BreakElement;
35
import org.apache.fop.layoutmgr.KeepUtil;
34
import org.apache.fop.layoutmgr.Keep;
36
import org.apache.fop.layoutmgr.KnuthBlockBox;
35
import org.apache.fop.layoutmgr.KnuthBlockBox;
37
import org.apache.fop.layoutmgr.KnuthBox;
36
import org.apache.fop.layoutmgr.KnuthBox;
38
import org.apache.fop.layoutmgr.KnuthElement;
39
import org.apache.fop.layoutmgr.KnuthGlue;
37
import org.apache.fop.layoutmgr.KnuthGlue;
40
import org.apache.fop.layoutmgr.KnuthPenalty;
38
import org.apache.fop.layoutmgr.KnuthPenalty;
41
import org.apache.fop.layoutmgr.LayoutContext;
39
import org.apache.fop.layoutmgr.LayoutContext;
Lines 241-280 Link Here
241
                }
239
                }
242
            }
240
            }
243
241
244
            int strength = BlockLevelLayoutManager.KEEP_AUTO;
242
            Keep keep = Keep.KEEP_AUTO;
245
            int stepPenalty = 0;
243
            int stepPenalty = 0;
246
            for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
244
            for (Iterator iter = activeCells.iterator(); iter.hasNext();) {
247
                ActiveCell activeCell = (ActiveCell) iter.next();
245
                ActiveCell activeCell = (ActiveCell) iter.next();
248
                strength = Math.max(strength, activeCell.getKeepWithNextStrength());
246
                keep = keep.compare(activeCell.getKeepWithNext());
249
                stepPenalty = Math.max(stepPenalty, activeCell.getPenaltyValue());
247
                stepPenalty = Math.max(stepPenalty, activeCell.getPenaltyValue());
250
            }
248
            }
251
            if (!rowFinished) {
249
            if (!rowFinished) {
252
                strength = Math.max(strength, rowGroup[activeRowIndex].getKeepTogetherStrength());
250
                keep = keep.compare(rowGroup[activeRowIndex].getKeepTogether());
253
                //The above call doesn't take the penalty from the table into account, so...
251
                //The above call doesn't take the penalty from the table into account, so...
254
                strength = Math.max(strength, getTableLM().getKeepTogetherStrength());
252
                keep = keep.compare(getTableLM().getKeepTogether());
255
            } else if (activeRowIndex < rowGroup.length - 1) {
253
            } else if (activeRowIndex < rowGroup.length - 1) {
256
                strength = Math.max(strength,
254
                keep = keep.compare(rowGroup[activeRowIndex].getKeepWithNext());
257
                        rowGroup[activeRowIndex].getKeepWithNextStrength());
255
                keep = keep.compare(rowGroup[activeRowIndex + 1].getKeepWithPrevious());
258
                strength = Math.max(strength,
259
                        rowGroup[activeRowIndex + 1].getKeepWithPreviousStrength());
260
                nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
256
                nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
261
                        rowGroup[activeRowIndex].getBreakAfter());
257
                        rowGroup[activeRowIndex].getBreakAfter());
262
                nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
258
                nextBreakClass = BreakUtil.compareBreakClasses(nextBreakClass,
263
                        rowGroup[activeRowIndex + 1].getBreakBefore());
259
                        rowGroup[activeRowIndex + 1].getBreakBefore());
264
            }
260
            }
265
            int p = KeepUtil.getPenaltyForKeep(strength);
261
            int p = keep.getPenalty();
266
            if (rowHeightSmallerThanFirstStep) {
262
            if (rowHeightSmallerThanFirstStep) {
267
                rowHeightSmallerThanFirstStep = false;
263
                rowHeightSmallerThanFirstStep = false;
268
                p = KnuthPenalty.INFINITE;
264
                p = KnuthPenalty.INFINITE;
269
            }
265
            }
270
            if (p > -KnuthElement.INFINITE) {
266
            p = Math.max(p, stepPenalty);
271
                p = Math.max(p, stepPenalty);
267
            int breakClass = keep.getContext();
272
            }
273
            if (nextBreakClass != Constants.EN_AUTO) {
268
            if (nextBreakClass != Constants.EN_AUTO) {
274
                log.trace("Forced break encountered");
269
                log.trace("Forced break encountered");
275
                p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in XSL 1.0)
270
                p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in XSL 1.0)
271
                breakClass = nextBreakClass;
276
            }
272
            }
277
            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, nextBreakClass, context));
273
            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, breakClass, context));
278
            if (penaltyOrGlueLen < 0) {
274
            if (penaltyOrGlueLen < 0) {
279
                returnList.add(new KnuthGlue(-penaltyOrGlueLen, 0, 0, new Position(null), true));
275
                returnList.add(new KnuthGlue(-penaltyOrGlueLen, 0, 0, new Position(null), true));
280
            }
276
            }
(-)src/java/org/apache/fop/layoutmgr/table/TableCaptionLayoutManager.java (-17 / +5 lines)
Lines 23-28 Link Here
23
import org.apache.fop.area.Block;
23
import org.apache.fop.area.Block;
24
import org.apache.fop.fo.flow.table.TableCaption;
24
import org.apache.fop.fo.flow.table.TableCaption;
25
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
25
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
26
import org.apache.fop.layoutmgr.Keep;
26
import org.apache.fop.layoutmgr.LayoutContext;
27
import org.apache.fop.layoutmgr.LayoutContext;
27
import org.apache.fop.layoutmgr.PositionIterator;
28
import org.apache.fop.layoutmgr.PositionIterator;
28
29
Lines 197-226 Link Here
197
    }
198
    }
198
199
199
    /** {@inheritDoc} */
200
    /** {@inheritDoc} */
200
    public int getKeepTogetherStrength() {
201
    public Keep getKeepWithNext() {
201
        int strength = KEEP_AUTO;
202
        return Keep.KEEP_AUTO;
202
        /* TODO Complete me!
203
        /* TODO Complete me!
203
        strength = Math.max(strength, KeepUtil.getKeepStrength(
204
                getTableCaptionFO().getKeepTogether().getWithinPage()));
205
        strength = Math.max(strength, KeepUtil.getKeepStrength(
206
                getTableCaptionFO().getKeepTogether().getWithinColumn()));
207
        */
208
        strength = Math.max(strength, getParentKeepTogetherStrength());
209
        return strength;
210
    }
211
212
    /** {@inheritDoc} */
213
    public int getKeepWithNextStrength() {
214
        return KEEP_AUTO;
215
        /* TODO Complete me!
216
        return KeepUtil.getCombinedBlockLevelKeepStrength(
204
        return KeepUtil.getCombinedBlockLevelKeepStrength(
217
                getTableCaptionFO().getKeepWithNext());
205
                getTableCaptionFO().getKeepWithNext());
218
        */
206
        */
219
    }
207
    }
220
208
221
    /** {@inheritDoc} */
209
    /** {@inheritDoc} */
222
    public int getKeepWithPreviousStrength() {
210
    public Keep getKeepWithPrevious() {
223
        return KEEP_AUTO;
211
        return Keep.KEEP_AUTO;
224
        /* TODO Complete me!
212
        /* TODO Complete me!
225
        return KeepUtil.getCombinedBlockLevelKeepStrength(
213
        return KeepUtil.getCombinedBlockLevelKeepStrength(
226
                getTableCaptionFO().getKeepWithPrevious());
214
                getTableCaptionFO().getKeepWithPrevious());
(-)src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java (-15 / +45 lines)
Lines 33-38 Link Here
33
import org.apache.fop.fo.FObj;
33
import org.apache.fop.fo.FObj;
34
import org.apache.fop.fo.properties.BreakPropertySet;
34
import org.apache.fop.fo.properties.BreakPropertySet;
35
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
35
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
36
import org.apache.fop.fo.properties.KeepProperty;
36
import org.apache.fop.fo.properties.SpaceProperty;
37
import org.apache.fop.fo.properties.SpaceProperty;
37
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
38
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
38
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
39
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
Lines 274-280 Link Here
274
275
275
        if (!firstVisibleMarkServed) {
276
        if (!firstVisibleMarkServed) {
276
            addKnuthElementsForSpaceBefore(returnList, alignment);
277
            addKnuthElementsForSpaceBefore(returnList, alignment);
277
            context.updateKeepWithPreviousPending(getKeepWithPreviousStrength());
278
            context.updateKeepWithPreviousPending(getKeepWithPrevious());
278
        }
279
        }
279
280
280
        addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
281
        addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
Lines 417-423 Link Here
417
            returnList.add(forcedBreakAfterLast);
418
            returnList.add(forcedBreakAfterLast);
418
        }
419
        }
419
420
420
        context.updateKeepWithNextPending(getKeepWithNextStrength());
421
        context.updateKeepWithNextPending(getKeepWithNext());
421
422
422
        setFinished(true);
423
        setFinished(true);
423
424
Lines 436-456 Link Here
436
                || context.isKeepWithNextPending()
437
                || context.isKeepWithNextPending()
437
                || childLC.isKeepWithPreviousPending()) {
438
                || childLC.isKeepWithPreviousPending()) {
438
439
439
            int strength = getKeepTogetherStrength();
440
            Keep keep = getKeepTogether();
440
441
441
            //Handle pending keep-with-next
442
            //Handle pending keep-with-next
442
            strength = Math.max(strength, context.getKeepWithNextPending());
443
            keep = keep.compare(context.getKeepWithNextPending());
443
            context.clearKeepWithNextPending();
444
            context.clearKeepWithNextPending();
444
445
445
            //Handle pending keep-with-previous from child LM
446
            //Handle pending keep-with-previous from child LM
446
            strength = Math.max(strength, childLC.getKeepWithPreviousPending());
447
            keep = keep.compare(childLC.getKeepWithPreviousPending());
447
            childLC.clearKeepWithPreviousPending();
448
            childLC.clearKeepWithPreviousPending();
448
449
449
            int penalty = KeepUtil.getPenaltyForKeep(strength);
450
            int penalty = keep.getPenalty();
450
451
451
            // add a penalty to forbid or discourage a break between blocks
452
            // add a penalty to forbid or discourage a break between blocks
452
            contentList.add(new BreakElement(
453
            contentList.add(new BreakElement(
453
                    new Position(this), penalty, context));
454
                    new Position(this), penalty, keep.getContext(), context));
454
            return;
455
            return;
455
        }
456
        }
456
457
Lines 817-851 Link Here
817
     * Retrieves and returns the keep-together strength from the parent element.
818
     * Retrieves and returns the keep-together strength from the parent element.
818
     * @return the keep-together strength
819
     * @return the keep-together strength
819
     */
820
     */
820
    protected int getParentKeepTogetherStrength() {
821
    protected Keep getParentKeepTogether() {
821
        int strength = KEEP_AUTO;
822
        Keep keep = Keep.KEEP_AUTO;
822
        if (getParent() instanceof BlockLevelLayoutManager) {
823
        if (getParent() instanceof BlockLevelLayoutManager) {
823
            strength = ((BlockLevelLayoutManager)getParent()).getKeepTogetherStrength();
824
            keep = ((BlockLevelLayoutManager)getParent()).getKeepTogether();
824
        } else if (getParent() instanceof InlineLayoutManager) {
825
        } else if (getParent() instanceof InlineLayoutManager) {
825
            if (((InlineLayoutManager) getParent()).mustKeepTogether()) {
826
            if (((InlineLayoutManager) getParent()).mustKeepTogether()) {
826
                strength = KEEP_ALWAYS;
827
                keep = Keep.KEEP_ALWAYS;
827
            }
828
            }
828
            //TODO Fix me
829
            //TODO Fix me
829
            //strength = ((InlineLayoutManager) getParent()).getKeepTogetherStrength();
830
            //strength = ((InlineLayoutManager) getParent()).getKeepTogetherStrength();
830
        }
831
        }
831
        return strength;
832
        return keep;
832
    }
833
    }
833
834
834
    /** {@inheritDoc} */
835
    /** {@inheritDoc} */
835
    public boolean mustKeepTogether() {
836
    public boolean mustKeepTogether() {
836
        return getKeepTogetherStrength() > KEEP_AUTO;
837
        return !getKeepTogether().isAuto();
837
    }
838
    }
838
839
839
    /** {@inheritDoc} */
840
    /** {@inheritDoc} */
840
    public boolean mustKeepWithPrevious() {
841
    public boolean mustKeepWithPrevious() {
841
        return getKeepWithPreviousStrength() > KEEP_AUTO;
842
        return !getKeepWithPrevious().isAuto();
842
    }
843
    }
843
844
844
    /** {@inheritDoc} */
845
    /** {@inheritDoc} */
845
    public boolean mustKeepWithNext() {
846
    public boolean mustKeepWithNext() {
846
        return getKeepWithNextStrength() > KEEP_AUTO;
847
        return !getKeepWithNext().isAuto();
847
    }
848
    }
848
849
850
    public KeepProperty getKeepTogetherProperty() {
851
        throw new IllegalStateException();
852
    }
853
854
    public KeepProperty getKeepWithPreviousProperty() {
855
        throw new IllegalStateException();
856
    }
857
858
    public KeepProperty getKeepWithNextProperty() {
859
        throw new IllegalStateException();
860
    }
861
862
    /** {@inheritDoc} */
863
    public Keep getKeepTogether() {
864
        Keep keep = Keep.getKeep(getKeepTogetherProperty());
865
        keep = keep.compare(getParentKeepTogether());
866
        return keep;
867
    }
868
869
    /** {@inheritDoc} */
870
    public Keep getKeepWithPrevious() {
871
        return Keep.getKeep(getKeepWithPreviousProperty());
872
    }
873
874
    /** {@inheritDoc} */
875
    public Keep getKeepWithNext() {
876
        return Keep.getKeep(getKeepWithNextProperty());
877
    }
878
849
    /**
879
    /**
850
     * Adds the unresolved elements for border and padding to a layout context so break
880
     * Adds the unresolved elements for border and padding to a layout context so break
851
     * possibilities can be properly constructed.
881
     * possibilities can be properly constructed.
(-)src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (-18 / +35 lines)
Lines 22-27 Link Here
22
import org.apache.commons.logging.Log;
22
import org.apache.commons.logging.Log;
23
import org.apache.commons.logging.LogFactory;
23
import org.apache.commons.logging.LogFactory;
24
24
25
import org.apache.fop.fo.Constants;
25
import org.apache.fop.fo.FONode;
26
import org.apache.fop.fo.FONode;
26
27
27
/**
28
/**
Lines 448-453 Link Here
448
449
449
        if (log.isTraceEnabled()) {
450
        if (log.isTraceEnabled()) {
450
            log.trace("Looping over " + (par.size() - startIndex) + " elements");
451
            log.trace("Looping over " + (par.size() - startIndex) + " elements");
452
            log.trace(par);
451
        }
453
        }
452
454
453
        KnuthNode lastForced = getNode(0);
455
        KnuthNode lastForced = getNode(0);
Lines 477-487 Link Here
477
                // only if its penalty is not infinite;
479
                // only if its penalty is not infinite;
478
                // consider all penalties, non-flagged penalties or non-forcing penalties
480
                // consider all penalties, non-flagged penalties or non-forcing penalties
479
                // according to the value of allowedBreaks
481
                // according to the value of allowedBreaks
480
                if (((KnuthPenalty) thisElement).getP() < KnuthElement.INFINITE
482
                KnuthPenalty p = (KnuthPenalty) thisElement;
481
                    && (!(allowedBreaks == NO_FLAGGED_PENALTIES)
483
                if (((p.getP() < KnuthElement.INFINITE || p.getBreakClass() != Constants.EN_LINE)
482
                            || !(((KnuthPenalty) thisElement).isFlagged()))
484
                        && (!(allowedBreaks == NO_FLAGGED_PENALTIES) || !p.isFlagged())
483
                    && (!(allowedBreaks == ONLY_FORCED_BREAKS)
485
                        && (!(allowedBreaks == ONLY_FORCED_BREAKS)
484
                            || ((KnuthPenalty) thisElement).getP() == -KnuthElement.INFINITE)) {
486
                                || p.isForcedBreak()))) {
485
                    considerLegalBreak(thisElement, i);
487
                    considerLegalBreak(thisElement, i);
486
                }
488
                }
487
                previousIsBox = false;
489
                previousIsBox = false;
Lines 495-507 Link Here
495
                // were "bad" breaks since the beginning;
497
                // were "bad" breaks since the beginning;
496
                // if it is not the node we just restarted from, lastDeactivated can
498
                // if it is not the node we just restarted from, lastDeactivated can
497
                // replace either lastTooShort or lastTooLong
499
                // replace either lastTooShort or lastTooLong
498
                if (lastDeactivated != null && lastDeactivated != lastForced) {
500
                // TODO re-enable and make it work with keep.within-column
499
                    if (lastDeactivated.adjustRatio > 0) {
501
//                if (lastDeactivated != null && lastDeactivated != lastForced) {
500
                        lastTooShort = lastDeactivated;
502
//                    if (lastDeactivated.adjustRatio > 0) {
501
                    } else {
503
//                        lastTooShort = lastDeactivated;
502
                        lastTooLong = lastDeactivated;
504
//                    } else {
503
                    }
505
//                        lastTooLong = lastDeactivated;
504
                }
506
//                    }
507
//                }
505
                if (lastTooShort == null || lastForced.position == lastTooShort.position) {
508
                if (lastTooShort == null || lastForced.position == lastTooShort.position) {
506
                    if (isPartOverflowRecoveryActivated()) {
509
                    if (isPartOverflowRecoveryActivated()) {
507
                        if (this.lastRecovered == null) {
510
                        if (this.lastRecovered == null) {
Lines 510-521 Link Here
510
                                log.debug("Recovery point: " + lastRecovered);
513
                                log.debug("Recovery point: " + lastRecovered);
511
                            }
514
                            }
512
                        }
515
                        }
513
                        // content would overflow, insert empty line/page and try again
516
                        KnuthNode node = recoverFromTooLong(lastTooLong);
514
                        KnuthNode node = createNode(
515
                                lastTooLong.previous.position, lastTooLong.previous.line + 1, 1,
516
                                0, 0, 0,
517
                                0, 0, 0,
518
                                0, 0, lastTooLong.previous);
519
                        lastForced = node;
517
                        lastForced = node;
520
                        node.fitRecoveryCounter = lastTooLong.previous.fitRecoveryCounter + 1;
518
                        node.fitRecoveryCounter = lastTooLong.previous.fitRecoveryCounter + 1;
521
                        if (log.isDebugEnabled()) {
519
                        if (log.isDebugEnabled()) {
Lines 571-576 Link Here
571
        return line;
569
        return line;
572
    }
570
    }
573
571
572
    protected KnuthNode recoverFromTooLong(KnuthNode lastTooLong) {
573
        // content would overflow, insert empty line/page and try again
574
        KnuthNode node = createNode(
575
                lastTooLong.previous.position, lastTooLong.previous.line + 1, 1,
576
                0, 0, 0,
577
                0, 0, 0,
578
                0, 0, lastTooLong.previous);
579
        return node;
580
    }
581
574
    /**
582
    /**
575
     * This method tries to find the context FO for a position in a KnuthSequence.
583
     * This method tries to find the context FO for a position in a KnuthSequence.
576
     * @param seq the KnuthSequence to inspect
584
     * @param seq the KnuthSequence to inspect
Lines 689-694 Link Here
689
        lastDeactivated = null;
697
        lastDeactivated = null;
690
        lastTooLong = null;
698
        lastTooLong = null;
691
        for (int line = startLine; line < endLine; line++) {
699
        for (int line = startLine; line < endLine; line++) {
700
            if (!elementCanEndLine(element, line + 1)) {
701
                continue;
702
            }
692
            for (KnuthNode node = getNode(line); node != null; node = node.next) {
703
            for (KnuthNode node = getNode(line); node != null; node = node.next) {
693
                if (node.position == elementIdx) {
704
                if (node.position == elementIdx) {
694
                    continue;
705
                    continue;
Lines 759-764 Link Here
759
                    }
770
                    }
760
771
761
                    if (r <= -1) {
772
                    if (r <= -1) {
773
                        log.debug("Considering tooLong, demerits=" + demerits);
762
                        if (lastTooLong == null || demerits < lastTooLong.totalDemerits) {
774
                        if (lastTooLong == null || demerits < lastTooLong.totalDemerits) {
763
                            lastTooLong = createNode(elementIdx, line + 1, fitnessClass,
775
                            lastTooLong = createNode(elementIdx, line + 1, fitnessClass,
764
                                    newWidth, newStretch, newShrink,
776
                                    newWidth, newStretch, newShrink,
Lines 791-796 Link Here
791
        }
803
        }
792
    }
804
    }
793
805
806
    protected boolean elementCanEndLine(KnuthElement element, int line) {
807
        return !(element instanceof KnuthPenalty)
808
                || ((KnuthPenalty) element).getP() < KnuthPenalty.INFINITE;
809
    }
810
794
    /**
811
    /**
795
     * Adds new active nodes for breaks at the given element.
812
     * Adds new active nodes for breaks at the given element.
796
     * @param line number of the previous line; this element will end line number (line+1)
813
     * @param line number of the previous line; this element will end line number (line+1)
(-)src/java/org/apache/fop/fo/flow/table/EffRow.java (-21 / +15 lines)
Lines 23-30 Link Here
23
import java.util.List;
23
import java.util.List;
24
24
25
import org.apache.fop.fo.Constants;
25
import org.apache.fop.fo.Constants;
26
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
26
import org.apache.fop.layoutmgr.Keep;
27
import org.apache.fop.layoutmgr.KeepUtil;
28
import org.apache.fop.layoutmgr.table.TableRowIterator;
27
import org.apache.fop.layoutmgr.table.TableRowIterator;
29
import org.apache.fop.traits.MinOptMax;
28
import org.apache.fop.traits.MinOptMax;
30
import org.apache.fop.util.BreakUtil;
29
import org.apache.fop.util.BreakUtil;
Lines 170-189 Link Here
170
     *
169
     *
171
     * @return the strength of the keep-with-previous constraint
170
     * @return the strength of the keep-with-previous constraint
172
     */
171
     */
173
    public int getKeepWithPreviousStrength() {
172
    public Keep getKeepWithPrevious() {
174
        int strength = BlockLevelLayoutManager.KEEP_AUTO;
173
        Keep keep = Keep.KEEP_AUTO;
175
        TableRow row = getTableRow();
174
        TableRow row = getTableRow();
176
        if (row != null) {
175
        if (row != null) {
177
            strength = Math.max(strength,
176
            keep = Keep.getKeep(row.getKeepWithPrevious());
178
                    KeepUtil.getCombinedBlockLevelKeepStrength(row.getKeepWithPrevious()));
179
        }
177
        }
180
        for (Iterator iter = gridUnits.iterator(); iter.hasNext();) {
178
        for (Iterator iter = gridUnits.iterator(); iter.hasNext();) {
181
            GridUnit gu = (GridUnit) iter.next();
179
            GridUnit gu = (GridUnit) iter.next();
182
            if (gu.isPrimary()) {
180
            if (gu.isPrimary()) {
183
                strength = Math.max(strength, gu.getPrimary().getKeepWithPreviousStrength());
181
                keep = keep.compare(gu.getPrimary().getKeepWithPrevious());
184
            }
182
            }
185
        }
183
        }
186
        return strength;
184
        return keep;
187
    }
185
    }
188
186
189
    /**
187
    /**
Lines 192-211 Link Here
192
     *
190
     *
193
     * @return the strength of the keep-with-next constraint
191
     * @return the strength of the keep-with-next constraint
194
     */
192
     */
195
    public int getKeepWithNextStrength() {
193
    public Keep getKeepWithNext() {
196
        int strength = BlockLevelLayoutManager.KEEP_AUTO;
194
        Keep keep = Keep.KEEP_AUTO;
197
        TableRow row = getTableRow();
195
        TableRow row = getTableRow();
198
        if (row != null) {
196
        if (row != null) {
199
            strength = Math.max(strength,
197
            keep = Keep.getKeep(row.getKeepWithNext());
200
                    KeepUtil.getCombinedBlockLevelKeepStrength(row.getKeepWithNext()));
201
        }
198
        }
202
        for (Iterator iter = gridUnits.iterator(); iter.hasNext();) {
199
        for (Iterator iter = gridUnits.iterator(); iter.hasNext();) {
203
            GridUnit gu = (GridUnit) iter.next();
200
            GridUnit gu = (GridUnit) iter.next();
204
            if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
201
            if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
205
                strength = Math.max(strength, gu.getPrimary().getKeepWithNextStrength());
202
                keep = keep.compare(gu.getPrimary().getKeepWithNext());
206
            }
203
            }
207
        }
204
        }
208
        return strength;
205
        return keep;
209
    }
206
    }
210
207
211
    /**
208
    /**
Lines 213-228 Link Here
213
     * not take the parent table's keeps into account!
210
     * not take the parent table's keeps into account!
214
     * @return the keep-together strength
211
     * @return the keep-together strength
215
     */
212
     */
216
    public int getKeepTogetherStrength() {
213
    public Keep getKeepTogether() {
217
        TableRow row = getTableRow();
214
        TableRow row = getTableRow();
218
        int strength = BlockLevelLayoutManager.KEEP_AUTO;
215
        Keep keep = Keep.KEEP_AUTO;
219
        if (row != null) {
216
        if (row != null) {
220
            strength = Math.max(strength, KeepUtil.getKeepStrength(
217
            keep = Keep.getKeep(row.getKeepTogether());
221
                    row.getKeepTogether().getWithinPage()));
222
            strength = Math.max(strength, KeepUtil.getKeepStrength(
223
                    row.getKeepTogether().getWithinColumn()));
224
        }
218
        }
225
        return strength;
219
        return keep;
226
    }
220
    }
227
221
228
    /**
222
    /**
(-)src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java (-12 / +11 lines)
Lines 19-32 Link Here
19
19
20
package org.apache.fop.fo.flow.table;
20
package org.apache.fop.fo.flow.table;
21
21
22
import java.util.LinkedList;
23
import java.util.List;
22
import java.util.List;
24
23
25
import org.apache.fop.fo.Constants;
24
import org.apache.fop.fo.Constants;
26
import org.apache.fop.fo.FONode;
25
import org.apache.fop.fo.FONode;
27
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
26
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
28
import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
29
import org.apache.fop.layoutmgr.ElementListUtils;
27
import org.apache.fop.layoutmgr.ElementListUtils;
28
import org.apache.fop.layoutmgr.Keep;
30
import org.apache.fop.layoutmgr.table.TableCellLayoutManager;
29
import org.apache.fop.layoutmgr.table.TableCellLayoutManager;
31
30
32
/**
31
/**
Lines 54-61 Link Here
54
    private boolean isSeparateBorderModel;
53
    private boolean isSeparateBorderModel;
55
    private int halfBorderSeparationBPD;
54
    private int halfBorderSeparationBPD;
56
55
57
    private int keepWithPrevious = BlockLevelLayoutManager.KEEP_AUTO;
56
    private Keep keepWithPrevious = Keep.KEEP_AUTO;
58
    private int keepWithNext = BlockLevelLayoutManager.KEEP_AUTO;
57
    private Keep keepWithNext = Keep.KEEP_AUTO;
59
    private int breakBefore = Constants.EN_AUTO;
58
    private int breakBefore = Constants.EN_AUTO;
60
    private int breakAfter = Constants.EN_AUTO;
59
    private int breakAfter = Constants.EN_AUTO;
61
60
Lines 334-349 Link Here
334
     *
333
     *
335
     * @return the keep-with-previous strength
334
     * @return the keep-with-previous strength
336
     */
335
     */
337
    public int getKeepWithPreviousStrength() {
336
    public Keep getKeepWithPrevious() {
338
        return keepWithPrevious;
337
        return keepWithPrevious;
339
    }
338
    }
340
339
341
    /**
340
    /**
342
     * Don't use, reserved for TableCellLM. TODO
341
     * Don't use, reserved for TableCellLM. TODO
343
     * @param strength the keep strength
342
     * @param keep the keep strength
344
     */
343
     */
345
    public void setKeepWithPreviousStrength(int strength) {
344
    public void setKeepWithPrevious(Keep keep) {
346
        this.keepWithPrevious = strength;
345
        this.keepWithPrevious = keep;
347
    }
346
    }
348
347
349
    /**
348
    /**
Lines 352-367 Link Here
352
     *
351
     *
353
     * @return the keep-with-next strength
352
     * @return the keep-with-next strength
354
     */
353
     */
355
    public int getKeepWithNextStrength() {
354
    public Keep getKeepWithNext() {
356
        return keepWithNext;
355
        return keepWithNext;
357
    }
356
    }
358
357
359
    /**
358
    /**
360
     * Don't use, reserved for TableCellLM. TODO
359
     * Don't use, reserved for TableCellLM. TODO
361
     * @param strength the keep strength
360
     * @param keep the keep strength
362
     */
361
     */
363
    public void setKeepWithNextStrength(int strength) {
362
    public void setKeepWithNext(Keep keep) {
364
        this.keepWithNext = strength;
363
        this.keepWithNext = keep;
365
    }
364
    }
366
365
367
    /**
366
    /**

Return to bug 46905