You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/01/07 11:52:12 UTC

svn commit: r609567 - in /xmlgraphics/fop/trunk: src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/area/ src/java/org/apache/fop/render/afp/extensions/ src/java/org/apache/fop/render/ps/extensions/ src/java/org/apache/fop/render/xml/ src/j...

Author: jeremias
Date: Mon Jan  7 02:52:09 2008
New Revision: 609567

URL: http://svn.apache.org/viewvc?rev=609567&view=rev
Log:
Reenabled documentation for fox:destination.
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).

Added:
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/extensions.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/DestinationData.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLizable.java

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/extensions.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/extensions.xml?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/extensions.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/extensions.xml Mon Jan  7 02:52:09 2008
@@ -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 @@
 <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 @@
         </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>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java Mon Jan  7 02:52:09 2008
@@ -36,16 +36,25 @@
 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.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 @@
             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) {
@@ -919,6 +923,26 @@
 
             public void endElement() {
                 assertObjectOfClass(areaStack.pop(), BookmarkData.class);
+            }
+        }
+
+        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);
             }
         }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/DestinationData.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/DestinationData.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/DestinationData.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/DestinationData.java Mon Jan  7 02:52:09 2008
@@ -22,7 +22,6 @@
 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 @@
      * @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 @@
         // TODO get rect area of id on page
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public String getName() {
         return "Destination";
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java Mon Jan  7 02:52:09 2008
@@ -21,11 +21,13 @@
 
 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.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSExtensionAttachment.java Mon Jan  7 02:52:09 2008
@@ -19,11 +19,13 @@
 
 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.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/extensions/PSSetPageDevice.java Mon Jan  7 02:52:09 2008
@@ -96,7 +96,7 @@
      * 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();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java Mon Jan  7 02:52:09 2008
@@ -41,7 +41,8 @@
 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.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.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 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 @@
     }
 
     /**
-     * {@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");

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLizable.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLizable.java?rev=609567&r1=609566&r2=609567&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLizable.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLizable.java Mon Jan  7 02:52:09 2008
@@ -25,20 +25,11 @@
  *                                           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 {
     
 }

Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml?rev=609567&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml Mon Jan  7 02:52:09 2008
@@ -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>

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_destination_1.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org