model = m;
}
+ /**
+ * Get the area tree model for this area tree.
+ *
+ * @return AreaTreeModel the model being used for this area tree
+ */
+ public AreaTreeModel getAreaTreeModel() {
+ return model;
+ }
+
/**
* Start a new page sequence.
* This signals that a new page sequence has started in the document.
* This is the model for the area tree object.
* The model implementation can handle the page sequence,
* page and extensions.
+ * The mathods to acces the page viewports can only
+ * assume the PageViewport is valid as it remains for
+ * the life of the area tree model.
*/
public abstract class AreaTreeModel {
/**
* Signal the end of the document for any processing.
*/
public abstract void endDocument();
+
+ /**
+ * Get the page sequence count.
+ * @return the number of page sequences in the document.
+ */
+ public abstract int getPageSequenceCount();
+
+ /**
+ * Get the title for a page sequence.
+ * @param count the page sequence count
+ * @return the title of the page sequence
+ */
+ public abstract Title getTitle(int count);
+
+ /**
+ * Get the page count.
+ * @param seq the page sequence to count.
+ * @return returns the number of pages in a page sequence
+ */
+ public abstract int getPageCount(int seq);
+
+ /**
+ * Get the page for a position in the document.
+ * @param seq the page sequence number
+ * @param count the page count in the sequence
+ * @return the PageViewport for the particular page
+ */
+ public abstract PageViewport getPage(int seq, int count);
+
}
import java.util.HashMap;
import java.util.Iterator;
+import org.apache.fop.fo.properties.RetrievePosition;
+
/**
* Page viewport that specifies the viewport area and holds the page contents.
* This is the top level object for a page and remains valid for the life
// hashmap of markers for this page
// start and end are added by the fo that contains the markers
- private Map markerStart = null;
- private Map markerEnd = null;
+ private Map markerFirstStart = null;
+ private Map markerLastStart = null;
+ private Map markerFirstEnd = null;
+ private Map markerLastEnd = null;
/**
* Create a page viewport.
}
/**
- * Add the start markers for this page.
+ * Add the markers for this page.
+ * Only the required markers are kept.
+ * For "first-starting-within-page" it adds the markers
+ * that are starting only if the marker class name is not
+ * already added.
+ * For "first-including-carryover" it adds any marker if
+ * the marker class name is not already added.
+ * For "last-starting-within-page" it adds all marks that
+ * are starting, replacing earlier markers.
+ * For "last-ending-within-page" it adds all markers that
+ * are ending, replacing earlier markers.
+ *
+ * Should this logic be placed in the Page layout manager.
*
- * @param marks the map of start markers to add
+ * @param marks the map of markers to add
+ * @param start if the area being added is starting or ending
*/
public void addMarkers(Map marks, boolean start) {
if (start) {
- if (markerStart == null) {
- markerStart = new HashMap();
+ if (markerFirstStart == null) {
+ markerFirstStart = new HashMap();
+ }
+ if (markerLastStart == null) {
+ markerLastStart = new HashMap();
+ }
+ if (markerFirstEnd == null) {
+ markerFirstEnd = new HashMap();
+ }
+ // 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));
+ }
+ if (!markerFirstEnd.containsKey(key)) {
+ markerFirstEnd.put(key, marks.get(key));
+ }
}
- markerStart.putAll(marks);
+ markerLastStart.putAll(marks);
} else {
- if (markerEnd == null) {
- markerEnd = new HashMap();
+ if (markerFirstEnd == null) {
+ markerFirstEnd = new HashMap();
+ }
+ if (markerLastEnd == null) {
+ markerLastEnd = new HashMap();
+ }
+ // only put in new values, leave current
+ for (Iterator iter = marks.keySet().iterator(); iter.hasNext();) {
+ Object key = iter.next();
+ if (!markerFirstEnd.containsKey(key)) {
+ markerFirstEnd.put(key, marks.get(key));
+ }
}
- markerEnd.putAll(marks);
+ markerLastEnd.putAll(marks);
}
}
+ /**
+ * Get a marker from this page.
+ * This will retrieve a marker with the class name
+ * and position.
+ *
+ * @param name The class name of the marker to retrieve
+ * @param pos the position to retrieve
+ * @return Object the marker found or null
+ */
public Object getMarker(String name, int pos) {
- if (markerStart != null) {
- return markerStart.get(name);
+ switch (pos) {
+ case RetrievePosition.FSWP:
+ if (markerFirstStart != null) {
+ return markerFirstStart.get(name);
+ }
+ break;
+ case RetrievePosition.FIC:
+ if (markerFirstStart != null) {
+ return markerFirstEnd.get(name);
+ }
+ break;
+ case RetrievePosition.LSWP:
+ if (markerFirstStart != null) {
+ return markerLastStart.get(name);
+ }
+ break;
+ case RetrievePosition.LEWP:
+ if (markerFirstStart != null) {
+ return markerLastEnd.get(name);
+ }
+ break;
}
return null;
}
int lineHeight = 14000;
int follow = 2000;
+ int iStartPos = 0;
+
protected List childBreaks = new ArrayList();
/**
protected boolean preLoadNext() {
while (proxy.hasNext()) {
LayoutManager lm = (LayoutManager) proxy.next();
+ lm.setParentLM(BlockLayoutManager.this);
if(lm.generatesInlineAreas()) {
LineLayoutManager lineLM = createLineManager(lm);
listLMs.add(lineLM);
return breakPoss;
}
- int iStartPos = 0;
-
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
}
}
+
+ addMarkers(false);
+
flush();
// if adjusted space after
import org.apache.fop.apps.FOPException;
import org.apache.fop.area.AreaTree;
+import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.Area;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Flow;
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.pagination.PageNumberGenerator;
import org.apache.fop.fo.properties.Constants;
+import org.apache.fop.fo.properties.RetrieveBoundary;
import java.util.ArrayList;
import java.util.List;
* @param start true if starting marker area, false for ending
*/
public void addMarkerMap(Map marks, boolean start) {
- getLogger().debug("adding markers: " + marks + ":" + start);
+ //getLogger().debug("adding markers: " + marks + ":" + start);
// add markers to page on area tree
curPage.addMarkers(marks, start);
}
/**
* Retrieve a marker from this layout manager.
+ * If the boundary is page then it will only check the
+ * current page. For page-sequence and document it will
+ * lookup preceding pages from the area tree and try to find
+ * a marker.
*
* @param name the marker class name to lookup
* @param pos the position to locate the marker
public Marker retrieveMarker(String name, int pos, int boundary) {
// get marker from the current markers on area tree
Marker mark = (Marker)curPage.getMarker(name, pos);
+ if (mark == null && boundary != RetrieveBoundary.PAGE) {
+ // go back over pages until mark found
+ // if document boundary then keep going
+ boolean doc = boundary == RetrieveBoundary.DOCUMENT;
+ AreaTreeModel atm = areaTree.getAreaTreeModel();
+ int seq = atm.getPageSequenceCount();
+ int page = atm.getPageCount(seq) - 1;
+ while (page >= 0) {
+ PageViewport pv = atm.getPage(seq, page);
+ mark = (Marker)curPage.getMarker(name, pos);
+ if (mark != null) {
+ return mark;
+ }
+ page--;
+ if (page == -1 && doc && seq > 0) {
+ seq--;
+ page = atm.getPageCount(seq) - 1;
+ }
+ }
+ }
+
return mark;
}
private LayoutManager replaceLM = null;
private boolean loaded = false;
private String name;
+ private int position;
+ private int boundary;
/**
* Create a new block container layout manager.
*/
public RetrieveMarkerLayoutManager(String n, int pos, int bound) {
name = n;
+ position = pos;
+ boundary = bound;
}
public boolean generatesInlineAreas() {
if (replaceLM == null) {
return null;
}
- getLogger().debug("getting breaks");
return replaceLM.getNextBreakPoss(context);
}
}
public boolean isFinished() {
+ loadLM();
if (replaceLM == null) {
return true;
}
loaded = true;
if (replaceLM == null) {
List list = new ArrayList();
- Marker marker = retrieveMarker(name, 0, 0);
- marker.addLayoutManager(list);
- if (list.size() > 0) {
- replaceLM = (LayoutManager)list.get(0);
- replaceLM.setParentLM(this);
- replaceLM.init();
- getLogger().debug("retrieved: " + replaceLM + ":" + list.size());
- } else {
- getLogger().debug("found no marker with name: " + name);
+ Marker marker = retrieveMarker(name, position, boundary);
+ if (marker != null) {
+ marker.addLayoutManager(list);
+ if (list.size() > 0) {
+ replaceLM = (LayoutManager)list.get(0);
+ replaceLM.setParentLM(this);
+ replaceLM.init();
+ getLogger().debug("retrieved: " + replaceLM + ":" + list.size());
+ } else {
+ getLogger().debug("found no marker with name: " + name);
+ }
}
}
}