From 4805c63fb1a1fd0c075dbf872cf1e07ae119a934 Mon Sep 17 00:00:00 2001 From: Kelly Campbell Date: Thu, 29 Mar 2001 07:34:57 +0000 Subject: [PATCH] Fixed basic-link horizontal position with justification turned on. PR: 953 Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194179 13f79535-47bb-0310-9956-ffa450edef68 --- docs/examples/build.xml | 2 + docs/examples/fo/newlinktest.fo | 114 ++++++++++++++++++ src/org/apache/fop/layout/LineArea.java | 31 +++-- src/org/apache/fop/layout/LinkSet.java | 10 +- .../apache/fop/layout/LinkedRectangle.java | 19 ++- .../apache/fop/layout/inline/InlineArea.java | 11 ++ 6 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 docs/examples/fo/newlinktest.fo diff --git a/docs/examples/build.xml b/docs/examples/build.xml index 09e3b7b04..5c22ea6e4 100644 --- a/docs/examples/build.xml +++ b/docs/examples/build.xml @@ -46,6 +46,7 @@ + @@ -85,6 +86,7 @@ + diff --git a/docs/examples/fo/newlinktest.fo b/docs/examples/fo/newlinktest.fo new file mode 100644 index 000000000..55df88218 --- /dev/null +++ b/docs/examples/fo/newlinktest.fo @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + FOP is the world's first print formatter driven by XSL formatting + objects. It is a Java 1.1 application that reads a formatting object + tree and then turns it into a PDF document. The formatting object + tree, can be in the form of an XML document (output by an XSLT engine + like XT or Xalan) or can be passed in memory as a DOM Document or (in + the case of XT) SAX events. + + + FOP is part of Apache's XML project. The homepage of FOP is + http://xml.apache.org/fop + + + +align="start" + + + + Apache FOP is the world's first print formatter driven by XSL formatting + objects. It is a Java 1.1 application that reads a formatting object + tree and then turns it into a PDF document. The formatting object + tree, can be in the form of an XML document (output by an XSLT engine + like XT or Xalan) or can be passed in memory as a DOM Document or (in + the case of XT) SAX events. + + + + +align="center" + + + + Apache FOP is the world's first print formatter driven by XSL formatting + objects. It is a Java 1.1 application that reads a formatting object + tree and then turns it into a PDF document. The formatting object + tree, can be in the form of an XML document (output by an XSLT engine + like XT or Xalan) or can be passed in memory as a DOM Document or (in + the case of XT) SAX events. + + + + +align="justify" + + + + Apache FOP is the world's first print formatter driven by XSL formatting + objects. It is a Java 1.1 application that reads a formatting object + tree and then turns it into a PDF document. The formatting object + tree, can be in the form of an XML document (output by an XSLT engine + like XT or Xalan) or can be passed in memory as a DOM Document or (in + the case of XT) SAX events. + + + + + + + + + + + good + bad + ugly + + + nice + dice + vice + + + literature + music + art + + + java + perl + python + + + + + + + + + + diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index 1c0a94f3f..6425330da 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -244,7 +244,7 @@ public class LineArea extends Area { ((InlineArea) box). getContentWidth(), fontState.getFontSize()); - ls.addRect(lr, this); + ls.addRect(lr, this, (InlineArea)box); } } addChild(box); @@ -277,7 +277,7 @@ public class LineArea extends Area { Rectangle lr = new Rectangle(finalWidth, 0, ia.getContentWidth(), fontState.getFontSize()); - ls.addRect(lr, this); + ls.addRect(lr, this, ia); } finalWidth += wordWidth; @@ -419,7 +419,7 @@ public class LineArea extends Area { Rectangle lr = new Rectangle(finalWidth + spaceWidth + embeddedLinkStart, spaceWidth, pia.getContentWidth(), fontState.getFontSize()); - ls.addRect(lr, this); + ls.addRect(lr, this, pia); } embeddedLinkStart += wordWidth; @@ -606,8 +606,7 @@ public class LineArea extends Area { endIndent += padding; break; case TextAlign.JUSTIFY: // justify - Vector spaceList = new Vector(); - + // first pass - count the spaces int spaceCount = 0; Enumeration e = children.elements(); while (e.hasMoreElements()) { @@ -615,7 +614,6 @@ public class LineArea extends Area { if (b instanceof InlineSpace) { InlineSpace space = (InlineSpace) b; if (space.getResizeable()) { - spaceList.addElement(space); spaceCount++; } } @@ -626,11 +624,22 @@ public class LineArea extends Area { } else { // no spaces padding = 0; } - Enumeration f = spaceList.elements(); - while (f.hasMoreElements()) { - InlineSpace space2 = (InlineSpace) f.nextElement(); - int i = space2.getSize(); - space2.setSize(i + padding); + // second pass - add additional space + spaceCount = 0; + e = children.elements(); + while (e.hasMoreElements()) { + Box b = (Box) e.nextElement(); + if (b instanceof InlineSpace) { + InlineSpace space = (InlineSpace) b; + if (space.getResizeable()) { + space.setSize(space.getSize() + padding); + spaceCount++; + } + } + else if (b instanceof InlineArea) { + ((InlineArea)b).setXOffset(spaceCount * padding); + } + } } } diff --git a/src/org/apache/fop/layout/LinkSet.java b/src/org/apache/fop/layout/LinkSet.java index 771ce4486..bce16ff59 100644 --- a/src/org/apache/fop/layout/LinkSet.java +++ b/src/org/apache/fop/layout/LinkSet.java @@ -59,6 +59,8 @@ import java.util.Vector; import java.util.Enumeration; import java.awt.Rectangle; +import org.apache.fop.layout.inline.InlineArea; + import org.apache.fop.fo.properties.WrapOption; // for enumerated // values // import org.apache.fop.fo.properties.WhiteSpaceCollapse; // for @@ -105,8 +107,8 @@ public class LinkSet { this.linkType = linkType; } - public void addRect(Rectangle r, LineArea lineArea) { - LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea); + public void addRect(Rectangle r, LineArea lineArea, InlineArea inlineArea) { + LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea, inlineArea); linkedRectangle.setY(this.yoffset); if (this.yoffset > maxY) { maxY = this.yoffset; @@ -171,7 +173,9 @@ public class LinkSet { Enumeration re = rects.elements(); while (re.hasMoreElements()) { LinkedRectangle r = (LinkedRectangle) re.nextElement(); - r.setX(r.getX() + r.getLineArea().getStartIndent()); + r.setX(r.getX() + + r.getLineArea().getStartIndent() + + r.getInlineArea().getXOffset()); } } diff --git a/src/org/apache/fop/layout/LinkedRectangle.java b/src/org/apache/fop/layout/LinkedRectangle.java index b23b763da..9956e3a80 100644 --- a/src/org/apache/fop/layout/LinkedRectangle.java +++ b/src/org/apache/fop/layout/LinkedRectangle.java @@ -57,6 +57,8 @@ package org.apache.fop.layout; // Java import java.awt.Rectangle; +import org.apache.fop.layout.inline.InlineArea; + /** * an object that stores a rectangle that is linked, and the LineArea * that it is logically associated with @@ -69,14 +71,19 @@ public class LinkedRectangle { /** the associated LineArea */ protected LineArea lineArea; - public LinkedRectangle(Rectangle link, LineArea lineArea) { + /** the associated InlineArea */ + protected InlineArea inlineArea; + + public LinkedRectangle(Rectangle link, LineArea lineArea, InlineArea inlineArea) { this.link = link; this.lineArea = lineArea; + this.inlineArea = inlineArea; } public LinkedRectangle(LinkedRectangle lr) { this.link = new Rectangle( lr.getRectangle() ); this.lineArea = lr.getLineArea(); + this.inlineArea = lr.getInlineArea(); } public void setRectangle(Rectangle link) { @@ -91,9 +98,17 @@ public class LinkedRectangle { return this.lineArea; } - public void setLineArea() { + public void setLineArea(LineArea lineArea) { this.lineArea = lineArea; } + + public InlineArea getInlineArea() { + return this.inlineArea; + } + + public void setLineArea(InlineArea inlineArea) { + this.inlineArea = inlineArea; + } public void setX(int x) { this.link.x = x; diff --git a/src/org/apache/fop/layout/inline/InlineArea.java b/src/org/apache/fop/layout/inline/InlineArea.java index c0dedb4b4..6f202bdae 100644 --- a/src/org/apache/fop/layout/inline/InlineArea.java +++ b/src/org/apache/fop/layout/inline/InlineArea.java @@ -58,6 +58,9 @@ import org.apache.fop.layout.*; public abstract class InlineArea extends Area { private int yOffset = 0; + + /** amount of space added since the original layout - needed by links */ + private int xOffset = 0; protected int height = 0; private int verticalAlign = 0; protected String pageNumberId = null; @@ -114,6 +117,14 @@ public abstract class InlineArea extends Area { return this.yOffset; } + public void setXOffset(int xOffset) { + this.xOffset = xOffset; + } + + public int getXOffset() { + return this.xOffset; + } + public String getPageNumberID() { return pageNumberId; } -- 2.39.5