Skip to content

Commit

Permalink
#180 Reinsert page guards in PagedBoxCollector.
Browse files Browse the repository at this point in the history
Needed for when a floated box goes over multiple pages but we are only interested in one page.
  • Loading branch information
danfickle committed Aug 12, 2018
1 parent 5cadc6d commit 8d0bea7
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ protected PagedBoxCollector() {
*/
public PagedBoxCollector(List<PageBox> pages, int minPage, int maxPage) {
this.pages = pages;
this.result = new ArrayList<PageResult>(Math.max(maxPage - minPage, 0) + 1);
this.result = new ArrayList<PageResult>(maxPage - minPage + 1);
this.finder = new PageFinder(pages);
this.startPage = Math.max(0, minPage);
this.startPage = minPage;

for (int i = minPage; i <= maxPage; i++) {
result.add(new PageResult());
Expand Down Expand Up @@ -319,6 +319,10 @@ public void collectFloats(CssContext c, Layer layer) {
int pgEnd = findEndPage(c, floater, layer.getCurrentTransformMatrix());

for (int i = pgStart; i <= pgEnd; i++) {
if (!isValidPage(i)) {
continue;
}

PageResult pgRes = getPageResult(i);
PageBox pageBox = getPageBox(i);

Expand Down Expand Up @@ -367,6 +371,10 @@ public void collect(CssContext c, Layer layer, Box container, int pgStart, int p
if (container instanceof LineBox) {

for (int i = pgStart; i <= pgEnd; i++) {
if (!isValidPage(i)) {
continue;
}

if (shadowPageNumber == PAGE_ALL) {
addLineBoxToAll(c, layer, (LineBox) container, i, true);
} else if (shadowPageNumber == PAGE_BASE_ONLY) {
Expand Down Expand Up @@ -436,6 +444,10 @@ public void collect(CssContext c, Layer layer, Box container, int pgStart, int p
private void addBlockToAll(CssContext c, Layer layer, Box container, int pgStart, int pgEnd, Shape ourClip,
List<PageResult> clipPages, boolean includeShadowPages) {
for (int i = pgStart; i <= pgEnd; i++) {
if (!isValidPage(i)) {
continue;
}

PageResult pageResult = getPageResult(i);
PageBox pageBox = getPageBox(i);
Rectangle pageClip = pageResult.getContentWindowOnDocument(pageBox, c);
Expand All @@ -461,6 +473,10 @@ private void addBlockToAll(CssContext c, Layer layer, Box container, int pgStart

private void addBlockToShadowPage(CssContext c, Layer layer, Box container, int pgStart, int pgEnd, Shape ourClip, List<PageResult> clipPages, int shadowPageNumber) {
for (int i = pgStart; i <= pgEnd; i++) {
if (!isValidPage(i)) {
continue;
}

PageResult pageResult = getPageResult(i);
PageBox pageBox = getPageBox(i);
Rectangle shadowPageClip = pageResult.getShadowWindowOnDocument(pageBox, c, shadowPageNumber);
Expand Down Expand Up @@ -628,6 +644,10 @@ private void addTableHeaderFooter(CssContext c, Layer layer, Box container, int
int tableEnd = findEndPage(c, table, layer.getCurrentTransformMatrix());

for (int pgTable = tableStart; pgTable <= tableEnd; pgTable++) {
if (!isValidPage(pgTable)) {
continue;
}

rc.setPage(pgTable, getPageBox(pgTable));
table.updateHeaderFooterPosition(rc);

Expand Down Expand Up @@ -799,6 +819,10 @@ protected int getMinPageNumber() {
return this.startPage;
}

protected boolean isValidPage(int pageNo) {
return pageNo >= getMinPageNumber() && pageNo <= getMaxPageNumber();
}

protected PageBox getPageBox(int pageNo) {
return pages.get(pageNo);
}
Expand Down

0 comments on commit 8d0bea7

Please sign in to comment.