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/04 17:10:19 UTC

cvs commit: xml-fop/src/java/org/apache/fop/layoutmgr/table TableRowIterator.java Cell.java GridUnit.java TableContentLayoutManager.java PrimaryGridUnit.java

jeremias    2005/05/04 08:10:19

  Modified:    src/java/org/apache/fop/layoutmgr/table Tag:
                        Temp_KnuthStylePageBreaking TableRowIterator.java
                        Cell.java GridUnit.java
                        TableContentLayoutManager.java PrimaryGridUnit.java
  Log:
  Fixed a number of issues mainly related to border painting and row spanning.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.6   +21 -5     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.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- TableRowIterator.java	4 May 2005 07:18:12 -0000	1.1.2.5
  +++ TableRowIterator.java	4 May 2005 15:10:19 -0000	1.1.2.6
  @@ -53,6 +53,7 @@
       /** The table on with this instance operates. */
       protected Table table;
       private ColumnSetup columns;
  +    private int type;
       
       /** Holds the current row (TableCell instances) */
       private List currentRow = new java.util.ArrayList();
  @@ -74,6 +75,7 @@
       public TableRowIterator(Table table, ColumnSetup columns, int what) {
           this.table = table;
           this.columns = columns;
  +        this.type = what;
           switch(what) {
               case HEADER: {
                   List bodyList = new java.util.ArrayList();
  @@ -197,8 +199,11 @@
                   if (rows.size() > 0) {
                       getCachedRow(rows.size() - 1).setFlagForAllGridUnits(
                               GridUnit.LAST_IN_BODY, true);
  -                    getCachedRow(rows.size() - 1).setFlagForAllGridUnits(
  -                            GridUnit.LAST_IN_TABLE, true);
  +                    if ((type == FOOTER || table.getTableFooter() == null) 
  +                            && type != HEADER) {
  +                        getCachedRow(rows.size() - 1).setFlagForAllGridUnits(
  +                                GridUnit.LAST_IN_TABLE, true);
  +                    }
                   }
                   return false;
               }
  @@ -235,7 +240,8 @@
           if (firstInBody) {
               gridUnits.setFlagForAllGridUnits(GridUnit.FIRST_IN_BODY, true);
           }
  -        if (firstInTable) {
  +        if (firstInTable && (type == HEADER || table.getTableHeader() == null)
  +                && type != FOOTER) {
               gridUnits.setFlagForAllGridUnits(GridUnit.FIRST_IN_TABLE, true);
           }
           log.debug(gridUnits);
  @@ -268,11 +274,21 @@
           //Create all row-spanned grid units based on information from the last row
           int colnum = 1;
           ListIterator spanIter = lastRowsSpanningCells.listIterator();
  +        GridUnit[] horzSpan = null;
           while (spanIter.hasNext()) {
               GridUnit gu = (GridUnit)spanIter.next();
               if (gu != null) {
  +                if (gu.getColSpanIndex() == 0) {
  +                    horzSpan = new GridUnit[gu.getCell().getNumberColumnsSpanned()];
  +                }
                   GridUnit newGU = gu.createNextRowSpanningGridUnit();
                   safelySetListItem(gridUnits, colnum - 1, newGU);
  +                horzSpan[newGU.getColSpanIndex()] = newGU;
  +                if (newGU.isLastGridUnitColSpan()) {
  +                    //Add the array of row-spanned grid units to the primary grid unit
  +                    newGU.getPrimary().addRow(horzSpan);
  +                    horzSpan = null;
  +                }
                   if (newGU.isLastGridUnitRowSpan()) {
                       spanIter.set(null);
                   } else {
  @@ -313,7 +329,7 @@
               
               if (gu.hasSpanning()) {
                   //Add grid units on spanned slots if any
  -                GridUnit[] horzSpan = new GridUnit[cell.getNumberColumnsSpanned()];
  +                horzSpan = new GridUnit[cell.getNumberColumnsSpanned()];
                   horzSpan[0] = gu;
                   for (int j = 1; j < cell.getNumberColumnsSpanned(); j++) {
                       colnum++;
  
  
  
  1.26.2.6  +2 -0      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.5
  retrieving revision 1.26.2.6
  diff -u -r1.26.2.5 -r1.26.2.6
  --- Cell.java	4 May 2005 07:18:12 -0000	1.26.2.5
  +++ Cell.java	4 May 2005 15:10:19 -0000	1.26.2.6
  @@ -460,6 +460,8 @@
                           int bpd = getContentHeight(rowHeight, gu);
                           bpd += gridUnit.getHalfMaxBeforeBorderWidth() 
                                   - (gu.getBorders().getBorderBeforeWidth(false) / 2);
  +                        bpd += gridUnit.getHalfMaxAfterBorderWidth() 
  +                                - (gu.getBorders().getBorderAfterWidth(false) / 2);
                           block.setBPD(bpd);
                           //TODO This needs to be fixed for row spanning
                           lastRowHeight = rowHeight;
  
  
  
  1.1.2.6   +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.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- GridUnit.java	4 May 2005 07:18:12 -0000	1.1.2.5
  +++ GridUnit.java	4 May 2005 15:10:19 -0000	1.1.2.6
  @@ -157,6 +157,13 @@
       }
       
       /**
  +     * @return the index of the grid unit inside a cell in column direction
  +     */
  +    public int getColSpanIndex() {
  +        return this.colSpanIndex;
  +    }
  +
  +    /**
        * Returns a BorderInfo instance for a side of the currently applicable cell before border
        * resolution (i.e. the value from the FO). A return value of null indicates an empty cell.
        * See CollapsingBorderModel(EyeCatching) where this method is used. 
  
  
  
  1.1.2.10  +92 -110   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.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- TableContentLayoutManager.java	4 May 2005 07:18:13 -0000	1.1.2.9
  +++ TableContentLayoutManager.java	4 May 2005 15:10:19 -0000	1.1.2.10
  @@ -220,13 +220,13 @@
               if ((prev == null) && (iter == this.trIter) && (this.headerIter != null)) {
                   prev = this.headerIter.getLastRow();
               }
  -            if ((prev == null) && (iter == this.headerIter)) {
  -                prev = this.trIter.getFirstRow();
  +            if ((next == null) && (iter == this.headerIter)) {
  +                next = this.trIter.getFirstRow();
               }
               if ((next == null) && (iter == this.trIter) && (this.footerIter != null)) {
                   next = this.footerIter.getFirstRow();
               }
  -            if ((next == null) && (iter == this.footerIter)) {
  +            if ((prev == null) && (iter == this.footerIter)) {
                   //TODO This could be bad for memory consumption because it already causes the
                   //whole body iterator to be prefetched!
                   prev = this.trIter.getLastRow();
  @@ -265,17 +265,22 @@
                       } else {
                           other = null;
                       }
  -                    if ((iter == this.trIter)
  -                            && gu.getFlag(GridUnit.FIRST_IN_TABLE)
  -                            && (this.headerIter == null)) {
  -                        flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  -                    }
  -                    if ((iter == this.headerIter)
  -                            && gu.getFlag(GridUnit.FIRST_IN_TABLE)) {
  -                        flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                    if (other == null 
  +                            || other.isEmpty() 
  +                            || gu.isEmpty() 
  +                            || gu.getPrimary() != other.getPrimary()) {
  +                        if ((iter == this.trIter)
  +                                && gu.getFlag(GridUnit.FIRST_IN_TABLE)
  +                                && (this.headerIter == null)) {
  +                            flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                        }
  +                        if ((iter == this.headerIter)
  +                                && gu.getFlag(GridUnit.FIRST_IN_TABLE)) {
  +                            flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                        }
  +                        gu.resolveBorder(other, 
  +                                CommonBorderPaddingBackground.BEFORE, flags);
                       }
  -                    gu.resolveBorder(other, 
  -                            CommonBorderPaddingBackground.BEFORE, flags);
                       
                       flags = 0;
                       if (next != null && i < next.getGridUnits().size()) {
  @@ -283,17 +288,22 @@
                       } else {
                           other = null;
                       }
  -                    if ((iter == this.trIter)
  -                            && gu.getFlag(GridUnit.LAST_IN_TABLE)
  -                            && (this.footerIter == null)) {
  -                        flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  -                    }
  -                    if ((iter == this.footerIter)
  -                            && gu.getFlag(GridUnit.LAST_IN_TABLE)) {
  -                        flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                    if (other == null 
  +                            || other.isEmpty() 
  +                            || gu.isEmpty() 
  +                            || gu.getPrimary() != other.getPrimary()) {
  +                        if ((iter == this.trIter)
  +                                && gu.getFlag(GridUnit.LAST_IN_TABLE)
  +                                && (this.footerIter == null)) {
  +                            flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                        }
  +                        if ((iter == this.footerIter)
  +                                && gu.getFlag(GridUnit.LAST_IN_TABLE)) {
  +                            flags |= CollapsingBorderModel.VERTICAL_START_END_OF_TABLE;
  +                        }
  +                        gu.resolveBorder(other, 
  +                                CommonBorderPaddingBackground.AFTER, flags);
                       }
  -                    gu.resolveBorder(other, 
  -                            CommonBorderPaddingBackground.AFTER, flags);
                   }
   
               }
  @@ -311,6 +321,7 @@
       private void createElementsForRowGroup(LayoutContext context, int alignment, 
               boolean isHeaderFooter, LinkedList returnList, 
               TableRowIterator.EffRow[] rowGroup) {
  +        log.debug("Handling row group with " + rowGroup.length + " rows...");
           MinOptMax[] rowHeights = new MinOptMax[rowGroup.length];
           TableRowIterator.EffRow row;
           List pgus = new java.util.ArrayList(); //holds a list of a row's primary grid units
  @@ -324,42 +335,46 @@
               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);
  -
  -                    //Determine the table-row if any
  -                    if (tableRow == null) {
  -                        tableRow = primary.getRow();
  -                        
  -                        //Check for bpd on row, see CSS21, 17.5.3 Table height algorithms
  -                        LengthRangeProperty bpd = tableRow.getBlockProgressionDimension();
  -                        if (!bpd.getMinimum().isAuto()) {
  -                            minContentHeight = Math.max(minContentHeight, 
  -                                    bpd.getMinimum().getLength().getValue());
  +                if ((gu.isPrimary() || (gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan())) 
  +                        && !gu.isEmpty()) {
  +                    PrimaryGridUnit primary = gu.getPrimary();
  +                    
  +                    if (gu.isPrimary()) {
  +                        primary.getCellLM().setParent(tableLM);
  +                     
  +                        //Determine the table-row if any
  +                        if (tableRow == null) {
  +                            tableRow = primary.getRow();
  +                            
  +                            //Check for bpd on row, see CSS21, 17.5.3 Table height algorithms
  +                            LengthRangeProperty bpd = tableRow.getBlockProgressionDimension();
  +                            if (!bpd.getMinimum().isAuto()) {
  +                                minContentHeight = Math.max(minContentHeight, 
  +                                        bpd.getMinimum().getLength().getValue());
  +                            }
                           }
  +
  +                        //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();
  +                        }
  +                        LayoutContext childLC = new LayoutContext(0);
  +                        childLC.setStackLimit(context.getStackLimit()); //necessary?
  +                        childLC.setRefIPD(spanWidth);
  +                        
  +                        //Get the element list for the cell contents
  +                        LinkedList elems = primary.getCellLM().getNextKnuthElements(childLC, alignment);
  +                        primary.setElements(elems);
  +                        log.debug("Elements: " + elems);
                       }
   
  -                    //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);
  -                    
  -                    //Get the element list for the cell contents
  -                    LinkedList elems = primary.getCellLM().getNextKnuthElements(childLC, alignment);
  -                    primary.setElements(elems);
  -                    log.debug("Elements: " + elems);
                       
                       //Calculate height of cell contents
  -                    primary.setContentLength(calcCellHeightFromContents(elems));
  +                    primary.setContentLength(calcCellHeightFromContents(primary.getElements()));
                       maxCellHeight = Math.max(maxCellHeight, primary.getContentLength());
   
                       //Calculate height of row, see CSS21, 17.5.3 Table height algorithms
  @@ -379,6 +394,9 @@
                           padding += cbpb.getPaddingBefore(false);
                           padding += cbpb.getPaddingAfter(false);
                           int effRowHeight = effCellContentHeight + padding + halfMaxBorderWidths;
  +                        for (int previous = 0; previous < gu.getRowSpanIndex(); previous++) {
  +                            effRowHeight -= rowHeights[rgi - previous - 1].opt;
  +                        }
                           if (effRowHeight > rowHeights[rgi].min) {
                               //This is the new height of the (grid) row
                               MinOptMaxUtil.extendMinimum(rowHeights[rgi], effRowHeight, false);
  @@ -386,71 +404,31 @@
                           }
                       }
                       
  -                    pgus.add(primary);
  +                    if (gu.isPrimary()) {
  +                        pgus.add(primary);
  +                    }
                   }
               }
               
  -            log.debug(row);
  +            log.debug("row: " + row);
               
               PrimaryGridUnit[] pguArray = new PrimaryGridUnit[pgus.size()];
               pguArray = (PrimaryGridUnit[])pgus.toArray(pguArray);
  +            
               LinkedList returnedList = getCombinedKnuthElementsForRow(pguArray, row, 
                       isHeaderFooter);
               if (returnedList != null) {
                   returnList.addAll(returnedList);
               }
  -
  -            /* not necessary anymore
  -            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);
  -            }*/
  -            
  -            //Calculate row height in row groups with spans
  -            /*
  -            if (tableRow != null) {
  -                LengthRangeProperty bpd = tableRow.getBlockProgressionDimension();
  -                if (bpd.getOptimum().isAuto()) {
  -                    rowHeights[rgi] = new MinOptMax(0, 0, Integer.MAX_VALUE);
  -                } else {
  -                    rowHeights[rgi] = MinOptMaxUtil.toMinOptMax(bpd);
  -                }
  -            } else {
  -                rowHeights[rgi] = new MinOptMax(0, 0, Integer.MAX_VALUE);
  -            }*/
  -            /*
  -            for (int j = 0; j < row.getGridUnits().size(); j++) {
  -                GridUnit gu = (GridUnit)row.getGridUnits().get(j);
  -                if (gu.isLastGridUnitRowSpan() && !gu.isEmpty()) {
  -                    log.debug(rgi + " - " + gu);
  -                    MinOptMax effCellHeight; 
  -                    LengthRangeProperty bpd = gu.getCell().getBlockProgressionDimension();
  -                    if (bpd.getOptimum().isAuto()) {
  -                        effCellHeight = new MinOptMax(0, 0, Integer.MAX_VALUE);
  -                    } else {
  -                        effCellHeight = MinOptMaxUtil.toMinOptMax(bpd);
  -                    }
  -                    int contentLen = gu.getPrimary().getContentLength();
  -                    if (getTableLM().getTable().isSeparateBorderModel()) {
  -                        //contentLen += before and after borders of that cell plus half the BPD border-separation 
  -                    } else {
  -                        //contentLen += half of before and after borders for that cell
  -                    }
  -                    for (int previous = 0; previous < gu.getRowSpanIndex(); previous++) {
  -                        contentLen -= rowHeights[rgi - previous - 1].opt;
  -                    }
  -                    log.debug("->" + contentLen);
  -                    if (contentLen > effCellHeight.min) {
  -                        MinOptMaxUtil.extendMinimum(effCellHeight, contentLen, true);
  -                    }
  -                    if (effCellHeight.min > rowHeights[rgi].min) {
  -                        MinOptMaxUtil.extendMinimum(rowHeights[rgi], effCellHeight.min, false);
  -                    }
  -                }
  -            }*/
  +        }
  +        if (log.isDebugEnabled()) {
  +            log.debug("rowGroup:");
  +            int totalHeight = 0;
  +            for (int i = 0; i < rowHeights.length; i++) {
  +                totalHeight += rowHeights[i].opt;
  +                log.debug("  " + rowHeights[i]);
  +            }
  +            log.debug("  totalHeigth=" + totalHeight);
           }
       }
   
  @@ -488,10 +466,14 @@
                   widths, fullWidths)) > 0) {
               int increase = step - laststep;
               int penaltyLen = step + getMaxRemainingHeight(fullWidths, widths) - totalHeight;
  +            int effPenaltyLen = penaltyLen;
               int boxLen = step - addedBoxLen - penaltyLen;
               addedBoxLen += boxLen;
               
  -            log.debug(step + " " + increase + " box=" + boxLen + " penalty=" + penaltyLen);
  +            log.debug("step=" + step + " (+" + increase + ")"
  +                    + " box=" + boxLen 
  +                    + " penalty=" + penaltyLen
  +                    + " effPenalty=" + effPenaltyLen);
               
               //Put all involved grid units into a list
               List gridUnitParts = new java.util.ArrayList(pguArray.length);
  
  
  
  1.1.2.4   +12 -5     xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/PrimaryGridUnit.java
  
  Index: PrimaryGridUnit.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/Attic/PrimaryGridUnit.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- PrimaryGridUnit.java	4 May 2005 07:18:13 -0000	1.1.2.3
  +++ PrimaryGridUnit.java	4 May 2005 15:10:19 -0000	1.1.2.4
  @@ -90,11 +90,10 @@
       }
       
       /** 
  -     * @return Returns the sum of half the maximum before and after border 
  -     * widths of this cell.
  +     * @return Returns the half the maximum after border width of this cell.
        */
  -    public int getHalfMaxBorderWidth() {
  -        int value = getHalfMaxBeforeBorderWidth();
  +    public int getHalfMaxAfterBorderWidth() {
  +        int value = 0;
           if (getRows() != null) {
               //Last row for after borders
               int after = 0;
  @@ -113,6 +112,14 @@
           return value;
       }
       
  +    /** 
  +     * @return Returns the sum of half the maximum before and after border 
  +     * widths of this cell.
  +     */
  +    public int getHalfMaxBorderWidth() {
  +        return getHalfMaxBeforeBorderWidth() + getHalfMaxAfterBorderWidth();
  +    }
  +    
       /** @param value The length of the cell content to remember. */
       public void setContentLength(int value) {
           this.contentLength = value;
  
  
  

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