diff options
-rw-r--r-- | src/org/apache/fop/pdf/Makefile | 6 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFAction.java | 100 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFAnnotList.java | 125 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFDocument.java | 32 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFFileSpec.java | 98 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFLink.java | 124 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFPage.java | 44 |
7 files changed, 515 insertions, 14 deletions
diff --git a/src/org/apache/fop/pdf/Makefile b/src/org/apache/fop/pdf/Makefile index 111ac16ed..7ebce2a15 100644 --- a/src/org/apache/fop/pdf/Makefile +++ b/src/org/apache/fop/pdf/Makefile @@ -5,9 +5,13 @@ include $(BASEDIR)/Makefile.rules SUBDIRS= -SOURCES=PDFDocument.java \ +SOURCES=PDFAction.java \ + PDFAnnotList.java \ + PDFDocument.java \ + PDFFileSpec.java \ PDFFont.java \ PDFInfo.java \ + PDFLink.java \ PDFObject.java \ PDFPage.java \ PDFPages.java \ diff --git a/src/org/apache/fop/pdf/PDFAction.java b/src/org/apache/fop/pdf/PDFAction.java new file mode 100644 index 000000000..2fa668599 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFAction.java @@ -0,0 +1,100 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ + +package org.apache.fop.pdf; + +/** + * class representing a /Action object. + */ +public class PDFAction extends PDFObject { + + /** the file specification */ + protected PDFFileSpec fileSpec; + + /** + * create an /Action object. + * + * @param number the object's number + * @param fileSpec the fileSpec associated with the action + */ + public PDFAction(int number, PDFFileSpec fileSpec) { + + /* generic creation of object */ + super(number); + + this.fileSpec = fileSpec; + } + + /** + * represent the object in PDF + * + * @return the PDF string + */ + public String toPDF() { + String p = new String(this.number + " " + this.generation + + " obj\n" + + "<<\n/S /GoToR\n" + + "/F " + fileSpec.referencePDF() + "\n" + + "/D [ 0 /XYZ null null null ]" + + " \n>>\nendobj\n"); + return p; + } + + /* example + 28 0 obj + << + /S /GoToR + /F 29 0 R + /D [ 0 /XYZ -6 797 null ] + >> + endobj + */ +} diff --git a/src/org/apache/fop/pdf/PDFAnnotList.java b/src/org/apache/fop/pdf/PDFAnnotList.java new file mode 100644 index 000000000..66bc79449 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFAnnotList.java @@ -0,0 +1,125 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ + +package org.apache.fop.pdf; + +// Java +import java.util.Vector; + +/** + * class representing an object which is a list of annotations. + * + * This PDF object is a list of references to /Annot objects. So far we + * are dealing only with links. + */ +public class PDFAnnotList extends PDFObject { + + /** the /Annot objects */ + protected Vector links = new Vector(); + + /** the number of /Annot objects */ + protected int count = 0; + + /** + * create a /Annots object. + * + * @param number the object's number + */ + public PDFAnnotList(int number) { + + /* generic creation of object */ + super(number); + } + + /** + * add an /Annot object of /Subtype /Link. + * + * @param link the PDFLink to add. + */ + public void addLink(PDFLink link) { + this.links.addElement(link); + this.count++; + } + + /** + * get the count of /Annot objects + * + * @return the number of links + */ + public int getCount() { + return this.count; + } + + /** + * represent the object in PDF + * + * @return the PDF string + */ + public String toPDF() { + StringBuffer p = new StringBuffer(this.number + " " + + this.generation + + " obj\n[\n"); + for (int i = 0; i < this.count; i++) { + p = p.append(((PDFObject) + links.elementAt(i)).referencePDF() + "\n"); + } + p = p.append("]\nendobj\n"); + return p.toString(); + } + + /* example + 20 0 obj + [ + 19 0 R + ] + endobj + */ +} diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 042f8b1a8..f8e454c04 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -22,7 +22,7 @@ Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to + 4. The names "FOP" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. @@ -48,6 +48,7 @@ Software Foundation, please see <http://www.apache.org/>. */ + /* image support modified from work of BoBoGi */ package org.apache.fop.pdf; @@ -60,6 +61,7 @@ import org.apache.fop.image.FopImage; import java.io.IOException; import java.io.PrintWriter; import java.util.Vector; +import java.awt.Rectangle; /** * class representing a PDF document. @@ -103,7 +105,10 @@ public class PDFDocument { /** the /Resources object */ protected PDFResources resources; + /** the counter for XObject numbering */ protected int xObjectCount = 0; + + /** the XObjects */ protected Vector xObjects = new Vector(); /** @@ -211,6 +216,7 @@ public class PDFDocument { * @param contents stream object with content * @param pagewidth width of the page in points * @param pageheight height of the page in points + * * @return the created /Page object */ public PDFPage makePage(PDFResources resources, @@ -232,6 +238,30 @@ public class PDFDocument { } /** + * make a link object + * + * @param rect the clickable rectangle + * @param destination the destination file + * + * @return the PDFLink object created + */ + public PDFLink makeLink(Rectangle rect, String destination) { + PDFLink link = new PDFLink(++this.objectcount, destination, rect); + this.objects.addElement(link); + + PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, + link.destination); + this.objects.addElement(fileSpec); + + PDFAction action = new PDFAction(++this.objectcount, + fileSpec); + this.objects.addElement(action); + link.setAction(action); + + return link; + } + + /** * make a stream object * * @return the stream object created diff --git a/src/org/apache/fop/pdf/PDFFileSpec.java b/src/org/apache/fop/pdf/PDFFileSpec.java new file mode 100644 index 000000000..f588b9c40 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFFileSpec.java @@ -0,0 +1,98 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ + +package org.apache.fop.pdf; + +/** + * class representing a /FileSpec object. + * + */ +public class PDFFileSpec extends PDFObject { + + /** the filename */ + protected String filename; + + /** + * create a /FileSpec object. + * + * @param number the object's number + * @param filename the filename represented by this object + */ + public PDFFileSpec(int number, String filename) { + + /* generic creation of object */ + super(number); + + this.filename = filename; + } + + /** + * represent the object in PDF + * + * @return the PDF string + */ + public String toPDF() { + String p = new String(this.number + " " + this.generation + + " obj\n<<\n/Type /FileSpec\n" + + "/F (" + this.filename + ")\n" + + ">>\nendobj\n"); + return p; + } + + /* example + 29 0 obj + << + /Type /FileSpec + /F (table1.pdf) + >> + endobj + */ +} diff --git a/src/org/apache/fop/pdf/PDFLink.java b/src/org/apache/fop/pdf/PDFLink.java new file mode 100644 index 000000000..5d847d0f2 --- /dev/null +++ b/src/org/apache/fop/pdf/PDFLink.java @@ -0,0 +1,124 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber <jtauber@jtauber.com>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + + */ + +package org.apache.fop.pdf; + +// Java +import java.awt.Rectangle; + +/** + * class representing an /Annot object of /Subtype /Link + */ +public class PDFLink extends PDFObject { + + float ulx; + float uly; + float brx; + float bry; + String destination; + String color; + PDFAction action; + + /** + * create objects associated with a link annotation (GoToR) + * + * @param number the object's number + * @param producer the application producing the PDF + */ + public PDFLink(int number, String destName, Rectangle r) { + /* generic creation of PDF object */ + super(number); + + this.ulx = r.x; + this.uly = r.y; + this.brx = r.x + r.width; + this.bry = r.y - r.height; + this.destination = destName; // what is this for? + this.color = "0 0 0.7"; // just for now + + } + + public void setAction(PDFAction action) { + this.action = action; + } + + /** + * produce the PDF representation of the object + * + * @return the PDF + */ + public String toPDF() { + String p = this.number + " " + this.generation + " obj\n" + + "<< /Type /Annot\n" + + "/Subtype /Link\n" + + "/Rect [ " + (ulx/1000f) + " " + (uly/1000f) + " " + + (brx/1000f) + " " + (bry/1000f) + " ]\n" + + "/C [ " + color + " ]\n" + + "/Border [ 0 0 1 ]\n" + + "/A " + action.referencePDF() + "\n" + + "/H /I\n>>\nendobj\n"; + return p; + } + + /* example + 19 0 obj + << + /Type /Annot + /Subtype /Link + /Rect [ 176.032 678.48412 228.73579 692.356 ] + /C [ 0.86491 0.03421 0.02591 ] + /Border [ 0 0 1 ] + /A 28 0 R + /H /I + >> + endobj + */ +} diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index 9242da03e..5d623d735 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -22,7 +22,7 @@ Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to + 4. The names "FOP" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. @@ -50,10 +50,6 @@ */ package org.apache.fop.pdf; -// Java -import java.io.PrintWriter; -import java.util.Vector; - /** * class representing a /Page object. * @@ -79,6 +75,9 @@ public class PDFPage extends PDFObject { /** the height of the page in points */ protected int pageheight; + /** the list of annotation objects for this page */ + protected PDFAnnotList annotList; + /** * create a /Page object * @@ -100,6 +99,8 @@ public class PDFPage extends PDFObject { this.contents = contents; this.pagewidth = pagewidth; this.pageheight = pageheight; + + this.annotList = null; } /** @@ -112,17 +113,36 @@ public class PDFPage extends PDFObject { } /** + * set this page's annotation list + * + * @param annotList a PDFAnnotList list of annotations + */ + public void setAnnotList(PDFAnnotList annotList) { + this.annotList = annotList; + } + + /** * represent this object as PDF * * @return the PDF string */ public String toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Page\n/Parent " - + this.parent.referencePDF() + "\n/MediaBox [ 0 0 " - + this.pagewidth + " " + this.pageheight + " ]\n/Resources " - + this.resources.referencePDF() + "\n/Contents " - + this.contents.referencePDF() + " >>\nendobj\n"; - return p; + StringBuffer sb = new StringBuffer(); + + sb = sb.append(this.number + " " + this.generation + " obj\n" + + "<< / Type /Page\n" + + "/Parent " + this.parent.referencePDF() + "\n" + + "/MediaBox [ 0 0 " + this.pagewidth + " " + + this.pageheight + " ]\n" + + "/Resources " + this.resources.referencePDF() + "\n" + + "/Contents " + this.contents.referencePDF() + "\n"); + if (this.annotList != null) { + sb = sb.append("/Annots " + + this.annotList.referencePDF() + "\n"); + } + + sb = sb.append(">>\nendobj\n"); + + return sb.toString(); } } |