From 02d1eaf0973bbd99a573bef82bb57ea9c5a46709 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Thu, 27 Feb 2003 23:30:51 +0000 Subject: [PATCH] improvement on markers, don't know if it is correct git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196005 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/area/PageViewport.java | 109 +++++++++++------- .../fop/layoutmgr/AbstractLayoutManager.java | 11 +- .../BlockContainerLayoutManager.java | 8 +- .../fop/layoutmgr/BlockLayoutManager.java | 4 +- .../fop/layoutmgr/ContentLayoutManager.java | 4 +- .../apache/fop/layoutmgr/LayoutManager.java | 6 +- .../fop/layoutmgr/PageLayoutManager.java | 4 +- .../layoutmgr/StaticContentLayoutManager.java | 3 +- 8 files changed, 86 insertions(+), 63 deletions(-) diff --git a/src/org/apache/fop/area/PageViewport.java b/src/org/apache/fop/area/PageViewport.java index 9986c6c7e..eb11f906f 100644 --- a/src/org/apache/fop/area/PageViewport.java +++ b/src/org/apache/fop/area/PageViewport.java @@ -47,8 +47,9 @@ public class PageViewport implements Resolveable, Cloneable { // start and end are added by the fo that contains the markers private Map markerFirstStart = null; private Map markerLastStart = null; - private Map markerFirstEnd = null; + private Map markerFirstAny = null; private Map markerLastEnd = null; + private Map markerLastAny = null; /** * Create a page viewport. @@ -185,8 +186,8 @@ public class PageViewport implements Resolveable, Cloneable { * 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 "first-including-carryover" it adds any starting 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 @@ -196,44 +197,58 @@ public class PageViewport implements Resolveable, Cloneable { * * @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 */ - public void addMarkers(Map marks, boolean start) { + public void addMarkers(Map marks, boolean start, boolean isfirst) { if (start) { - 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 (isfirst) { + if (markerFirstStart == null) { + markerFirstStart = new HashMap(); } - if (!markerFirstEnd.containsKey(key)) { - markerFirstEnd.put(key, marks.get(key)); + if (markerFirstAny == null) { + markerFirstAny = 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 (!markerFirstAny.containsKey(key)) { + markerFirstAny.put(key, marks.get(key)); + } + } + if (markerLastStart == null) { + markerLastStart = new HashMap(); + } + // replace all + markerLastStart.putAll(marks); + + } else { + if (markerFirstAny == null) { + markerFirstAny = new HashMap(); + } + // 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)); + } } } - markerLastStart.putAll(marks); } else { - 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)); + if (!isfirst) { + if (markerLastEnd == null) { + markerLastEnd = new HashMap(); } + // replace all + markerLastEnd.putAll(marks); + } + if (markerLastAny == null) { + markerLastAny = new HashMap(); } - markerLastEnd.putAll(marks); + // replace all + markerLastAny.putAll(marks); } } @@ -247,29 +262,39 @@ public class PageViewport implements Resolveable, Cloneable { * @return Object the marker found or null */ public Object getMarker(String name, int pos) { + Object mark = null; switch (pos) { case RetrievePosition.FSWP: if (markerFirstStart != null) { - return markerFirstStart.get(name); + mark = markerFirstStart.get(name); + } + if (mark == null && markerFirstAny != null) { + mark = markerFirstAny.get(name); } break; case RetrievePosition.FIC: - if (markerFirstStart != null) { - return markerFirstEnd.get(name); + if (markerFirstAny != null) { + mark = markerFirstAny.get(name); } break; case RetrievePosition.LSWP: - if (markerFirstStart != null) { - return markerLastStart.get(name); + if (markerLastStart != null) { + mark = markerLastStart.get(name); + } + if (mark == null && markerLastAny != null) { + mark = markerLastAny.get(name); } break; case RetrievePosition.LEWP: - if (markerFirstStart != null) { - return markerLastEnd.get(name); + if (markerLastEnd != null) { + mark = markerLastEnd.get(name); + } + if (mark == null && markerLastAny != null) { + mark = markerLastAny.get(name); } break; } - return null; + return mark; } /** @@ -321,7 +346,7 @@ public class PageViewport implements Resolveable, Cloneable { /** * Clear the page contents to save memory. * This object is kept for the life of the area tree since - * it holds id information and is used as a key. + * it holds id and marker information and is used as a key. */ public void clear() { page = null; diff --git a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 33b7feaca..47ba39a85 100644 --- a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -174,7 +174,8 @@ public abstract class AbstractLayoutManager implements LayoutManager { curChildLM.resetPosition(null); curChildLM = (LayoutManager) childLMiter.previous(); } - childLMiter.next(); // Otherwise next returns same object + // Otherwise next returns same object + childLMiter.next(); } if(curChildLM != null) { curChildLM.resetPosition(pos); @@ -324,10 +325,10 @@ public abstract class AbstractLayoutManager implements LayoutManager { /** * Add the markers when adding an area. */ - protected void addMarkers(boolean start) { + protected void addMarkers(boolean start, boolean isfirst) { // add markers if (markers != null) { - addMarkerMap(markers, start); + addMarkerMap(markers, start, isfirst); } } @@ -336,8 +337,8 @@ public abstract class AbstractLayoutManager implements LayoutManager { * * @see org.apache.fop.layoutmgr.LayoutManager */ - public void addMarkerMap(Map marks, boolean start) { - parentLM.addMarkerMap(marks, start); + public void addMarkerMap(Map marks, boolean start, boolean isfirst) { + parentLM.addMarkerMap(marks, start, isfirst); } /** diff --git a/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index af0837d2c..fc265215b 100644 --- a/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -20,7 +20,6 @@ import org.apache.fop.datatypes.FODimension; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.awt.geom.Rectangle2D; @@ -203,7 +202,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { getParentArea(null); addID(); - addMarkers(true); + addMarkers(true, true); LayoutManager childLM ; int iStartPos = 0; @@ -221,6 +220,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { } flush(); + addMarkers(true, true); childBreaks.clear(); viewportBlockArea = null; @@ -298,9 +298,5 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager { } } - public void addMarkerMap(Map marks, boolean start) { - parentLM.addMarkerMap(marks, start); - } - } diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index a7b6e7239..b7a4ea511 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -220,7 +220,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { addBlockSpacing(adjust, layoutProps.spaceBefore.space); addID(); - addMarkers(true); + addMarkers(true, true); LayoutManager childLM ; LayoutContext lc = new LayoutContext(0); @@ -242,7 +242,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } - addMarkers(false); + addMarkers(false, true); flush(); diff --git a/src/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/org/apache/fop/layoutmgr/ContentLayoutManager.java index 639e35986..28a91e996 100644 --- a/src/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -214,8 +214,8 @@ public class ContentLayoutManager implements LayoutManager { } /** @see org.apache.fop.layoutmgr.LayoutManager */ - public void addMarkerMap(Map marks, boolean start) { - parentLM.addMarkerMap(marks, start); + public void addMarkerMap(Map marks, boolean start, boolean isfirst) { + parentLM.addMarkerMap(marks, start, isfirst); } /** @see org.apache.fop.layoutmgr.LayoutManager */ diff --git a/src/org/apache/fop/layoutmgr/LayoutManager.java b/src/org/apache/fop/layoutmgr/LayoutManager.java index 771c36048..bc50a0298 100644 --- a/src/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LayoutManager.java @@ -9,6 +9,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FOUserAgent; import org.apache.fop.fo.FObj; + import org.apache.fop.fo.flow.Marker; import org.apache.fop.area.Area; @@ -193,10 +194,10 @@ public interface LayoutManager { * method is used to add those markers to the page. * * @param name the marker class name - * @param lm the layout manager of the marker child * @param start true if the formatting object is starting false is finishing + * @param isfirst a flag for is first */ - public void addMarkerMap(Map marks, boolean start); + public void addMarkerMap(Map marks, boolean start, boolean isfirst); /** * Retrieve a marker. @@ -208,5 +209,4 @@ public interface LayoutManager { * @return the layout manaager of the retrieved marker if any */ public Marker retrieveMarker(String name, int pos, int boundary); - } diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index 234a053aa..75b65f155 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -268,10 +268,10 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @param lm the layout manager for the marker contents * @param start true if starting marker area, false for ending */ - public void addMarkerMap(Map marks, boolean start) { + public void addMarkerMap(Map marks, boolean start, boolean isfirst) { //getLogger().debug("adding markers: " + marks + ":" + start); // add markers to page on area tree - curPage.addMarkers(marks, start); + curPage.addMarkers(marks, start, isfirst); } /** diff --git a/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java b/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java index 25ce1ecd1..5789c8ef3 100644 --- a/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/StaticContentLayoutManager.java @@ -13,6 +13,7 @@ import org.apache.fop.area.Block; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * LayoutManager for an fo:flow object. @@ -102,7 +103,7 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { * * @see org.apache.fop.layoutmgr.LayoutManager */ - public void addMarker(String name, LayoutManager lm, boolean start) { + public void addMarker(Map marks, boolean start, boolean isfirst) { // error markers not allowed in static getLogger().error("Cannot add marker to static areas"); } -- 2.39.5