From: arved Date: Wed, 14 Jun 2000 02:01:00 +0000 (+0000) Subject: NEW: Simple link mods X-Git-Tag: pre-columns~476 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=55f2533f275ab3b7829049eaed52c1a993183a0f;p=xmlgraphics-fop.git NEW: Simple link mods git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193401 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 8d743ee41..e3e771242 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -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); diff --git a/src/org/apache/fop/fo/flow/ListBlock.java b/src/org/apache/fop/fo/flow/ListBlock.java index 723b7d4d9..607f1b4c0 100644 --- a/src/org/apache/fop/fo/flow/ListBlock.java +++ b/src/org/apache/fop/fo/flow/ListBlock.java @@ -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); diff --git a/src/org/apache/fop/fo/flow/ListItem.java b/src/org/apache/fop/fo/flow/ListItem.java index 7c7fa49be..b3f0afe9b 100644 --- a/src/org/apache/fop/fo/flow/ListItem.java +++ b/src/org/apache/fop/fo/flow/ListItem.java @@ -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); diff --git a/src/org/apache/fop/fo/flow/SimpleLink.java b/src/org/apache/fop/fo/flow/SimpleLink.java index 6566cc371..353c54d69 100644 --- a/src/org/apache/fop/fo/flow/SimpleLink.java +++ b/src/org/apache/fop/fo/flow/SimpleLink.java @@ -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" ); diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index 01b3f5f3a..f019d3040 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -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); } diff --git a/src/org/apache/fop/fo/flow/TableBody.java b/src/org/apache/fop/fo/flow/TableBody.java index 440a53b4a..4a9b8d26d 100644 --- a/src/org/apache/fop/fo/flow/TableBody.java +++ b/src/org/apache/fop/fo/flow/TableBody.java @@ -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); } diff --git a/src/org/apache/fop/fo/flow/TableCell.java b/src/org/apache/fop/fo/flow/TableCell.java index 784d205f7..13174ceef 100644 --- a/src/org/apache/fop/fo/flow/TableCell.java +++ b/src/org/apache/fop/fo/flow/TableCell.java @@ -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); diff --git a/src/org/apache/fop/fo/flow/TableRow.java b/src/org/apache/fop/fo/flow/TableRow.java index 503459fa4..f8bc1875d 100644 --- a/src/org/apache/fop/fo/flow/TableRow.java +++ b/src/org/apache/fop/fo/flow/TableRow.java @@ -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"); diff --git a/src/org/apache/fop/layout/Area.java b/src/org/apache/fop/layout/Area.java index fe445c47d..47166c855 100644 --- a/src/org/apache/fop/layout/Area.java +++ b/src/org/apache/fop/layout/Area.java @@ -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) { diff --git a/src/org/apache/fop/layout/AreaContainer.java b/src/org/apache/fop/layout/AreaContainer.java index 45fedba8e..cdd66f62b 100644 --- a/src/org/apache/fop/layout/AreaContainer.java +++ b/src/org/apache/fop/layout/AreaContainer.java @@ -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; } diff --git a/src/org/apache/fop/layout/BlockArea.java b/src/org/apache/fop/layout/BlockArea.java index 79c170a1c..4831b0fea 100644 --- a/src/org/apache/fop/layout/BlockArea.java +++ b/src/org/apache/fop/layout/BlockArea.java @@ -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; + } + } diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index 1a34faf82..4c1c5a42d 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -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; diff --git a/src/org/apache/fop/layout/LinkSet.java b/src/org/apache/fop/layout/LinkSet.java index e69d572f6..32172bc7d 100644 --- a/src/org/apache/fop/layout/LinkSet.java +++ b/src/org/apache/fop/layout/LinkSet.java @@ -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 diff --git a/src/org/apache/fop/pdf/PDFAction.java b/src/org/apache/fop/pdf/PDFAction.java index 2fa668599..238f936d8 100644 --- a/src/org/apache/fop/pdf/PDFAction.java +++ b/src/org/apache/fop/pdf/PDFAction.java @@ -52,49 +52,50 @@ 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 - */ -} + } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index ee0b39c53..72710eeb2 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -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 diff --git a/src/org/apache/fop/pdf/PDFLink.java b/src/org/apache/fop/pdf/PDFLink.java index 7d3345c62..2fc56e675 100644 --- a/src/org/apache/fop/pdf/PDFLink.java +++ b/src/org/apache/fop/pdf/PDFLink.java @@ -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; }