aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/flow
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2002-09-07 08:58:07 +0000
committerKeiron Liddle <keiron@apache.org>2002-09-07 08:58:07 +0000
commitcf02e02cc3e1d392b9abfd2eabba9054bb5f5ddc (patch)
treefc107ad0958bac3485a4b4278a062af90dac027e /src/org/apache/fop/fo/flow
parent514cf028e74ee9c45b77cbed401ad07340458fce (diff)
downloadxmlgraphics-fop-cf02e02cc3e1d392b9abfd2eabba9054bb5f5ddc.tar.gz
xmlgraphics-fop-cf02e02cc3e1d392b9abfd2eabba9054bb5f5ddc.zip
implemented basic link with linking from pdf
improved some resolving of references git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195155 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/fo/flow')
-rw-r--r--src/org/apache/fop/fo/flow/BasicLink.java93
-rw-r--r--src/org/apache/fop/fo/flow/Leader.java22
-rw-r--r--src/org/apache/fop/fo/flow/PageNumberCitation.java67
3 files changed, 128 insertions, 54 deletions
diff --git a/src/org/apache/fop/fo/flow/BasicLink.java b/src/org/apache/fop/fo/flow/BasicLink.java
index fb66c9733..6f7dfdfed 100644
--- a/src/org/apache/fop/fo/flow/BasicLink.java
+++ b/src/org/apache/fop/fo/flow/BasicLink.java
@@ -13,13 +13,24 @@ import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.datatypes.ColorType;
+import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.Trait;
+import org.apache.fop.area.Resolveable;
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.Area;
+import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
+import org.apache.fop.layoutmgr.LMiter;
+import org.apache.fop.layoutmgr.LayoutManager;
// Java
import java.util.Enumeration;
import java.awt.Rectangle;
import java.util.List;
+import java.util.ArrayList;
public class BasicLink extends Inline {
+ String link = null;
+ boolean external = false;
public BasicLink(FONode parent) {
super(parent);
@@ -27,7 +38,32 @@ public class BasicLink extends Inline {
// add start and end properties for the link
public void addLayoutManager(List lms) {
- super.addLayoutManager(lms);
+ setup();
+ lms.add(new InlineStackingLayoutManager(this,
+ new LMiter(children.listIterator())) {
+ protected InlineParent createArea() {
+ InlineParent area = super.createArea();
+ setupLinkArea(parentLM, area);
+ return area;
+ }
+ });
+ }
+
+ protected void setupLinkArea(LayoutManager parentLM, InlineParent area) {
+ if(link == null) {
+ return;
+ }
+ if(external) {
+ area.addTrait(Trait.EXTERNAL_LINK, link);
+ } else {
+ PageViewport page = parentLM.resolveRefID(link);
+ if(page != null) {
+ area.addTrait(Trait.INTERNAL_LINK, page);
+ } else {
+ LinkResolver res = new LinkResolver(link, area);
+ parentLM.addUnresolvedArea(link, res);
+ }
+ }
}
public void setup() {
@@ -55,20 +91,61 @@ public class BasicLink extends Inline {
// this.properties.get("baseline-shift");
// this.properties.get("destination-place-offset");
// this.properties.get("dominant-baseline");
- // this.properties.get("external-destination");
+ String ext = properties.get("external-destination").getString();
setupID();
- // this.properties.get("indicate-destination");
- // this.properties.get("internal-destination");
+ // this.properties.get("indicate-destination");
+ String internal = properties.get("internal-destination").getString();
+ if(ext.length() > 0) {
+ link = ext;
+ external = true;
+ } else if(internal.length() > 0) {
+ link = internal;
+ } else {
+ getLogger().error("basic-link requires an internal or external destination");
+ }
// this.properties.get("keep-together");
// this.properties.get("keep-with-next");
// this.properties.get("keep-with-previous");
// this.properties.get("line-height");
// this.properties.get("line-height-shift-adjustment");
- // this.properties.get("show-destination");
- // this.properties.get("target-processing-context");
- // this.properties.get("target-presentation-context");
- // this.properties.get("target-stylesheet");
+ // this.properties.get("show-destination");
+ // this.properties.get("target-processing-context");
+ // this.properties.get("target-presentation-context");
+ // this.properties.get("target-stylesheet");
+
+ }
+
+ protected static class LinkResolver implements Resolveable {
+ private boolean resolved = false;
+ private String idRef;
+ // NOTE: there will be a problem with serialization
+ private Area area;
+
+ public LinkResolver(String id, Area a) {
+ idRef = id;
+ area = a;
+ }
+
+ public boolean isResolved() {
+ return resolved;
+ }
+
+ public String[] getIDs() {
+ return new String[] {idRef};
+ }
+
+ /**
+ * Resolve by removing the id link and replacing with
+ * an internal link.
+ */
+ public void resolve(String id, List pages) {
+ if(idRef.equals(id) && pages != null) {
+ PageViewport page = (PageViewport)pages.get(0);
+ area.addTrait(Trait.INTERNAL_LINK, page);
+ }
+ }
}
}
+
diff --git a/src/org/apache/fop/fo/flow/Leader.java b/src/org/apache/fop/fo/flow/Leader.java
index 0a84fc928..be4274cc3 100644
--- a/src/org/apache/fop/fo/flow/Leader.java
+++ b/src/org/apache/fop/fo/flow/Leader.java
@@ -55,25 +55,21 @@ public class Leader extends FObjMixed {
public void addLayoutManager(List list) {
LeafNodeLayoutManager lm = new LeafNodeLayoutManager(this) {
public InlineArea get(LayoutContext context) {
- int refIPD = context.getRefIPD();
- return getInlineArea(refIPD);
+ return getInlineArea();
+ }
+
+ protected MinOptMax getAllocationIPD(int refIPD) {
+ return getAllocIPD(refIPD);
}
};
lm.setAlignment(properties.get("leader-alignment").getEnum());
list.add(lm);
}
- protected InlineArea getInlineArea(int refIPD) {
+ protected InlineArea getInlineArea() {
if(leaderArea == null) {
createLeaderArea();
}
- MinOptMax alloc = getAllocationIPD(refIPD);
- if(leaderArea instanceof Stretch) {
- ((Stretch)leaderArea).setAllocationIPD(alloc);
- } else if(leaderArea instanceof FilledArea) {
- ((FilledArea)leaderArea).setAllocationIPD(alloc);
- }
- leaderArea.setWidth(alloc.opt);
return leaderArea;
}
@@ -88,9 +84,7 @@ public class Leader extends FObjMixed {
leaderArea = leader;
} else if (leaderPattern == LeaderPattern.SPACE) {
- Space space = new Space();
-
- leaderArea = space;
+ leaderArea = new Space();
} else if(leaderPattern == LeaderPattern.DOTS) {
Word w = new Word();
char dot = '.'; // userAgent.getLeaderDotChar();
@@ -226,7 +220,7 @@ public class Leader extends FObjMixed {
}
- protected MinOptMax getAllocationIPD(int ipd) {
+ protected MinOptMax getAllocIPD(int ipd) {
// length of the leader
int opt = getLength("leader-length.optimum", ipd);
int min = getLength("leader-length.minimum", ipd);
diff --git a/src/org/apache/fop/fo/flow/PageNumberCitation.java b/src/org/apache/fop/fo/flow/PageNumberCitation.java
index 7d343cb2e..3093dfc37 100644
--- a/src/org/apache/fop/fo/flow/PageNumberCitation.java
+++ b/src/org/apache/fop/fo/flow/PageNumberCitation.java
@@ -16,6 +16,7 @@ import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.area.PageViewport;
import org.apache.fop.util.CharUtilities;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.layoutmgr.LayoutContext;
@@ -67,52 +68,54 @@ public class PageNumberCitation extends FObj {
}
public void addAreas(PositionIterator posIter,
- LayoutContext context) {
+ LayoutContext context) {
super.addAreas(posIter, context);
- if(unresolved) {
- parentLM.addUnresolvedArea(refId, (Resolveable)inline);
+ if (unresolved) {
+ parentLM.addUnresolvedArea(refId,
+ (Resolveable) inline);
}
}
}
);
}
- // is id can be resolved then simply return a word, otherwise
+ // if id can be resolved then simply return a word, otherwise
// return a resolveable area
private InlineArea getInlineArea(LayoutManager parentLM) {
if (refId.equals("")) {
getLogger().error("page-number-citation must contain \"ref-id\"");
return null;
}
- String str = parentLM.resolveRefID(refId);
- if(str != null) {
- // get page string from parent, build area
- Word word = new Word();
- inline = word;
- int width = getStringWidth(str);
- word.setWord(str);
- inline.setIPD(width);
- inline.setHeight(fontState.getAscender() -
- fontState.getDescender());
- inline.setOffset(fontState.getAscender());
-
- inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
- inline.addTrait(Trait.FONT_SIZE,
- new Integer(fontState.getFontSize()));
+ PageViewport page = parentLM.resolveRefID(refId);
+ if (page != null) {
+ String str = page.getPageNumber();
+ // get page string from parent, build area
+ Word word = new Word();
+ inline = word;
+ int width = getStringWidth(str);
+ word.setWord(str);
+ inline.setIPD(width);
+ inline.setHeight(fontState.getAscender() -
+ fontState.getDescender());
+ inline.setOffset(fontState.getAscender());
+
+ inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
+ inline.addTrait(Trait.FONT_SIZE,
+ new Integer(fontState.getFontSize()));
+ unresolved = false;
} else {
- unresolved = true;
- inline = new UnresolvedPageNumber(refId);
- str = "MMM"; // reserve three spaces for page number
- int width = getStringWidth(str);
- inline.setIPD(width);
- inline.setHeight(fontState.getAscender() -
- fontState.getDescender());
- inline.setOffset(fontState.getAscender());
-
- inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
- inline.addTrait(Trait.FONT_SIZE,
- new Integer(fontState.getFontSize()));
-
+ unresolved = true;
+ inline = new UnresolvedPageNumber(refId);
+ String str = "MMM"; // reserve three spaces for page number
+ int width = getStringWidth(str);
+ inline.setIPD(width);
+ inline.setHeight(fontState.getAscender() -
+ fontState.getDescender());
+ inline.setOffset(fontState.getAscender());
+
+ inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
+ inline.addTrait(Trait.FONT_SIZE,
+ new Integer(fontState.getFontSize()));
}
return inline;
}