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

(-)src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java (-47 / +19 lines)
Lines 94-154 Link Here
94
     * @param isFirstPage True if page is first page
94
     * @param isFirstPage True if page is first page
95
     * @param isLastPage True if page is last page
95
     * @param isLastPage True if page is last page
96
     * @param isBlankPage True if page is blank
96
     * @param isBlankPage True if page is blank
97
     * @param isOnlyPage True if page is the only page
98
     * @return True if the conditions for this reference are met
97
     * @return True if the conditions for this reference are met
99
     */
98
     */
100
    protected boolean isValid(boolean isOddPage,
99
    protected boolean isValid(boolean isOddPage,
101
                              boolean isFirstPage,
100
                              boolean isFirstPage,
102
                              boolean isLastPage,
101
                              boolean isLastPage,
103
                              boolean isOnlyPage,
104
                              boolean isBlankPage) {
102
                              boolean isBlankPage) {
105
        // page-position
106
        if (isOnlyPage) {
107
            if (pagePosition != EN_ONLY) {
108
                return false;
109
            }
110
        } else if (isFirstPage) {
111
            if (pagePosition == EN_REST) {
112
                return false;
113
            } else if (pagePosition == EN_LAST) {
114
                return false;
115
            }
116
        } else if (isLastPage) {
117
            if (pagePosition == EN_REST) {
118
                return false;
119
            } else if (pagePosition == EN_FIRST) {
120
                return false;
121
            }
122
        } else {
123
            if (pagePosition == EN_FIRST) {
124
                return false;
125
            } else if (pagePosition == EN_LAST) {
126
                return false;
127
            }
128
        }
129
103
130
        // odd-or-even
104
        return (
131
        if (isOddPage) {
105
            // page-position
132
            if (oddOrEven == EN_EVEN) {
106
            (pagePosition == EN_ANY
133
              return false;
107
                || (pagePosition == EN_FIRST && isFirstPage)
134
            }
108
                || (pagePosition == EN_LAST && isLastPage)
135
        } else {
109
                || (pagePosition == EN_ONLY && (isFirstPage && isLastPage))
136
            if (oddOrEven == EN_ODD) {
110
                || (pagePosition == EN_REST && !(isFirstPage || isLastPage))
137
              return false;
111
                )
138
            }
112
            // odd-or-even
139
        }
113
            && (oddOrEven == EN_ANY
114
                || (oddOrEven == EN_ODD && isOddPage)
115
                || (oddOrEven == EN_EVEN && !isOddPage)
116
                )
117
            // blank-or-not-blank
118
            && (blankOrNotBlank == EN_ANY
119
                || (blankOrNotBlank == EN_BLANK && isBlankPage)
120
                || (blankOrNotBlank == EN_NOT_BLANK && !isBlankPage)
121
                ));
140
122
141
        // blank-or-not-blank
123
142
        if (isBlankPage) {
143
            if (blankOrNotBlank == EN_NOT_BLANK) {
144
                return false;
145
            }
146
        } else {
147
            if (blankOrNotBlank == EN_BLANK) {
148
                return false;
149
            }
150
        }
151
        return true;
152
    }
124
    }
153
125
154
    /**
126
    /**
(-)src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java (-2 / +1 lines)
Lines 117-123 Link Here
117
    public String getNextPageMasterName(boolean isOddPage,
117
    public String getNextPageMasterName(boolean isOddPage,
118
                                        boolean isFirstPage,
118
                                        boolean isFirstPage,
119
                                        boolean isLastPage,
119
                                        boolean isLastPage,
120
                                        boolean isOnlyPage,
121
                                        boolean isBlankPage) {
120
                                        boolean isBlankPage) {
122
        if (getMaximumRepeats() != INFINITE) {
121
        if (getMaximumRepeats() != INFINITE) {
123
            if (numberConsumed < getMaximumRepeats()) {
122
            if (numberConsumed < getMaximumRepeats()) {
Lines 132-138 Link Here
132
        for (int i = 0; i < conditionalPageMasterRefs.size(); i++) {
131
        for (int i = 0; i < conditionalPageMasterRefs.size(); i++) {
133
            ConditionalPageMasterReference cpmr
132
            ConditionalPageMasterReference cpmr
134
                = (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i);
133
                = (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i);
135
            if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage)) {
134
            if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isBlankPage)) {
136
                return cpmr.getMasterReference();
135
                return cpmr.getMasterReference();
137
            }
136
            }
138
        }
137
        }
(-)src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (-2 lines)
Lines 31-37 Link Here
31
     * @param isOddPage True if the next page number is odd
31
     * @param isOddPage True if the next page number is odd
32
     * @param isFirstPage True if the next page is the first
32
     * @param isFirstPage True if the next page is the first
33
     * @param isLastPage True if the next page is the last
33
     * @param isLastPage True if the next page is the last
34
     * @param isOnlyPage True if the next page is the only page
35
     * @param isBlankPage True if the next page is blank
34
     * @param isBlankPage True if the next page is blank
36
     * @return the page master name
35
     * @return the page master name
37
     * @throws PageProductionException if there's a problem determining the next page master
36
     * @throws PageProductionException if there's a problem determining the next page master
Lines 39-45 Link Here
39
    String getNextPageMasterName(boolean isOddPage,
38
    String getNextPageMasterName(boolean isOddPage,
40
                                 boolean isFirstPage,
39
                                 boolean isFirstPage,
41
                                 boolean isLastPage,
40
                                 boolean isLastPage,
42
                                 boolean isOnlyPage,
43
                                 boolean isBlankPage)
41
                                 boolean isBlankPage)
44
                                    throws PageProductionException;
42
                                    throws PageProductionException;
45
43
(-)src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (-4 / +2 lines)
Lines 177-183 Link Here
177
     * @param isOddPage True if the next page number is odd
177
     * @param isOddPage True if the next page number is odd
178
     * @param isFirstPage True if the next page is the first
178
     * @param isFirstPage True if the next page is the first
179
     * @param isLastPage True if the next page is the last
179
     * @param isLastPage True if the next page is the last
180
     * @param isOnlyPage True if the next page is the only page
181
     * @param isBlankPage True if the next page is blank
180
     * @param isBlankPage True if the next page is blank
182
     * @return the requested page master
181
     * @return the requested page master
183
     * @throws PageProductionException if there's a problem determining the next page master
182
     * @throws PageProductionException if there's a problem determining the next page master
Lines 185-191 Link Here
185
    public SimplePageMaster getNextSimplePageMaster(boolean isOddPage,
184
    public SimplePageMaster getNextSimplePageMaster(boolean isOddPage,
186
                                                    boolean isFirstPage,
185
                                                    boolean isFirstPage,
187
                                                    boolean isLastPage,
186
                                                    boolean isLastPage,
188
                                                    boolean isOnlyPage,
189
                                                    boolean isBlankPage)
187
                                                    boolean isBlankPage)
190
                                                      throws PageProductionException {
188
                                                      throws PageProductionException {
191
        if (currentSubSequence == null) {
189
        if (currentSubSequence == null) {
Lines 198-204 Link Here
198
            }
196
            }
199
        }
197
        }
200
        String pageMasterName = currentSubSequence
198
        String pageMasterName = currentSubSequence
201
            .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage);
199
            .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isBlankPage);
202
        boolean canRecover = true;
200
        boolean canRecover = true;
203
        while (pageMasterName == null) {
201
        while (pageMasterName == null) {
204
            SubSequenceSpecifier nextSubSequence = getNextSubSequence();
202
            SubSequenceSpecifier nextSubSequence = getNextSubSequence();
Lines 213-219 Link Here
213
                currentSubSequence = nextSubSequence;
211
                currentSubSequence = nextSubSequence;
214
            }
212
            }
215
            pageMasterName = currentSubSequence
213
            pageMasterName = currentSubSequence
216
                .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage);
214
                .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isBlankPage);
217
        }
215
        }
218
        SimplePageMaster pageMaster = this.layoutMasterSet
216
        SimplePageMaster pageMaster = this.layoutMasterSet
219
            .getSimplePageMaster(pageMasterName);
217
            .getSimplePageMaster(pageMasterName);
(-)src/java/org/apache/fop/fo/pagination/PageSequence.java (-36 / +25 lines)
Lines 127-145 Link Here
127
    protected void validateChildNode(Locator loc, String nsURI, String localName)
127
    protected void validateChildNode(Locator loc, String nsURI, String localName)
128
                throws ValidationException {
128
                throws ValidationException {
129
        if (FO_URI.equals(nsURI)) {
129
        if (FO_URI.equals(nsURI)) {
130
            if (localName.equals("title")) {
130
            if ("title".equals(localName)) {
131
                if (titleFO != null) {
131
                if (titleFO != null) {
132
                    tooManyNodesError(loc, "fo:title");
132
                    tooManyNodesError(loc, "fo:title");
133
                } else if (flowMap.size() > 0) {
133
                } else if (!flowMap.isEmpty()) {
134
                    nodesOutOfOrderError(loc, "fo:title", "fo:static-content");
134
                    nodesOutOfOrderError(loc, "fo:title", "fo:static-content");
135
                } else if (mainFlow != null) {
135
                } else if (mainFlow != null) {
136
                    nodesOutOfOrderError(loc, "fo:title", "fo:flow");
136
                    nodesOutOfOrderError(loc, "fo:title", "fo:flow");
137
                }
137
                }
138
            } else if (localName.equals("static-content")) {
138
            } else if ("static-content".equals(localName)) {
139
                if (mainFlow != null) {
139
                if (mainFlow != null) {
140
                    nodesOutOfOrderError(loc, "fo:static-content", "fo:flow");
140
                    nodesOutOfOrderError(loc, "fo:static-content", "fo:flow");
141
                }
141
                }
142
            } else if (localName.equals("flow")) {
142
            } else if ("flow".equals(localName)) {
143
                if (mainFlow != null) {
143
                if (mainFlow != null) {
144
                    tooManyNodesError(loc, "fo:flow");
144
                    tooManyNodesError(loc, "fo:flow");
145
                }
145
                }
Lines 157-171 Link Here
157
    public void addChildNode(FONode child) throws FOPException {
157
    public void addChildNode(FONode child) throws FOPException {
158
        int childId = child.getNameId();
158
        int childId = child.getNameId();
159
159
160
        if (childId == FO_TITLE) {
160
        switch (childId) {
161
            this.titleFO = (Title) child;
161
            case FO_TITLE:
162
        } else if (childId == FO_FLOW) {
162
                this.titleFO = (Title)child;
163
            this.mainFlow = (Flow) child;
163
                break;
164
            addFlow(mainFlow);
164
            case FO_FLOW:
165
        } else if (childId == FO_STATIC_CONTENT) {
165
                this.mainFlow = (Flow)child;
166
            addFlow((StaticContent) child);
166
                addFlow(mainFlow);
167
            String flowName = ((StaticContent) child).getFlowName();
167
                break;
168
            flowMap.put(flowName, child);
168
            case FO_STATIC_CONTENT:
169
                addFlow((StaticContent)child);
170
                flowMap.put(((StaticContent)child).getFlowName(), child);
171
                break;
172
            default:
173
                assert false;
169
        }
174
        }
170
    }
175
    }
171
176
Lines 245-261 Link Here
245
     *      page sequence
250
     *      page sequence
246
     * @param isLastPage indicator whether this page is the last page of the
251
     * @param isLastPage indicator whether this page is the last page of the
247
     *      page sequence
252
     *      page sequence
248
     * @param isOnlyPage indicator whether this page is the only page of the
249
     *      page sequence
250
     * @param isBlank indicator whether the page will be blank
253
     * @param isBlank indicator whether the page will be blank
251
     * @return the SimplePageMaster to use for this page
254
     * @return the SimplePageMaster to use for this page
252
     * @throws PageProductionException if there's a problem determining the page master
255
     * @throws PageProductionException if there's a problem determining the page master
253
     */
256
     */
254
    public SimplePageMaster getNextSimplePageMaster(int page,
257
    public SimplePageMaster getNextSimplePageMaster(int page,
255
            boolean isFirstPage,
258
                                                    boolean isFirstPage,
256
            boolean isLastPage,
259
                                                    boolean isLastPage,
257
            boolean isOnlyPage,
260
                                                    boolean isBlank) throws PageProductionException {
258
            boolean isBlank) throws PageProductionException {
259
261
260
        if (pageSequenceMaster == null) {
262
        if (pageSequenceMaster == null) {
261
            return simplePageMaster;
263
            return simplePageMaster;
Lines 266-276 Link Here
266
                    + " isOdd=" + isOddPage
268
                    + " isOdd=" + isOddPage
267
                    + " isFirst=" + isFirstPage
269
                    + " isFirst=" + isFirstPage
268
                    + " isLast=" + isLastPage
270
                    + " isLast=" + isLastPage
269
                    + " isOnly=" + isOnlyPage
270
                    + " isBlank=" + isBlank + ")");
271
                    + " isBlank=" + isBlank + ")");
271
        }
272
        }
272
        return pageSequenceMaster.getNextSimplePageMaster(isOddPage,
273
        return pageSequenceMaster.getNextSimplePageMaster(isOddPage,
273
            isFirstPage, isLastPage, isOnlyPage, isBlank);
274
            isFirstPage, isLastPage, isBlank);
274
    }
275
    }
275
276
276
    /**
277
    /**
Lines 278-306 Link Here
278
     * @return true if there is a previous item, false if the current one was the first one.
279
     * @return true if there is a previous item, false if the current one was the first one.
279
     */
280
     */
280
    public boolean goToPreviousSimplePageMaster() {
281
    public boolean goToPreviousSimplePageMaster() {
281
        if (pageSequenceMaster == null) {
282
        return pageSequenceMaster == null || pageSequenceMaster.goToPreviousSimplePageMaster();
282
            return true;
283
        } else {
284
            return pageSequenceMaster.goToPreviousSimplePageMaster();
285
        }
286
    }
283
    }
287
284
288
    /** @return true if the page-sequence has a page-master with page-position="last" */
285
    /** @return true if the page-sequence has a page-master with page-position="last" */
289
    public boolean hasPagePositionLast() {
286
    public boolean hasPagePositionLast() {
290
        if (pageSequenceMaster == null) {
287
        return pageSequenceMaster != null && pageSequenceMaster.hasPagePositionLast();
291
            return false;
292
        } else {
293
            return pageSequenceMaster.hasPagePositionLast();
294
        }
295
    }
288
    }
296
289
297
    /** @return true if the page-sequence has a page-master with page-position="only" */
290
    /** @return true if the page-sequence has a page-master with page-position="only" */
298
    public boolean hasPagePositionOnly() {
291
    public boolean hasPagePositionOnly() {
299
        if (pageSequenceMaster == null) {
292
        return pageSequenceMaster != null && pageSequenceMaster.hasPagePositionOnly();
300
            return false;
301
        } else {
302
            return pageSequenceMaster.hasPagePositionOnly();
303
        }
304
    }
293
    }
305
294
306
    /**
295
    /**
(-)src/java/org/apache/fop/render/rtf/RTFHandler.java (-1 / +1 lines)
Lines 222-228 Link Here
222
                    PageSequenceMaster master
222
                    PageSequenceMaster master
223
                        = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference);
223
                        = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference);
224
                    this.pagemaster = master.getNextSimplePageMaster(
224
                    this.pagemaster = master.getNextSimplePageMaster(
225
                            false, false, false, false, false);
225
                            false, false, false, false);
226
                }
226
                }
227
            }
227
            }
228
228
(-)src/java/org/apache/fop/layoutmgr/PageProvider.java (-3 / +4 lines)
Lines 234-246 Link Here
234
            indexOfCachedLastPage = (isLastPage ? intIndex : -1);
234
            indexOfCachedLastPage = (isLastPage ? intIndex : -1);
235
        }
235
        }
236
        if (replace) {
236
        if (replace) {
237
            disardCacheStartingWith(intIndex);
237
            discardCacheStartingWith(intIndex);
238
            page = cacheNextPage(index, isBlank, isLastPage);
238
            page = cacheNextPage(index, isBlank, isLastPage);
239
        }
239
        }
240
        return page;
240
        return page;
241
    }
241
    }
242
242
243
    private void disardCacheStartingWith(int index) {
243
    private void discardCacheStartingWith(int index) {
244
        while (index < cachedPages.size()) {
244
        while (index < cachedPages.size()) {
245
            this.cachedPages.remove(cachedPages.size() - 1);
245
            this.cachedPages.remove(cachedPages.size() - 1);
246
            if (!pageSeq.goToPreviousSimplePageMaster()) {
246
            if (!pageSeq.goToPreviousSimplePageMaster()) {
Lines 251-258 Link Here
251
251
252
    private Page cacheNextPage(int index, boolean isBlank, boolean isLastPage) {
252
    private Page cacheNextPage(int index, boolean isBlank, boolean isLastPage) {
253
        String pageNumberString = pageSeq.makeFormattedPageNumber(index);
253
        String pageNumberString = pageSeq.makeFormattedPageNumber(index);
254
        boolean isFirstPage = (startPageOfPageSequence == index);
254
        SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
255
        SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
255
                index, (startPageOfPageSequence == index), isLastPage, false, isBlank);
256
                index, isFirstPage, isLastPage, isBlank);
256
257
257
        Region body = spm.getRegion(FO_REGION_BODY);
258
        Region body = spm.getRegion(FO_REGION_BODY);
258
        if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {
259
        if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {

Return to bug 40798