xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject cvs commit: xml-fop/src/java/org/apache/fop/layoutmgr/table TableRowIterator.java Cell.java GridUnit.java TableContentLayoutManager.java
Date Thu, 28 Apr 2005 13:44:01 GMT
jeremias    2005/04/28 06:44:01

  Modified:    src/java/org/apache/fop/layoutmgr/table Tag:
                        Temp_KnuthStylePageBreaking TableRowIterator.java
                        Cell.java GridUnit.java
                        TableContentLayoutManager.java
  Log:
  Fix for NPE in Cell.java (getBorders() can return null).
  Added fetching of row groups as per definition in http://wiki.apache.org/xmlgraphics-fop/TableLayout/KnuthElementsForTables.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.4   +47 -3     xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/TableRowIterator.java
  
  Index: TableRowIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/TableRowIterator.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- TableRowIterator.java	9 Apr 2005 12:11:15 -0000	1.1.2.3
  +++ TableRowIterator.java	28 Apr 2005 13:44:01 -0000	1.1.2.4
  @@ -18,6 +18,7 @@
   
   package org.apache.fop.layoutmgr.table;
   
  +import java.util.Iterator;
   import java.util.List;
   import java.util.ListIterator;
   
  @@ -32,7 +33,10 @@
   import org.apache.fop.traits.MinOptMax;
   
   /**
  - * Iterator that lets the table layout manager step over all rows of a table.
  + * <p>Iterator that lets the table layout manager step over all rows of a table.
  + * </p>
  + * <p>Note: This class is not thread-safe.
  + * </p>
    */
   public class TableRowIterator {
   
  @@ -46,6 +50,7 @@
       /** Logger **/
       private static Log log = LogFactory.getLog(TableRowIterator.class);
   
  +    /** The table on with this instance operates. */
       protected Table table;
       private ColumnSetup columns;
       
  @@ -57,6 +62,7 @@
       private int currentRowIndex = -1;
       //TODO rows should later be a Jakarta Commons LinkedList so concurrent modifications
while 
       //using a ListIterator are possible
  +    /** List of cache rows. */
       private List rows = new java.util.ArrayList();
       //private int indexOfFirstRowInList;
       private int currentIndex = -1;
  @@ -93,6 +99,44 @@
           }
       }
       
  +    /**
  +     * Returns the next row group if any. A row group in this context is the minimum number
of 
  +     * consecutive rows which contains all spanned grid units of its cells.
  +     * @return the next row group, or null
  +     */
  +    public EffRow[] getNextRowGroup() {
  +        EffRow firstRowInGroup = getNextRow();
  +        if (firstRowInGroup == null) {
  +            return null;
  +        }
  +        EffRow lastRowInGroup = firstRowInGroup;
  +        int lastIndex = lastRowInGroup.getIndex();
  +        boolean allFinished = true;
  +        do {
  +            Iterator iter = lastRowInGroup.getGridUnits().iterator();
  +            while (iter.hasNext()) {
  +                GridUnit gu = (GridUnit)iter.next();
  +                if (!gu.isLastGridUnitRowSpan()) {
  +                    allFinished = false;
  +                    break;
  +                }
  +            }
  +            if (!allFinished) {
  +                lastIndex = lastRowInGroup.getIndex();
  +                lastRowInGroup = getNextRow();
  +                if (lastRowInGroup == null) {
  +                    allFinished = true;
  +                }
  +            }
  +        } while (!allFinished);
  +        int rowCount = lastIndex - firstRowInGroup.getIndex() + 1;
  +        EffRow[] rowGroup = new EffRow[rowCount];
  +        for (int i = 0; i < rowCount; i++) {
  +            rowGroup[i] = getCachedRow(i + firstRowInGroup.getIndex());
  +        }
  +        return rowGroup;
  +    }
  +    
       public EffRow getNextRow() {
           currentIndex++;
           boolean moreRows = true;
  @@ -375,5 +419,5 @@
               return sb.toString();
           }
       }
  -    
  +
   }
  
  
  
  1.26.2.4  +1 -1      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.26.2.3
  retrieving revision 1.26.2.4
  diff -u -r1.26.2.3 -r1.26.2.4
  --- Cell.java	7 Apr 2005 07:09:24 -0000	1.26.2.3
  +++ Cell.java	28 Apr 2005 13:44:01 -0000	1.26.2.4
  @@ -434,7 +434,7 @@
                       int lastRowHeight = 0;
                       for (int x = 0; x < gridUnits.length; x++) {
                           GridUnit gu = gridUnits[x];
  -                        if (!gu.getBorders().hasBorder()) {
  +                        if (!gu.hasBorders()) {
                               continue;
                           }
                           
  
  
  
  1.1.2.4   +8 -1      xml-fop/src/java/org/apache/fop/layoutmgr/table/GridUnit.java
  
  Index: GridUnit.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/GridUnit.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- GridUnit.java	9 Apr 2005 12:11:35 -0000	1.1.2.3
  +++ GridUnit.java	28 Apr 2005 13:44:01 -0000	1.1.2.4
  @@ -154,6 +154,13 @@
       }
       
       /**
  +     * @return true if the grid unit has any borders.
  +     */
  +    public boolean hasBorders() {
  +        return (getBorders() != null) && getBorders().hasBorder();
  +    }
  +    
  +    /**
        * Assigns the borders from the given cell to this cell info. Used in
        * case of separate border model.
        */
  
  
  
  1.1.2.8   +75 -68    xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/TableContentLayoutManager.java
  
  Index: TableContentLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/TableContentLayoutManager.java,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- TableContentLayoutManager.java	9 Apr 2005 12:11:15 -0000	1.1.2.7
  +++ TableContentLayoutManager.java	28 Apr 2005 13:44:01 -0000	1.1.2.8
  @@ -67,10 +67,12 @@
           Table table = getTableLM().getTable();
           this.trIter = new TableRowIterator(table, getTableLM().getColumns(), TableRowIterator.BODY);
           if (table.getTableHeader() != null) {
  -            headerIter = new TableRowIterator(table, getTableLM().getColumns(), TableRowIterator.HEADER);
  +            headerIter = new TableRowIterator(table, 
  +                    getTableLM().getColumns(), TableRowIterator.HEADER);
           }
           if (table.getTableFooter() != null) {
  -            footerIter = new TableRowIterator(table, getTableLM().getColumns(), TableRowIterator.FOOTER);
  +            footerIter = new TableRowIterator(table, 
  +                    getTableLM().getColumns(), TableRowIterator.FOOTER);
           }
       }
       
  @@ -86,7 +88,7 @@
        * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext,
int)
        */
       public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
  -        log.debug("Columns: " +getTableLM().getColumns());
  +        log.debug("Columns: " + getTableLM().getColumns());
           KnuthBox headerAsFirst = null;
           KnuthBox headerAsSecondToLast = null;
           KnuthBox footerAsLast = null;
  @@ -164,83 +166,88 @@
       
       /**
        * Creates Knuth elements by iterating over a TableRowIterator.
  -     * @param context
  -     * @param alignment
  -     * @return
  +     * @param iter TableRowIterator instance to fetch rows from
  +     * @param context Active LayoutContext
  +     * @param alignment alignment indicator
  +     * @return An element list
        */
       private LinkedList getKnuthElementsForRowIterator(TableRowIterator iter, 
               LayoutContext context, int alignment, boolean disableHeaderFooter) {
           LinkedList returnList = new LinkedList();
  +        TableRowIterator.EffRow[] rowGroup = null;
           TableRowIterator.EffRow row = null;
  -        while ((row = iter.getNextRow()) != null) {
  -            List pgus = new java.util.ArrayList();
  -            TableRow tableRow = null;
  -            int maxCellHeight = 0;
  -            for (int j = 0; j < row.getGridUnits().size(); j++) {
  -                GridUnit gu = (GridUnit)row.getGridUnits().get(j);
  -                if (gu.isPrimary() && !gu.isEmpty()) {
  -                    PrimaryGridUnit primary = (PrimaryGridUnit)gu;
  -                    primary.getCellLM().setParent(tableLM);
  -
  -                    //Calculate width of cell
  -                    int spanWidth = 0;
  -                    for (int i = primary.getStartCol(); 
  -                            i < primary.getStartCol() + primary.getCell().getNumberColumnsSpanned();
  -                            i++) {
  -                        spanWidth += getTableLM().getColumns().getColumn(i + 1)
  -                            .getColumnWidth().getValue();
  -                    }
  -                    log.info("spanWidth=" + spanWidth);
  -                    LayoutContext childLC = new LayoutContext(0);
  -                    childLC.setStackLimit(context.getStackLimit()); //necessary?
  -                    childLC.setRefIPD(spanWidth);
  -                    
  -                    LinkedList elems = primary.getCellLM().getNextKnuthElements(childLC,
alignment);
  -                    primary.setElements(elems);
  -                    log.debug("Elements: " + elems);
  -                    int len = calcCellHeightFromContents(elems);
  -                    pgus.add(primary);
  -                    maxCellHeight = Math.max(maxCellHeight, len);
  -                    if (len > row.getHeight().opt) {
  -                        row.setHeight(new MinOptMax(len));
  +        while ((rowGroup = iter.getNextRowGroup()) != null) {
  +            for (int rgi = 0; rgi < rowGroup.length; rgi++) {
  +                row = rowGroup[rgi];
  +                List pgus = new java.util.ArrayList();
  +                TableRow tableRow = null;
  +                int maxCellHeight = 0;
  +                for (int j = 0; j < row.getGridUnits().size(); j++) {
  +                    GridUnit gu = (GridUnit)row.getGridUnits().get(j);
  +                    if (gu.isPrimary() && !gu.isEmpty()) {
  +                        PrimaryGridUnit primary = (PrimaryGridUnit)gu;
  +                        primary.getCellLM().setParent(tableLM);
  +
  +                        //Calculate width of cell
  +                        int spanWidth = 0;
  +                        for (int i = primary.getStartCol(); 
  +                                i < primary.getStartCol() + primary.getCell().getNumberColumnsSpanned();
  +                                i++) {
  +                            spanWidth += getTableLM().getColumns().getColumn(i + 1)
  +                                .getColumnWidth().getValue();
  +                        }
  +                        log.info("spanWidth=" + spanWidth);
  +                        LayoutContext childLC = new LayoutContext(0);
  +                        childLC.setStackLimit(context.getStackLimit()); //necessary?
  +                        childLC.setRefIPD(spanWidth);
  +                        
  +                        LinkedList elems = primary.getCellLM().getNextKnuthElements(childLC,
alignment);
  +                        primary.setElements(elems);
  +                        log.debug("Elements: " + elems);
  +                        int len = calcCellHeightFromContents(elems);
  +                        pgus.add(primary);
  +                        maxCellHeight = Math.max(maxCellHeight, len);
  +                        if (len > row.getHeight().opt) {
  +                            row.setHeight(new MinOptMax(len));
  +                        }
  +                        LengthRangeProperty bpd = primary.getCell().getBlockProgressionDimension();
  +                        if (!bpd.getOptimum().isAuto()) {
  +                            if (bpd.getOptimum().getLength().getValue() > row.getHeight().opt)
{
  +                                row.setHeight(new MinOptMax(bpd.getOptimum().getLength().getValue()));
  +                            }
  +                        }
  +                        if (tableRow == null) {
  +                            tableRow = primary.getRow();
  +                        }
                       }
  -                    LengthRangeProperty bpd = primary.getCell().getBlockProgressionDimension();
  +                }
  +                
  +                if (tableRow != null) {
  +                    LengthRangeProperty bpd = tableRow.getBlockProgressionDimension();
                       if (!bpd.getOptimum().isAuto()) {
                           if (bpd.getOptimum().getLength().getValue() > row.getHeight().opt)
{
                               row.setHeight(new MinOptMax(bpd.getOptimum().getLength().getValue()));
                           }
                       }
  -                    if (tableRow == null) {
  -                        tableRow = primary.getRow();
  -                    }
                   }
  -            }
  -            
  -            if (tableRow != null) {
  -                LengthRangeProperty bpd = tableRow.getBlockProgressionDimension();
  -                if (!bpd.getOptimum().isAuto()) {
  -                    if (bpd.getOptimum().getLength().getValue() > row.getHeight().opt)
{
  -                        row.setHeight(new MinOptMax(bpd.getOptimum().getLength().getValue()));
  -                    }
  +                log.debug(row);
  +                
  +                PrimaryGridUnit[] pguArray = new PrimaryGridUnit[pgus.size()];
  +                pguArray = (PrimaryGridUnit[])pgus.toArray(pguArray);
  +                LinkedList returnedList = getCombinedKnuthElementsForRow(pguArray, row,

  +                        disableHeaderFooter);
  +                if (returnedList != null) {
  +                    returnList.addAll(returnedList);
  +                }
  +
  +                if (row.getHeight().opt > maxCellHeight) {
  +                    int space = row.getHeight().opt - maxCellHeight;
  +                    KnuthPenalty penalty = (KnuthPenalty)returnList.removeLast();
  +                    //Insert dummy box before penalty
  +                    returnList.add(new KnuthBox(space, new Position(getTableLM()), false));
  +                    returnList.add(penalty);
                   }
               }
  -            log.debug(row);
  -            
  -            PrimaryGridUnit[] pguArray = new PrimaryGridUnit[pgus.size()];
  -            pguArray = (PrimaryGridUnit[])pgus.toArray(pguArray);
  -            LinkedList returnedList = getCombinedKnuthElementsForRow(pguArray, row, 
  -                    disableHeaderFooter);
  -            if (returnedList != null) {
  -                returnList.addAll(returnedList);
  -            }
  -
  -            if (row.getHeight().opt > maxCellHeight) {
  -                int space = row.getHeight().opt - maxCellHeight;
  -                KnuthPenalty penalty = (KnuthPenalty)returnList.removeLast();
  -                //Insert dummy box before penalty
  -                returnList.add(new KnuthBox(space, new Position(getTableLM()), false));
  -                returnList.add(penalty);
  -            }
           }
           
           //Remove last penalty
  @@ -322,7 +329,7 @@
       
       private int getNextStep(int laststep, List[] elementLists, int[] index, 
               int[] start, int[] end, int[] widths, int[] fullWidths) {
  -        int backupWidths[] = new int[start.length];
  +        int[] backupWidths = new int[start.length];
           System.arraycopy(widths, 0, backupWidths, 0, backupWidths.length);
           //set starting points
           for (int i = 0; i < start.length; i++) {
  
  
  

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


Mime
View raw message