]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Improve link hotspot positioning
authorKaren Lease <klease@apache.org>
Thu, 26 Sep 2002 21:09:19 +0000 (21:09 +0000)
committerKaren Lease <klease@apache.org>
Thu, 26 Sep 2002 21:09:19 +0000 (21:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195249 13f79535-47bb-0310-9956-ffa450edef68

16 files changed:
src/org/apache/fop/fo/flow/AbstractTableBody.java
src/org/apache/fop/fo/flow/BasicLink.java
src/org/apache/fop/fo/flow/Block.java
src/org/apache/fop/fo/flow/BlockContainer.java
src/org/apache/fop/fo/flow/ExternalGraphic.java
src/org/apache/fop/fo/flow/FootnoteBody.java
src/org/apache/fop/fo/flow/InstreamForeignObject.java
src/org/apache/fop/fo/flow/ListBlock.java
src/org/apache/fop/fo/flow/ListItem.java
src/org/apache/fop/fo/flow/StaticContent.java
src/org/apache/fop/fo/flow/Table.java
src/org/apache/fop/fo/flow/TableCell.java
src/org/apache/fop/fo/flow/TableRow.java
src/org/apache/fop/layout/Area.java
src/org/apache/fop/layout/LineArea.java
src/org/apache/fop/layout/inline/ForeignObjectArea.java

index 0882c0daf131ebc07baf79b9b4c063d79fa1db2b..62fb0a5a8add44713c266f0825884ba030b0837a 100644 (file)
@@ -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);
index 749ba2c648c55619f42ee2768e4a343e0b3bd011..13d60ad1837103b136e6c3d206a5808ef2cbf2b4 100644 (file)
@@ -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();
         }
 
index c130235f5cb26eeb0920e9a100a5240f8fae9731..b420d9ca161ddab94468c19db3c1d449ae2ab6bd 100644 (file)
@@ -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();
+    }
+
 }
index 8c1a96f94d5396101408c2e29446c4cafaa87615..2b41c00f125f95d0a63d41e6a54a8fedf19417a5 100644 (file)
@@ -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)
index b3420456dcc047d50b3c446f72d94d49a0aaa8d2..c3fcae73aef921b50f3d960ad054e6d5b556bfbb 100644 (file)
@@ -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());
index f8a1afc2ccc6a3b26db5d5c3bd1ddd0d035d66ae..18a8c091759b48286570c02cdb24834a3350e09b 100644 (file)
@@ -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();
 
index 2c0025c823d4ca926a0955c450cafa91777288c5..3ec4b03b3750b2224b1466a74eecae265049bc31 100644 (file)
@@ -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 {
     }
 
 }
+
index b4a66f87f6532a5b7614ddea9b321ed301e10a9c..8c72b1bc66fd9ad425ad0f02a8ba26d195ebbf5a 100644 (file)
@@ -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);
index dc49dcd9163a2dd1d56e4206796f6ee4236bca1e..a7b86821660df66c3340c990c682a7bd4572581c 100644 (file)
@@ -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);
index a670fe9561a8c3c14966315b3bcc882686c67499..7cd81481abf112718959b4e4e2208377722d58f4 100644 (file)
@@ -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++) {
index e7f7335c97c6f05247c5b0bcfc0282ab97e9f24a..d7e263c7b4dc319377dcf125924d850aaadb2094 100644 (file)
@@ -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);
         }
index f71f5133a3b0538f6f731c2f332b3203403d5be6..1d8c786f2b0472a61df8979c591c32166c22d6ea 100644 (file)
@@ -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++) {
index 32b712ebb37ce81f83f3969dcaef4f7be8d401e2..3d6e9aba18169ad6d0d8f2b56d9e25caeeec9729 100644 (file)
@@ -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();
index 6a0170a0fc394a70ff9471fa7f46deca674a3978..ff5ee07f01dffa278094650c58a2bf4bb39768ee 100644 (file)
@@ -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;
index 86ed14532e6b441bfc935f0025af5f8d59c956a3..50c18e43b7d454de54add9dc1efae9a93457f68c 100644 (file)
@@ -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 {
 
 }
 
+
index ea23d5cf4fd6183ff1e3d3d51a45e435991ddcaa..534a99db7ae879a7ac85dcc983d0503df0e12ebb 100644 (file)
@@ -62,6 +62,10 @@ public class ForeignObjectArea extends InlineArea {
         return getEffectiveHeight();
     }
 
+    public int getContentHeight() {
+        return getEffectiveHeight();
+    }
+
     public int getXOffset() {
         return this.xOffset;
     }