diff options
author | Keiron Liddle <keiron@apache.org> | 2002-05-17 14:47:13 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-05-17 14:47:13 +0000 |
commit | 419405d1934e8a9b7ba9cc9e44fb967c39cafa19 (patch) | |
tree | 56be2377226eb9aea407f7487e516b40a2a6462f /src/org/apache/fop/extensions | |
parent | 7be7b7e54762346f41ab92f4b92bae326811df95 (diff) | |
download | xmlgraphics-fop-419405d1934e8a9b7ba9cc9e44fb967c39cafa19.tar.gz xmlgraphics-fop-419405d1934e8a9b7ba9cc9e44fb967c39cafa19.zip |
cleaned up bookmark extension a bit
make multi page sequences work properly
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194825 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/extensions')
-rw-r--r-- | src/org/apache/fop/extensions/BookmarkData.java | 90 | ||||
-rw-r--r-- | src/org/apache/fop/extensions/Bookmarks.java | 44 | ||||
-rw-r--r-- | src/org/apache/fop/extensions/ExtensionElementMapping.java | 11 | ||||
-rw-r--r-- | src/org/apache/fop/extensions/ExtensionObj.java | 28 | ||||
-rw-r--r-- | src/org/apache/fop/extensions/Label.java | 8 | ||||
-rw-r--r-- | src/org/apache/fop/extensions/Outline.java | 77 |
6 files changed, 173 insertions, 85 deletions
diff --git a/src/org/apache/fop/extensions/BookmarkData.java b/src/org/apache/fop/extensions/BookmarkData.java new file mode 100644 index 000000000..5114df1bb --- /dev/null +++ b/src/org/apache/fop/extensions/BookmarkData.java @@ -0,0 +1,90 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.extensions; + +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.Resolveable; +import org.apache.fop.area.TreeExt; + +import java.util.*; + +public class BookmarkData implements Resolveable, TreeExt { + private ArrayList subData = new ArrayList(); + private HashMap idRefs = new HashMap(); + + String idRef; + PageViewport pageRef = null; + String label = null; + + public BookmarkData() { + idRef = null; + } + + public BookmarkData(String id) { + idRef = id; + idRefs.put(idRef, this); + } + + public String getID() { + return idRef; + } + + public void addSubData(BookmarkData sub) { + subData.add(sub); + idRefs.put(sub.getID(), sub); + } + + public void setLabel(String l) { + label = l; + } + + public boolean isResolveable() { + return true; + } + + public String getMimeType() { + return "application/pdf"; + } + + public String getName() { + return "Bookmark"; + } + + public boolean isResolved() { + return idRefs == null; + } + + public String[] getIDs() { + return (String[])idRefs.keySet().toArray(new String[] {}); + } + + public void resolve(String id, ArrayList pages) { + if(!id.equals(idRef)) { + BookmarkData bd = (BookmarkData)idRefs.get(id); + bd.resolve(id, pages); + if(bd.isResolved()) { + idRefs.remove(id); + if(idRefs.size() == 0) { + idRefs = null; + } + } + } else { + if(pages != null) { + pageRef = (PageViewport)pages.get(0); + } + // TODO + // get rect area of id on page + + idRefs.remove(idRef); + if(idRefs.size() == 0) { + idRefs = null; + } + } + } +} + diff --git a/src/org/apache/fop/extensions/Bookmarks.java b/src/org/apache/fop/extensions/Bookmarks.java new file mode 100644 index 000000000..69ab04f52 --- /dev/null +++ b/src/org/apache/fop/extensions/Bookmarks.java @@ -0,0 +1,44 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.extensions; + +import org.apache.fop.fo.FONode; + +import java.util.*; + +import org.xml.sax.Attributes; + +public class Bookmarks extends ExtensionObj { + private ArrayList outlines = new ArrayList(); + private BookmarkData data; + + public Bookmarks(FONode parent) { + super(parent); + } + + protected void addChild(FONode obj) { + if (obj instanceof Outline) { + outlines.add(obj); + } + } + + public BookmarkData getData() { + return data; + } + + public void end() { + log.debug("adding bookmarks to area tree"); + data = new BookmarkData(); + for(int count = 0; count < outlines.size(); count++) { + Outline out = (Outline)outlines.get(count); + data.addSubData(out.getData()); + } + // add data to area tree for resolving and handling + } +} + diff --git a/src/org/apache/fop/extensions/ExtensionElementMapping.java b/src/org/apache/fop/extensions/ExtensionElementMapping.java index 479c4b3ca..e2fd1702e 100644 --- a/src/org/apache/fop/extensions/ExtensionElementMapping.java +++ b/src/org/apache/fop/extensions/ExtensionElementMapping.java @@ -22,16 +22,25 @@ public class ExtensionElementMapping implements ElementMapping { private static synchronized void setupExt() { if(foObjs == null) { foObjs = new HashMap(); + foObjs.put("bookmarks", new B()); foObjs.put("outline", new O()); foObjs.put("label", new L()); } } public void addToBuilder(FOTreeBuilder builder) { - setupExt(); + if(foObjs == null) { + setupExt(); + } builder.addMapping(URI, foObjs); } + static class B extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new Bookmarks(parent); + } + } + static class O extends ElementMapping.Maker { public FONode make(FONode parent) { return new Outline(parent); diff --git a/src/org/apache/fop/extensions/ExtensionObj.java b/src/org/apache/fop/extensions/ExtensionObj.java index 3ae492d18..f18f38b12 100644 --- a/src/org/apache/fop/extensions/ExtensionObj.java +++ b/src/org/apache/fop/extensions/ExtensionObj.java @@ -7,9 +7,8 @@ package org.apache.fop.extensions; -import org.apache.fop.fo.*; -import org.apache.fop.layout.*; -import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; /** * base class for extension objects @@ -25,28 +24,5 @@ public abstract class ExtensionObj extends FObj { super(parent); } - /** - * Called for extensions within a page sequence or flow. These extensions - * are allowed to generate visible areas within the layout. - * - * @param area - */ - public Status layout(Area area) throws FOPException { - ExtensionArea extArea = new ExtensionArea(this); - area.addChild(extArea); - return new Status(Status.OK); - } - - /** - * Called for root extensions. Root extensions aren't allowed to generate - * any visible areas. They are used for extra items that don't show up in - * the page layout itself. For example: pdf outlines - * - * @param areaTree - */ - public void format(AreaTree areaTree) throws FOPException { - ExtensionArea extArea = new ExtensionArea(this); - areaTree.addExtension(this); - } } diff --git a/src/org/apache/fop/extensions/Label.java b/src/org/apache/fop/extensions/Label.java index fc645d4aa..c373550ff 100644 --- a/src/org/apache/fop/extensions/Label.java +++ b/src/org/apache/fop/extensions/Label.java @@ -7,21 +7,21 @@ package org.apache.fop.extensions; -import org.apache.fop.fo.*; +import org.apache.fop.fo.FONode; public class Label extends ExtensionObj { - private String _label = ""; + private String label = ""; public Label(FONode parent) { super(parent); } protected void addCharacters(char data[], int start, int end) { - _label += new String(data, start, end - start); + label += new String(data, start, end - start); } public String toString() { - return _label; + return label; } } diff --git a/src/org/apache/fop/extensions/Outline.java b/src/org/apache/fop/extensions/Outline.java index 48efad0f4..4f8236c3e 100644 --- a/src/org/apache/fop/extensions/Outline.java +++ b/src/org/apache/fop/extensions/Outline.java @@ -7,10 +7,7 @@ package org.apache.fop.extensions; -import org.apache.fop.fo.*; -import org.apache.fop.pdf.PDFGoTo; -import org.apache.fop.pdf.PDFAction; -import org.apache.fop.datatypes.IDReferences; +import org.apache.fop.fo.FONode; import org.apache.fop.apps.FOPException; import java.util.*; @@ -18,79 +15,51 @@ import java.util.*; import org.xml.sax.Attributes; public class Outline extends ExtensionObj { - private Label _label; - private ArrayList _outlines = new ArrayList(); + private Label label; + private ArrayList outlines = new ArrayList(); - private String _internalDestination; - private String _externalDestination; - - /** - * The parent outline object if it exists - */ - private Outline _parentOutline; - - /** - * an opaque renderer context object, e.g. PDFOutline for PDFRenderer - */ - private Object _rendererObject; + private String internalDestination; + private String externalDestination; public Outline(FONode parent) { super(parent); } public void handleAttrs(Attributes attlist) throws FOPException { - _internalDestination = - attlist.getValue(null, "internal-destination"); - _externalDestination = - attlist.getValue(null, "external-destination"); - if (_externalDestination != null &&!_externalDestination.equals("")) { + internalDestination = + attlist.getValue("internal-destination"); + externalDestination = + attlist.getValue("external-destination"); + if (externalDestination != null &&!externalDestination.equals("")) { log.warn("fox:outline external-destination not supported currently."); } - if (_internalDestination == null || _internalDestination.equals("")) { + if (internalDestination == null || internalDestination.equals("")) { log.warn("fox:outline requires an internal-destination."); } - for (FONode node = getParent(); node != null; - node = node.getParent()) { - if (node instanceof Outline) { - _parentOutline = (Outline)node; - break; - } - } - } protected void addChild(FONode obj) { if (obj instanceof Label) { - _label = (Label)obj; + label = (Label)obj; } else if (obj instanceof Outline) { - _outlines.add(obj); + outlines.add(obj); } } - public void setRendererObject(Object o) { - _rendererObject = o; - } - - public Object getRendererObject() { - return _rendererObject; - } - - public Outline getParentOutline() { - return _parentOutline; - } - - public Label getLabel() { - return _label == null ? new Label(this) : _label; - } - - public ArrayList getOutlines() { - return _outlines; + public BookmarkData getData() { + BookmarkData data = new BookmarkData(internalDestination); + data.setLabel(getLabel()); + for(int count = 0; count < outlines.size(); count++) { + Outline out = (Outline)outlines.get(count); + data.addSubData(out.getData()); + } + return data; } - public String getInternalDestination() { - return _internalDestination; + public String getLabel() { + return label == null ? "" : label.toString(); } } |