From 81678377851511edbf4e94170298cac6a19ff129 Mon Sep 17 00:00:00 2001 From: Joerg Pietschmann Date: Sun, 20 Jul 2003 20:49:28 +0000 Subject: [PATCH] Added fix (hackery) to release pointers to areas held by table elements, thereby allowing (hopefully) rendering of large tables. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@196733 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/flow/AbstractTableBody.java | 19 ++++++----- src/org/apache/fop/fo/flow/Table.java | 33 ++++++++++++------- src/org/apache/fop/fo/flow/TableCell.java | 21 +++++++----- src/org/apache/fop/fo/flow/TableFooter.java | 5 +-- src/org/apache/fop/fo/flow/TableRow.java | 13 +++++--- 5 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/org/apache/fop/fo/flow/AbstractTableBody.java b/src/org/apache/fop/fo/flow/AbstractTableBody.java index 581234ce0..661040bc9 100644 --- a/src/org/apache/fop/fo/flow/AbstractTableBody.java +++ b/src/org/apache/fop/fo/flow/AbstractTableBody.java @@ -69,7 +69,8 @@ public abstract class AbstractTableBody extends FObj { ArrayList columns; RowSpanMgr rowSpanMgr; // manage information about spanning rows - AreaContainer areaContainer; + // public AreaContainer areaContainer; + public java.lang.ref.WeakReference areaContainerRef; public AbstractTableBody(FObj parent, PropertyList propertyList, String systemId, int line, int column) @@ -87,15 +88,15 @@ public abstract class AbstractTableBody extends FObj { } public void setYPosition(int value) { - areaContainer.setYPosition(value); + ((AreaContainer)areaContainerRef.get()).setYPosition(value); } public int getYPosition() { - return areaContainer.getCurrentYPosition(); + return ((AreaContainer)areaContainerRef.get()).getCurrentYPosition(); } public int getHeight() { - return areaContainer.getHeight() + spaceBefore + spaceAfter; + return ((AreaContainer)areaContainerRef.get()).getHeight() + spaceBefore + spaceAfter; } public int layout(Area area) throws FOPException { @@ -170,7 +171,7 @@ public abstract class AbstractTableBody extends FObj { * of the containing table area, and its relative position is 0,0. * Strictly speaking (CR), this FO should generate no areas! */ - this.areaContainer = + AreaContainer areaContainer = new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0, area.getContentHeight(), area.getContentWidth(), // IPD @@ -185,6 +186,8 @@ public abstract class AbstractTableBody extends FObj { areaContainer.setAbsoluteHeight(area.getAbsoluteHeight()); areaContainer.setIDReferences(area.getIDReferences()); + this.areaContainerRef = new java.lang.ref.WeakReference(areaContainer); + ArrayList keepWith = new ArrayList(); int numChildren = this.children.size(); TableRow lastRow = null; @@ -292,7 +295,7 @@ public abstract class AbstractTableBody extends FObj { } lastRow = row; area.setMaxHeight(area.getMaxHeight() - spaceLeft - + this.areaContainer.getMaxHeight()); + + areaContainer.getMaxHeight()); spaceLeft = area.spaceLeft(); } area.addChild(areaContainer); @@ -313,8 +316,8 @@ public abstract class AbstractTableBody extends FObj { } public void removeLayout(Area area) { - if (areaContainer != null) { - area.removeChild(areaContainer); + if (areaContainerRef != null) { + area.removeChild((AreaContainer)areaContainerRef.get()); } if (spaceBefore != 0) { area.increaseHeight(-spaceBefore); diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index 56a2015fd..321bc1e49 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -99,7 +99,8 @@ public class Table extends FObj { /** Maximum inline-progression-dimension */ private int maxIPD; - AreaContainer areaContainer; + // public AreaContainer areaContainer; + public java.lang.ref.WeakReference areaContainerRef; public Table(FObj parent, PropertyList propertyList, String systemId, int line, int column) { @@ -179,7 +180,7 @@ public class Table extends FObj { area.end(); } // check if anything was previously laid out - if (this.areaContainer == null) { + if (this.areaContainerRef == null) { try { area.getIDReferences().createID(id); } @@ -212,13 +213,14 @@ public class Table extends FObj { area.addDisplaySpace(spaceBefore); } - if (marker == 0 && areaContainer == null) { + if (marker == 0 && this.areaContainerRef == null) { // configure id area.getIDReferences().configureID(id, area); } int spaceLeft = area.spaceLeft(); - this.areaContainer = + // Hack alert! + AreaContainer areaContainer = new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0, 0, area.getAllocationWidth(), area.spaceLeft(), Position.STATIC); @@ -232,6 +234,7 @@ public class Table extends FObj { areaContainer.setAbsoluteHeight(area.getAbsoluteHeight()); areaContainer.setIDReferences(area.getIDReferences()); + this.areaContainerRef = new java.lang.ref.WeakReference(areaContainer); boolean addedHeader = false; boolean addedFooter = false; @@ -286,7 +289,7 @@ public class Table extends FObj { addedHeader = true; tableHeader.resetMarker(); area.setMaxHeight(area.getMaxHeight() - spaceLeft - + this.areaContainer.getMaxHeight()); + + areaContainer.getMaxHeight()); } if (tableFooter != null &&!this.omitFooterAtBreak &&!addedFooter) { @@ -324,7 +327,7 @@ public class Table extends FObj { tableFooter.setYPosition(tableFooter.getYPosition() + ((TableBody)fo).getHeight()); } - setupColumnHeights(); + setupColumnHeights(areaContainer); status = Status.AREA_FULL_SOME; this.areasGenerated++; } @@ -333,7 +336,7 @@ public class Table extends FObj { bodyCount++; } area.setMaxHeight(area.getMaxHeight() - spaceLeft - + this.areaContainer.getMaxHeight()); + + areaContainer.getMaxHeight()); if (tableFooter != null &&!this.omitFooterAtBreak) { // move footer to bottom of area and move up body // space before and after footer will make this wrong @@ -367,7 +370,7 @@ public class Table extends FObj { if (height != 0) areaContainer.setHeight(height); - setupColumnHeights(); + setupColumnHeights(areaContainer); areaContainer.end(); area.addChild(areaContainer); @@ -401,7 +404,12 @@ public class Table extends FObj { return Status.OK; } - protected void setupColumnHeights() { + public void resetMarker() { + this.areasGenerated=0; + super.resetMarker(); + } + + protected void setupColumnHeights(AreaContainer areaContainer) { for (int i = 0; i < columns.size(); i++) { TableColumn c = (TableColumn)columns.get(i); if ( c != null) { @@ -561,15 +569,16 @@ public class Table extends FObj { public int getAreaHeight() { - return areaContainer.getHeight(); + return ((AreaContainer)areaContainerRef.get()).getHeight(); } /** * Return the content width of the boxes generated by this table FO. */ public int getContentWidth() { - if (areaContainer != null) - return areaContainer.getContentWidth(); // getAllocationWidth()?? + if (areaContainerRef != null) + // getAllocationWidth()?? + return ((AreaContainer)areaContainerRef.get()).getContentWidth(); else return 0; // not laid out yet } diff --git a/src/org/apache/fop/fo/flow/TableCell.java b/src/org/apache/fop/fo/flow/TableCell.java index 853931da4..eeabf6dbe 100644 --- a/src/org/apache/fop/fo/flow/TableCell.java +++ b/src/org/apache/fop/fo/flow/TableCell.java @@ -136,7 +136,8 @@ public class TableCell extends FObj { */ int m_borderSeparation = 0; - AreaContainer cellArea; + // public AreaContainer cellArea; + public java.lang.ref.WeakReference areaContainerRef; public TableCell(FObj parent, PropertyList propertyList, String systemId, int line, int column) @@ -288,7 +289,7 @@ public class TableCell extends FObj { int spaceLeft = area.spaceLeft() - m_borderSeparation; // The Area position defines the content rectangle! Borders // and padding are outside of this rectangle. - this.cellArea = + AreaContainer cellArea = new AreaContainer(propMgr.getFontState(area.getFontInfo()), startOffset + startAdjust, beforeOffset, width - widthAdjust, spaceLeft, @@ -311,6 +312,8 @@ public class TableCell extends FObj { cellArea.setIDReferences(area.getIDReferences()); // Add adjust for padding and border to fix link alignment! cellArea.setTableCellXOffset(startOffset + startAdjust); + + this.areaContainerRef = new java.lang.ref.WeakReference(cellArea); int numChildren = this.children.size(); for (int i = this.marker; bDone==false && i < numChildren; i++) { @@ -336,7 +339,7 @@ public class TableCell extends FObj { } area.setMaxHeight(area.getMaxHeight() - spaceLeft - + this.cellArea.getMaxHeight()); + + cellArea.getMaxHeight()); } this.bDone=true; cellArea.end(); @@ -371,7 +374,7 @@ public class TableCell extends FObj { * overestimate the allocation height). */ public int getHeight() { - return cellArea.getHeight() + m_borderSeparation - borderHeight; + return ((AreaContainer)areaContainerRef.get()).getHeight() + m_borderSeparation - borderHeight; } /** @@ -388,14 +391,14 @@ public class TableCell extends FObj { // Must get info for all cells starting in row! // verticalAlign can be BEFORE or BASELINE // For now just treat like "before" - cellArea.increaseHeight(delta); + ((AreaContainer)areaContainerRef.get()).increaseHeight(delta); } else if (delta > 0) { - BorderAndPadding cellBP = cellArea.getBorderAndPadding(); + BorderAndPadding cellBP = ((AreaContainer)areaContainerRef.get()).getBorderAndPadding(); switch (verticalAlign) { case DisplayAlign.CENTER: // Increase cell padding before and after and change // "Y" position of content rectangle - cellArea.shiftYPosition(delta / 2); + ((AreaContainer)areaContainerRef.get()).shiftYPosition(delta / 2); cellBP.setPaddingLength(BorderAndPadding.TOP, cellBP.getPaddingTop(false) + delta / 2); @@ -408,7 +411,7 @@ public class TableCell extends FObj { // "Y" position of content rectangle cellBP.setPaddingLength(BorderAndPadding.TOP, cellBP.getPaddingTop(false) + delta); - cellArea.shiftYPosition(delta); + ((AreaContainer)areaContainerRef.get()).shiftYPosition(delta); break; case DisplayAlign.BEFORE: // cellArea.increaseHeight(delta); @@ -463,7 +466,7 @@ public class TableCell extends FObj { this.beforeOffset = m_borderSeparation / 2 + bp.getBorderTopWidth(false) + bp.getPaddingTop(false); - // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false); + // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false); } else { // System.err.println("Collapse borders"); diff --git a/src/org/apache/fop/fo/flow/TableFooter.java b/src/org/apache/fop/fo/flow/TableFooter.java index bc6923092..9117e46be 100644 --- a/src/org/apache/fop/fo/flow/TableFooter.java +++ b/src/org/apache/fop/fo/flow/TableFooter.java @@ -80,12 +80,13 @@ public class TableFooter extends AbstractTableBody { return "fo:table-footer"; } + // FIXME: this seems odd. public int getYPosition() { - return areaContainer.getCurrentYPosition() - spaceBefore; + return super.getYPosition() - spaceBefore; } public void setYPosition(int value) { - areaContainer.setYPosition(value + 2 * spaceBefore); + super.setYPosition(value + 2 * spaceBefore); } } diff --git a/src/org/apache/fop/fo/flow/TableRow.java b/src/org/apache/fop/fo/flow/TableRow.java index b11d2831c..05e14646f 100644 --- a/src/org/apache/fop/fo/flow/TableRow.java +++ b/src/org/apache/fop/fo/flow/TableRow.java @@ -89,7 +89,8 @@ public class TableRow extends FObj { int minHeight = 0; // force row height ArrayList columns; - AreaContainer areaContainer; + // public AreaContainer areaContainer; + public java.lang.ref.WeakReference areaContainerRef; boolean areaAdded = false; @@ -296,7 +297,7 @@ public class TableRow extends FObj { int spaceLeft = area.spaceLeft(); - this.areaContainer = + AreaContainer areaContainer = new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0, 0, area.getContentWidth(), spaceLeft, Position.RELATIVE); @@ -310,6 +311,8 @@ public class TableRow extends FObj { areaContainer.setAbsoluteHeight(area.getAbsoluteHeight()); areaContainer.setIDReferences(area.getIDReferences()); + this.areaContainerRef = new java.lang.ref.WeakReference(areaContainer); + largestCellHeight = minHeight; // Flag indicaing whether any cell didn't fit in available space @@ -391,7 +394,7 @@ public class TableRow extends FObj { // This is in case a float was composed in the cells area.setMaxHeight(area.getMaxHeight() - spaceLeft - + this.areaContainer.getMaxHeight()); + + areaContainer.getMaxHeight()); // Only do this for "STARTCELL", ending spans are handled separately // What about empty cells? Yes, we should set their height too! @@ -468,12 +471,12 @@ public class TableRow extends FObj { } public int getAreaHeight() { - return areaContainer.getHeight(); + return ((AreaContainer)areaContainerRef.get()).getHeight(); } public void removeLayout(Area area) { if (areaAdded) { - area.removeChild(areaContainer); + area.removeChild((AreaContainer)areaContainerRef.get()); areaAdded = false; } this.resetMarker(); -- 2.39.5