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 ke...@locus.apache.org on 2000/12/14 07:38:32 UTC

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

keiron      00/12/13 22:38:32

  Modified:    src/org/apache/fop/fo/flow TableBody.java TableCell.java
                        TableRow.java
  Log:
  Fixed a problem where space after's where not being removed if table
  row was being removed.
  Fixed problem with keep-with not storing the correct rows
  
  Added vertical alignment for table cell contents
  
  Code changes sponsored by Dresdner Bank, Germany
  
  Revision  Changes    Path
  1.17      +172 -165  xml-fop/src/org/apache/fop/fo/flow/TableBody.java
  
  Index: TableBody.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/TableBody.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TableBody.java	2000/12/13 03:53:22	1.16
  +++ TableBody.java	2000/12/14 06:38:31	1.17
  @@ -1,36 +1,36 @@
  -/*-- $Id: TableBody.java,v 1.16 2000/12/13 03:53:22 keiron Exp $ -- 
  +/*-- $Id: TableBody.java,v 1.17 2000/12/14 06:38:31 keiron Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
       Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "FOP" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -41,12 +41,12 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - James Tauber <jt...@jtauber.com>. For more  information on the Apache 
  + James Tauber <jt...@jtauber.com>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
  - 
  +
    */
   
   package org.apache.fop.fo.flow;
  @@ -63,16 +63,16 @@
   import java.util.Enumeration;
   
   public class TableBody extends FObj {
  -	
  +
       public static class Maker extends FObj.Maker {
  -	public FObj make(FObj parent, PropertyList propertyList)
  -	    throws FOPException {
  -	    return new TableBody(parent, propertyList);
  -	}
  +        public FObj make(FObj parent,
  +                         PropertyList propertyList) throws FOPException {
  +            return new TableBody(parent, propertyList);
  +        }
       }
   
       public static FObj.Maker maker() {
  -	return new TableBody.Maker();
  +        return new TableBody.Maker();
       }
   
       FontState fs;
  @@ -82,197 +82,204 @@
       ColorType borderColor;
       int borderWidth;
       int borderStyle;
  -    String id;            
  +    String id;
   
       Vector columns;
   
       AreaContainer areaContainer;
   
       public TableBody(FObj parent, PropertyList propertyList) {
  -	super(parent, propertyList);
  -	this.name = "fo:table-body";
  +        super(parent, propertyList);
  +        this.name = "fo:table-body";
       }
   
       public void setColumns(Vector columns) {
  -	this.columns = columns;
  +        this.columns = columns;
       }
   
  -    public void setYPosition(int value)
  -    {
  +    public void setYPosition(int value) {
           areaContainer.setYPosition(value);
       }
   
  -    public int getYPosition()
  -    {
  +    public int getYPosition() {
           return areaContainer.getCurrentYPosition();
       }
   
  -    public int getHeight()
  -    {
  +    public int getHeight() {
           return areaContainer.getHeight() + spaceBefore + spaceAfter;
       }
   
       public Status layout(Area area) throws FOPException {
  -	if (this.marker == BREAK_AFTER) {
  -	    return new Status(Status.OK);
  -	}
  -
  -	if (this.marker == START) {
  -	    String fontFamily =
  -		this.properties.get("font-family").getString(); 
  -	    String fontStyle =
  -		this.properties.get("font-style").getString(); 
  -	    String fontWeight =
  -		this.properties.get("font-weight").getString(); 
  -	    int fontSize =
  -		this.properties.get("font-size").getLength().mvalue(); 
  -	    
  -	    this.fs = new FontState(area.getFontInfo(), fontFamily, 
  -				    fontStyle, fontWeight, fontSize);  
  -	    this.spaceBefore =
  -		this.properties.get("space-before.optimum").getLength().mvalue();  
  -	    this.spaceAfter =
  -		this.properties.get("space-after.optimum").getLength().mvalue(); 
  -	    this.backgroundColor =
  -		this.properties.get("background-color").getColorType();
  -	    this.borderColor =
  -		this.properties.get("border-color").getColorType();
  -	    this.borderWidth =
  -		this.properties.get("border-width").getLength().mvalue();
  -	    this.borderStyle =
  -		this.properties.get("border-style").getEnum();
  -            this.id = 
  -                this.properties.get("id").getString();            
  -
  -	    area.getIDReferences().createID(id);
  -            
  -	    if (area instanceof BlockArea) {
  -		area.end();
  -	    }
  -
  -	    //if (this.isInListBody) {
  -	    //startIndent += bodyIndent + distanceBetweenStarts;
  -	    //}
  -
  -	    this.marker = 0;
  -
  -	}
  -
  -	if ((spaceBefore != 0) && (this.marker ==0)) {
  -	    area.addDisplaySpace(spaceBefore);
  -	}
  -
  -        if ( marker==0 ) {
  -            // configure id                                   
  -            area.getIDReferences().configureID(id,area);                        
  +        if (this.marker == BREAK_AFTER) {
  +            return new Status(Status.OK);
           }
  +
  +        if (this.marker == START) {
  +            String fontFamily =
  +              this.properties.get("font-family").getString();
  +            String fontStyle =
  +              this.properties.get("font-style").getString();
  +            String fontWeight =
  +              this.properties.get("font-weight").getString();
  +            int fontSize =
  +              this.properties.get("font-size").getLength().mvalue();
  +
  +            this.fs = new FontState(area.getFontInfo(), fontFamily,
  +                                    fontStyle, fontWeight, fontSize);
  +            this.spaceBefore = this.properties.get(
  +                                 "space-before.optimum").getLength().mvalue();
  +            this.spaceAfter = this.properties.get(
  +                                "space-after.optimum").getLength().mvalue();
  +            this.backgroundColor = this.properties.get(
  +                                     "background-color").getColorType();
  +            this.borderColor =
  +              this.properties.get("border-color").getColorType();
  +            this.borderWidth = this.properties.get(
  +                                 "border-width").getLength().mvalue();
  +            this.borderStyle =
  +              this.properties.get("border-style").getEnum();
  +            this.id = this.properties.get("id").getString();
  +
  +            area.getIDReferences().createID(id);
  +
  +            if (area instanceof BlockArea) {
  +                area.end();
  +            }
  +
  +            //if (this.isInListBody) {
  +            //startIndent += bodyIndent + distanceBetweenStarts;
  +            //}
   
  -	this.areaContainer =
  -	    new AreaContainer(fs, -area.borderWidthLeft, -area.borderWidthTop + area.getHeight(), area.getAllocationWidth(), 
  -			  area.spaceLeft(), Position.RELATIVE);
  -	areaContainer.setPage(area.getPage());
  -	areaContainer.setBackgroundColor(backgroundColor);
  -        areaContainer.setBorderStyle(borderStyle, borderStyle, borderStyle, borderStyle); 
  -        areaContainer.setBorderWidth(borderWidth, borderWidth, borderWidth, borderWidth); 
  -        areaContainer.setBorderColor(borderColor, borderColor, borderColor, borderColor); 
  -	areaContainer.start();
  +            this.marker = 0;
   
  +        }
  +
  +        if ((spaceBefore != 0) && (this.marker == 0)) {
  +            area.addDisplaySpace(spaceBefore);
  +        }
  +
  +        if (marker == 0) {
  +            // configure id
  +            area.getIDReferences().configureID(id, area);
  +        }
  +
  +        this.areaContainer = new AreaContainer(fs, -area.borderWidthLeft,
  +                                               -area.borderWidthTop + area.getHeight(),
  +                                               area.getAllocationWidth(), area.spaceLeft(),
  +                                               Position.RELATIVE);
  +        areaContainer.setPage(area.getPage());
  +        areaContainer.setBackgroundColor(backgroundColor);
  +        areaContainer.setBorderStyle(borderStyle, borderStyle,
  +                                     borderStyle, borderStyle);
  +        areaContainer.setBorderWidth(borderWidth, borderWidth,
  +                                     borderWidth, borderWidth);
  +        areaContainer.setBorderColor(borderColor, borderColor,
  +                                     borderColor, borderColor);
  +        areaContainer.start();
  +
           areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
           areaContainer.setIDReferences(area.getIDReferences());
   
  -	Vector keepWith = new Vector();
  -	int numChildren = this.children.size();
  -	TableRow lastRow = null;
  -	for (int i = this.marker; i < numChildren; i++) {
  -	    TableRow row = (TableRow) children.elementAt(i);
  -
  -	    row.setColumns(columns);
  -	    row.doSetup(areaContainer);
  -	    if(row.getKeepWithPrevious() != 0 && lastRow != null) {
  -	        keepWith.addElement(lastRow);
  -	    }
  -
  -	    Status status;
  -	    if ((status = row.layout(areaContainer)).isIncomplete()) {
  -	            if(keepWith.size() > 0) { // && status.getCode() == Status.AREA_FULL_NONE
  -	                for(Enumeration e = keepWith.elements(); e.hasMoreElements(); ) {
  -	                    TableRow tr = (TableRow)e.nextElement();
  -	                    tr.removeLayout(areaContainer);
  -	                    i--;
  -	                }
  -	            }
  -		this.marker = i;
  -		if ((i != 0) && (status.getCode() == Status.AREA_FULL_NONE)) {
  -		    status = new Status(Status.AREA_FULL_SOME);
  -		}
  -            if(i < widows && numChildren >= widows) {
  -                resetMarker();
  -                return new Status(Status.AREA_FULL_NONE);
  -            }
  -            if(numChildren <= orphans) {
  -                resetMarker();
  -                return new Status(Status.AREA_FULL_NONE);
  +        Vector keepWith = new Vector();
  +        int numChildren = this.children.size();
  +        TableRow lastRow = null;
  +        for (int i = this.marker; i < numChildren; i++) {
  +            TableRow row = (TableRow) children.elementAt(i);
  +
  +            row.setColumns(columns);
  +            row.doSetup(areaContainer);
  +            if (row.getKeepWithPrevious() != 0 && lastRow != null &&
  +                    keepWith.indexOf(lastRow) != -1) {
  +                keepWith.addElement(lastRow);
               }
  -            if(numChildren - i < orphans && numChildren > orphans) {
  -                for(int count = numChildren - orphans - i; count > 0; count--) {
  -	                row = (TableRow) children.elementAt(count);
  +
  +            Status status;
  +            if ((status = row.layout(areaContainer)).isIncomplete()) {
  +                if (keepWith.size() > 0) { // && status.getCode() == Status.AREA_FULL_NONE
                       row.removeLayout(areaContainer);
  -                    i--;
  +                    for (Enumeration e = keepWith.elements();
  +                            e.hasMoreElements();) {
  +                        TableRow tr = (TableRow) e.nextElement();
  +                        tr.removeLayout(areaContainer);
  +                        i--;
  +                    }
  +                }
  +                this.marker = i;
  +                if ((i != 0) &&
  +                        (status.getCode() == Status.AREA_FULL_NONE)) {
  +                    status = new Status(Status.AREA_FULL_SOME);
                   }
  -                if(i < widows && numChildren >= widows) {
  +                if (i < widows && numChildren >= widows) {
                       resetMarker();
                       return new Status(Status.AREA_FULL_NONE);
                   }
  -        		this.marker = i;
  -    	        area.addChild(areaContainer);
  -		//areaContainer.end();
  -
  -		        area.increaseHeight(areaContainer.getHeight());
  -                area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  -                return new Status(Status.AREA_FULL_SOME);
  -            }
  -		if(!((i == 0) && (areaContainer.getContentHeight() <= 0))) {
  -    	        area.addChild(areaContainer);
  -		//areaContainer.end();
  -
  -		        area.increaseHeight(areaContainer.getHeight());
  -                area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  +                if (numChildren <= orphans) {
  +                    resetMarker();
  +                    return new Status(Status.AREA_FULL_NONE);
  +                }
  +                if (numChildren - i < orphans && numChildren > orphans) {
  +                    for (int count = numChildren - orphans - i;
  +                            count > 0; count--) {
  +                        row = (TableRow) children.elementAt(count);
  +                        row.removeLayout(areaContainer);
  +                        i--;
  +                    }
  +                    if (i < widows && numChildren >= widows) {
  +                        resetMarker();
  +                        return new Status(Status.AREA_FULL_NONE);
  +                    }
  +                    this.marker = i;
  +                    area.addChild(areaContainer);
  +                    //areaContainer.end();
  +
  +                    area.increaseHeight(areaContainer.getHeight());
  +                    area.setAbsoluteHeight(
  +                      areaContainer.getAbsoluteHeight());
  +                    return new Status(Status.AREA_FULL_SOME);
  +                }
  +                if (!((i == 0) &&
  +                        (areaContainer.getContentHeight() <= 0))) {
  +                    area.addChild(areaContainer);
  +                    //areaContainer.end();
  +
  +                    area.increaseHeight(areaContainer.getHeight());
  +                    area.setAbsoluteHeight(
  +                      areaContainer.getAbsoluteHeight());
  +                }
  +                return status;
  +            } else if (status.getCode() == Status.KEEP_WITH_NEXT) {
  +                keepWith.addElement(row);
  +            } else {
  +                if (keepWith.size() > 0 && row.getKeepWithPrevious() == 0) {
  +                    keepWith = new Vector();
  +                }
               }
  -		return status;
  -        } else if(status.getCode() == Status.KEEP_WITH_NEXT) {
  -            keepWith.addElement(row);
  -	    } else {
  -            if(keepWith.size() > 0 && row.getKeepWithPrevious() != 0) {
  -	            keepWith = new Vector();
  -	        }
  -	    }
  -	    lastRow = row;
  -	}
  -	area.addChild(areaContainer);
  -	areaContainer.end();
  +            lastRow = row;
  +        }
  +        area.addChild(areaContainer);
  +        areaContainer.end();
   
  -	/* should this be combined into above? */
  -	area.increaseHeight(areaContainer.getHeight());
  +        /* should this be combined into above? */
  +        area.increaseHeight(areaContainer.getHeight());
   
           area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  +
  +        if (spaceAfter != 0) {
  +            area.addDisplaySpace(spaceAfter);
  +        }
   
  -	if (spaceAfter != 0) {
  -	    area.addDisplaySpace(spaceAfter);
  -	}
  -
  -	if (area instanceof BlockArea) {
  -	    area.start();
  -	}
  +        if (area instanceof BlockArea) {
  +            area.start();
  +        }
   
  -	return new Status(Status.OK);
  +        return new Status(Status.OK);
       }
   
       public int getAreaHeight() {
  -	return areaContainer.getHeight();
  +        return areaContainer.getHeight();
       }
   
  -    public void removeLayout(Area area)
  -    {
  +    public void removeLayout(Area area) {
           area.removeChild(areaContainer);
           this.resetMarker();
       }
  
  
  
  1.20      +19 -3     xml-fop/src/org/apache/fop/fo/flow/TableCell.java
  
  Index: TableCell.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/TableCell.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TableCell.java	2000/12/12 03:12:51	1.19
  +++ TableCell.java	2000/12/14 06:38:31	1.20
  @@ -1,4 +1,4 @@
  -/*-- $Id: TableCell.java,v 1.19 2000/12/12 03:12:51 keiron Exp $ -- 
  +/*-- $Id: TableCell.java,v 1.20 2000/12/14 06:38:31 keiron Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -98,7 +98,11 @@
       
       protected int startOffset;
       protected int width;
  +
       protected int height = 0;
  +    protected int top;
  +    protected int verticalAlign = 0;
  +
       boolean setup = false;
   
       AreaContainer areaContainer;
  @@ -270,6 +274,7 @@
   	    FObj fo = (FObj) children.elementAt(i);
   	    fo.setIsInTableCell();
   	    fo.forceWidth(width);
  +	    verticalAlign = fo.properties.get("vertical-align").getEnum();
   	    Status status;
   	    if ((status = fo.layout(areaContainer)).isIncomplete()) {
   		this.marker = i;
  @@ -288,6 +293,8 @@
   	areaContainer.end();
   	area.addChild(areaContainer);
   
  + 	height = getHeight();
  + 	top = areaContainer.getCurrentYPosition();
    	area.setHeight(getHeight());
    	// reset absoluteHeight to beginning of row
    	area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  @@ -299,8 +306,17 @@
   	return areaContainer.getHeight();
       }
       
  -    public void setHeight(int height) {
  +    public void setRowHeight(int h) {
   	areaContainer.setMaxHeight(height);
  -	areaContainer.setHeight(height);
  +	    switch(verticalAlign) {
  +	        case VerticalAlign.MIDDLE:
  +	            areaContainer.setHeight(height);
  +	            areaContainer.setYPosition(top + h / 2 - height / 2);
  +	    	break;
  +    		case VerticalAlign.BASELINE:
  +		    default:
  +	            areaContainer.setHeight(h);
  +	    	break;
  +	    }
       }
   }
  
  
  
  1.27      +10 -8     xml-fop/src/org/apache/fop/fo/flow/TableRow.java
  
  Index: TableRow.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/TableRow.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TableRow.java	2000/12/13 03:37:52	1.26
  +++ TableRow.java	2000/12/14 06:38:31	1.27
  @@ -1,4 +1,4 @@
  -/*-- $Id: TableRow.java,v 1.26 2000/12/13 03:37:52 keiron Exp $ --
  +/*-- $Id: TableRow.java,v 1.27 2000/12/14 06:38:31 keiron Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -111,9 +111,8 @@
   
       // added by Dresdner Bank, Germany
       DisplaySpace spacer = null;
  +    DisplaySpace spacerAfter = null;
   
  -
  -
       /**
        * The list of cell states for this row. This is the location of
        * where I will be storing the state of each cell so that I can
  @@ -482,6 +481,8 @@
                       // added on 11/28/2000, by Dresdner Bank, Germany
                       if (spacer != null)
                           area.removeChild(spacer);
  +                    if(spacerAfter != null)
  +                        area.removeChild(spacerAfter);
   
                       // removing something that was added by succession
                       // of cell.layout()
  @@ -501,8 +502,6 @@
                   cellState.setLayoutComplete(true);
               }
   
  -
  -
               int h = cell.getHeight();
               if (h > largestCellHeight) {
                   largestCellHeight = h;
  @@ -511,7 +510,7 @@
   
           for (int i = 0; i < numChildren; i++) {
               TableCell cell = (TableCell) children.elementAt(i);
  -            cell.setHeight(largestCellHeight);
  +            cell.setRowHeight(largestCellHeight);
           }
   
           // added by Dresdner Bank, Germany
  @@ -532,7 +531,9 @@
           //area.increaseHeight(largestCellHeight);
   
           if (spaceAfter != 0) {
  -            area.addDisplaySpace(spaceAfter);
  +            spacerAfter = new DisplaySpace(spaceAfter);
  +            area.increaseHeight(spaceAfter);
  +            area.addChild(spacerAfter);
           }
   
           if (area instanceof BlockArea) {
  @@ -572,7 +573,8 @@
       public void removeLayout(Area area) {
           if (spacer != null)
               area.removeChild(spacer);
  -
  +        if(spacerAfter != null)
  +            area.removeChild(spacerAfter);
           // removing something that was added by succession
           // of cell.layout()
           // just to keep my sanity here, Hani