From 6412f011d36b7b693aa9bd08dcdf2789303e9dd6 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Sun, 20 Feb 2005 19:50:47 +0000 Subject: [PATCH] Corrected the logic of adding markers. LayoutManagers are responsible for correctly setting is-first and is-last on the BreakPoss and from there in the arguments of the addMarkers method. Implemented this for BlockLM. Also made a small change in the retrieval of markers from preceding pages. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198447 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/PageViewport.java | 65 +++++++++++++------ .../fop/layoutmgr/AbstractLayoutManager.java | 8 +-- .../BlockContainerLayoutManager.java | 5 +- .../fop/layoutmgr/BlockLayoutManager.java | 15 ++++- .../fop/layoutmgr/ContentLayoutManager.java | 4 +- .../apache/fop/layoutmgr/LayoutManager.java | 7 +- .../layoutmgr/PageSequenceLayoutManager.java | 15 +++-- 7 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index 90f3aaba6..78f478b09 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -1,5 +1,5 @@ /* - * 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. @@ -15,7 +15,7 @@ */ /* $Id$ */ - + package org.apache.fop.area; import java.awt.geom.Rectangle2D; @@ -27,6 +27,9 @@ import java.util.Map; 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; /** @@ -38,7 +41,7 @@ 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; @@ -51,7 +54,7 @@ public class PageViewport implements Resolvable, Cloneable { // 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 @@ -62,6 +65,11 @@ public class PageViewport implements Resolvable, Cloneable { 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 @@ -206,11 +214,14 @@ public class PageViewport implements Resolvable, Cloneable { * 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(); @@ -218,47 +229,54 @@ public class PageViewport implements Resolvable, Cloneable { 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"); } } @@ -273,38 +291,47 @@ public class PageViewport implements Resolvable, Cloneable { */ 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; } /** @@ -361,7 +388,7 @@ public class PageViewport implements Resolvable, Cloneable { public void clear() { page = null; } - + /** * @see java.lang.Object#toString() */ @@ -371,4 +398,4 @@ public class PageViewport implements Resolvable, Cloneable { sb.append(getPageNumberString()); return sb.toString(); } -} +} \ No newline at end of file diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 4e6c6221f..ceb8184ac 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -358,10 +358,10 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants /** * Add the markers when adding an area. */ - protected void addMarkers(boolean start, boolean isfirst) { + protected void addMarkers(boolean starting, boolean isfirst, boolean islast) { // add markers if (markers != null) { - addMarkerMap(markers, start, isfirst); + addMarkerMap(markers, starting, isfirst, islast); } } @@ -370,8 +370,8 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants * * @see org.apache.fop.layoutmgr.LayoutManager */ - public void addMarkerMap(Map marks, boolean start, boolean isfirst) { - parentLM.addMarkerMap(marks, start, isfirst); + public void addMarkerMap(Map marks, boolean starting, boolean isfirst, boolean islast) { + parentLM.addMarkerMap(marks, starting, isfirst, islast); } /** diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index a92558ee2..2d789328d 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -449,8 +449,9 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { foBlockSpaceBefore = null; }*/ + BreakPoss bp1 = (BreakPoss)parentIter.peekNext(); addID(fobj.getId()); - addMarkers(true, true); + addMarkers(true, bp1.isFirstArea(), bp1.isLastArea()); LayoutManager childLM; int iStartPos = 0; @@ -468,7 +469,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { } flush(); - addMarkers(true, true); + addMarkers(true, bp1.isFirstArea(), bp1.isLastArea()); /* if (!isAbsoluteOrFixed()) { diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 454afa2bd..55354fe40 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -70,6 +70,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { /** 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. @@ -269,12 +271,21 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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; } @@ -295,7 +306,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { if (!isBogus()) { addID(fobj.getId()); - addMarkers(true, true); + addMarkers(true, bp1.isFirstArea(), bp1.isLastArea()); } try { @@ -317,7 +328,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } } finally { if (!isBogus()) { - addMarkers(false, true); + addMarkers(false, bp1.isFirstArea(), bp1.isLastArea()); } flush(); diff --git a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java index 06cd94230..e1dc46e89 100644 --- a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -254,8 +254,8 @@ public class ContentLayoutManager implements InlineLevelLayoutManager { } /** @see org.apache.fop.layoutmgr.LayoutManager */ - public void addMarkerMap(Map marks, boolean start, boolean isfirst) { - parentLM.addMarkerMap(marks, start, isfirst); + public void addMarkerMap(Map marks, boolean starting, boolean isfirst, boolean islast) { + parentLM.addMarkerMap(marks, starting, isfirst, islast); } /** @see org.apache.fop.layoutmgr.LayoutManager */ diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java index 93b674281..a06da78be 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java @@ -207,10 +207,11 @@ public interface LayoutManager { * method is used to add those markers to the page. * * @param name the marker class name - * @param start true if the formatting object is starting false is finishing - * @param isfirst a flag for is first + * @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 */ - void addMarkerMap(Map marks, boolean start, boolean isfirst); + void addMarkerMap(Map marks, boolean starting, boolean isfirst, boolean islast); /** * Retrieve a marker. diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index f08bf5820..a571ffa86 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -335,14 +335,12 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { /** * 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); } /** @@ -351,6 +349,11 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { * 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 @@ -372,7 +375,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { } 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; } -- 2.39.5