From b421ed51fafe11acef8a939c7fda33c3ed119194 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Thu, 14 Dec 2000 06:38:31 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193872 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/flow/TableBody.java | 335 +++++++++++----------- src/org/apache/fop/fo/flow/TableCell.java | 20 +- src/org/apache/fop/fo/flow/TableRow.java | 16 +- 3 files changed, 198 insertions(+), 173 deletions(-) diff --git a/src/org/apache/fop/fo/flow/TableBody.java b/src/org/apache/fop/fo/flow/TableBody.java index befcb02ef..0d3e1bd9e 100644 --- a/src/org/apache/fop/fo/flow/TableBody.java +++ b/src/org/apache/fop/fo/flow/TableBody.java @@ -1,36 +1,36 @@ -/*-- $Id$ -- +/*-- $Id$ -- ============================================================================ 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 . For more information on the Apache + James Tauber . For more information on the Apache Software Foundation, please see . - + */ package org.apache.fop.fo.flow; @@ -63,16 +63,16 @@ import java.util.Vector; 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 @@ public class TableBody extends FObj { 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.marker = 0; + } - 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(); + 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 (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(); + } } - if(!((i == 0) && (areaContainer.getContentHeight() <= 0))) { - area.addChild(areaContainer); - //areaContainer.end(); + lastRow = row; + } + 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(); - } - } - 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(); } diff --git a/src/org/apache/fop/fo/flow/TableCell.java b/src/org/apache/fop/fo/flow/TableCell.java index d6de38989..56af8d181 100644 --- a/src/org/apache/fop/fo/flow/TableCell.java +++ b/src/org/apache/fop/fo/flow/TableCell.java @@ -98,7 +98,11 @@ public class TableCell extends FObj { 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 @@ public class TableCell extends FObj { 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 @@ public class TableCell extends FObj { 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 @@ public class TableCell extends FObj { 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; + } } } diff --git a/src/org/apache/fop/fo/flow/TableRow.java b/src/org/apache/fop/fo/flow/TableRow.java index d7bdcf028..2db9989ef 100644 --- a/src/org/apache/fop/fo/flow/TableRow.java +++ b/src/org/apache/fop/fo/flow/TableRow.java @@ -111,8 +111,7 @@ public class TableRow extends FObj { // added by Dresdner Bank, Germany DisplaySpace spacer = null; - - + DisplaySpace spacerAfter = null; /** * The list of cell states for this row. This is the location of @@ -482,6 +481,8 @@ public class TableRow extends FObj { // 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 @@ public class TableRow extends FObj { cellState.setLayoutComplete(true); } - - int h = cell.getHeight(); if (h > largestCellHeight) { largestCellHeight = h; @@ -511,7 +510,7 @@ public class TableRow extends FObj { 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 @@ public class TableRow extends FObj { //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 class TableRow extends FObj { 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 -- 2.39.5