/*
- * 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.
*/
/* $Id$ */
-
+
package org.apache.fop.area;
import java.awt.geom.Rectangle2D;
import java.util.HashMap;
import java.util.Iterator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.fo.Constants;
/**
* The page (reference area) is then rendered inside the page object
*/
public class PageViewport implements Resolvable, Cloneable {
-
+
private Page page;
private Rectangle2D viewArea;
private boolean clip = false;
// once an idref is resolved it is removed
// when this is empty the page can be rendered
private HashMap unresolvedIDRefs = new HashMap();
-
+
private Map pendingResolved = null;
// hashmap of markers for this page
private Map markerLastEnd = null;
private Map markerLastAny = null;
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(PageViewport.class);
+
/**
* Create a page viewport.
* @param p the page reference area that holds the contents
* Should this logic be placed in the Page layout manager.
*
* @param marks the map of markers to add
- * @param start if the area being added is starting or ending
- * @param isfirst isfirst or islast flag
+ * @param starting if the area being added is starting or ending
+ * @param isfirst if the area being added has is-first trait
+ * @param islast if the area being added has is-last trait
*/
- public void addMarkers(Map marks, boolean start, boolean isfirst) {
- if (start) {
+ public void addMarkers(Map marks, boolean starting,
+ boolean isfirst, boolean islast) {
+ // at the start of the area, register is-first and any areas
+ if (starting) {
if (isfirst) {
if (markerFirstStart == null) {
markerFirstStart = new HashMap();
if (markerFirstAny == null) {
markerFirstAny = new HashMap();
}
- // only put in new values, leave current
+ // first on page: only put in new values, leave current
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
if (!markerFirstStart.containsKey(key)) {
markerFirstStart.put(key, marks.get(key));
+ 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 (markerLastStart == null) {
markerLastStart = new HashMap();
}
- // replace all
+ // last on page: replace all
markerLastStart.putAll(marks);
-
+ log.trace("page " + pageNumberString + ": " + "Adding all markers to LastStart");
} else {
if (markerFirstAny == null) {
markerFirstAny = new HashMap();
}
- // only put in new values, leave current
+ // first on page: only put in new values, leave current
for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
if (!markerFirstAny.containsKey(key)) {
markerFirstAny.put(key, marks.get(key));
+ log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstAny");
}
}
}
- } else {
- if (!isfirst) {
+ }
+ // at the end of the area, register is-last and any areas
+ else {
+ if (islast) {
if (markerLastEnd == null) {
markerLastEnd = new HashMap();
}
- // replace all
+ // last on page: replace all
markerLastEnd.putAll(marks);
+ log.trace("page " + pageNumberString + ": " + "Adding all markers to LastEnd");
}
if (markerLastAny == null) {
markerLastAny = new HashMap();
}
- // replace all
+ // last on page: replace all
markerLastAny.putAll(marks);
+ log.trace("page " + pageNumberString + ": " + "Adding all markers to LastAny");
}
}
*/
public Object getMarker(String name, int pos) {
Object mark = null;
+ String posName = null;
switch (pos) {
case Constants.EN_FSWP:
if (markerFirstStart != null) {
mark = markerFirstStart.get(name);
+ posName = "FSWP";
}
if (mark == null && markerFirstAny != null) {
mark = markerFirstAny.get(name);
+ posName = "FirstAny after " + posName;
}
break;
case Constants.EN_FIC:
if (markerFirstAny != null) {
mark = markerFirstAny.get(name);
+ posName = "FIC";
}
break;
case Constants.EN_LSWP:
if (markerLastStart != null) {
mark = markerLastStart.get(name);
+ posName = "LSWP";
}
if (mark == null && markerLastAny != null) {
mark = markerLastAny.get(name);
+ posName = "LastAny after " + posName;
}
break;
case Constants.EN_LEWP:
if (markerLastEnd != null) {
mark = markerLastEnd.get(name);
+ posName = "LEWP";
}
if (mark == null && markerLastAny != null) {
mark = markerLastAny.get(name);
+ posName = "LastAny after " + posName;
}
break;
}
- return mark;
+ log.trace("page " + pageNumberString + ": " + "Retrieving marker " + name + "at position " + posName);
+ return mark;
}
/**
public void clear() {
page = null;
}
-
+
/**
* @see java.lang.Object#toString()
*/
sb.append(getPageNumberString());
return sb.toString();
}
-}
+}
\ No newline at end of file
/** The list of child BreakPoss instances. */
protected List childBreaks = new java.util.ArrayList();
+ private boolean isfirst = true;
+
/**
* Creates a new BlockLayoutManager.
* @param inBlock the block FO object to create the layout manager for.
breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
}
breakPoss.setStackingSize(stackSize);
+ if (isfirst && breakPoss.getStackingSize().opt > 0) {
+ breakPoss.setFlag(BreakPoss.ISFIRST, true);
+ isfirst = false;
+ }
+ if (isFinished()) {
+ breakPoss.setFlag(BreakPoss.ISLAST, true);
+ }
return breakPoss;
}
}
setFinished(true);
BreakPoss breakPoss = new BreakPoss(new LeafPosition(this, FINISHED_LEAF_POS));
breakPoss.setStackingSize(stackSize);
+ breakPoss.setFlag(BreakPoss.ISFIRST, isfirst);
+ breakPoss.setFlag(BreakPoss.ISLAST, true);
return breakPoss;
}
if (!isBogus()) {
addID(fobj.getId());
- addMarkers(true, true);
+ addMarkers(true, bp1.isFirstArea(), bp1.isLastArea());
}
try {
}
} finally {
if (!isBogus()) {
- addMarkers(false, true);
+ addMarkers(false, bp1.isFirstArea(), bp1.isLastArea());
}
flush();
/**
* Add the marker to the page layout manager.
*
- * @param name the marker class name
- * @param lm the layout manager for the marker contents
- * @param start true if starting marker area, false for ending
+ * @see org.apache.fop.layoutmgr.LayoutManager
*/
- public void addMarkerMap(Map marks, boolean start, boolean isfirst) {
+ public void addMarkerMap(Map marks, boolean starting, boolean isfirst, boolean islast) {
//getLogger().debug("adding markers: " + marks + ":" + start);
// add markers to page on area tree
- curPage.addMarkers(marks, start, isfirst);
+ curPage.addMarkers(marks, starting, isfirst, islast);
}
/**
* current page. For page-sequence and document it will
* lookup preceding pages from the area tree and try to find
* a marker.
+ * If we retrieve a marker from a preceding page,
+ * then the containing page does not have a qualifying area,
+ * and all qualifying areas have ended.
+ * Therefore we use last-ending-within-page (Constants.EN_LEWP)
+ * as the position.
*
* @param name the marker class name to lookup
* @param pos the position to locate the marker
}
while (page >= 0) {
PageViewport pv = areaTreeModel.getPage(seq, page);
- mark = (Marker)pv.getMarker(name, pos);
+ mark = (Marker)pv.getMarker(name, Constants.EN_LEWP);
if (mark != null) {
return mark;
}