spepping    2005/02/20 11:50:47

  Modified:    src/java/org/apache/fop/area PageViewport.java
               src/java/org/apache/fop/layoutmgr AbstractLayoutManager.java
                        BlockContainerLayoutManager.java
                        BlockLayoutManager.java ContentLayoutManager.java
                        LayoutManager.java PageSequenceLayoutManager.java
  Log:
  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.
  
  Revision  Changes    Path
  1.12      +47 -20    xml-fop/src/java/org/apache/fop/area/PageViewport.java
  
  Index: PageViewport.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/PageViewport.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PageViewport.java 6 Feb 2005 20:48:47 -0000       1.11
  +++ PageViewport.java 20 Feb 2005 19:50:47 -0000      1.12
  @@ -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.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 @@
    * 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 @@
       // 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
  @@ -63,6 +66,11 @@
       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
        * @param bounds the bounds of this viewport
  @@ -206,11 +214,14 @@
        * 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
  -     */
  -    public void addMarkers(Map marks, boolean start, boolean isfirst) {
  -        if (start) {
  +     * @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 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 @@
                   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 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 void clear() {
           page = null;
       }
  -    
  +
       /**
        * @see java.lang.Object#toString()
        */
  @@ -371,4 +398,4 @@
           sb.append(getPageNumberString());
           return sb.toString();
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.40      +4 -4      
xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
  
  Index: AbstractLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- AbstractLayoutManager.java        17 Feb 2005 00:27:54 -0000      1.39
  +++ AbstractLayoutManager.java        20 Feb 2005 19:50:47 -0000      1.40
  @@ -358,10 +358,10 @@
       /**
        * 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 @@
        *
        * @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);
       }
   
       /**
  
  
  
  1.35      +3 -2      
xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
  
  Index: BlockContainerLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- BlockContainerLayoutManager.java  26 Jan 2005 15:00:04 -0000      1.34
  +++ BlockContainerLayoutManager.java  20 Feb 2005 19:50:47 -0000      1.35
  @@ -449,8 +449,9 @@
               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 @@
           }
   
           flush();
  -        addMarkers(true, true);
  +        addMarkers(true, bp1.isFirstArea(), bp1.isLastArea());
   
           /*
           if (!isAbsoluteOrFixed()) {
  
  
  
  1.42      +13 -2     
xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
  
  Index: BlockLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- BlockLayoutManager.java   7 Feb 2005 11:01:36 -0000       1.41
  +++ BlockLayoutManager.java   20 Feb 2005 19:50:47 -0000      1.42
  @@ -70,6 +70,8 @@
       /** 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 @@
                       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 @@
   
           if (!isBogus()) {
               addID(fobj.getId());
  -            addMarkers(true, true);
  +            addMarkers(true, bp1.isFirstArea(), bp1.isLastArea());
           }
   
           try {
  @@ -317,7 +328,7 @@
               }
           } finally {
               if (!isBogus()) {
  -                addMarkers(false, true);
  +                addMarkers(false, bp1.isFirstArea(), bp1.isLastArea());
               }
               flush();
   
  
  
  
  1.21      +2 -2      
xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
  
  Index: ContentLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ContentLayoutManager.java 17 Feb 2005 00:27:54 -0000      1.20
  +++ ContentLayoutManager.java 20 Feb 2005 19:50:47 -0000      1.21
  @@ -254,8 +254,8 @@
       }
   
       /** @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 */
  
  
  
  1.20      +4 -3      
xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java
  
  Index: LayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- LayoutManager.java        17 Feb 2005 00:27:54 -0000      1.19
  +++ LayoutManager.java        20 Feb 2005 19:50:47 -0000      1.20
  @@ -207,10 +207,11 @@
        * 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.
  
  
  
  1.37      +10 -7     
xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
  
  Index: PageSequenceLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- PageSequenceLayoutManager.java    19 Feb 2005 03:56:58 -0000      1.36
  +++ PageSequenceLayoutManager.java    20 Feb 2005 19:50:47 -0000      1.37
  @@ -335,14 +335,12 @@
       /**
        * 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 @@
        * 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 @@
               }
               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;
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to