private Page page;
private Rectangle2D viewArea;
- private boolean clip = false;
+ private String simplePageMasterName;
private String pageNumberString = null;
private int pageIndex = -1; //-1 = undetermined
- private SimplePageMaster spm = null;
private boolean blank;
// list of id references and the rectangle on the page
- private Map idReferences = null;
+ //private Map idReferences = null;
// this keeps a list of currently unresolved areas or extensions
// once an idref is resolved it is removed
// when this is empty the page can be rendered
- private HashMap unresolvedIDRefs = new HashMap();
+ private Map unresolvedIDRefs = new java.util.HashMap();
private Map pendingResolved = null;
private Map markerFirstAny = null;
private Map markerLastEnd = null;
private Map markerLastAny = null;
+
+ //Arbitrary attachments to the page from extensions that need to pass information
+ //down to the renderers.
+ private List extensionAttachments = null;
/**
* logging instance
* @param blank true if this is a blank page
*/
public PageViewport(SimplePageMaster spm, String pageStr, boolean blank) {
- this.spm = spm;
+ this.simplePageMasterName = spm.getMasterName();
+ this.extensionAttachments = spm.getExtensionAttachments();
this.blank = blank;
int pageWidth = spm.getPageWidth().getValue();
int pageHeight = spm.getPageHeight().getValue();
}
/**
- * Create a page viewport
- * @param spm SimplePageMaster indicating the page and region dimensions
- * @param pageStr the page number as string.
- * @param p Page Reference Area
- * @param bounds Page Viewport dimensions
+ * Copy constructor.
+ * @param original the original PageViewport to copy from
*/
- public PageViewport(SimplePageMaster spm, String pageStr, Page p, Rectangle2D bounds) {
- this.spm = spm;
- this.pageNumberString = pageStr;
- this.page = p;
- this.viewArea = bounds;
- }
-
- /**
- * Set if this viewport should clip.
- * @param c true if this viewport should clip
- */
- public void setClip(boolean c) {
- clip = c;
+ public PageViewport(PageViewport original) {
+ this.extensionAttachments = new java.util.ArrayList(original.extensionAttachments);
+ this.pageNumberString = original.pageNumberString;
+ this.page = (Page)original.page.clone();
+ this.viewArea = (Rectangle2D)original.viewArea.clone();
}
/**
Object key = iter.next();
if (!markerFirstStart.containsKey(key)) {
markerFirstStart.put(key, marks.get(key));
- log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstStart");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding marker " + key + " to FirstStart");
+ }
}
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
- log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstAny");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding marker " + key + " to FirstAny");
+ }
}
}
if (markerLastStart == null) {
}
// last on page: replace all
markerLastStart.putAll(marks);
- log.trace("page " + pageNumberString + ": " + "Adding all markers to LastStart");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding all markers to LastStart");
+ }
} else {
if (markerFirstAny == null) {
markerFirstAny = new HashMap();
Object key = iter.next();
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
- log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstAny");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding marker " + key + " to FirstAny");
+ }
}
}
}
}
// last on page: replace all
markerLastEnd.putAll(marks);
- log.trace("page " + pageNumberString + ": " + "Adding all markers to LastEnd");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding all markers to LastEnd");
+ }
}
if (markerLastAny == null) {
markerLastAny = new HashMap();
}
// last on page: replace all
markerLastAny.putAll(marks);
- log.trace("page " + pageNumberString + ": " + "Adding all markers to LastAny");
+ if (log.isTraceEnabled()) {
+ log.trace("page " + pageNumberString + ": "
+ + "Adding all markers to LastAny");
+ }
}
}
* @return a copy of this page and associated viewports
*/
public Object clone() {
- Page p = (Page)page.clone();
- PageViewport ret = new PageViewport(spm, pageNumberString,
- p, (Rectangle2D)viewArea.clone());
- ret.pageNumberString = pageNumberString;
- return ret;
+ return new PageViewport(this);
}
/**
sb.append(getPageNumberString());
return sb.toString();
}
- /**
- * @return Returns the spm.
- */
- public SimplePageMaster getSPM() {
- return spm;
+
+ /** @return the name of the simple-page-master that created this page */
+ public String getSimplePageMasterName() {
+ return this.simplePageMasterName;
+ }
+
+ /** @return the list of extension attachments for this page */
+ public List getExtensionAttachments() {
+ return this.extensionAttachments;
}
/** @return True if this is a blank page. */
*/
private PageSequence pageSeq;
- private PageViewportProvider pvProvider;
+ private PageProvider pageProvider;
/**
- * Current page-viewport-area being filled by
+ * Current page with page-viewport-area being filled by
* the PSLM.
*/
- private PageViewport curPV = null;
+ private Page curPage = null;
/**
* The FlowLayoutManager object, which processes
super(pseq);
this.areaTreeHandler = ath;
this.pageSeq = pseq;
- this.pvProvider = new PageViewportProvider(this.pageSeq);
+ this.pageProvider = new PageProvider(this.pageSeq);
}
/**
return areaTreeHandler.getLayoutManagerMaker();
}
- /** @return the PageViewportProvider applicable to this page-sequence. */
- public PageViewportProvider getPageViewportProvider() {
- return this.pvProvider;
+ /** @return the PageProvider applicable to this page-sequence. */
+ public PageProvider getPageProvider() {
+ return this.pageProvider;
}
/**
areaTreeHandler.getAreaTreeModel().startPageSequence(title);
log.debug("Starting layout");
- curPV = makeNewPage(false, false);
+ curPage = makeNewPage(false, false);
addIDToPage(pageSeq.getId());
Flow mainFlow = pageSeq.getMainFlow();
makeFlowLayoutManager(this, mainFlow);
PageBreaker breaker = new PageBreaker(this);
- int flowBPD = (int) curPV.getBodyRegion().getRemainingBPD();
+ int flowBPD = (int)getCurrentPV().getBodyRegion().getRemainingBPD();
breaker.doLayout(flowBPD);
finishPage();
/** @see org.apache.fop.layoutmgr.AbstractBreaker */
protected void updateLayoutContext(LayoutContext context) {
- int flowIPD = curPV.getCurrentSpan().getColumnWidth();
+ int flowIPD = getCurrentPV().getCurrentSpan().getColumnWidth();
context.setRefIPD(flowIPD);
}
return null; // unneeded for PSLM
}
- /** @see org.apache.fop.layoutmgr.AbstractBreaker#getPageViewportProvider() */
- protected PageSequenceLayoutManager.PageViewportProvider getPageViewportProvider() {
- return pvProvider;
+ /** @see org.apache.fop.layoutmgr.AbstractBreaker#getPageProvider() */
+ protected PageSequenceLayoutManager.PageProvider getPageProvider() {
+ return pageProvider;
}
/** @see org.apache.fop.layoutmgr.AbstractBreaker */
}
firstPart = false;
pageBreakHandled = true;
- pvProvider.setStartOfNextElementList(currentPageNum,
- curPV.getCurrentSpan().getCurrentFlowIndex());
+ pageProvider.setStartOfNextElementList(currentPageNum,
+ getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
return super.getNextBlockList(childLC, nextSequenceStartsOn, blockLists);
}
}
protected int getCurrentDisplayAlign() {
- return curPV.getSPM().getRegion(Constants.FO_REGION_BODY).getDisplayAlign();
+ return curPage.getSimplePageMaster().getRegion(
+ Constants.FO_REGION_BODY).getDisplayAlign();
}
protected boolean hasMoreContent() {
"xsl-footnote-separator");
// create a Block area that will contain the separator areas
separatorArea = new Block();
- separatorArea.setIPD(curPV.getRegionReference(Constants.FO_REGION_BODY).getIPD());
+ separatorArea.setIPD(
+ getCurrentPV().getRegionReference(Constants.FO_REGION_BODY).getIPD());
// create a StaticContentLM for the footnote separator
footnoteSeparatorLM = (StaticContentLayoutManager)
getLayoutManagerMaker().makeStaticContentLayoutManager(
if (needColumnBalancing) {
AbstractBreaker.log.debug("Column balancing now!!!");
AbstractBreaker.log.debug("===================================================");
- int restartPoint = pvProvider.getStartingPartIndexForLastPage(partCount);
+ int restartPoint = pageProvider.getStartingPartIndexForLastPage(partCount);
if (restartPoint > 0) {
addAreas(alg, restartPoint, originalList, effectiveList);
}
}
pageBreakHandled = true;
//Update so the available BPD is reported correctly
- pvProvider.setStartOfNextElementList(currentPageNum,
- curPV.getCurrentSpan().getCurrentFlowIndex());
+ pageProvider.setStartOfNextElementList(currentPageNum,
+ getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
//Restart last page
PageBreakingAlgorithm algRestart = new BalancingColumnBreakingAlgorithm(
getTopLevelLM(),
- getPageViewportProvider(),
+ getPageProvider(),
alignment, Constants.EN_START, footnoteSeparatorLength,
isPartOverflowRecoveryActivated(),
getCurrentPV().getBodyRegion().getColumnCount());
protected void startPart(BlockSequence list, int breakClass) {
AbstractBreaker.log.debug("startPart() breakClass=" + breakClass);
- if (curPV == null) {
- throw new IllegalStateException("curPV must not be null");
+ if (curPage == null) {
+ throw new IllegalStateException("curPage must not be null");
}
if (!pageBreakHandled) {
// otherwise, we may simply need a new page
handleBreakTrait(breakClass);
}
- pvProvider.setStartOfNextElementList(currentPageNum,
- curPV.getCurrentSpan().getCurrentFlowIndex());
+ pageProvider.setStartOfNextElementList(currentPageNum,
+ getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
}
pageBreakHandled = false;
// add static areas and resolve any new id areas
/** @see org.apache.fop.layoutmgr.AbstractBreaker#handleEmptyContent() */
protected void handleEmptyContent() {
- curPV.getPage().fakeNonEmpty();
+ getCurrentPV().getPage().fakeNonEmpty();
}
protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) {
}
// set the offset from the top margin
Footnote parentArea = (Footnote) getCurrentPV().getBodyRegion().getFootnote();
- int topOffset = (int) curPV.getBodyRegion().getBPD() - parentArea.getBPD();
+ int topOffset = (int) getCurrentPV().getBodyRegion().getBPD() - parentArea.getBPD();
if (separatorArea != null) {
topOffset -= separatorArea.getBPD();
}
/**
* Provides access to the current page.
- * @return the current PageViewport
+ * @return the current Page
*/
- public PageViewport getCurrentPV() {
- return curPV;
+ public Page getCurrentPage() {
+ return curPage;
}
+ /**
+ * Provides access to the current page viewport.
+ * @return the current PageViewport
+ *//*
+ public PageViewport getCurrentPageViewport() {
+ return curPage.getPageViewport();
+ }*/
+
/**
* Provides access to this object
* @return this PageSequenceLayoutManager instance
*/
public void addIDToPage(String id) {
if (id != null && id.length() > 0) {
- areaTreeHandler.associateIDWithPageViewport(id, curPV);
+ areaTreeHandler.associateIDWithPageViewport(id, curPage.getPageViewport());
}
}
* @param res the resolvable object that needs resolving
*/
public void addUnresolvedArea(String id, Resolvable res) {
- curPV.addUnresolvedIDRef(id, res);
- areaTreeHandler.addUnresolvedIDRef(id, curPV);
+ curPage.getPageViewport().addUnresolvedIDRef(id, res);
+ areaTreeHandler.addUnresolvedIDRef(id, curPage.getPageViewport());
}
/**
int boundary = rm.getRetrieveBoundary();
// get marker from the current markers on area tree
- Marker mark = (Marker)curPV.getMarker(name, pos);
+ Marker mark = (Marker)getCurrentPV().getMarker(name, pos);
if (mark == null && boundary != EN_PAGE) {
// go back over pages until mark found
// if document boundary then keep going
}
}
- private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) {
- if (curPV != null) {
+ private Page makeNewPage(boolean bIsBlank, boolean bIsLast) {
+ if (curPage != null) {
finishPage();
}
currentPageNum++;
- curPV = pvProvider.getPageViewport(bIsBlank,
- currentPageNum, PageViewportProvider.RELTO_PAGE_SEQUENCE);
+ curPage = pageProvider.getPage(bIsBlank,
+ currentPageNum, PageProvider.RELTO_PAGE_SEQUENCE);
if (log.isDebugEnabled()) {
- log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
+ log.debug("[" + curPage.getPageViewport().getPageNumberString()
+ + (bIsBlank ? "*" : "") + "]");
}
- return curPV;
+ return curPage;
}
private void layoutSideRegion(int regionID) {
- SideRegion reg = (SideRegion)curPV.getSPM().getRegion(regionID);
+ SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID);
if (reg == null) {
return;
}
}
private void finishPage() {
- curPV.dumpMarkers();
+ curPage.getPageViewport().dumpMarkers();
// Layout side regions
layoutSideRegion(FO_REGION_BEFORE);
layoutSideRegion(FO_REGION_AFTER);
// Try to resolve any unresolved IDs for the current page.
//
- areaTreeHandler.tryIDResolution(curPV);
+ areaTreeHandler.tryIDResolution(curPage.getPageViewport());
// Queue for ID resolution and rendering
- areaTreeHandler.getAreaTreeModel().addPage(curPV);
+ areaTreeHandler.getAreaTreeModel().addPage(curPage.getPageViewport());
if (log.isDebugEnabled()) {
- log.debug("page finished: " + curPV.getPageNumberString()
+ log.debug("page finished: " + curPage.getPageViewport().getPageNumberString()
+ ", current num: " + currentPageNum);
}
- curPV = null;
+ curPage = null;
}
/**
private void handleBreakTrait(int breakVal) {
if (breakVal == Constants.EN_ALL) {
//break due to span change in multi-column layout
- curPV.createSpan(true);
+ curPage.getPageViewport().createSpan(true);
return;
} else if (breakVal == Constants.EN_NONE) {
- curPV.createSpan(false);
+ curPage.getPageViewport().createSpan(false);
return;
} else if (breakVal == Constants.EN_COLUMN || breakVal <= 0) {
- if (curPV.getCurrentSpan().hasMoreFlows()) {
- curPV.getCurrentSpan().moveToNextFlow();
+ if (curPage.getPageViewport().getCurrentSpan().hasMoreFlows()) {
+ curPage.getPageViewport().getCurrentSpan().moveToNextFlow();
} else {
- curPV = makeNewPage(false, false);
+ curPage = makeNewPage(false, false);
}
return;
}
log.debug("handling break-before after page " + currentPageNum
+ " breakVal=" + breakVal);
if (needBlankPageBeforeNew(breakVal)) {
- curPV = makeNewPage(true, false);
+ curPage = makeNewPage(true, false);
}
if (needNewPage(breakVal)) {
- curPV = makeNewPage(false, false);
+ curPage = makeNewPage(false, false);
}
}
* @param breakVal - value of break-before or break-after trait.
*/
private boolean needBlankPageBeforeNew(int breakVal) {
- if (breakVal == Constants.EN_PAGE || (curPV.getPage().isEmpty())) {
+ if (breakVal == Constants.EN_PAGE || (curPage.getPageViewport().getPage().isEmpty())) {
// any page is OK or we already have an empty page
return false;
} else {
* @param breakVal - value of break-before or break-after trait.
*/
private boolean needNewPage(int breakVal) {
- if (curPV.getPage().isEmpty()) {
+ if (curPage.getPageViewport().getPage().isEmpty()) {
if (breakVal == Constants.EN_PAGE) {
return false;
} else if (currentPageNum % 2 == 0) { // even page
/**
- * <p>This class delivers PageViewport instances. It also caches them as necessary.
+ * <p>This class delivers Page instances. It also caches them as necessary.
* </p>
* <p>Additional functionality makes sure that surplus instances that are requested by the
* page breaker are properly discarded, especially in situations where hard breaks cause
* additional pages since it doesn't know exactly until the end how many pages it really needs.
* </p>
*/
- public class PageViewportProvider {
+ public class PageProvider {
- private Log log = LogFactory.getLog(PageViewportProvider.class);
+ private Log log = LogFactory.getLog(PageProvider.class);
/** Indices are evaluated relative to the first page in the page-sequence. */
public static final int RELTO_PAGE_SEQUENCE = 0;
private int startPageOfPageSequence;
private int startPageOfCurrentElementList;
private int startColumnOfCurrentElementList;
- private List cachedPageViewports = new java.util.ArrayList();
+ private List cachedPages = new java.util.ArrayList();
//Cache to optimize getAvailableBPD() calls
private int lastRequestedIndex = -1;
* Main constructor.
* @param ps The page-sequence the provider operates on
*/
- public PageViewportProvider(PageSequence ps) {
+ public PageProvider(PageSequence ps) {
this.startPageOfPageSequence = ps.getStartingPageNumber();
}
int c = index;
int pageIndex = 0;
int colIndex = startColumnOfCurrentElementList;
- PageViewport pv = getPageViewport(
+ Page page = getPage(
false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
while (c > 0) {
colIndex++;
- if (colIndex >= pv.getCurrentSpan().getColumnCount()) {
+ if (colIndex >= page.getPageViewport().getCurrentSpan().getColumnCount()) {
colIndex = 0;
pageIndex++;
- pv = getPageViewport(
+ page = getPage(
false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
}
c--;
}
this.lastRequestedIndex = index;
- this.lastReportedBPD = pv.getBodyRegion().getRemainingBPD();
+ this.lastReportedBPD = page.getPageViewport().getBodyRegion().getRemainingBPD();
if (log.isTraceEnabled()) {
log.trace("getAvailableBPD(" + index + ") -> " + lastReportedBPD);
}
int idx = 0;
int pageIndex = 0;
int colIndex = startColumnOfCurrentElementList;
- PageViewport pv = getPageViewport(
+ Page page = getPage(
false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
while (idx < partCount) {
- if ((colIndex >= pv.getCurrentSpan().getColumnCount())) {
+ if ((colIndex >= page.getPageViewport().getCurrentSpan().getColumnCount())) {
colIndex = 0;
pageIndex++;
- pv = getPageViewport(
+ page = getPage(
false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
result = idx;
}
}
/**
- * Returns a PageViewport.
+ * Returns a Page.
* @param bIsBlank true if this page is supposed to be blank.
* @param index Index of the page (see relativeTo)
* @param relativeTo Defines which value the index parameter should be evaluated relative
- * to. (One of PageViewportProvider.RELTO_*)
- * @return the requested PageViewport
+ * to. (One of PageProvider.RELTO_*)
+ * @return the requested Page
*/
- public PageViewport getPageViewport(boolean bIsBlank, int index, int relativeTo) {
+ public Page getPage(boolean bIsBlank, int index, int relativeTo) {
if (relativeTo == RELTO_PAGE_SEQUENCE) {
- return getPageViewport(bIsBlank, index);
+ return getPage(bIsBlank, index);
} else if (relativeTo == RELTO_CURRENT_ELEMENT_LIST) {
int effIndex = startPageOfCurrentElementList + index;
effIndex += startPageOfPageSequence - 1;
- return getPageViewport(bIsBlank, effIndex);
+ return getPage(bIsBlank, effIndex);
} else {
throw new IllegalArgumentException(
"Illegal value for relativeTo: " + relativeTo);
}
}
- private PageViewport getPageViewport(boolean bIsBlank, int index) {
+ private Page getPage(boolean bIsBlank, int index) {
if (log.isTraceEnabled()) {
- log.trace("getPageViewport(" + index + " " + bIsBlank);
+ log.trace("getPage(" + index + " " + bIsBlank);
}
int intIndex = index - startPageOfPageSequence;
if (log.isTraceEnabled()) {
log.trace("blank page requested: " + index);
}
}
- while (intIndex >= cachedPageViewports.size()) {
+ while (intIndex >= cachedPages.size()) {
if (log.isTraceEnabled()) {
log.trace("Caching " + index);
}
- cacheNextPageViewport(index, bIsBlank);
+ cacheNextPage(index, bIsBlank);
}
- PageViewport pv = (PageViewport)cachedPageViewports.get(intIndex);
- if (pv.isBlank() != bIsBlank) {
+ Page page = (Page)cachedPages.get(intIndex);
+ if (page.getPageViewport().isBlank() != bIsBlank) {
log.debug("blank condition doesn't match. Replacing PageViewport.");
- while (intIndex < cachedPageViewports.size()) {
- this.cachedPageViewports.remove(cachedPageViewports.size() - 1);
+ while (intIndex < cachedPages.size()) {
+ this.cachedPages.remove(cachedPages.size() - 1);
if (!pageSeq.goToPreviousSimplePageMaster()) {
log.warn("goToPreviousSimplePageMaster() on the first page called!");
}
}
- cacheNextPageViewport(index, bIsBlank);
+ cacheNextPage(index, bIsBlank);
}
- return pv;
+ return page;
}
- private void cacheNextPageViewport(int index, boolean bIsBlank) {
+ private void cacheNextPage(int index, boolean bIsBlank) {
try {
String pageNumberString = pageSeq.makeFormattedPageNumber(index);
SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
+ spm.getMasterName() + "'. FOP presently "
+ "does not support this.");
}
- PageViewport pv = new PageViewport(spm, pageNumberString, bIsBlank);
- cachedPageViewports.add(pv);
+ Page page = new Page(spm, pageNumberString, bIsBlank);
+ cachedPages.add(page);
} catch (FOPException e) {
//TODO Maybe improve. It'll mean to propagate this exception up several
//methods calls.