From 16bf84e64f38e9d2a29fd6d0d5627df6a8240d85 Mon Sep 17 00:00:00 2001 From: Karen Lease Date: Thu, 26 Sep 2002 21:09:19 +0000 Subject: [PATCH] Improve link hotspot positioning git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195249 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/flow/AbstractTableBody.java | 5 +-- src/org/apache/fop/fo/flow/BasicLink.java | 12 +++++- src/org/apache/fop/fo/flow/Block.java | 9 +++-- .../apache/fop/fo/flow/BlockContainer.java | 4 +- .../apache/fop/fo/flow/ExternalGraphic.java | 2 +- src/org/apache/fop/fo/flow/FootnoteBody.java | 1 + .../fop/fo/flow/InstreamForeignObject.java | 3 +- src/org/apache/fop/fo/flow/ListBlock.java | 5 ++- src/org/apache/fop/fo/flow/ListItem.java | 7 +++- src/org/apache/fop/fo/flow/StaticContent.java | 7 +--- src/org/apache/fop/fo/flow/Table.java | 5 +-- src/org/apache/fop/fo/flow/TableCell.java | 5 ++- src/org/apache/fop/fo/flow/TableRow.java | 1 + src/org/apache/fop/layout/Area.java | 38 ++++++++++++------- src/org/apache/fop/layout/LineArea.java | 10 ++++- .../fop/layout/inline/ForeignObjectArea.java | 4 ++ 16 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/org/apache/fop/fo/flow/AbstractTableBody.java b/src/org/apache/fop/fo/flow/AbstractTableBody.java index 0882c0daf..62fb0a5a8 100644 --- a/src/org/apache/fop/fo/flow/AbstractTableBody.java +++ b/src/org/apache/fop/fo/flow/AbstractTableBody.java @@ -124,6 +124,7 @@ public abstract class AbstractTableBody extends FObj { area.spaceLeft(), Position.RELATIVE); areaContainer.foCreator = this; // G Seshadri areaContainer.setPage(area.getPage()); + areaContainer.setParent(area); areaContainer.setBackground(propMgr.getBackgroundProps()); areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding()); areaContainer.start(); @@ -165,7 +166,6 @@ public abstract class AbstractTableBody extends FObj { // areaContainer.end(); area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); if (i == numChildren - 1) { this.marker = BREAK_AFTER; if (spaceAfter != 0) { @@ -202,7 +202,6 @@ public abstract class AbstractTableBody extends FObj { // areaContainer.end(); area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); } // Fix for infinite loop bug if spanned rows are too big for page @@ -226,8 +225,6 @@ public abstract class AbstractTableBody extends FObj { area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); - if (spaceAfter != 0) { area.increaseHeight(spaceAfter); area.setMaxHeight(area.getMaxHeight() - spaceAfter); diff --git a/src/org/apache/fop/fo/flow/BasicLink.java b/src/org/apache/fop/fo/flow/BasicLink.java index 749ba2c64..13d60ad18 100644 --- a/src/org/apache/fop/fo/flow/BasicLink.java +++ b/src/org/apache/fop/fo/flow/BasicLink.java @@ -100,7 +100,15 @@ public class BasicLink extends Inline { Page p = area.getPage(); - AreaContainer ac = p.getBody().getCurrentColumnArea(); + //AreaContainer ac = p.getBody().getCurrentColumnArea(); + AreaContainer ac = area.getNearestAncestorAreaContainer(); + while (ac!=null && ac.getPosition()!=Position.ABSOLUTE) { + ac = ac.getNearestAncestorAreaContainer(); + } + if (ac == null) { + ac = p.getBody().getCurrentColumnArea(); + //System.err.println("Using currentColumnArea as AC for link"); + } if (ac == null) { throw new FOPException("Couldn't get ancestor AreaContainer when processing basic-link"); } @@ -121,7 +129,7 @@ public class BasicLink extends Inline { // pass on command line String mergeLinks = System.getProperty("links.merge"); - if ((null != mergeLinks) &&!mergeLinks.equalsIgnoreCase("no")) { + if ((null == mergeLinks) || mergeLinks.equalsIgnoreCase("yes")) { ls.mergeLinks(); } diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index c130235f5..b420d9ca1 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -210,7 +210,6 @@ public class Block extends FObjMixed { area.setMaxHeight(area.getMaxHeight() - spaceLeft + blockArea.getMaxHeight()); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); anythingLaidOut = true; return status; @@ -226,7 +225,6 @@ public class Block extends FObjMixed { area.setMaxHeight(area.getMaxHeight() - spaceLeft + blockArea.getMaxHeight()); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); anythingLaidOut = true; return status; } @@ -243,8 +241,6 @@ public class Block extends FObjMixed { /* should this be combined into above? */ area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); - if (spaceAfter != 0) { area.addDisplaySpace(spaceAfter); } @@ -294,4 +290,9 @@ public class Block extends FObjMixed { return this.span; } + public void resetMarker() { + anythingLaidOut = false; + super.resetMarker(); + } + } diff --git a/src/org/apache/fop/fo/flow/BlockContainer.java b/src/org/apache/fop/fo/flow/BlockContainer.java index 8c1a96f94..2b41c00f1 100644 --- a/src/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/org/apache/fop/fo/flow/BlockContainer.java @@ -118,7 +118,8 @@ public class BlockContainer extends FObj { areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding()); areaContainer.start(); - areaContainer.setAbsoluteHeight(area.getAbsoluteHeight()); + //areaContainer.setAbsoluteHeight(top); + areaContainer.setAbsoluteHeight(0); areaContainer.setIDReferences(area.getIDReferences()); int numChildren = this.children.size(); @@ -145,7 +146,6 @@ public class BlockContainer extends FObj { prevChildMustKeepWithNext = true; } } - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); areaContainer.end(); if (position == Position.ABSOLUTE) diff --git a/src/org/apache/fop/fo/flow/ExternalGraphic.java b/src/org/apache/fop/fo/flow/ExternalGraphic.java index b3420456d..c3fcae73a 100644 --- a/src/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/org/apache/fop/fo/flow/ExternalGraphic.java @@ -218,7 +218,7 @@ public class ExternalGraphic extends FObj { return new Status(Status.AREA_FULL_NONE); } } - la.addInlineArea(imageArea); + la.addInlineArea(imageArea, this.getLinkSet()); } else { area.addChild(imageArea); area.increaseHeight(imageArea.getContentHeight()); diff --git a/src/org/apache/fop/fo/flow/FootnoteBody.java b/src/org/apache/fop/fo/flow/FootnoteBody.java index f8a1afc2c..18a8c0917 100644 --- a/src/org/apache/fop/fo/flow/FootnoteBody.java +++ b/src/org/apache/fop/fo/flow/FootnoteBody.java @@ -57,6 +57,7 @@ public class FootnoteBody extends FObj { alignLast, lineHeight); blockArea.setGeneratedBy(this); blockArea.isFirst(true); + blockArea.setParent(area); blockArea.setPage(area.getPage()); blockArea.start(); diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java index 2c0025c82..3ec4b03b3 100644 --- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -238,7 +238,7 @@ public class InstreamForeignObject extends FObj { return new Status(Status.AREA_FULL_NONE); } } - la.addInlineArea(areaCurrent); + la.addInlineArea(areaCurrent, this.getLinkSet()); } else { area.addChild(areaCurrent); area.increaseHeight(areaCurrent.getEffectiveHeight()); @@ -297,3 +297,4 @@ public class InstreamForeignObject extends FObj { } } + diff --git a/src/org/apache/fop/fo/flow/ListBlock.java b/src/org/apache/fop/fo/flow/ListBlock.java index b4a66f87f..8c72b1bc6 100644 --- a/src/org/apache/fop/fo/flow/ListBlock.java +++ b/src/org/apache/fop/fo/flow/ListBlock.java @@ -117,6 +117,8 @@ public class ListBlock extends FObj { area.getAllocationWidth(), area.spaceLeft(), startIndent, endIndent, 0, align, alignLast, lineHeight); + // Fix links in lists in tables problem + blockArea.setTableCellXOffset(area.getTableCellXOffset()); blockArea.setGeneratedBy(this); this.areasGenerated++; if (this.areasGenerated == 1) @@ -129,6 +131,7 @@ public class ListBlock extends FObj { blockArea.addMarkers(this.getMarkers()); + blockArea.setParent(area); blockArea.setPage(area.getPage()); blockArea.setBackground(propMgr.getBackgroundProps()); blockArea.start(); @@ -152,7 +155,6 @@ public class ListBlock extends FObj { blockArea.end(); area.addChild(blockArea); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); return status; } } @@ -160,7 +162,6 @@ public class ListBlock extends FObj { blockArea.end(); area.addChild(blockArea); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); if (spaceAfter != 0) { area.addDisplaySpace(spaceAfter); diff --git a/src/org/apache/fop/fo/flow/ListItem.java b/src/org/apache/fop/fo/flow/ListItem.java index dc49dcd91..a7b868216 100644 --- a/src/org/apache/fop/fo/flow/ListItem.java +++ b/src/org/apache/fop/fo/flow/ListItem.java @@ -104,6 +104,10 @@ public class ListItem extends FObj { new BlockArea(propMgr.getFontState(area.getFontInfo()), area.getAllocationWidth(), area.spaceLeft(), 0, 0, 0, align, alignLast, lineHeight); + + // Fix links in lists in tables problem + blockArea.setTableCellXOffset(area.getTableCellXOffset()); + this.blockArea.setGeneratedBy(this); this.areasGenerated++; if (this.areasGenerated == 1) @@ -115,6 +119,7 @@ public class ListItem extends FObj { if (this.hasMarkers()) this.blockArea.addMarkers(this.getMarkers()); + blockArea.setParent(area); blockArea.setPage(area.getPage()); blockArea.start(); @@ -148,7 +153,6 @@ public class ListItem extends FObj { blockArea.end(); area.addChild(blockArea); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); this.marker = 1; return status; } @@ -156,7 +160,6 @@ public class ListItem extends FObj { blockArea.end(); area.addChild(blockArea); area.increaseHeight(blockArea.getHeight()); - area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); if (spaceAfter != 0) { area.addDisplaySpace(spaceAfter); diff --git a/src/org/apache/fop/fo/flow/StaticContent.java b/src/org/apache/fop/fo/flow/StaticContent.java index a670fe956..7cd81481a 100644 --- a/src/org/apache/fop/fo/flow/StaticContent.java +++ b/src/org/apache/fop/fo/flow/StaticContent.java @@ -62,11 +62,8 @@ public class StaticContent extends AbstractFlow { if (area instanceof org.apache.fop.layout.AreaContainer) ((org.apache.fop.layout.AreaContainer)area).setAreaName(regionClass); - if (regionClass.equals(RegionBefore.REGION_CLASS)) { - area.setAbsoluteHeight(-area.getMaxHeight()); - } else if (regionClass.equals(RegionAfter.REGION_CLASS)) { - area.setAbsoluteHeight(area.getPage().getBody().getMaxHeight()); - } + area.setAbsoluteHeight(0); // Ytop relative to self! + setContentWidth(area.getContentWidth()); for (int i = 0; i < numChildren; i++) { diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index e7f7335c9..d7e263c7b 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -172,6 +172,7 @@ public class Table extends FObj { areaContainer.foCreator = this; // G Seshadri areaContainer.setPage(area.getPage()); + areaContainer.setParent(area); areaContainer.setBackground(propMgr.getBackgroundProps()); areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding()); areaContainer.start(); @@ -256,7 +257,6 @@ public class Table extends FObj { if (areaContainer.getContentHeight() > 0) { area.addChild(areaContainer); area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); if (this.omitHeaderAtBreak) { // remove header, no longer needed tableHeader = null; @@ -295,7 +295,6 @@ public class Table extends FObj { log.warn("footer could not fit on page, moving last body row to next page"); area.addChild(areaContainer); area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); if (this.omitHeaderAtBreak) { // remove header, no longer needed tableHeader = null; @@ -317,8 +316,6 @@ public class Table extends FObj { /* should this be combined into above? */ area.increaseHeight(areaContainer.getHeight()); - area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); - if (spaceAfter != 0) { area.addDisplaySpace(spaceAfter); } diff --git a/src/org/apache/fop/fo/flow/TableCell.java b/src/org/apache/fop/fo/flow/TableCell.java index f71f5133a..1d8c786f2 100644 --- a/src/org/apache/fop/fo/flow/TableCell.java +++ b/src/org/apache/fop/fo/flow/TableCell.java @@ -244,6 +244,7 @@ public class TableCell extends FObj { cellArea.foCreator = this; // G Seshadri cellArea.setPage(area.getPage()); + cellArea.setParent(area); try { cellArea.setBorderAndPadding((BorderAndPadding) propMgr.getBorderAndPadding().clone()); @@ -256,8 +257,8 @@ public class TableCell extends FObj { cellArea.setAbsoluteHeight(area.getAbsoluteHeight()); // ??? cellArea.setIDReferences(area.getIDReferences()); - // ******** CHECK THIS: we've changed startOffset (KL) - cellArea.setTableCellXOffset(startOffset); + // Add adjust for padding and border to fix link alignment! + cellArea.setTableCellXOffset(startOffset + startAdjust); int numChildren = this.children.size(); for (int i = this.marker; bDone==false && i < numChildren; i++) { diff --git a/src/org/apache/fop/fo/flow/TableRow.java b/src/org/apache/fop/fo/flow/TableRow.java index 32b712ebb..3d6e9aba1 100644 --- a/src/org/apache/fop/fo/flow/TableRow.java +++ b/src/org/apache/fop/fo/flow/TableRow.java @@ -250,6 +250,7 @@ public class TableRow extends FObj { Position.RELATIVE); areaContainer.foCreator = this; // G Seshadri areaContainer.setPage(area.getPage()); + areaContainer.setParent(area); areaContainer.setBackground(propMgr.getBackgroundProps()); areaContainer.start(); diff --git a/src/org/apache/fop/layout/Area.java b/src/org/apache/fop/layout/Area.java index 6a0170a0f..ff5ee07f0 100644 --- a/src/org/apache/fop/layout/Area.java +++ b/src/org/apache/fop/layout/Area.java @@ -38,8 +38,10 @@ abstract public class Area extends Box { // used to keep track of the current x position within a table. Required for drawing rectangle links. protected int tableCellXOffset = 0; - // used to keep track of the absolute height on the page. Required for drawing rectangle links. - private int absoluteHeight = 0; + /** Stores position of top of this area relative to page column Ypos. + * Used to set the position of link hotspot rectangles. + */ + private int absoluteYtop = 0; protected int contentRectangleWidth; @@ -114,7 +116,6 @@ abstract public class Area extends Box { public void addDisplaySpace(int size) { this.addChild(new DisplaySpace(size)); - this.absoluteHeight += size; this.currentHeight += size; } @@ -253,33 +254,43 @@ abstract public class Area extends Box { tableCellXOffset = offset; } + /** + * Return absolute Y position of the current bottom of this area, + * not counting any bottom padding or border. This is used + * to set positions for link hotspots. + * In fact, the position is not really absolute, but is relative + * to the Ypos of the column-level AreaContainer, even when the + * area is in a page header or footer! + */ public int getAbsoluteHeight() { - return absoluteHeight; + return absoluteYtop + getPaddingTop() + getBorderTopWidth() + + currentHeight; } + /** + * Set "absolute" Y position of the top of this area. In fact, the + * position is not really absolute, but relative to the Ypos of + * the column-level AreaContainer, even when the area is in a + * page header or footer! + * It is set from the value of getAbsoluteHeight() on the parent + * area, just before adding this area. + */ public void setAbsoluteHeight(int value) { - absoluteHeight = value; - } - - public void increaseAbsoluteHeight(int value) { - absoluteHeight += value; + absoluteYtop = value; } public void increaseHeight(int amount) { this.currentHeight += amount; - this.absoluteHeight += amount; } // Remove allocation height of child public void removeChild(Area area) { this.currentHeight -= area.getHeight(); - this.absoluteHeight -= area.getHeight(); this.children.remove(area); } public void removeChild(DisplaySpace spacer) { this.currentHeight -= spacer.getSize(); - this.absoluteHeight -= spacer.getSize(); this.children.remove(spacer); } @@ -329,7 +340,6 @@ abstract public class Area extends Box { if (currentHeight > getMaxHeight()) { currentHeight = getMaxHeight(); } - absoluteHeight += (currentHeight - prevHeight); } public void setMaxHeight(int height) { @@ -361,7 +371,7 @@ abstract public class Area extends Box { public AreaContainer getNearestAncestorAreaContainer() { Area area = this.getParent(); - while (!(area instanceof AreaContainer)) { + while (area != null && !(area instanceof AreaContainer)) { area = area.getParent(); } return (AreaContainer)area; diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index 86ed14532..50c18e43b 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -551,7 +551,7 @@ public class LineArea extends Area { } addSpacedWord(new String(data, wordStart, wordLength), ls, - finalWidth + spaceWidth + embeddedLinkStart, + finalWidth + pendingWidth, spaceWidth, textState, true); embeddedLinkStart += wordWidth; @@ -1051,9 +1051,14 @@ public class LineArea extends Area { public void setLinkSet(LinkSet ls) {} - public void addInlineArea(Area box) { + public void addInlineArea(InlineArea box, LinkSet ls) { addPending(); addChild(box); + if (ls != null) { + Rectangle lr=new Rectangle(finalWidth, 0,box.getContentWidth(), + box.getContentHeight()); + ls.addRect(lr, this, box); + } prev = TEXT; finalWidth += box.getContentWidth(); } @@ -1406,3 +1411,4 @@ public class LineArea extends Area { } + diff --git a/src/org/apache/fop/layout/inline/ForeignObjectArea.java b/src/org/apache/fop/layout/inline/ForeignObjectArea.java index ea23d5cf4..534a99db7 100644 --- a/src/org/apache/fop/layout/inline/ForeignObjectArea.java +++ b/src/org/apache/fop/layout/inline/ForeignObjectArea.java @@ -62,6 +62,10 @@ public class ForeignObjectArea extends InlineArea { return getEffectiveHeight(); } + public int getContentHeight() { + return getEffectiveHeight(); + } + public int getXOffset() { return this.xOffset; } -- 2.39.5