From fcbe55c3c029b4fdf1f6197b7f4f936aa734be22 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Thu, 20 Feb 2003 02:47:45 +0000 Subject: [PATCH] implement position and boundary for markers git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195976 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/area/AreaTree.java | 9 ++ src/org/apache/fop/area/AreaTreeModel.java | 32 +++++++ src/org/apache/fop/area/PageViewport.java | 95 ++++++++++++++++--- .../fop/layoutmgr/BlockLayoutManager.java | 8 +- .../fop/layoutmgr/PageLayoutManager.java | 29 +++++- .../RetrieveMarkerLayoutManager.java | 26 +++-- 6 files changed, 174 insertions(+), 25 deletions(-) diff --git a/src/org/apache/fop/area/AreaTree.java b/src/org/apache/fop/area/AreaTree.java index 2fc4ddd04..e2831ed19 100644 --- a/src/org/apache/fop/area/AreaTree.java +++ b/src/org/apache/fop/area/AreaTree.java @@ -72,6 +72,15 @@ public class AreaTree { 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. diff --git a/src/org/apache/fop/area/AreaTreeModel.java b/src/org/apache/fop/area/AreaTreeModel.java index 0a10acafd..a257d88f3 100644 --- a/src/org/apache/fop/area/AreaTreeModel.java +++ b/src/org/apache/fop/area/AreaTreeModel.java @@ -11,6 +11,9 @@ package org.apache.fop.area; * 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 { /** @@ -36,4 +39,33 @@ 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); + } diff --git a/src/org/apache/fop/area/PageViewport.java b/src/org/apache/fop/area/PageViewport.java index a63f963c1..9986c6c7e 100644 --- a/src/org/apache/fop/area/PageViewport.java +++ b/src/org/apache/fop/area/PageViewport.java @@ -16,6 +16,8 @@ import java.util.Map; 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 @@ -43,8 +45,10 @@ public class PageViewport implements Resolveable, Cloneable { // 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. @@ -176,27 +180,94 @@ public class PageViewport implements Resolveable, Cloneable { } /** - * 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; } diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index 3d83e5d20..a7b6e7239 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -36,6 +36,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { int lineHeight = 14000; int follow = 2000; + int iStartPos = 0; + protected List childBreaks = new ArrayList(); /** @@ -56,6 +58,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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); @@ -208,8 +211,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return breakPoss; } - int iStartPos = 0; - public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); @@ -240,6 +241,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } } + + addMarkers(false); + flush(); // if adjusted space after diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index 56cfd51ab..234a053aa 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -9,6 +9,7 @@ package org.apache.fop.layoutmgr; 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; @@ -27,6 +28,7 @@ import org.apache.fop.fo.pagination.Region; 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; @@ -267,13 +269,17 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @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 @@ -283,6 +289,27 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable 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; } diff --git a/src/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java b/src/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java index 73bc4b02a..346ab4702 100644 --- a/src/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java @@ -20,12 +20,16 @@ public class RetrieveMarkerLayoutManager extends AbstractLayoutManager { 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() { @@ -41,7 +45,6 @@ public class RetrieveMarkerLayoutManager extends AbstractLayoutManager { if (replaceLM == null) { return null; } - getLogger().debug("getting breaks"); return replaceLM.getNextBreakPoss(context); } @@ -55,6 +58,7 @@ public class RetrieveMarkerLayoutManager extends AbstractLayoutManager { } public boolean isFinished() { + loadLM(); if (replaceLM == null) { return true; } @@ -74,15 +78,17 @@ public class RetrieveMarkerLayoutManager extends AbstractLayoutManager { 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); + } } } } -- 2.39.5