aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-08-09 19:02:34 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-08-09 19:02:34 +0000
commit6c9c875c0d1429d392cd7e4e810bb146c063ea27 (patch)
treebca3e73ad9e324ff6bd0330df643d3dcf5d3db44 /src
parent2c2c292121674e5e67fc2f5762be66e1528d5161 (diff)
downloadxmlgraphics-fop-6c9c875c0d1429d392cd7e4e810bb146c063ea27.tar.gz
xmlgraphics-fop-6c9c875c0d1429d392cd7e4e810bb146c063ea27.zip
Bugzilla #53688: Wrong page number reported when a column overflows the region-body in a multi-column document
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1371386 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageBreaker.java3
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageProvider.java80
2 files changed, 41 insertions, 42 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/PageBreaker.java b/src/java/org/apache/fop/layoutmgr/PageBreaker.java
index 58cb0ae4e..309f4e32f 100644
--- a/src/java/org/apache/fop/layoutmgr/PageBreaker.java
+++ b/src/java/org/apache/fop/layoutmgr/PageBreaker.java
@@ -95,8 +95,7 @@ public class PageBreaker extends AbstractBreaker {
return new PageBreakingLayoutListener() {
public void notifyOverflow(int part, int amount, FObj obj) {
- Page p = pageProvider.getPage(
- false, part, PageProvider.RELTO_CURRENT_ELEMENT_LIST);
+ Page p = pageProvider.getPageFromColumnIndex(part);
RegionBody body = (RegionBody)p.getSimplePageMaster().getRegion(
Region.FO_REGION_BODY);
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
diff --git a/src/java/org/apache/fop/layoutmgr/PageProvider.java b/src/java/org/apache/fop/layoutmgr/PageProvider.java
index 0ad990899..8117d547d 100644
--- a/src/java/org/apache/fop/layoutmgr/PageProvider.java
+++ b/src/java/org/apache/fop/layoutmgr/PageProvider.java
@@ -151,18 +151,37 @@ public class PageProvider implements Constants {
return this.lastReportedBPD;
}
- // Wish there were a more elegant way to do this in Java
- private int[] getColIndexAndColCount(int index) {
+ private static class Column {
+
+ final Page page;
+
+ final int pageIndex;
+
+ final int colIndex;
+
+ final int columnCount;
+
+ Column(Page page, int pageIndex, int colIndex, int columnCount) {
+ this.page = page;
+ this.pageIndex = pageIndex;
+ this.colIndex = colIndex;
+ this.columnCount = columnCount;
+ }
+
+ }
+
+ private Column getColumn(int index) {
int columnCount = 0;
int colIndex = startColumnOfCurrentElementList + index;
int pageIndex = -1;
+ Page page;
do {
colIndex -= columnCount;
pageIndex++;
- Page page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
+ page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
} while (colIndex >= columnCount);
- return new int[] {colIndex, columnCount};
+ return new Column(page, pageIndex, colIndex, columnCount);
}
/**
@@ -173,22 +192,13 @@ public class PageProvider implements Constants {
* than, equal to or greater than the IPD of the following part
*/
public int compareIPDs(int index) {
- int columnCount = 0;
- int colIndex = startColumnOfCurrentElementList + index;
- int pageIndex = -1;
- Page page;
- do {
- colIndex -= columnCount;
- pageIndex++;
- page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
- columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
- } while (colIndex >= columnCount);
- if (colIndex + 1 < columnCount) {
+ Column column = getColumn(index);
+ if (column.colIndex + 1 < column.columnCount) {
// Next part is a column on same page => same IPD
return 0;
} else {
- Page nextPage = getPage(false, pageIndex + 1, RELTO_CURRENT_ELEMENT_LIST);
- return page.getPageViewport().getBodyRegion().getIPD()
+ Page nextPage = getPage(false, column.pageIndex + 1, RELTO_CURRENT_ELEMENT_LIST);
+ return column.page.getPageViewport().getBodyRegion().getIPD()
- nextPage.getPageViewport().getBodyRegion().getIPD();
}
}
@@ -199,7 +209,7 @@ public class PageProvider implements Constants {
* @return {@code true} if the break starts a new page
*/
boolean startPage(int index) {
- return getColIndexAndColCount(index)[0] == 0;
+ return getColumn(index).colIndex == 0;
}
/**
@@ -208,8 +218,8 @@ public class PageProvider implements Constants {
* @return {@code true} if the break ends a page
*/
boolean endPage(int index) {
- int[] colIndexAndColCount = getColIndexAndColCount(index);
- return colIndexAndColCount[0] == colIndexAndColCount[1] - 1;
+ Column column = getColumn(index);
+ return column.colIndex == column.columnCount - 1;
}
/**
@@ -219,7 +229,7 @@ public class PageProvider implements Constants {
* @return the number of columns
*/
int getColumnCount(int index) {
- return getColIndexAndColCount(index)[1];
+ return getColumn(index).columnCount;
}
/**
@@ -229,24 +239,12 @@ public class PageProvider implements Constants {
* @return the requested part index
*/
public int getStartingPartIndexForLastPage(int partCount) {
- int result = 0;
- int idx = 0;
- int pageIndex = 0;
- int colIndex = startColumnOfCurrentElementList;
- Page page = getPage(
- false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
- while (idx < partCount) {
- if ((colIndex >= page.getPageViewport().getCurrentSpan().getColumnCount())) {
- colIndex = 0;
- pageIndex++;
- page = getPage(
- false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
- result = idx;
- }
- colIndex++;
- idx++;
- }
- return result;
+ int lastPartIndex = partCount - 1;
+ return lastPartIndex - getColumn(lastPartIndex).colIndex;
+ }
+
+ Page getPageFromColumnIndex(int columnIndex) {
+ return getColumn(columnIndex).page;
}
/**
@@ -291,7 +289,9 @@ public class PageProvider implements Constants {
log.trace("last page requested: " + index);
}
}
- while (intIndex >= cachedPages.size()) {
+ if (intIndex > cachedPages.size()) {
+ throw new UnsupportedOperationException("Cannot handle holes in page cache");
+ } else if (intIndex == cachedPages.size()) {
if (log.isTraceEnabled()) {
log.trace("Caching " + index);
}