aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/documentation/content/xdocs/trunk/extensions.xml7
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java40
-rw-r--r--src/java/org/apache/fop/area/DestinationData.java17
-rw-r--r--src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java6
-rw-r--r--src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java6
-rw-r--r--src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java2
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRenderer.java29
-rw-r--r--src/java/org/apache/fop/util/XMLizable.java13
-rw-r--r--test/layoutengine/standard-testcases/fox_destination_1.xml61
9 files changed, 142 insertions, 39 deletions
diff --git a/src/documentation/content/xdocs/trunk/extensions.xml b/src/documentation/content/xdocs/trunk/extensions.xml
index 288695286..f54afea00 100644
--- a/src/documentation/content/xdocs/trunk/extensions.xml
+++ b/src/documentation/content/xdocs/trunk/extensions.xml
@@ -63,8 +63,7 @@
</section>
<section id="named-destinations">
<title>Anchors or Named Destinations</title>
- <p>This extension element hasn't been reimplemented for the redesigned code, yet.</p>
- <!--p>Use the fox:destination element to define "named destinations" inside a PDF document.
+ <p>Use the fox:destination element to define "named destinations" inside a PDF document.
These are useful as fragment identifiers, e.g. "http://server/document.pdf#anchor-name".
fox:destination elements can be placed almost anywhere in the fo document, including a child of
root, a block-level element, or an inline-level element.
@@ -77,7 +76,7 @@ PDF document. The fox:destination simply gives that view an independent name.
<fo:block id="table-of-contents">Table of Contents</fo:block>]]></source>
<warning>It is possible that in some future release of FOP, <em>all </em>elements with
"id" attributes will generate named-destinations, which will eliminate the need for
-fox:destination.</warning-->
+fox:destination.</warning>
</section>
<section id="table-continue-label">
<title>Table Continuation Label</title>
@@ -136,7 +135,7 @@ to following pages. Here is an example of FO code creating such a table-header:<
</p>
<p>
<code>
- (layout-master-set, declarations?, bookmark-tree?, (page-sequence|page-sequence-wrapper|fox:external-document)+)
+ (layout-master-set, declarations?, bookmark-tree?, (page-sequence|page-sequence-wrapper|fox:external-document|fox:destination)+)
</code>
</p>
<section>
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index aa499338b..b4a804712 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -36,16 +36,25 @@ import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.area.Trait.InternalLink;
import org.apache.fop.area.Trait.Background;
-import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.area.Trait.InternalLink;
import org.apache.fop.area.inline.AbstractTextArea;
import org.apache.fop.area.inline.Character;
import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
+import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.InlineBlockParent;
import org.apache.fop.area.inline.InlineParent;
import org.apache.fop.area.inline.Leader;
@@ -68,12 +77,6 @@ import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
import org.apache.fop.util.DefaultErrorListener;
import org.apache.fop.util.QName;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
/**
* This is a parser for the area tree XML (intermediate format) which is used to reread an area
@@ -179,6 +182,7 @@ public class AreaTreeParser {
makers.put("foreignObject", new ForeignObjectMaker());
makers.put("bookmarkTree", new BookmarkTreeMaker());
makers.put("bookmark", new BookmarkMaker());
+ makers.put("destination", new DestinationMaker());
}
private static Rectangle2D parseRect(String rect) {
@@ -922,6 +926,26 @@ public class AreaTreeParser {
}
}
+ private class DestinationMaker extends AbstractMaker {
+
+ public void startElement(Attributes attributes) {
+ String[] linkdata
+ = InternalLink.parseXMLAttribute(lastAttributes.getValue("internal-link"));
+ PageViewport pv = (PageViewport) pageViewportsByKey.get(linkdata[0]);
+ DestinationData dest = new DestinationData(linkdata[1]);
+ List pages = new java.util.ArrayList();
+ pages.add(pv);
+ dest.resolveIDRef(linkdata[1], pages);
+ areaStack.push(dest);
+ }
+
+ public void endElement() {
+ Object tos = areaStack.pop();
+ assertObjectOfClass(tos, DestinationData.class);
+ treeModel.handleOffDocumentItem((DestinationData) tos);
+ }
+ }
+
// ====================================================================
diff --git a/src/java/org/apache/fop/area/DestinationData.java b/src/java/org/apache/fop/area/DestinationData.java
index b23605972..2cff02ef4 100644
--- a/src/java/org/apache/fop/area/DestinationData.java
+++ b/src/java/org/apache/fop/area/DestinationData.java
@@ -22,7 +22,6 @@ package org.apache.fop.area;
import java.util.List;
import org.apache.fop.fo.extensions.destination.Destination;
-import org.apache.fop.area.PageViewport;
/**
* An instance of this class is named destination from fox:destination
*/
@@ -46,11 +45,19 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab
* @param destination the fo:bookmark object
*/
public DestinationData(Destination destination) {
- idRef = destination.getInternalDestination();
- idRefs = new String[] {idRef};
+ this(destination.getInternalDestination());
}
/**
+ * Create a new named destination.
+ * @param idRef the id reference of the destination
+ */
+ public DestinationData(String idRef) {
+ this.idRef = idRef;
+ this.idRefs = new String[] {idRef};
+ }
+
+ /**
* Get the idref for this destination
*
* @return the idref for the destination
@@ -99,9 +106,7 @@ public class DestinationData extends AbstractOffDocumentItem implements Resolvab
// TODO get rect area of id on page
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String getName() {
return "Destination";
}
diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
index ca568028e..91ab2dfa5 100644
--- a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
+++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
@@ -21,12 +21,14 @@ package org.apache.fop.render.afp.extensions;
import java.io.Serializable;
-import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.util.XMLizable;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.xmlgraphics.util.XMLizable;
+
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+
/**
* This is the pass-through value object for the PostScript extension.
*/
diff --git a/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java b/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
index 0fb623bdc..80a2aeee3 100644
--- a/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
+++ b/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
@@ -19,12 +19,14 @@
package org.apache.fop.render.ps.extensions;
-import org.apache.fop.fo.extensions.ExtensionAttachment;
-import org.apache.fop.util.XMLizable;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.xmlgraphics.util.XMLizable;
+
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+
/**
* This is the pass-through value object for the PostScript extension.
*/
diff --git a/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java b/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
index 5684ba6a3..da84f97a2 100644
--- a/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
+++ b/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
@@ -96,7 +96,7 @@ public class PSSetPageDevice extends PSExtensionAttachment {
* Generates SAX events representing the object's state.
* @param handler ContentHandler instance to send the SAX events to
* @throws SAXException if there's a problem generating the SAX events
- * @see org.apache.fop.util.XMLizable#toSAX(org.xml.sax.ContentHandler)
+ * @see org.apache.xmlgraphics.util.XMLizable#toSAX(org.xml.sax.ContentHandler)
*/
public void toSAX(ContentHandler handler) throws SAXException {
AttributesImpl atts = new AttributesImpl();
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index b969afac1..213cba58d 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -41,7 +41,8 @@ import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
-import org.apache.fop.util.QName;
+import org.apache.xmlgraphics.util.XMLizable;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
@@ -51,21 +52,22 @@ import org.apache.fop.area.BeforeFloat;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.BodyRegion;
+import org.apache.fop.area.BookmarkData;
import org.apache.fop.area.CTM;
+import org.apache.fop.area.DestinationData;
import org.apache.fop.area.Footnote;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.MainReference;
import org.apache.fop.area.NormalFlow;
import org.apache.fop.area.OffDocumentExtensionAttachment;
import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.area.BookmarkData;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.RegionReference;
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Span;
import org.apache.fop.area.Trait;
-import org.apache.fop.area.Trait.InternalLink;
import org.apache.fop.area.Trait.Background;
+import org.apache.fop.area.Trait.InternalLink;
import org.apache.fop.area.inline.Container;
import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
@@ -87,7 +89,7 @@ import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.XMLHandler;
import org.apache.fop.util.ColorUtil;
-import org.apache.fop.util.XMLizable;
+import org.apache.fop.util.QName;
/**
* Renderer that renders areas to XML for debugging purposes.
@@ -419,6 +421,8 @@ public class XMLRenderer extends PrintRenderer {
public void processOffDocumentItem(OffDocumentItem oDI) {
if (oDI instanceof BookmarkData) {
renderBookmarkTree((BookmarkData) oDI);
+ } else if (oDI instanceof DestinationData) {
+ renderDestination((DestinationData) oDI);
} else if (oDI instanceof OffDocumentExtensionAttachment) {
ExtensionAttachment attachment = ((OffDocumentExtensionAttachment)oDI).getAttachment();
if (extensionAttachments == null) {
@@ -466,8 +470,23 @@ public class XMLRenderer extends PrintRenderer {
}
/**
- * {@inheritDoc}
+ * Renders a DestinationData object (named destination)
+ * @param destination the destination object
*/
+ protected void renderDestination(DestinationData destination) {
+ if (destination.getWhenToProcess() == OffDocumentItem.END_OF_DOC) {
+ endPageSequence();
+ }
+ atts.clear();
+ PageViewport pv = destination.getPageViewport();
+ String pvKey = pv == null ? null : pv.getKey();
+ addAttribute("internal-link",
+ InternalLink.makeXMLAttribute(pvKey, destination.getIDRef()));
+ startElement("destination", atts);
+ endElement("destination");
+ }
+
+ /** {@inheritDoc} */
public void startRenderer(OutputStream outputStream)
throws IOException {
log.debug("Rendering areas to Area Tree XML");
diff --git a/src/java/org/apache/fop/util/XMLizable.java b/src/java/org/apache/fop/util/XMLizable.java
index c1213638b..a16131989 100644
--- a/src/java/org/apache/fop/util/XMLizable.java
+++ b/src/java/org/apache/fop/util/XMLizable.java
@@ -25,20 +25,11 @@ package org.apache.fop.util;
* src/java/org/apache/excalibur/xml/sax/XMLizable.java
*/
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
/**
* This interface can be implemented by classes willing to provide an XML representation
* of their current state as SAX events.
+ * @deprecated Use the interface in Apache XML Graphics Commons instead.
*/
-public interface XMLizable {
-
- /**
- * Generates SAX events representing the object's state.
- * @param handler ContentHandler instance to send the SAX events to
- * @throws SAXException if there's a problem generating the SAX events
- */
- void toSAX(ContentHandler handler) throws SAXException;
+public interface XMLizable extends org.apache.xmlgraphics.util.XMLizable {
}
diff --git a/test/layoutengine/standard-testcases/fox_destination_1.xml b/test/layoutengine/standard-testcases/fox_destination_1.xml
new file mode 100644
index 000000000..a5c6b15f7
--- /dev/null
+++ b/test/layoutengine/standard-testcases/fox_destination_1.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+ <info>
+ <p>
+ This test checks the basics of fox:destination.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fox:destination internal-destination="chapter1"/>
+ <fox:destination internal-destination="chapter2"/>
+ <fox:destination internal-destination="chapter2-sec1"/>
+
+ <fo:page-sequence id="page-sequence" master-reference="normal">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block id="chapter1" font-weight="bold" font-size="larger">Chapter 1</fo:block>
+ <fo:block>Blah blah bla.</fo:block>
+ <fo:block id="chapter2" font-weight="bold" font-size="larger" break-before="page">Chapter 2</fo:block>
+ <fo:block>Blah blah bla.</fo:block>
+ <fo:block id="chapter2-sec1" font-weight="bold">Section 1</fo:block>
+ <fo:block>Blah blah bla.</fo:block>
+ <fo:block id="chapter2-sec2" font-weight="bold"><fox:destination internal-destination="chapter2-sec2"/>Section 2</fo:block>
+ <fo:block>Blah blah bla.</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <eval expected="1" xpath="count(/areaTree/pageSequence)"/>
+ <eval expected="2" xpath="count(//pageViewport)"/>
+
+ <eval expected="4" xpath="count(//destination)"/>
+ <eval expected="(P1,chapter1)" xpath="//destination[1]/@internal-link"/>
+ <eval expected="(P2,chapter2)" xpath="//destination[2]/@internal-link"/>
+ <eval expected="(P2,chapter2-sec1)" xpath="//destination[3]/@internal-link"/>
+ <eval expected="(P2,chapter2-sec2)" xpath="//destination[4]/@internal-link"/>
+ </checks>
+</testcase>