]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
NEW: Simple link mods
authorarved <arved@unknown>
Wed, 14 Jun 2000 02:01:00 +0000 (02:01 +0000)
committerarved <arved@unknown>
Wed, 14 Jun 2000 02:01:00 +0000 (02:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193401 13f79535-47bb-0310-9956-ffa450edef68

16 files changed:
src/org/apache/fop/fo/flow/Block.java
src/org/apache/fop/fo/flow/ListBlock.java
src/org/apache/fop/fo/flow/ListItem.java
src/org/apache/fop/fo/flow/SimpleLink.java
src/org/apache/fop/fo/flow/Table.java
src/org/apache/fop/fo/flow/TableBody.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/AreaContainer.java
src/org/apache/fop/layout/BlockArea.java
src/org/apache/fop/layout/LineArea.java
src/org/apache/fop/layout/LinkSet.java
src/org/apache/fop/pdf/PDFAction.java
src/org/apache/fop/pdf/PDFDocument.java
src/org/apache/fop/pdf/PDFLink.java

index 8d743ee41b9dd0d947c5130ef0a7918f73346f3b..e3e7712426f3613edc6f7540bb5d476fc285ca63 100644 (file)
@@ -219,6 +219,9 @@ public class Block extends FObjMixed {
         blockArea.setBorderColor(borderColor, borderColor, borderColor, borderColor); 
        blockArea.start();
 
+        blockArea.setAbsoluteHeight(area.getAbsoluteHeight()); 
+
+        blockArea.setTableCellXOffset(area.getTableCellXOffset());
        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
            FONode fo = (FONode) children.elementAt(i);
@@ -236,6 +239,7 @@ public class Block extends FObjMixed {
                //blockArea.end();
                area.addChild(blockArea);
                area.increaseHeight(blockArea.getHeight());
+                area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
                anythingLaidOut = true;
                return status;
            }
@@ -247,6 +251,8 @@ 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);
index 723b7d4d9fffac8c245918371d923ef3d265ae11..607f1b4c0ff49ec86a969386b3a2b8aa3e7728cc 100644 (file)
@@ -160,6 +160,8 @@ public class ListBlock extends FObj {
        blockArea.setPage(area.getPage());
        blockArea.setBackgroundColor(backgroundColor);
        blockArea.start();
+        
+        blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
 
        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
@@ -177,6 +179,7 @@ public class ListBlock extends FObj {
                blockArea.end();
                area.addChild(blockArea);
                area.increaseHeight(blockArea.getHeight());
+                area.setAbsoluteHeight(blockArea.getAbsoluteHeight()); 
                return status;
            }
        }
@@ -184,6 +187,7 @@ 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 7c7fa49be38d3b7959604b8c0f78294e365ac7c2..b3f0afe9bb0275f662858709343967f49930b4c5 100644 (file)
@@ -140,6 +140,8 @@ public class ListItem extends FObj {
        blockArea.setPage(area.getPage());
        blockArea.start();
 
+        blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
+
        int numChildren = this.children.size();
        if (numChildren != 2) {
            throw new FOPException("list-item must have exactly two children");
@@ -174,6 +176,7 @@ public class ListItem extends FObj {
            blockArea.end();
            area.addChild(blockArea);
            area.increaseHeight(blockArea.getHeight());
+            area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
            this.marker = 1;
            return status;
        }
@@ -181,6 +184,7 @@ 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 6566cc3718009e83929f40b536314a11c77208d4..353c54d69183a0fc7c7add94b6bf3ca8402336b9 100644 (file)
@@ -119,7 +119,7 @@ public class SimpleLink extends FObjMixed {
            }
        }
                
-       ls.applyAreaContainerOffsets(ac);
+       ls.applyAreaContainerOffsets(ac, area);
                
        // pass on command line
        String mergeLinks = System.getProperty( "links.merge" );
index 01b3f5f3a9f2cb3765cbade0110bc7aa6eee7d2a..f019d304007dfcdb1189d0a16eda7a777223f451 100644 (file)
@@ -169,6 +169,8 @@ public class Table extends FObj {
         areaContainer.setBorderColor(borderColor, borderColor, borderColor, borderColor); 
        areaContainer.start();
 
+        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
+
        // added by Eric Schaeffer
        currentColumnNumber = 0;
         int offset = 0;
@@ -207,6 +209,7 @@ public class Table extends FObj {
                    //areaContainer.end();
                    area.addChild(areaContainer);
                    area.increaseHeight(areaContainer.getHeight());
+                    area.setAbsoluteHeight(areaContainer.getAbsoluteHeight()); 
                    return status;
                }
            }
@@ -227,6 +230,8 @@ 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 440a53b4a3bc328ca27487f80eccc0cc43398c9d..4a9b8d26d58cba2c3e4a32a5c23246fb2f9e16ab 100644 (file)
@@ -139,6 +139,8 @@ public class TableBody extends FObj {
        areaContainer.setBackgroundColor(backgroundColor);
        areaContainer.start();
 
+        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
+
        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
            TableRow row = (TableRow) children.elementAt(i);
@@ -153,7 +155,9 @@ public class TableBody extends FObj {
                }
                area.addChild(areaContainer);
                //areaContainer.end();
+
                area.increaseHeight(areaContainer.getHeight());
+                area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
                return status;
            }
        }
@@ -163,6 +167,8 @@ public class TableBody extends FObj {
        /* should this be combined into above? */
        area.increaseHeight(areaContainer.getHeight());
 
+        area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
+
        if (spaceAfter != 0) {
            area.addDisplaySpace(spaceAfter);
        }
index 784d205f78ab0c5efacdc2c121dbd73aa6c48567..13174ceef2a86ec323a2ecefaf7e3c9f4ce6c247 100644 (file)
@@ -178,6 +178,8 @@ public class TableCell extends FObj {
         areaContainer.setBorderColor(borderColor, borderColor, borderColor, borderColor); 
        areaContainer.start();
 
+        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
+        areaContainer.setTableCellXOffset(startOffset);
        int numChildren = this.children.size();
        for (int i = this.marker; i < numChildren; i++) {
            FObj fo = (FObj) children.elementAt(i);
index 503459fa47cf7cd36cee8de0d844d79cf7477145..f8bc1875d088b2ecff7a4bdd09b56596d2e53cc2 100644 (file)
@@ -152,6 +152,8 @@ public class TableRow extends FObj {
         areaContainer.setBorderColor(borderColor, borderColor, borderColor, borderColor); 
        areaContainer.start();
 
+        areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
+
        int numChildren = this.children.size();
        if (numChildren != columns.size()) {
            System.err.println("WARNING: Number of children under table-row not equal to number of table-columns");
index fe445c47d445b3da3d4535e7b1850df94a93362d..47166c855dc571014635bf9b34746950a3f4714b 100644 (file)
@@ -69,6 +69,12 @@ abstract public class Area extends Box {
     protected int maxHeight;
 
     protected int currentHeight = 0;
+    
+    // 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;  
 
     protected int contentRectangleWidth;
 
@@ -120,6 +126,7 @@ abstract public class Area extends Box {
        
     public void addDisplaySpace(int size) {
        this.addChild(new DisplaySpace(size));
+        this.absoluteHeight += size;
        this.currentHeight += size;
     }
 
@@ -182,12 +189,39 @@ abstract public class Area extends Box {
        return this.paddingRight;
     }
 
+    public int getTableCellXOffset()
+    {
+        return tableCellXOffset;
+    }
+    
+    public void setTableCellXOffset(int offset)
+    {
+        tableCellXOffset=offset;
+    }
+    
+    public int getAbsoluteHeight()
+    {
+        return absoluteHeight;
+    }
+
+    public void setAbsoluteHeight(int value)
+    {
+        absoluteHeight=value;
+    }
+
+    public void increaseAbsoluteHeight(int value)
+    {
+        absoluteHeight+=value;
+    } 
+    
     public void increaseHeight(int amount) {
        this.currentHeight += amount;
+        this.absoluteHeight += amount;
     }
 
     protected void removeChild(Area area) {
        this.currentHeight -= area.getHeight();
+        this.absoluteHeight -= area.getHeight();
        this.children.removeElement(area);
     }
        
@@ -241,8 +275,10 @@ abstract public class Area extends Box {
     public void setHeight(int height) {
       if (height > currentHeight)
         currentHeight = height;
+        absoluteHeight = height;        
       if (currentHeight > getMaxHeight())
         currentHeight = getMaxHeight();
+        absoluteHeight = getMaxHeight();        
     }
     
     public void setMaxHeight(int height) {
index 45fedba8e267643a21449dae490bde31f6ac822d..cdd66f62bbbe57a6b7669eca000fead9f73923dc 100644 (file)
@@ -83,6 +83,11 @@ public class AreaContainer extends Area {
         return xPosition + this.paddingLeft + this.borderWidthLeft;
     }
 
+    public void setXPosition(int value)
+    {
+        xPosition=value;
+    }
+
     public int getYPosition() {
       return yPosition + this.paddingTop + this.borderWidthTop;
     }
index 79c170a1c1fd00f898afa06e9f3a66389998f375..4831b0feaa971b3e77d4d402fa2bab46f9631648 100644 (file)
@@ -70,6 +70,7 @@ public class BlockArea extends Area {
        
     protected int halfLeading;
 
+    
     /* text-align of all but the last line */
     protected int align;
 
@@ -197,4 +198,10 @@ public class BlockArea extends Area {
     public int spaceLeft() {
        return maxHeight - currentHeight;
     }
+    
+    public int getHalfLeading()
+    {
+        return halfLeading;
+    }
+
 }
index 1a34faf822c30d98ec2d097b2b031c1683c6bd26..4c1c5a42dd212db3099fb05167030f218b56a7d4 100644 (file)
@@ -89,6 +89,9 @@ public class LineArea extends Area {
        area */
     protected int finalWidth = 0;
 
+    /* the position to shift a link rectangle in order to compensate for links embedded within a word*/
+    protected int embeddedLinkStart=0;
+
     /* the width of the current word so far */
     protected int wordWidth = 0;
 
@@ -224,7 +227,7 @@ public class LineArea extends Area {
                                              finalWidth,
                                              0,
                                              inlineArea.getContentWidth(),
-                                             lineHeight);
+                                             fontState.getFontSize());
                            ls.addRect(lr, this);
                        }
 
@@ -252,7 +255,7 @@ public class LineArea extends Area {
                                              finalWidth,
                                              0,
                                              ia.getContentWidth(),
-                                             lineHeight);
+                                             fontState.getFontSize());                            
                            ls.addRect(lr, this);
                        }
                        finalWidth += wordWidth;
@@ -265,6 +268,8 @@ public class LineArea extends Area {
                    // word we just added
 
                    prev = WHITESPACE;
+
+                    embeddedLinkStart=0; //reset embeddedLinkStart since a space was encountered                    
                    
                    if (this.whiteSpaceTreatment ==
                        WhiteSpaceTreatment.IGNORE) {
@@ -354,13 +359,14 @@ public class LineArea extends Area {
            
            if (ls != null) {
                Rectangle lr =
-                   new Rectangle(startIndent + finalWidth + spaceWidth,
+                   new Rectangle(startIndent + finalWidth + spaceWidth + embeddedLinkStart,
                                  spaceWidth,
                                  pia.getContentWidth(),
-                                 lineHeight);
+                                 fontState.getFontSize());                             
                ls.addRect(lr, this);
            }
            
+           embeddedLinkStart += wordWidth;
            pendingAreas.addElement(pia);
            pendingWidth += wordWidth;
            wordWidth = 0;
index e69d572f6bbb1ff7f4b103619c2868e255134f2b..32172bc7d92ab1068a00194a4719eea627ff39f2 100644 (file)
@@ -83,6 +83,9 @@ public class LinkSet {
     private int xoffset = 0;
     private int yoffset = 0;
     
+    /* the maximum Y offset value encountered for this LinkSet*/
+    private int maxY = 0;
+
     protected int startIndent;
     protected int endIndent;
 
@@ -100,6 +103,10 @@ public class LinkSet {
        LinkedRectangle linkedRectangle =
            new LinkedRectangle(r, lineArea);
        linkedRectangle.setY(this.yoffset);
+        if(this.yoffset>maxY)
+        {
+            maxY=this.yoffset;
+        }
        rects.addElement(linkedRectangle);
     }
        
@@ -115,13 +122,15 @@ public class LinkSet {
        this.contentRectangleWidth = contentRectangleWidth;
     }
        
-    public void applyAreaContainerOffsets(AreaContainer ac) {
-       Enumeration re = rects.elements();
-       while (re.hasMoreElements()) {
+    public void applyAreaContainerOffsets(AreaContainer ac, Area area) {        
+       int height=area.getAbsoluteHeight();
+        BlockArea ba = (BlockArea)area;
+        Enumeration re = rects.elements();                 
+        while (re.hasMoreElements()) {
            LinkedRectangle r = (LinkedRectangle)re.nextElement();
-           r.setX( r.getX() + ac.getXPosition() );
-           r.setY( ac.getYPosition() - ac.getHeight() - r.getY() );
-       }
+            r.setX(r.getX() + ac.getXPosition() + area.getTableCellXOffset() - ba.startIndent);             
+            r.setY( ac.getYPosition() - height +(maxY-r.getY()) - ba.getHalfLeading());                    
+         }
     }
        
     // intermediate implementation for joining all sublinks on same line
index 2fa668599d850f3cc44bd6297dab09166739acd5..238f936d80b998b988d2e95beaa764f56de0dcc4 100644 (file)
 package org.apache.fop.pdf;
 
 /**
- * class representing a /Action object.
+ * class representing an action object.
  */
-public class PDFAction extends PDFObject {
-
-    /** the file specification */
-    protected PDFFileSpec fileSpec;
+public abstract class PDFAction extends PDFObject {
 
+    
     /**
-     * create an /Action object.
+     * create an Action object.
+     * this constructor is used for passing on the object number to the PDFObject
      *
-     * @param number the object's number
-     * @param fileSpec the fileSpec associated with the action
+     * @param number the object's number     
      */
-    public PDFAction(int number, PDFFileSpec fileSpec) {
+    public PDFAction(int number) {
 
        /* generic creation of object */
-       super(number);
-       
-       this.fileSpec = fileSpec;
+       super(number);      
+    }
+
+    /**
+     * empty constructor for PDFAction.
+     * this constructor is used when there is no additional object being created
+     *     
+     */
+    public PDFAction()
+    {
     }
 
+    /**
+     * represent the action to call
+     * this method should be implemented to return the action which gets
+     * called by the Link Object.  This could be a reference to another object
+     * or the specific destination of the link
+     *
+     * @return the action to place next to /A within a Link
+     */
+    abstract public String getAction();
+    
+
     /**
      * represent the object in PDF
+     * this method should be implemented to return the PDF which is to be
+     * generated by the Action object
      *
      * @return the PDF string
      */
-    public String toPDF() {
-       String p = new String(this.number + " " + this.generation +
-                             " obj\n" +
-                             "<<\n/S /GoToR\n" +
-                             "/F " + fileSpec.referencePDF() + "\n" +
-                             "/D [ 0 /XYZ null null null ]" +
-                             " \n>>\nendobj\n"); 
-       return p;
-    }
+    abstract public String toPDF();
 
-    /* example
-       28 0 obj
-       << 
-       /S /GoToR 
-       /F 29 0 R 
-       /D [ 0 /XYZ -6 797 null ] 
-       >> 
-       endobj
-    */
-}
+    }
index ee0b39c538687982b36015e89a08b7b91bff5402..72710eeb23a3e0752a8ab7daf4e2864d27fe48be 100644 (file)
@@ -787,20 +787,29 @@ public class PDFDocument {
         */
        public PDFLink makeLink(Rectangle rect, String destination) {
 
-       PDFLink link = new PDFLink(++this.objectcount, rect);
-       this.objects.addElement(link);
-
-       PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount,
-                                                  destination);
-       this.objects.addElement(fileSpec);
-
-       PDFAction action = new PDFAction(++this.objectcount,
-                                        fileSpec);
-       this.objects.addElement(action);
-       link.setAction(action);
-
-       return link;
-       }
+        PDFLink linkObject;
+        PDFAction action;
+
+        PDFLink link = new PDFLink(++this.objectcount, rect);
+        this.objects.addElement(link);               
+        
+        //check destination
+        if ( destination.endsWith(".pdf") ) //FileSpec
+        {                        
+            PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount,destination);
+            this.objects.addElement(fileSpec);
+            action = new PDFGoToRemote(++this.objectcount,fileSpec);
+            this.objects.addElement(action);
+            link.setAction(action);                    
+        }
+        else //URI
+        {            
+            PDFUri uri = new PDFUri(destination);    
+            link.setAction(uri);    
+        }
+             
+        return link;
+    }
 
        /**
         * make a stream object
index 7d3345c6299caf5d964dc4878215e0d45dbb0d33..2fc56e67515d5ce948a1b9cdbb7d2b6922eb0675 100644 (file)
@@ -101,7 +101,7 @@ public class PDFLink extends PDFObject {
            (brx/1000f) + " " + (bry/1000f) + " ]\n"
            + "/C [ " + this.color + " ]\n" + 
            "/Border [ 0 0 0 ]\n" +
-           "/A " + this.action.referencePDF() + "\n" +
+           "/A " + this.action.getAction() + "\n" +
            "/H /I\n>>\nendobj\n";
        return p;
     }