You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/05/23 15:02:41 UTC

cvs commit: xml-fop/src/java/org/apache/fop/fo/flow TableRow.java

jeremias    2005/05/23 06:02:41

  Modified:    src/java/org/apache/fop/layoutmgr/table TableStepper.java
                        EffRow.java Cell.java
                        TableContentLayoutManager.java
               src/java/org/apache/fop/layoutmgr AbstractBreaker.java
               src/java/org/apache/fop/fo/flow TableRow.java
  Added:       src/java/org/apache/fop/layoutmgr ElementListObserver.java
  Log:
  First step towards keep-together on tables (should work on table-rows now).
  Logging of element lists removed from AbstractBreaker.
  Instead creates ElementListObserver which receives notifications on newly created element lists so they can be logged, checked or whatever. Please see the next commit under the "test" directory.
  
  Revision  Changes    Path
  1.4       +15 -9     xml-fop/src/java/org/apache/fop/layoutmgr/table/TableStepper.java
  
  Index: TableStepper.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/TableStepper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TableStepper.java	23 May 2005 07:43:05 -0000	1.3
  +++ TableStepper.java	23 May 2005 13:02:41 -0000	1.4
  @@ -131,19 +131,25 @@
           EffRow row = getActiveRow();
           if (gu.isPrimary() && !gu.isEmpty()) {
               PrimaryGridUnit pgu = (PrimaryGridUnit)gu;
  +            boolean makeBoxForWholeRow = false;
               if (row.getExplicitHeight().min > 0) {
                   boolean contentsSmaller = ElementListUtils.removeLegalBreaks(
                           pgu.getElements(), row.getExplicitHeight());
                   if (contentsSmaller) {
  -                    List list = new java.util.ArrayList(1);
  -                    list.add(new KnuthBoxCellWithBPD(
  -                            row.getExplicitHeight().opt, pgu));
  -                    elementLists[column] = list;
  -                } else {
  -                    //Copy elements (LinkedList) to array lists to improve 
  -                    //element access performance
  -                    elementLists[column] = new java.util.ArrayList(pgu.getElements());
  +                    makeBoxForWholeRow = true;
  +                }
  +            }
  +            if (pgu.isLastGridUnitRowSpan() && pgu.getRow() != null) {
  +                makeBoxForWholeRow |= pgu.getRow().mustKeepTogether();
  +            }
  +            if (makeBoxForWholeRow) {
  +                List list = new java.util.ArrayList(1);
  +                int height = row.getExplicitHeight().opt;
  +                if (height == 0) {
  +                    height = row.getHeight().opt;
                   }
  +                list.add(new KnuthBoxCellWithBPD(height, pgu));
  +                elementLists[column] = list;
               } else {
                   //Copy elements (LinkedList) to array lists to improve 
                   //element access performance
  
  
  
  1.3       +1 -2      xml-fop/src/java/org/apache/fop/layoutmgr/table/EffRow.java
  
  Index: EffRow.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/EffRow.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EffRow.java	13 May 2005 19:16:53 -0000	1.2
  +++ EffRow.java	23 May 2005 13:02:41 -0000	1.3
  @@ -38,7 +38,6 @@
       public EffRow(int index, int bodyType) {
           this.index = index;
           this.bodyType = bodyType;
  -        this.height = height;
       }
       
       public int getIndex() {
  
  
  
  1.30      +9 -7      xml-fop/src/java/org/apache/fop/layoutmgr/table/Cell.java
  
  Index: Cell.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/Cell.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- Cell.java	18 May 2005 15:25:52 -0000	1.29
  +++ Cell.java	23 May 2005 13:02:41 -0000	1.30
  @@ -139,7 +139,7 @@
       }
       
       /**
  -     * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext, int)
  +     * @see org.apache.fop.layoutmgr.LayoutManager
        */
       public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
           MinOptMax stackLimit = new MinOptMax(context.getStackLimit());
  @@ -458,7 +458,7 @@
               //curBlockArea.setHeight();
   
               // Set up dimensions
  -            Area parentArea = parentLM.getParentArea(curBlockArea);
  +            /*Area parentArea =*/ parentLM.getParentArea(curBlockArea);
               // Get reference IPD from parentArea
               setCurrentArea(curBlockArea); // ??? for generic operations
           }
  @@ -488,7 +488,7 @@
       }
   
       /**
  -     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#negotiateBPDAdjustment(int, org.apache.fop.layoutmgr.KnuthElement)
  +     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
        */
       public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
           // TODO Auto-generated method stub
  @@ -496,7 +496,7 @@
       }
   
       /**
  -     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#discardSpace(org.apache.fop.layoutmgr.KnuthGlue)
  +     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
        */
       public void discardSpace(KnuthGlue spaceGlue) {
           // TODO Auto-generated method stub
  @@ -507,9 +507,11 @@
        */
       public boolean mustKeepTogether() {
           //TODO Keeps will have to be more sophisticated sooner or later
  -        return ((BlockLevelLayoutManager)getParent()).mustKeepTogether()/* 
  -                || !fobj.getKeepTogether().getWithinPage().isAuto()
  -                || !fobj.getKeepTogether().getWithinColumn().isAuto()*/;
  +        boolean keep = ((BlockLevelLayoutManager)getParent()).mustKeepTogether();
  +        if (gridUnit.getRow() != null) {
  +            keep |= gridUnit.getRow().mustKeepTogether();
  +        }
  +        return keep;
       }
   
       /**
  
  
  
  1.8       +4 -5      xml-fop/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
  
  Index: TableContentLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TableContentLayoutManager.java	23 May 2005 08:40:36 -0000	1.7
  +++ TableContentLayoutManager.java	23 May 2005 13:02:41 -0000	1.8
  @@ -32,6 +32,7 @@
   import org.apache.fop.fo.flow.TableRow;
   import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
   import org.apache.fop.fo.properties.LengthRangeProperty;
  +import org.apache.fop.layoutmgr.ElementListObserver;
   import org.apache.fop.layoutmgr.ElementListUtils;
   import org.apache.fop.layoutmgr.KnuthBox;
   import org.apache.fop.layoutmgr.KnuthElement;
  @@ -121,9 +122,7 @@
           return this.footerList;
       }
   
  -    /**
  -     * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext, int)
  -     */
  +    /** @see org.apache.fop.layoutmgr.LayoutManager */
       public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
           log.debug("==> Columns: " + getTableLM().getColumns());
           KnuthBox headerAsFirst = null;
  @@ -381,7 +380,7 @@
                           LinkedList elems = primary.getCellLM().getNextKnuthElements(
                                                   childLC, alignment);
                           primary.setElements(elems);
  -                        log.debug("Elements: " + elems);
  +                        ElementListObserver.observe(elems, "table-cell", primary.getCell().getId());
                       }
   
                       
  
  
  
  1.6       +3 -43     xml-fop/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
  
  Index: AbstractBreaker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractBreaker.java	17 May 2005 16:53:58 -0000	1.5
  +++ AbstractBreaker.java	23 May 2005 13:02:41 -0000	1.6
  @@ -158,8 +158,8 @@
                           : (blockList.startOn == Constants.EN_ODD_PAGE) ? "odd page"
                                   : "even page";
                   log.debug("  sequence starts on " + pagina);
  -                logBlocklist(blockList);
               }
  +            ElementListObserver.observe(blockList, "breaker", null);
               //debug code end
   
               log.debug("PLM> start of algorithm (" + this.getClass().getName() 
  @@ -571,52 +571,12 @@
           // false, new Position(this), false));
           effectiveList.endSequence();
   
  -        logEffectiveList(effectiveList);
  +        ElementListObserver.observe(effectiveList, "breaker-effective", null);
   
           alg.getPageBreaks().clear(); //Why this?
           return effectiveList;
       }
   
  -    /**
  -     * Logs the contents of a block list for debugging purposes
  -     * @param blockList block list to log
  -     */
  -    private void logBlocklist(KnuthSequence blockList) {
  -        if (!log.isDebugEnabled()) {
  -            return;
  -        }
  -        ListIterator tempIter = blockList.listIterator();
  -
  -        KnuthElement temp;
  -        log.debug(" ");
  -        while (tempIter.hasNext()) {
  -            temp = (KnuthElement) tempIter.next();
  -            if (temp.isBox()) {
  -                log.debug(tempIter.previousIndex()
  -                        + ") " + temp);
  -            } else if (temp.isGlue()) {
  -                log.debug(tempIter.previousIndex()
  -                        + ") " + temp);
  -            } else {
  -                log.debug(tempIter.previousIndex()
  -                        + ") " + temp);
  -            }
  -            if (temp.getPosition() != null) {
  -                log.debug("            " + temp.getPosition());
  -            }
  -        }
  -        log.debug(" ");
  -    }
  -
  -    /**
  -     * Logs the contents of an effective block list for debugging purposes
  -     * @param effectiveList block list to log
  -     */
  -    private void logEffectiveList(KnuthSequence effectiveList) {
  -        log.debug("Effective list");
  -        logBlocklist(effectiveList);
  -    }
  -
       private int adjustBlockSpaces(LinkedList spaceList, int difference, int total) {
           if (log.isDebugEnabled()) {
               log.debug("AdjustBlockSpaces: difference " + difference + " / " + total 
  
  
  
  1.1                  xml-fop/src/java/org/apache/fop/layoutmgr/ElementListObserver.java
  
  Index: ElementListObserver.java
  ===================================================================
  /*
   * Copyright 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.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /* $Id: ElementListObserver.java,v 1.1 2005/05/23 13:02:41 jeremias Exp $ */
  
  package org.apache.fop.layoutmgr;
  
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * This class is used to observe Knuth element lists generated within the layout managers. This
   * is mainly used for the purpose of automated testing. This implementation here does nothing.
   * Please see the subclass within the test code.
   */
  public class ElementListObserver {
      
      private static List activeObservers = null;
      
      /**
       * Adds a new Observer to the list.
       * @param observer the observer implementation
       */
      public static void addObserver(Observer observer) {
          if (!isObservationActive()) {
              activeObservers = new java.util.ArrayList();
          }
          activeObservers.add(observer);
      }
      
      /**
       * Removes an Observer from the list. This call simply returns if the observer was not on
       * the list and does nothing.
       * @param observer the observer to remove
       */
      public static void removeObserver(Observer observer) {
          if (isObservationActive()) {
              activeObservers.remove(observer);
          }
      }
      
      /**
       * Notifies all registered observers about the element list.
       * @param elementList the Knuth element list
       * @param category the category for the element list (example: main, static-content, table-cell)
       * @param id ID for the element list (may be null)
       */
      public static void observe(List elementList, String category, String id) {
          if (isObservationActive()) {
              if (category == null) {
                  throw new NullPointerException("category must not be null");
              }
              Iterator i = activeObservers.iterator();
              while (i.hasNext()) {
                  ((Observer)i.next()).observe(elementList, category, id);
              }
          }
      }
      
      /** @return true if observation is active, i.e. Observers are registered. */
      public static boolean isObservationActive() {
          return activeObservers != null;
      }
  
      /**
       * Implement this interface to receive notifications on element lists.
       */
      public interface Observer {
          
          /**
           * Notifies the observer about the element list.
           * @param elementList the Knuth element list
           * @param category the category for the element list (example: main, static-content or
           * table-cell)
           * @param id ID for the element list (may be null)
           */
          void observe(List elementList, String category, String id);
          
      }
      
  }
  
  
  
  1.47      +12 -9     xml-fop/src/java/org/apache/fop/fo/flow/TableRow.java
  
  Index: TableRow.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableRow.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- TableRow.java	15 Feb 2005 19:30:51 -0000	1.46
  +++ TableRow.java	23 May 2005 13:02:41 -0000	1.47
  @@ -138,28 +138,31 @@
           return id;
       }
   
  -    /**
  -     * @return the "keep-with-previous" property.
  -     */
  +    /** @return the "keep-with-previous" property. */
       public KeepProperty getKeepWithPrevious() {
           return keepWithPrevious;
       }
   
  -    /**
  -     * Return the "keep-with-next" property.
  -     */
  +    /** @return the "keep-with-next" property. */
       public KeepProperty getKeepWithNext() {
           return keepWithNext;
       }
   
  -    /**
  -     * Return the "keep-together" property.
  -     */
  +    /** @return the "keep-together" property. */
       public KeepProperty getKeepTogether() {
           return keepTogether;
       }
   
       /**
  +     * Convenience method to check if a keep-together constraint is specified.
  +     * @return true if keep-together is active.
  +     */
  +    public boolean mustKeepTogether() {
  +        return !getKeepTogether().getWithinPage().isAuto()
  +                || !getKeepTogether().getWithinColumn().isAuto();
  +    }
  +    
  +    /**
        * @return the "block-progression-dimension" property.
        */
       public LengthRangeProperty getBlockProgressionDimension() {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org