/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
public class AreaTreeModel {
private List pageSequenceList = null;
+ private int currentPageSequenceIndex = -1;
private List currentPageSequencePageList;
private List offDocumentItems = new java.util.ArrayList();
public void startPageSequence(LineArea title) {
currentPageSequencePageList = new java.util.ArrayList();
pageSequenceList.add(currentPageSequencePageList);
+ currentPageSequenceIndex = pageSequenceList.size() - 1;
}
/**
*/
public void addPage(PageViewport page) {
currentPageSequencePageList.add(page);
+ int pageIndex = 0;
+ for (int i = 0; i < currentPageSequenceIndex; i++) {
+ pageIndex += ((List)pageSequenceList.get(i)).size();
+ }
+ pageIndex += currentPageSequencePageList.size() - 1;
+ page.setPageIndex(pageIndex);
}
/**
private Rectangle2D viewArea;
private boolean clip = false;
private String pageNumberString = null;
+ private int pageIndex = -1; //-1 = undetermined
private SimplePageMaster spm = null;
private boolean blank;
return pageNumberString;
}
+ /**
+ * Sets the page index of the page in this rendering run.
+ * @param index the page index (zero-based), -1 if it is undetermined
+ */
+ public void setPageIndex(int index) {
+ this.pageIndex = index;
+ }
+
+ /**
+ * @return the overall page index of the page in this rendering run (zero-based,
+ * -1 if it is undetermined).
+ */
+ public int getPageIndex() {
+ return this.pageIndex;
+ }
+
/**
* Get the key for this page viewport.
* This is used so that a serializable key can be used to
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* PDFDocument later using addObject().
*
* @param resources resources object to use
- * @param pagewidth width of the page in points
- * @param pageheight height of the page in points
+ * @param pageWidth width of the page in points
+ * @param pageHeight height of the page in points
+ * @param pageIndex index of the page (zero-based)
*
* @return the created /Page object
*/
public PDFPage makePage(PDFResources resources,
- int pagewidth, int pageheight) {
+ int pageWidth, int pageHeight, int pageIndex) {
/*
* create a PDFPage with the next object number, the given
* resources, contents and dimensions
*/
PDFPage page = new PDFPage(resources,
- pagewidth, pageheight);
+ pageWidth, pageHeight, pageIndex);
getDocument().assignObjectNumber(page);
getDocument().getPages().addPage(page);
return page;
}
+ /**
+ * Make a /Page object. The page is assigned an object number immediately
+ * so references can already be made. The page must be added to the
+ * PDFDocument later using addObject().
+ *
+ * @param resources resources object to use
+ * @param pageWidth width of the page in points
+ * @param pageHeight height of the page in points
+ *
+ * @return the created /Page object
+ */
+ public PDFPage makePage(PDFResources resources,
+ int pageWidth, int pageHeight) {
+ return makePage(resources, pageWidth, pageHeight, -1);
+ }
+
/* ========================= functions ================================= */
/**
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
protected int pageheight;
+ /** the page index (zero-based) */
+ protected int pageIndex;
+
/**
* Duration to display page
*/
protected TransitionDictionary trDictionary = null;
/**
- * create a /Page object
+ * Create a /Page object
*
* @param resources the /Resources object
* @param contents the content stream
- * @param pagewidth the page's width in points
- * @param pageheight the page's height in points
+ * @param pageWidth the page's width in points
+ * @param pageHeight the page's height in points
+ * @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined)
*/
public PDFPage(PDFResources resources, PDFStream contents,
- int pagewidth, int pageheight) {
+ int pageWidth, int pageHeight, int pageIndex) {
/* generic creation of object */
super(resources);
/* set fields using parameters */
this.contents = contents;
- this.pagewidth = pagewidth;
- this.pageheight = pageheight;
+ this.pagewidth = pageWidth;
+ this.pageheight = pageHeight;
+ this.pageIndex = pageIndex;
}
/**
- * create a /Page object
+ * Create a /Page object
*
* @param resources the /Resources object
- * @param pagewidth the page's width in points
- * @param pageheight the page's height in points
+ * @param pageWidth the page's width in points
+ * @param pageHeight the page's height in points
+ * @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined)
*/
public PDFPage(PDFResources resources,
- int pagewidth, int pageheight) {
-
- /* generic creation of object */
- super(resources);
-
- /* set fields using parameters */
- this.pagewidth = pagewidth;
- this.pageheight = pageheight;
+ int pageWidth, int pageHeight, int pageIndex) {
+ this(resources, null, pageWidth, pageHeight, pageIndex);
}
/**
return this.pageheight;
}
+ /**
+ * @return the page Index of this page (zero-based), -1 if it the page index should
+ * automatically be determined.
+ */
+ public int getPageIndex() {
+ return this.pageIndex;
+ }
+
/**
* @see org.apache.fop.pdf.PDFObject#toPDFString()
*/
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @param page the child page
*/
public void notifyKidRegistered(PDFPage page) {
- this.kids.add(page.referencePDF());
+ int idx = page.getPageIndex();
+ if (idx >= 0) {
+ while (idx > this.kids.size() - 1) {
+ this.kids.add(null);
+ }
+ if (this.kids.get(idx) != null) {
+ throw new IllegalStateException("A page already exists at index "
+ + idx + " (zero-based).");
+ }
+ this.kids.set(idx, page.referencePDF());
+ } else {
+ this.kids.add(page.referencePDF());
+ }
}
/**
append(this.getCount()).
append("\n/Kids [");
for (int i = 0; i < kids.size(); i++) {
- sb.append(kids.get(i)).append(" ");
+ Object kid = kids.get(i);
+ if (kid == null) {
+ throw new IllegalStateException("Gap in the kids list!");
+ }
+ sb.append(kid).append(" ");
}
sb.append("] >>\nendobj\n");
return sb.toString();
* @see org.apache.fop.render.Renderer#supportsOutOfOrder()
*/
public boolean supportsOutOfOrder() {
- return false;
+ //return false;
+ return true;
}
/**
* @param page the page to prepare
*/
public void preparePage(PageViewport page) {
+ setupPage(page);
+ if (pages == null) {
+ pages = new java.util.HashMap();
+ }
+ pages.put(page, currentPage);
+ }
+
+ private void setupPage(PageViewport page) {
this.pdfResources = this.pdfDoc.getResources();
Rectangle2D bounds = page.getViewArea();
double h = bounds.getHeight();
currentPage = this.pdfDoc.getFactory().makePage(
this.pdfResources,
- (int) Math.round(w / 1000), (int) Math.round(h / 1000));
- if (pages == null) {
- pages = new java.util.HashMap();
- }
- pages.put(page, currentPage);
+ (int) Math.round(w / 1000), (int) Math.round(h / 1000),
+ page.getPageIndex());
pageReferences.put(page.getKey(), currentPage.referencePDF());
pvReferences.put(page.getKey(), page);
}
-
+
/**
* This method creates a pdf stream for the current page
* uses it as the contents of a new page. The page is written
throws IOException, FOPException {
if (pages != null
&& (currentPage = (PDFPage) pages.get(page)) != null) {
+ //Retrieve previously prepared page (out-of-line rendering)
pages.remove(page);
- Rectangle2D bounds = page.getViewArea();
- double h = bounds.getHeight();
- pageHeight = (int) h;
} else {
- this.pdfResources = this.pdfDoc.getResources();
- Rectangle2D bounds = page.getViewArea();
- double w = bounds.getWidth();
- double h = bounds.getHeight();
- pageHeight = (int) h;
- currentPage = this.pdfDoc.getFactory().makePage(
- this.pdfResources,
- (int) Math.round(w / 1000), (int) Math.round(h / 1000));
- pageReferences.put(page.getKey(), currentPage.referencePDF());
- pvReferences.put(page.getKey(), page);
+ setupPage(page);
}
+ Rectangle2D bounds = page.getViewArea();
+ double h = bounds.getHeight();
+ pageHeight = (int) h;
+
currentStream = this.pdfDoc.getFactory()
.makeStream(PDFFilterList.CONTENT_FILTER, false);