</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.
<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>
</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>
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;
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
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) {
}
}
+ 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);
+ }
+ }
+
// ====================================================================
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
*/
* @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
*
// TODO get rect area of id on page
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String getName() {
return "Destination";
}
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.
*/
\r
package org.apache.fop.render.ps.extensions;\r
\r
-import org.apache.fop.fo.extensions.ExtensionAttachment;\r
-import org.apache.fop.util.XMLizable;\r
import org.xml.sax.ContentHandler;\r
import org.xml.sax.SAXException;\r
import org.xml.sax.helpers.AttributesImpl;\r
\r
+import org.apache.xmlgraphics.util.XMLizable;\r
+\r
+import org.apache.fop.fo.extensions.ExtensionAttachment;\r
+\r
/**\r
* This is the pass-through value object for the PostScript extension.\r
*/\r
* Generates SAX events representing the object's state.\r
* @param handler ContentHandler instance to send the SAX events to\r
* @throws SAXException if there's a problem generating the SAX events\r
- * @see org.apache.fop.util.XMLizable#toSAX(org.xml.sax.ContentHandler)\r
+ * @see org.apache.xmlgraphics.util.XMLizable#toSAX(org.xml.sax.ContentHandler)\r
*/\r
public void toSAX(ContentHandler handler) throws SAXException {\r
AttributesImpl atts = new AttributesImpl();\r
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;
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;
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.
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) {
}
/**
- * {@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");
* 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 {
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+-->\r
+<!-- $Id$ -->\r
+<testcase>\r
+ <info>\r
+ <p>\r
+ This test checks the basics of fox:destination.\r
+ </p>\r
+ </info>\r
+ <fo>\r
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"\r
+ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">\r
+ <fo:layout-master-set>\r
+ <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">\r
+ <fo:region-body/>\r
+ </fo:simple-page-master>\r
+ </fo:layout-master-set>\r
+ <fox:destination internal-destination="chapter1"/>\r
+ <fox:destination internal-destination="chapter2"/>\r
+ <fox:destination internal-destination="chapter2-sec1"/>\r
+ \r
+ <fo:page-sequence id="page-sequence" master-reference="normal">\r
+ <fo:flow flow-name="xsl-region-body">\r
+ <fo:block id="chapter1" font-weight="bold" font-size="larger">Chapter 1</fo:block>
+ <fo:block>Blah blah bla.</fo:block>\r
+ <fo:block id="chapter2" font-weight="bold" font-size="larger" break-before="page">Chapter 2</fo:block>\r
+ <fo:block>Blah blah bla.</fo:block>\r
+ <fo:block id="chapter2-sec1" font-weight="bold">Section 1</fo:block>\r
+ <fo:block>Blah blah bla.</fo:block>\r
+ <fo:block id="chapter2-sec2" font-weight="bold"><fox:destination internal-destination="chapter2-sec2"/>Section 2</fo:block>\r
+ <fo:block>Blah blah bla.</fo:block>\r
+ </fo:flow>\r
+ </fo:page-sequence>\r
+ </fo:root>\r
+ </fo>\r
+ <checks>\r
+ <eval expected="1" xpath="count(/areaTree/pageSequence)"/>\r
+ <eval expected="2" xpath="count(//pageViewport)"/>\r
+
+ <eval expected="4" xpath="count(//destination)"/>\r
+ <eval expected="(P1,chapter1)" xpath="//destination[1]/@internal-link"/>\r
+ <eval expected="(P2,chapter2)" xpath="//destination[2]/@internal-link"/>\r
+ <eval expected="(P2,chapter2-sec1)" xpath="//destination[3]/@internal-link"/>\r
+ <eval expected="(P2,chapter2-sec2)" xpath="//destination[4]/@internal-link"/>\r
+ </checks>\r
+</testcase>\r