]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Reenabled documentation for fox:destination.
authorJeremias Maerki <jeremias@apache.org>
Mon, 7 Jan 2008 10:52:09 +0000 (10:52 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 7 Jan 2008 10:52:09 +0000 (10:52 +0000)
Enabled intermediate format functionality for fox:destination.
Added a test case to check fox:destination.
Deprecated FOP's XMLizable in favor of the XML Graphics Commons variant (and extend that variant).

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@609567 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/trunk/extensions.xml
src/java/org/apache/fop/area/AreaTreeParser.java
src/java/org/apache/fop/area/DestinationData.java
src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
src/java/org/apache/fop/render/xml/XMLRenderer.java
src/java/org/apache/fop/util/XMLizable.java
test/layoutengine/standard-testcases/fox_destination_1.xml [new file with mode: 0644]

index 288695286b15ea2a969e713dedaf2c5d62db4968..f54afea00eb16de3c2d5ce2ed353fbe1661a3680 100644 (file)
@@ -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>
index aa499338b773bf717e1aac01253aed146e6eeb2f..b4a804712a83b52de2788c4f17a44034f1994ec8 100644 (file)
@@ -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);
+            }
+        }
+
         // ====================================================================
 
 
index b2360597273525a7cf9ba2c7daaef547e094458c..2cff02ef49995ce706dc51d36328716dc4ddb7ca 100644 (file)
@@ -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,10 +45,18 @@ 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
      *
@@ -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";
     }
index ca568028e251832f1095cd905a6426b968dac604..91ab2dfa5652afd1e2c2aa214f8a8f86e62371ec 100644 (file)
@@ -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.
  */
index 0fb623bdcc814c47632ddaab4a711af6d5428905..80a2aeee31871df12ffb09811e44d64a669e3427 100644 (file)
 \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
index 5684ba6a34afa7e358e8a0ff4ef4d11f55ea765a..da84f97a22b2904836c9fce0815c0047a8356ab3 100644 (file)
@@ -96,7 +96,7 @@ public class PSSetPageDevice extends PSExtensionAttachment {
      * 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
index b969afac1d195c2c8c0a8ffe31a5003d662bcc4b..213cba58dea1627404fa9614588bbe7abf17756c 100644 (file)
@@ -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");
index c1213638b8f4d3d0e3f8609de52781564cf6f594..a16131989fb26ac4fbfc8c7666daf3d6b3db84f3 100644 (file)
@@ -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 (file)
index 0000000..a5c6b15
--- /dev/null
@@ -0,0 +1,61 @@
+<?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