diff options
author | Jeremias Maerki <jeremias@apache.org> | 2003-03-11 13:25:33 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2003-03-11 13:25:33 +0000 |
commit | 77930a96151d680333f3c11b8dcb5f7c9b6761e7 (patch) | |
tree | 2bd2afef42926ee98914666ef27ae08ef0c98edd /src/org/apache/fop/pdf | |
parent | b7052c02f1a0da7b6d2c04a799e947e8f9227d81 (diff) | |
download | xmlgraphics-fop-77930a96151d680333f3c11b8dcb5f7c9b6761e7.tar.gz xmlgraphics-fop-77930a96151d680333f3c11b8dcb5f7c9b6761e7.zip |
Moved sources from src/org/** to src/java/org/**
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196064 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/pdf')
61 files changed, 0 insertions, 13785 deletions
diff --git a/src/org/apache/fop/pdf/ASCII85Filter.java b/src/org/apache/fop/pdf/ASCII85Filter.java deleted file mode 100644 index f19bccce6..000000000 --- a/src/org/apache/fop/pdf/ASCII85Filter.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.OutputStream; -import java.io.InputStream; -import java.io.IOException; - -/** - * PDF Filter for ASCII85. - * This applies a filter to a pdf stream that converts - * the data to ASCII. - */ -public class ASCII85Filter extends PDFFilter { - private static final char ASCII85_ZERO = 'z'; - private static final char ASCII85_START = '!'; - private static final String ASCII85_EOD = "~>"; - - private static final long BASE85_4 = 85; - //private static final long base85_3 = base85_4 * base85_4; - //private static final long base85_2 = base85_3 * base85_4; - //private static final long base85_1 = base85_2 * base85_4; - - /** - * Get the PDF name of this filter. - * - * @return the name of the filter to be inserted into the PDF - */ - public String getName() { - return "/ASCII85Decode"; - } - - /** - * Get the decode parameters. - * - * @return always null - */ - public String getDecodeParms() { - return null; - } - - /** - * Encode a pdf stream using this filter. - * - * @param in the input stream to read the data from - * @param out the output stream to write the data - * @param length the length of the data to filter - * @throws IOException if there is an error reading or writing to the streams - */ - public void encode(InputStream in, OutputStream out, int length) throws IOException { - - int i; - int total = 0; - int diff = 0; - - // first encode the majority of the data - // each 4 byte group becomes a 5 byte group - for (i = 0; i + 3 < length; i += 4) { - - long val = ((in.read() << 24) - & 0xff000000L) // note: must have the L at the - + ((in.read() << 16) & 0xff0000L) // end, otherwise you get into - + ((in.read() << 8) & 0xff00L) // weird signed value problems - + (in.read() & 0xffL); // cause we're using a full 32 bits - byte[] conv = convertWord(val); - - out.write(conv, 0, conv.length); - - } - - // now take care of the trailing few bytes. - // with n leftover bytes, we append 0 bytes to make a full group of 4 - // then convert like normal (except not applying the special zero rule) - // and write out the first n+1 bytes from the result - if (i < length) { - int n = length - i; - byte[] lastdata = new byte[4]; - for (int j = 0; j < 4; j++) { - if (j < n) { - lastdata[j] = (byte)in.read(); - } else { - lastdata[j] = 0; - } - } - - long val = ((lastdata[0] << 24) & 0xff000000L) - + ((lastdata[1] << 16) & 0xff0000L) - + ((lastdata[2] << 8) & 0xff00L) - + (lastdata[3] & 0xffL); - byte[] conv = convertWord(val); - - // special rule for handling zeros at the end - if (val == 0) { - conv = new byte[5]; - for (int j = 0; j < 5; j++) { - conv[j] = (byte)'!'; - } - } - // assert n+1 <= 5 - out.write(conv, 0, n + 1); - // System.out.println("ASCII85 end of data was "+n+" bytes long"); - - } - // finally write the two character end of data marker - out.write(ASCII85_EOD.getBytes(), 0, - ASCII85_EOD.getBytes().length); - - - // assert that we have the correct outgoing length - /* - * int in = (data.length % 4); - * int out = (result.length-ASCII85_EOD.getBytes().length) % 5; - * if ((in+1 != out) && !(in == 0 && out == 0)) { - * System.out.println("ASCII85 assertion failed:"); - * System.out.println("inlength = "+data.length+" inlength % 4 = " - * + (data.length % 4)+" outlength = " - * + (result.length-ASCII85_EOD.getBytes().length) - * + " outlength % 5 = " - * + ((result.length-ASCII85_EOD.getBytes().length) % 5)); - * } - */ - - out.close(); - } - - /** - * This converts a 32 bit value (4 bytes) into 5 bytes using base 85. - * each byte in the result starts with zero at the '!' character so - * the resulting base85 number fits into printable ascii chars - * - * @param word the 32 bit unsigned (hence the long datatype) word - * @return 5 bytes (or a single byte of the 'z' character for word - * values of 0) - */ - private byte[] convertWord(long word) { - word = word & 0xffffffff; - if (word < 0) { - word = -word; - } - - if (word == 0) { - byte[] result = { - (byte)ASCII85_ZERO - }; - return result; - } else { - /* - byte c1 = (byte)((word / base85_1) & 0xFF); - byte c2 = (byte)(((word - (c1 * base85_1)) / base85_2) & 0xFF); - byte c3 = - (byte)(((word - (c1 * base85_1) - (c2 * base85_2)) / base85_3) - & 0xFF); - byte c4 = (byte)(((word - (c1 * base85_1) - - (c2 * base85_2) - (c3 * base85_3)) / base85_4) - & 0xFF); - byte c5 = (byte)(((word - (c1 * base85_1) - - (c2 * base85_2) - (c3 * base85_3) - (c4 * base85_4))) - & 0xFF); - - byte[] ret = { - (byte)(c1 + ASCII85_START), (byte)(c2 + ASCII85_START), - (byte)(c3 + ASCII85_START), (byte)(c4 + ASCII85_START), - (byte)(c5 + ASCII85_START) - }; - */ - - byte c5 = (byte)((word % BASE85_4) + ASCII85_START); - word = word / BASE85_4; - byte c4 = (byte)((word % BASE85_4) + ASCII85_START); - word = word / BASE85_4; - byte c3 = (byte)((word % BASE85_4) + ASCII85_START); - word = word / BASE85_4; - byte c2 = (byte)((word % BASE85_4) + ASCII85_START); - word = word / BASE85_4; - byte c1 = (byte)((word % BASE85_4) + ASCII85_START); - - byte[] ret = { - c1 , c2, c3, c4, c5 - }; - - for (int i = 0; i < ret.length; i++) { - if (ret[i] < 33 || ret[i] > 117) { - System.out.println("illegal char value " - + new Integer(ret[i])); - } - } - - return ret; - - - } - } - -} diff --git a/src/org/apache/fop/pdf/ASCIIHexFilter.java b/src/org/apache/fop/pdf/ASCIIHexFilter.java deleted file mode 100644 index 639851a4d..000000000 --- a/src/org/apache/fop/pdf/ASCIIHexFilter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.OutputStream; -import java.io.InputStream; -import java.io.Writer; -import java.io.OutputStreamWriter; -import java.io.IOException; - -/** - * ASCII Hex filter for PDF streams. - * This filter converts a pdf stream to ASCII hex data. - */ -public class ASCIIHexFilter extends PDFFilter { - private static final String ASCIIHEX_EOD = ">"; - - /** - * Get the name of this filter. - * - * @return the name of this filter for pdf - */ - public String getName() { - return "/ASCIIHexDecode"; - } - - /** - * Get the decode params. - * - * @return always null - */ - public String getDecodeParms() { - return null; - } - - /** - * Encode the pdf stream using this filter. - * - * @param in the input stream to read the data from - * @param out the output stream to write data to - * @param length the length of data to read from the stream - * @throws IOException if an error occurs reading or writing to - * the streams - */ - public void encode(InputStream in, OutputStream out, int length) throws IOException { - Writer writer = new OutputStreamWriter(out); - for (int i = 0; i < length; i++) { - int val = (int)(in.read() & 0xFF); - if (val < 16) { - writer.write("0"); - } - writer.write(Integer.toHexString(val)); - } - writer.write(ASCIIHEX_EOD); - writer.close(); - } - -} diff --git a/src/org/apache/fop/pdf/BitmapImage.java b/src/org/apache/fop/pdf/BitmapImage.java deleted file mode 100644 index f908340cc..000000000 --- a/src/org/apache/fop/pdf/BitmapImage.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.IOException; -import java.util.Map; - -/** - * Bitmap image. - * This is used to create a bitmap image that will be inserted - * into pdf. - */ -public class BitmapImage implements PDFImage { - private int height; - private int width; - private int bitsPerPixel; - private PDFColorSpace colorSpace; - private byte[] bitmaps; - private String maskRef; - private PDFColor transparent = null; - private String key; - private Map filters; - - /** - * Create a bitmap image. - * Creates a new bitmap image with the given data. - * - * @param k the key to be used to lookup the image - * @param width the width of the image - * @param height the height of the image - * @param data the bitmap data - * @param mask the transparancy mask reference if any - */ - public BitmapImage(String k, int width, int height, byte[] data, - String mask) { - this.key = k; - this.height = height; - this.width = width; - this.bitsPerPixel = 8; - this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - this.bitmaps = data; - maskRef = mask; - } - - /** - * Setup this image with the pdf document. - * - * @param doc the pdf document this will be inserted into - */ - public void setup(PDFDocument doc) { - filters = doc.getFilterMap(); - } - - /** - * Get the key for this image. - * This key is used by the pdf document so that it will only - * insert an image once. All other references to the same image - * will use the same XObject reference. - * - * @return the unique key to identify this image - */ - public String getKey() { - return key; - } - - /** - * Get the width of this image. - * - * @return the width of the image - */ - public int getWidth() { - return width; - } - - /** - * Get the height of this image. - * - * @return the height of the image - */ - public int getHeight() { - return height; - } - - /** - * Set the color space for this image. - * - * @param cs the pdf color space - */ - public void setColorSpace(PDFColorSpace cs) { - colorSpace = cs; - } - - /** - * Get the color space for the image data. - * Possible options are: DeviceGray, DeviceRGB, or DeviceCMYK - * - * @return the pdf doclor space - */ - public PDFColorSpace getColorSpace() { - return colorSpace; - } - - /** - * Get the number of bits per pixel. - * - * @return the number of bits per pixel - */ - public int getBitsPerPixel() { - return bitsPerPixel; - } - - /** - * Set the transparent color for this iamge. - * - * @param t the transparent color - */ - public void setTransparent(PDFColor t) { - transparent = t; - } - - /** - * Check if this image has a transparent color. - * - * @return true if it has a transparent color - */ - public boolean isTransparent() { - return transparent != null; - } - - /** - * Get the transparent color for this image. - * - * @return the transparent color if any - */ - public PDFColor getTransparentColor() { - return transparent; - } - - /** - * Get the bitmap mask reference for this image. - * Current not supported. - * - * @return the bitmap mask reference - */ - public String getMask() { - return null; - } - - /** - * Get the soft mask reference for this image. - * - * @return the soft mask reference if any - */ - public String getSoftMask() { - return maskRef; - } - - /** - * Get the pdf data stream for the bitmap data. - * - * @return a pdf stream containing the filtered image data - * @throws IOException if there is an error handling the data - */ - public PDFStream getDataStream() throws IOException { - // delegate the stream work to PDFStream - PDFStream imgStream = new PDFStream(0); - - imgStream.setData(bitmaps); - - imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); - return imgStream; - } - - /** - * Get the ICC stream. - * @return always returns null since this has no icc color space - */ - public PDFICCStream getICCStream() { - return null; - } - - /** - * Check if this is a postscript image. - * @return always returns false - */ - public boolean isPS() { - return false; - } -} - - diff --git a/src/org/apache/fop/pdf/DCTFilter.java b/src/org/apache/fop/pdf/DCTFilter.java deleted file mode 100644 index 1ff1bb270..000000000 --- a/src/org/apache/fop/pdf/DCTFilter.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.util.StreamUtilities; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * DCT Filter class. Right now it is just used as a dummy filter flag so - * we can write JPG images to the PDF. The encode method just returns the - * data passed to it. In the future an actual JPEG compression should be - * added to the encode method so other images can be compressed. - * - * @author Eric Dalquist - */ -public class DCTFilter extends PDFFilter { - - /** - * Get filter name. - * @return the pdf name for the DCT filter - */ - public String getName() { - return "/DCTDecode"; - } - - /** - * Get the decode params for this filter. - * @return the DCT filter has no decode params - */ - public String getDecodeParms() { - return null; - } - - /** - * Encode a stream with this filter. - * Currently no encoding is performed, it is assumed that the data - * is already encoded. - * @param in the input data stream - * @param out the output stream - * @param length the length of the data - * @throws IOException if there is an io error - */ - public void encode(InputStream in, OutputStream out, int length) throws IOException { - StreamUtilities.streamCopy(in, out, length); - out.close(); - } - -} - diff --git a/src/org/apache/fop/pdf/FlateFilter.java b/src/org/apache/fop/pdf/FlateFilter.java deleted file mode 100644 index 553daee31..000000000 --- a/src/org/apache/fop/pdf/FlateFilter.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.util.StreamUtilities; - -import java.io.OutputStream; -import java.io.InputStream; -import java.io.IOException; -import java.util.zip.DeflaterOutputStream; - -/** - * A filter to deflate a stream. Note that the attributes for - * prediction, colors, bitsPerComponent, and columns are not supported - * when this filter is used to handle the data compression. They are - * only valid for externally encoded data such as that from a graphics - * file. - */ -public class FlateFilter extends PDFFilter { - /** - * The supported mode when this filter is used for data compression - */ - public static final int PREDICTION_NONE = 1; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_TIFF2 = 2; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_NONE = 10; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_SUB = 11; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_UP = 12; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_AVG = 13; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_PAETH = 14; - - /** - * Mode for externally encoded data. - */ - public static final int PREDICTION_PNG_OPT = 15; - - - private int predictor = PREDICTION_NONE; - private int colors; - private int bitsPerComponent; - private int columns; - - /** - * Get the name of this filter. - * - * @return the pdf name of the flate decode filter - */ - public String getName() { - return "/FlateDecode"; - } - - /** - * Get the decode params for this filter. - * - * @return a string containing the decode params for this filter - */ - public String getDecodeParms() { - if (predictor > PREDICTION_NONE) { - StringBuffer sb = new StringBuffer(); - sb.append("<< /Predictor "); - sb.append(predictor); - if (colors > 0) { - sb.append(" /Colors " + colors); - } - if (bitsPerComponent > 0) { - sb.append(" /BitsPerComponent " + bitsPerComponent); - } - if (columns > 0) { - sb.append(" /Columns " + columns); - } - sb.append(" >> "); - return sb.toString(); - } - return null; - } - - - /** - * Encode the given data and return it. Note: a side effect of - * this method is that it resets the prediction to the default - * because these attributes are not supported. So the DecodeParms - * should be retrieved after calling this method. - * - * @param in the input stream to read the data from - * @param out the output stream to write the data to - * @param length the length of data to read - * @throws IOException if there is an error reading or writing to the streams - */ - public void encode(InputStream in, OutputStream out, int length) throws IOException { - predictor = PREDICTION_NONE; - try { - DeflaterOutputStream compressedStream = - new DeflaterOutputStream(out); - StreamUtilities.streamCopy(in, compressedStream, length); - compressedStream.flush(); - compressedStream.close(); - } catch (IOException e) { - //log.error("Fatal error: " - // + e.getMessage(), e); - } - - } - - /** - * Set the predictor for this filter. - * - * @param predictor the predictor to use - * @throws PDFFilterException if there is an error with the predictor - */ - public void setPredictor(int predictor) throws PDFFilterException { - this.predictor = predictor; - - } - - /** - * Get the predictor for this filter. - * - * @return the predictor used for this filter - */ - public int getPredictor() { - return predictor; - } - - /** - * Set the colors for this filter. - * - * @param colors the colors to use - * @throws PDFFilterException if predictor is not PREDICTION_NONE - */ - public void setColors(int colors) throws PDFFilterException { - if (predictor != PREDICTION_NONE) { - this.colors = colors; - } else { - throw new PDFFilterException( - "Prediction must not be PREDICTION_NONE in" - + " order to set Colors"); - } - } - - /** - * Get the colors for this filter. - * - * @return the colors for this filter - */ - public int getColors() { - return colors; - } - - /** - * Set the number of bits per component. - * - * @param bits the number of bits per component - * @throws PDFFilterException if predictor is not PREDICTION_NONE - */ - public void setBitsPerComponent(int bits) throws PDFFilterException { - if (predictor != PREDICTION_NONE) { - bitsPerComponent = bits; - } else { - throw new PDFFilterException( - "Prediction must not be PREDICTION_NONE in order" - + " to set bitsPerComponent"); - } - } - - /** - * Get the number of bits per component. - * - * @return the number of bits per component - */ - public int getBitsPerComponent() { - return bitsPerComponent; - } - - /** - * Set the number of columns for this filter. - * - * @param columns the number of columns to use for the filter - * @throws PDFFilterException if predictor is not PREDICTION_NONE - */ - public void setColumns(int columns) throws PDFFilterException { - if (predictor != PREDICTION_NONE) { - this.columns = columns; - } else { - throw new PDFFilterException( - "Prediction must not be PREDICTION_NONE in" - + " order to set Columns"); - } - } - - /** - * Get the number of columns for this filter. - * - * @return the number of columns - */ - public int getColumns() { - return columns; - } - - -} diff --git a/src/org/apache/fop/pdf/InMemoryStreamCache.java b/src/org/apache/fop/pdf/InMemoryStreamCache.java deleted file mode 100644 index aa7c49c39..000000000 --- a/src/org/apache/fop/pdf/InMemoryStreamCache.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.ByteArrayOutputStream; -import java.io.ByteArrayInputStream; -import java.io.OutputStream; -import java.io.IOException; - -/** - * StreamCache implementation that uses temporary files rather than heap. - */ -public class InMemoryStreamCache extends StreamCache { - - /** - * The current output stream. - */ - private ByteArrayOutputStream output; - - /** - * Creates a new InMemoryStreamCache. - */ - public InMemoryStreamCache() { - } - - /** - * Get the current OutputStream. Do not store it - it may change - * from call to call. - * @throws IOException if there is an error getting the output stream - * @return the output stream containing the data - */ - public OutputStream getOutputStream() throws IOException { - if (output == null) { - output = new ByteArrayOutputStream(); - } - return output; - } - - /** - * Filter the cache with the supplied PDFFilter. - * @param filter the filter to apply - * @throws IOException if an IO error occurs - */ - public void applyFilter(PDFFilter filter) throws IOException { - if (output == null) { - return; - } - - output.close(); - - // make inputstream from copy of outputted bytes - int size = getSize(); - ByteArrayInputStream input = - new ByteArrayInputStream(output.toByteArray()); - - // reset output - output.reset(); - - // run filter - filter.encode(input, output, size); - input.close(); - output.close(); - } - - /** - * Outputs the cached bytes to the given stream. - * @param stream the output stream to write to - * @throws IOException if there is an IO error writing to the output stream - */ - public void outputStreamData(OutputStream stream) throws IOException { - if (output == null) { - return; - } - - output.writeTo(stream); - } - - /** - * Returns the current size of the stream. - * @throws IOException if there is an error getting the size - * @return the length of the stream - */ - public int getSize() throws IOException { - if (output == null) { - return 0; - } else { - return output.size(); - } - } - - /** - * Closes the cache and frees resources. - * @throws IOException if there is an error closing the stream - */ - public void close() throws IOException { - if (output != null) { - output.close(); - output = null; - } - } - - /** - * Clears and resets the cache. - * @throws IOException if there is an error closing the stream - */ - public void reset() throws IOException { - if (output != null) { - output.close(); - output = null; - } - } -} diff --git a/src/org/apache/fop/pdf/PDFAction.java b/src/org/apache/fop/pdf/PDFAction.java deleted file mode 100644 index 6f99a8783..000000000 --- a/src/org/apache/fop/pdf/PDFAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 an action object. - */ -public abstract class PDFAction extends PDFObject { - - - /** - * create an Action object. - * this constructor is used for passing on the object number to the PDFObject - * - * @param number the object's number - */ - public PDFAction(int number) { - - /* generic creation of object */ - super(number); - } - - /** - * empty constructor for PDFAction. - * this constructor is used when there is no additional object being created - * - */ - public PDFAction() { } - - /** - * represent the action to call - * this method should be implemented to return the action which gets - * called by the Link Object. This could be a reference to another object - * or the specific destination of the link - * - * @return the action to place next to /A within a Link - */ - public abstract String getAction(); - - - /** - * represent the object in PDF - * this method should be implemented to return the PDF which is to be - * generated by the Action object - * - * @return the PDF string - */ - public abstract byte[] toPDF(); - -} diff --git a/src/org/apache/fop/pdf/PDFAnnotList.java b/src/org/apache/fop/pdf/PDFAnnotList.java deleted file mode 100644 index 4b328b7d7..000000000 --- a/src/org/apache/fop/pdf/PDFAnnotList.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 addAnnot(PDFObject 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 byte[] 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().getBytes(); - } - - /* - * example - * 20 0 obj - * [ - * 19 0 R - * ] - * endobj - */ -} diff --git a/src/org/apache/fop/pdf/PDFArray.java b/src/org/apache/fop/pdf/PDFArray.java deleted file mode 100644 index a27d7020e..000000000 --- a/src/org/apache/fop/pdf/PDFArray.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 an array object - */ -public class PDFArray extends PDFObject { - /** - * Array of calues for this pdf object. - */ - protected int[] values; - - /** - * create the array object - * - * @param number the object's number - * @param values the actual array wrapped by this object - */ - public PDFArray(int number, int[] values) { - - /* generic creation of PDF object */ - super(number); - - /* set fields using paramaters */ - this.values = values; - } - - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation + " obj\n["); - for (int i = 0; i < values.length; i++) { - p.append(" "); - p.append(values[i]); - } - p.append("]\nendobj\n"); - return p.toString().getBytes(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFCIDFont.java b/src/org/apache/fop/pdf/PDFCIDFont.java deleted file mode 100644 index fd8ae6f68..000000000 --- a/src/org/apache/fop/pdf/PDFCIDFont.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.CIDFontType; - -// based on work by Takayuki Takeuchi - -/** - * Class representing a "character identifier" font (p 210 and onwards). - */ -public class PDFCIDFont extends PDFObject { - - private String basefont; - private CIDFontType cidtype; - private Integer dw; - private PDFWArray w; - private int[] dw2; - private PDFWArray w2; - private PDFCIDSystemInfo systemInfo; - private PDFCIDFontDescriptor descriptor; - private PDFCMap cmap; - - /** - * /CIDToGIDMap (only for CIDFontType2, see p 212) - * can be either "Identity" (default) or a PDFStream - */ - private PDFStream cidMap; - - - /** - * Create the /Font object - * @param number PDF object number - * @param basefont Name of the basefont - * @param cidtype CID type - * @param dw default width - * @param w array of character widths - * @param registry name of the issuer - * @param ordering Unique name of the font - * @param supplement Supplement number - * @param descriptor CID font descriptor - */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, - int[] w, String registry, String ordering, - int supplement, PDFCIDFontDescriptor descriptor) { - - this(number, basefont, cidtype, dw, - new PDFWArray(w), - new PDFCIDSystemInfo(registry, ordering, supplement), - descriptor); - } - - /** - * Create the /Font object - * @param number PDF object number - * @param basefont Name of the basefont - * @param cidtype CID type - * @param dw default width - * @param w array of character widths - * @param systemInfo CID system info - * @param descriptor CID font descriptor - */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, - int[] w, PDFCIDSystemInfo systemInfo, - PDFCIDFontDescriptor descriptor) { - - this(number, basefont, cidtype, dw, - new PDFWArray(w), - systemInfo, - descriptor); - } - - /** - * Create the /Font object - * @param number PDF object number - * @param basefont Name of the basefont - * @param cidtype CID type - * @param dw default width - * @param w array of character widths - * @param systemInfo CID system info - * @param descriptor CID font descriptor - */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, - PDFWArray w, PDFCIDSystemInfo systemInfo, - PDFCIDFontDescriptor descriptor) { - - super(number); - - this.basefont = basefont; - this.cidtype = cidtype; - this.dw = new Integer(dw); - this.w = w; - this.dw2 = null; - this.w2 = null; - this.systemInfo = systemInfo; - this.descriptor = descriptor; - this.cidMap = null; - this.cmap = null; - } - - /** - * Set the /DW attribute - * @param dw the default width - */ - public void setDW(int dw) { - this.dw = new Integer(dw); - } - - /** - * Set the /W array - * @param w the width array - */ - public void setW(PDFWArray w) { - this.w = w; - } - - /** - * Set the (two elements) /DW2 array - * @param dw2 the default metrics for vertical writing - */ - public void setDW2(int[] dw2) { - this.dw2 = dw2; - } - - /** - * Set the two elements of the /DW2 array - * @param posY position vector - * @param displacementY displacement vector - */ - public void setDW2(int posY, int displacementY) { - this.dw2 = new int[] { - posY, displacementY - }; - } - - /** - * Set the CMap used as /ToUnicode cmap - * @param cmap character map - */ - public void setCMAP(PDFCMap cmap) { - this.cmap = cmap; - } - - /** - * Set the /W2 array - * @param w2 array of metrics for vertical writing - */ - public void setW2(PDFWArray w2) { - this.w2 = w2; - } - - /** - * Set the /CIDToGIDMap (to be used only for CIDFontType2) - * @param map mapping information - */ - public void setCIDMap(PDFStream map) { - this.cidMap = map; - } - - /** - * Set the /CIDToGIDMap (to be used only for CIDFontType2) to "Identity" - */ - public void setCIDMapIdentity() { - this.cidMap = null; // not an error here, simply use the default - } - - /** - * Returns the PDF name for a certain CID font type. - * @param cidFontType CID font type - * @return corresponding PDF name - */ - protected String getPDFNameForCIDFontType(CIDFontType cidFontType) { - if (cidFontType == CIDFontType.CIDTYPE0) { - return cidFontType.getName(); - } else if (cidFontType == CIDFontType.CIDTYPE2) { - return cidFontType.getName(); - } else { - throw new IllegalArgumentException("Unsupported CID font type: " - + cidFontType.getName()); - } - } - - /** - * Produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - /** - * Produce the PDF representation for the object - * @return the generated code - */ - public String toPDFString() { - StringBuffer p = new StringBuffer(); - p.append(this.number); - p.append(" "); - p.append(this.generation); - p.append(" obj\n<< /Type /Font"); - p.append("\n/BaseFont /"); - p.append(this.basefont); - if (cidMap != null) { - p.append(" \n/CIDToGIDMap "); - p.append(cidMap.referencePDF()); - } - p.append(" \n/Subtype /"); - p.append(getPDFNameForCIDFontType(this.cidtype)); - p.append("\n"); - p.append(systemInfo.toPDFString()); - p.append("\n/FontDescriptor "); - p.append(this.descriptor.referencePDF()); - - if (cmap != null) { - p.append("\n/ToUnicode "); - p.append(cmap.referencePDF()); - } - if (dw != null) { - p.append("\n/DW "); - p.append(this.dw); - } - if (w != null) { - p.append("\n/W "); - p.append(w.toPDFString()); - } - if (dw2 != null) { - p.append("\n/DW2 ["); // always two values, see p 211 - p.append(this.dw2[0]); - p.append(this.dw2[1]); - p.append("] \n>>\nendobj\n"); - } - if (w2 != null) { - p.append("\n/W2 "); - p.append(w2.toPDFString()); - p.append(" \n>>\nendobj\n"); - } - p.append(" \n>>\nendobj\n"); - return p.toString(); - } - -} - diff --git a/src/org/apache/fop/pdf/PDFCIDFontDescriptor.java b/src/org/apache/fop/pdf/PDFCIDFontDescriptor.java deleted file mode 100644 index 317833603..000000000 --- a/src/org/apache/fop/pdf/PDFCIDFontDescriptor.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -// based on work by Takayuki Takeuchi - -/** - * class representing a font descriptor for CID fonts. - * - * Font descriptors for CID fonts are specified on page 227 and onwards of the PDF 1.3 spec. - */ -public class PDFCIDFontDescriptor extends PDFFontDescriptor { - - /** - * The language for the font - */ - protected String lang; - - /** - * The cid set stream - */ - protected PDFStream cidSet; - - /** - * create the /FontDescriptor object - * - * @param number the object's number - * @param basefont the base font name - * @param fontBBox the bounding box for the described font - * @param flags various characteristics of the font - * @param capHeight height of the capital letters - * @param stemV the width of the dominant vertical stems of glyphs - * @param italicAngle the angle of the vertical dominant strokes - * @param lang the language - */ - public PDFCIDFontDescriptor(int number, String basefont, int[] fontBBox, - int capHeight, int flags, int italicAngle, - int stemV, String lang) { - - super(number, basefont, fontBBox[3], fontBBox[1], capHeight, flags, - new PDFRectangle(fontBBox), italicAngle, stemV); - - this.lang = lang; - } - - /** - * Set the CID set stream. - * @param cidSet the pdf stream cotnaining the CID set - */ - public void setCIDSet(PDFStream cidSet) { - this.cidSet = cidSet; - } - - /** - * Fill in the pdf data for this font descriptor. - * The charset specific dictionary entries are output. - * @param p the string buffer to append the data - */ - protected void fillInPDF(StringBuffer p) { - p.append("\n/MissingWidth 500\n"); - if (lang != null) { - p.append("\n/Lang /"); - p.append(lang); - } - if (cidSet != null) { - p.append("\n/CIDSet /"); - p.append(this.cidSet.referencePDF()); - } - } - -} diff --git a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java b/src/org/apache/fop/pdf/PDFCIDSystemInfo.java deleted file mode 100644 index 69c60545c..000000000 --- a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -// based on work by Takayuki Takeuchi - -/** - * class representing system information for "character identifier" fonts. - * - * this small object is used in the CID fonts and in the CMaps. - */ -public class PDFCIDSystemInfo extends PDFObject { - private String registry; - private String ordering; - private int supplement; - - /** - * Create a CID system info. - * - * @param registry the registry value - * @param ordering the ordering value - * @param supplement the supplement value - */ - public PDFCIDSystemInfo(String registry, String ordering, - int supplement) { - this.registry = registry; - this.ordering = ordering; - this.supplement = supplement; - } - - /** - * produce the PDF representation for the object. - * - * unlike the other objects, the CIDSystemInfo is written directly inside - * the referencing object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - /** - * Create a string for the CIDSystemInfo dictionary. - * The entries are placed as an inline dictionary. - * - * @return the string for the CIDSystemInfo entry with the inline dictionary - */ - public String toPDFString() { - StringBuffer p = new StringBuffer(); - p.setLength(0); - p.append("/CIDSystemInfo << /Registry ("); - p.append(registry); - p.append(")/Ordering ("); - p.append(ordering); - p.append(")/Supplement "); - p.append(supplement); - p.append(" >>"); - return p.toString(); - } - -} - diff --git a/src/org/apache/fop/pdf/PDFCMap.java b/src/org/apache/fop/pdf/PDFCMap.java deleted file mode 100644 index 76849451e..000000000 --- a/src/org/apache/fop/pdf/PDFCMap.java +++ /dev/null @@ -1,515 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 the CMap encodings. - * - * CMaps are defined in the "Predefined CJK CMap names" table. - * In section 5.6.4 of PDF reference 1.4. - */ -public class PDFCMap extends PDFStream { - - /* - * Chinese (simplified) - */ - - /** - * GB-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GB 2312-80 - * character set, EUC-CN encoding - */ - public static final String ENC_GB_EUC_H = "GB-EUC-H"; - - /** - * GB-EUC-V Vertical version of GB-EUC-H - */ - public static final String ENC_GB_EUC_V = "GB_EUC_V"; - - /** - * GBpc-EUC-H Mac OS, GB 2312-80 character set, EUC-CN encoding, Script Manager code 19 - */ - public static final String ENC_GBPC_EUC_H = "GBpc-EUC-H"; - - /** - * GBpc-EUC-V Vertical version of GBpc-EUC-H - */ - public static final String ENC_GBPC_EUC_V = "GBpc-EUC-V"; - - /** - * GBK-EUC-H Microsoft Code Page 936 (lfCharSet 0x86), GBK character set, GBK encoding - */ - public static final String ENC_GBK_EUC_H = "GBK-EUC-H"; - - /** - * GBK-EUC-V Vertical version of GBK-EUC-H - */ - public static final String ENC_GBK_EUC_V = "GBK-EUC-V"; - - /** - * GBKp-EUC-H Same as GBK-EUC-H, but replaces half-width - * Latin characters with proportional forms and maps character - * code 0x24 to a dollar sign ($) instead of a yuan symbol - */ - public static final String ENC_GBKP_EUC_H = "GBKp-EUC-H"; - - /** - * GBKp-EUC-V Vertical version of GBKp-EUC-H - */ - public static final String ENC_GBKP_EUC_V = "GBKp-EUC-V"; - - /** - * GBK2K-H GB 18030-2000 character set, mixed 1-, 2-, and 4-byte encoding - */ - public static final String ENC_GBK2K_H = "GBK2K-H"; - - /** - * GBK2K-V Vertical version of GBK2K-H - */ - public static final String ENC_GBK2K_V = "GBK2K-V"; - - /** - * UniGB-UCS2-H Unicode (UCS-2) encoding for the Adobe-GB1 character collection - */ - public static final String ENC_UNIGB_UCS2_H = "UniGB-UCS2-H"; - - /** - * UniGB-UCS2-V Vertical version of UniGB-UCS2-H - */ - public static final String ENC_UNIGB_UCS2_V = "UniGB-UCS2-V"; - - - /* - * Chinese (Traditional) - */ - - /** - * B5pc-H Mac OS, Big Five character set, Big Five encoding, Script Manager code 2 - */ - public static final String ENC_B5PC_H = "B5pc-H"; - - /** - * B5pc-V Vertical version of B5pc-H - */ - public static final String ENC_B5PC_V = "B5pc-V"; - - /** - * HKscs-B5-H Hong Kong SCS, an extension to the Big Five - * character set and encoding - */ - public static final String ENC_HKSCS_B5_H = "HKscs-B5-H"; - - /** - * HKscs-B5-V Vertical version of HKscs-B5-H - */ - public static final String ENC_HKSCS_B5_V = "HKscs-B5-V"; - - /** - * ETen-B5-H Microsoft Code Page 950 (lfCharSet 0x88), Big Five - * character set with ETen extensions - */ - public static final String ENC_ETEN_B5_H = "ETen-B5-H"; - - /** - * ETen-B5-V Vertical version of ETen-B5-H - */ - public static final String ENC_ETEN_B5_V = "ETen-B5-V"; - - /** - * ETenms-B5-H Same as ETen-B5-H, but replaces half-width - * Latin characters with proportional forms - */ - public static final String ENC_ETENMS_B5_H = "ETenms-B5-H"; - - /** - * ETenms-B5-V Vertical version of ETenms-B5-H - */ - public static final String ENC_ETENMS_B5_V = "ETenms-B5-V"; - - /** - * CNS-EUC-H CNS 11643-1992 character set, EUC-TW encoding - */ - public static final String ENC_CNS_EUC_H = "CNS-EUC-H"; - - /** - * CNS-EUC-V Vertical version of CNS-EUC-H - */ - public static final String ENC_CNS_EUC_V = "CNS-EUC-V"; - - /** - * UniCNS-UCS2-H Unicode (UCS-2) encoding for the - * Adobe-CNS1 character collection - */ - public static final String ENC_UNICNS_UCS2_H = "UniCNS-UCS2-H"; - - /** - * UniCNS-UCS2-V Vertical version of UniCNS-UCS2-H - */ - public static final String ENC_UNICNS_UCS2_V = "UniCNS-UCS2-V"; - - /* - * Japanese - */ - - /** - * 83pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk6 - * extensions, Shift-JIS encoding, Script Manager code 1 - */ - public static final String ENC_83PV_RKSJ_H = "83pv-RKSJ-H"; // no V version - - /** - * 90ms-RKSJ-H Microsoft Code Page 932 (lfCharSet 0x80), JIS X 0208 - * character set with NEC and IBM extensions - */ - public static final String ENC_90MS_RKSJ_H = "90ms-RKSJ-H"; - - /** - * 90ms-RKSJ-V Vertical version of 90ms-RKSJ-H - */ - public static final String ENC_90MS_RKSJ_V = "90ms-RKSJ-V"; - - /** - * 90msp-RKSJ-H Same as 90ms-RKSJ-H, but replaces half-width Latin - * characters with proportional forms - */ - public static final String ENC_90MSP_RKSJ_H = "90msp-RKSJ-H"; - - /** - * 90msp-RKSJ-V Vertical version of 90msp-RKSJ-H - */ - public static final String ENC_90MSP_RKSJ_V = "90msp-RKSJ-V"; - - /** - * 90pv-RKSJ-H Mac OS, JIS X 0208 character set with KanjiTalk7 - * extensions, Shift-JIS encoding, Script Manager code 1 - */ - public static final String ENC_90PV_RKSJ_H = "90pv-RKSJ-H"; // no V version - - /** - * Add-RKSJ-H JIS X 0208 character set with Fujitsu FMR - * extensions, Shift-JIS encoding - */ - public static final String ENC_ADD_RKSJ_H = "Add-RKSJ-H"; - - /** - * Add-RKSJ-V Vertical version of Add-RKSJ-H - */ - public static final String ENC_ADD_RKSJ_V = "Add-RKSJ-V"; - - /** - * EUC-H JIS X 0208 character set, EUC-JP encoding - */ - public static final String ENC_EUC_H = "EUC-H"; - - /** - * EUC-V Vertical version of EUC-H - */ - public static final String ENC_EUC_V = "EUC-V"; - - /** - * Ext-RKSJ-H JIS C 6226 (JIS78) character set with - * NEC extensions, Shift-JIS encoding - */ - public static final String ENC_EXT_RKSJ_H = "Ext-RKSJ-H"; - - /** - * Ext-RKSJ-V Vertical version of Ext-RKSJ-H - */ - public static final String ENC_EXT_RKSJ_V = "Ext-RKSJ-V"; - - /** - * H JIS X 0208 character set, ISO-2022-JP encoding - */ - public static final String ENC_H = "H"; - - /** - * V Vertical version of H - */ - public static final String ENC_V = "V"; - - /** - * UniJIS-UCS2-H Unicode (UCS-2) encoding for the - * Adobe-Japan1 character collection - */ - public static final String ENC_UNIJIS_UCS2_H = "UniJIS-UCS2-H"; - - /** - * UniJIS-UCS2-V Vertical version of UniJIS-UCS2-H - */ - public static final String ENC_UNIJIS_UCS2_V = "UniJIS-UCS2-V"; - - /** - * UniJIS-UCS2-HW-H Same as UniJIS-UCS2-H, but replaces proportional - * Latin characters with half-width forms - */ - public static final String ENC_UNIJIS_UCS2_HW_H = "UniJIS-UCS2-HW-H"; - - /** - * UniJIS-UCS2-HW-V Vertical version of UniJIS-UCS2-HW-H - */ - public static final String ENC_UNIJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V"; - - /* - * Korean - */ - - /** - * KSC-EUC-H KS X 1001:1992 character set, EUC-KR encoding - */ - public static final String ENC_KSC_EUC_H = "KSC-EUC-H"; - - /** - * KSC-EUC-V Vertical version of KSC-EUC-H - */ - public static final String ENC_KSC_EUC_V = "KSC-EUC-V"; - - /** - * KSCms-UHC-H Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992 - * character set plus 8822 additional hangul, - * Unified Hangul Code (UHC) encoding - */ - public static final String ENC_KSCMS_UHC_H = "KSCms-UHC-H"; - - /** - * KSCms-UHC-V Vertical version of KSCms-UHC-H - */ - public static final String ENC_KSCMS_UHC_V = "KSCms-UHC-V"; - - /** - * KSCms-UHC-HW-H Same as KSCms-UHC-H, but replaces proportional - * Latin characters with half-width forms - */ - public static final String ENC_KSCMS_UHC_HW_H = "KSCms-UHC-HW-H"; - - /** - * KSCms-UHC-HW-V Vertical version of KSCms-UHC-HW-H - */ - public static final String ENC_KSCMS_UHC_HW_V = "KSCms-UHC-HW-V"; - - /** - * KSCpc-EUC-H Mac OS, KS X 1001:1992 character set with - * Mac OS KH extensions, Script Manager Code 3 - */ - public static final String ENC_KSCPC_EUC_H = "KSCpc-EUC-H"; // no V version - - /** - * UniKS-UCS2-H Unicode (UCS-2) encoding for the - * Adobe-Korea1 character collection - */ - public static final String ENC_UNIKSC_UCS2_H = "UniKSC-UCS2-H"; - - /** - * UniKS-UCS2-V Vertical version of UniKS-UCS2-H - */ - public static final String ENC_UNIKSC_UCS2_V = "UniKSC-UCS2-V"; - - /* - * Generic - */ - - /** - * Identity-H The horizontal identity mapping for 2-byte CIDs; - * may be used with CIDFonts using any Registry, Ordering, and - * Supplement values. It maps 2-byte character codes ranging from - * 0 to 65,535 to the same 2-byte CID value, interpreted - * high-order byte first. - */ - public static final String ENC_IDENTITY_H = "Identity-H"; - - /** - * Identity-V Vertical version of Identity-H. The mapping - * is the same as for Identity-H. - */ - public static final String ENC_IDENTTITY_V = "Identity-V"; - - /** - * /CMapName attribute, one of the predefined constants - */ - protected String name; - - /** - * /CIDSystemInfo attribute - */ - protected PDFCIDSystemInfo sysInfo; - - /** - * horizontal writing direction - */ - public static final byte WMODE_HORIZONTAL = 0; - - /** - * vertical writing direction - */ - public static final byte WMODE_VERTICAL = 1; - - /** - * font's writing direction - */ - protected byte wMode = WMODE_HORIZONTAL; - - /** - * base CMap (String or PDFStream) - */ - protected Object base; - - /** - * create the /CMap object - * - * @param number the pdf object number - * @param name one the registered names (see Table 7.20 on p 215) - * @param sysInfo the attributes of the character collection of the CIDFont - */ - public PDFCMap(int number, String name, PDFCIDSystemInfo sysInfo) { - super(number); - this.name = name; - this.sysInfo = sysInfo; - this.base = null; - } - - /** - * set the writing direction - * - * @param mode is either <code>WMODE_HORIZONTAL</code> - * or <code>WMODE_VERTICAL</code> - */ - public void setWMode(byte mode) { - this.wMode = mode; - } - - /** - * Add the contents of this pdf object to the PDF stream. - */ - public void addContents() { - StringBuffer p = new StringBuffer(); - fillInPDF(p); - add(p.toString()); - } - - /** - * set the base CMap - * - * @param base the name of the base CMap - */ - public void setUseCMap(String base) { - this.base = base; - } - - /** - * set the base CMap - * - * @param base the stream to be used as base CMap - */ - public void setUseCMap(PDFStream base) { - this.base = base; - } - - /** - * Fill in the pdf string for this CMap. - * - * @param p the string buffer to add the pdf data to - */ - public void fillInPDF(StringBuffer p) { - // p.append("/Type /CMap\n"); - // p.append(sysInfo.toPDFString()); - // p.append("/CMapName /" + name); - // p.append("\n"); - p.append("%!PS-Adobe-3.0 Resource-CMap\n"); - p.append("%%DocumentNeededResources: ProcSet (CIDInit)\n"); - p.append("%%IncludeResource: ProcSet (CIDInit)\n"); - p.append("%%BeginResource: CMap (" + name + ")\n"); - p.append("%%EndComments\n"); - - p.append("/CIDInit /ProcSet findresource begin\n"); - p.append("12 dict begin\n"); - p.append("begincmap\n"); - - p.append("/CIDSystemInfo 3 dict dup begin\n"); - p.append(" /Registry (Adobe) def\n"); - p.append(" /Ordering (Identity) def\n"); - p.append(" /Supplement 0 def\n"); - p.append("end def\n"); - - p.append("/CMapVersion 1 def\n"); - p.append("/CMapType 1 def\n"); - p.append("/CMapName /" + name + " def\n"); - - p.append("1 begincodespacerange\n"); - p.append("<0000> <FFFF>\n"); - p.append("endcodespacerange\n"); - p.append("1 begincidrange\n"); - p.append("<0000> <FFFF> 0\n"); - p.append("endcidrange\n"); - - // p.append("1 beginbfrange\n"); - // p.append("<0020> <0100> <0000>\n"); - // p.append("endbfrange\n"); - - p.append("endcmap\n"); - p.append("CMapName currentdict /CMap defineresource pop\n"); - p.append("end\n"); - p.append("end\n"); - p.append("%%EndResource\n"); - p.append("%%EOF\n"); - /* - * p.append(" /Type /CMap\n/CMapName /" + name); - * p.append("\n"); - * p.append("\n/WMode "); p.append(wMode); - * if (base != null) { - * p.append("\n/UseCMap "); - * if (base instanceof String) { - * p.append("/"+base); - * } else {// base instanceof PDFStream - * p.append(((PDFStream)base).referencePDF()); - * } - * } - */ - } - -} diff --git a/src/org/apache/fop/pdf/PDFCharProcs.java b/src/org/apache/fop/pdf/PDFCharProcs.java deleted file mode 100644 index be402a65d..000000000 --- a/src/org/apache/fop/pdf/PDFCharProcs.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.Map; -import java.util.HashMap; - -/** - * class representing a /CharProcs dictionary for Type3 fonts. - * - * <p><b>CAUTION: this is not yet fully implemented!!!!!!!</b> - * I miss an exemple of <i>how</i> to output this dictionary. - * </p> - * - * Type3 fonts are specified on page 206 and onwards of the PDF 1.3 spec. - */ -public class PDFCharProcs extends PDFObject { - - /** - * the (character name, drawing stream) pairs for a Type3 font - */ - protected Map keys; - - /** - * Create a new PDF char proc store. - */ - public PDFCharProcs() { - keys = new HashMap(); - } - - /** - * add a character definition in the dictionary - * - * @param name the character name - * @param stream the stream that draws the character - */ - public void addCharacter(String name, PDFStream stream) { - keys.put(name, stream); - } - - /** - * not done yet - * @return the pdf byte array - */ - public byte[] toPDF() { - // todo implement this org.apache.fop.pdf.PDFObject abstract method - return new byte[0]; - } - -} diff --git a/src/org/apache/fop/pdf/PDFColor.java b/src/org/apache/fop/pdf/PDFColor.java deleted file mode 100644 index eb8565f08..000000000 --- a/src/org/apache/fop/pdf/PDFColor.java +++ /dev/null @@ -1,481 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; -import java.util.ArrayList; - -/** - * PDF Color object. - * This is used to output color to a PDF content stream. - */ -public class PDFColor extends PDFPathPaint { - // could be 3.0 as well. - private static double blackFactor = 2.0; - private double red = -1.0; - private double green = -1.0; - private double blue = -1.0; - - private double cyan = -1.0; - private double magenta = -1.0; - private double yellow = -1.0; - private double black = -1.0; - - /** - * Create a PDF color with double values ranging from 0 to 1 - * - * @param theRed the red double value - * @param theGreen the green double value - * @param theBlue the blue double value - */ - public PDFColor(double theRed, double theGreen, double theBlue) { - // super(theNumber); - this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - - this.red = theRed; - this.green = theGreen; - this.blue = theBlue; - } - - /** - * Create a PDF color with int values ranging from 0 to 255 - * - * @param theRed the red integer value - * @param theGreen the green integer value - * @param theBlue the blue integer value - */ - public PDFColor(int theRed, int theGreen, int theBlue) { - this(((double)theRed) / 255d, ((double)theGreen) / 255d, - ((double)theBlue) / 255d); - - } - - /** - * Create a PDF color with CMYK values. - * - * @param theCyan the cyan value - * @param theMagenta the magenta value - * @param theYellow the yellow value - * @param theBlack the black value - */ - public PDFColor(double theCyan, double theMagenta, double theYellow, - double theBlack) { - // super(theNumber);//? - - this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_CMYK); - - this.cyan = theCyan; - this.magenta = theMagenta; - this.yellow = theYellow; - this.black = theBlack; - } - - /** - * Return a vector representation of the color - * in the appropriate colorspace. - * - * @return a list containing the Double values of the color - */ - public List getVector() { - List theColorVector = new ArrayList(); - if (this.colorSpace.getColorSpace() == PDFColorSpace.DEVICE_RGB) { - // RGB - theColorVector.add(new Double(this.red)); - theColorVector.add(new Double(this.green)); - theColorVector.add(new Double(this.blue)); - } else if (this.colorSpace.getColorSpace() - == PDFColorSpace.DEVICE_CMYK) { - // CMYK - theColorVector.add(new Double(this.cyan)); - theColorVector.add(new Double(this.magenta)); - theColorVector.add(new Double(this.yellow)); - theColorVector.add(new Double(this.black)); - } else { - // GRAY - theColorVector.add(new Double(this.black)); - } - return (theColorVector); - } - - /** - * Get the red component. - * - * @return the red double value - */ - public double red() { - return (this.red); - } - - /** - * Get the green component. - * - * @return the green double value - */ - public double green() { - return (this.green); - } - - /** - * Get the blue component. - * - * @return the blue double value - */ - public double blue() { - return (this.blue); - } - - /** - * Get the red integer component. - * - * @return the red integer value - */ - public int red255() { - return (int)(this.red * 255d); - } - - /** - * Get the green integer component. - * - * @return the green integer value - */ - public int green255() { - return (int)(this.green * 255d); - } - - /** - * Get the blue integer component. - * - * @return the blue integer value - */ - public int blue255() { - return (int)(this.blue * 255d); - } - - /** - * Get the cyan component. - * - * @return the cyan double value - */ - public double cyan() { - return (this.cyan); - } - - /** - * Get the magenta component. - * - * @return the magenta double value - */ - public double magenta() { - return (this.magenta); - } - - /** - * Get the yellow component. - * - * @return the yellow double value - */ - public double yellow() { - return (this.yellow); - } - - /** - * Get the black component. - * - * @return the black double value - */ - public double black() { - return (this.black); - } - - /** - * Set the color space for this color. - * If the new color space is different the values are converted - * to the new color space. - * - * @param theColorSpace the new color space - */ - public void setColorSpace(int theColorSpace) { - int theOldColorSpace = this.colorSpace.getColorSpace(); - if (theOldColorSpace != theColorSpace) { - if (theOldColorSpace == PDFColorSpace.DEVICE_RGB) { - if (theColorSpace == PDFColorSpace.DEVICE_CMYK) { - this.convertRGBtoCMYK(); - } else { - // convert to Gray? - this.convertRGBtoGRAY(); - } - } else if (theOldColorSpace == PDFColorSpace.DEVICE_CMYK) { - if (theColorSpace == PDFColorSpace.DEVICE_RGB) { - this.convertCMYKtoRGB(); - } else { - // convert to Gray? - this.convertCMYKtoGRAY(); - } - } else { - // used to be Gray - if (theColorSpace == PDFColorSpace.DEVICE_RGB) { - this.convertGRAYtoRGB(); - } else { - // convert to CMYK? - this.convertGRAYtoCMYK(); - } - } - this.colorSpace.setColorSpace(theColorSpace); - } - } - - /** - * Get the PDF output string for this color. - * This returns the string to be inserted into PDF for setting - * the current color. - * - * @param fillNotStroke whether to return fill or stroke command - * @return the PDF string for setting the fill/stroke color - */ - public String getColorSpaceOut(boolean fillNotStroke) { - StringBuffer p = new StringBuffer(""); - - double tempDouble; - - if (this.colorSpace.getColorSpace() - == PDFColorSpace.DEVICE_RGB) { // colorspace is RGB - // according to pdfspec 12.1 p.399 - // if the colors are the same then just use the g or G operator - boolean same = false; - if (this.red == this.green && this.red == this.blue) { - same = true; - } - // output RGB - if (fillNotStroke) { - // fill - if (same) { - p.append(PDFNumber.doubleOut(this.red) + " g\n"); - } else { - p.append(PDFNumber.doubleOut(this.red) + " " - + PDFNumber.doubleOut(this.green) + " " - + PDFNumber.doubleOut(this.blue) - + " rg\n"); - } - } else { - // stroke/border - if (same) { - p.append(PDFNumber.doubleOut(this.red) + " G\n"); - } else { - p.append(PDFNumber.doubleOut(this.red) + " " - + PDFNumber.doubleOut(this.green) + " " - + PDFNumber.doubleOut(this.blue) - + " RG\n"); - } - } - } else if (this.colorSpace.getColorSpace() - == PDFColorSpace.DEVICE_CMYK) { - // colorspace is CMYK - - if (fillNotStroke) { - // fill - p.append(PDFNumber.doubleOut(this.cyan) + " " - + PDFNumber.doubleOut(this.magenta) + " " - + PDFNumber.doubleOut(this.yellow) + " " - + PDFNumber.doubleOut(this.black) + " k\n"); - } else { - // stroke - p.append(PDFNumber.doubleOut(this.cyan) + " " - + PDFNumber.doubleOut(this.magenta) + " " - + PDFNumber.doubleOut(this.yellow) + " " - + PDFNumber.doubleOut(this.black) + " K\n"); - } - - } else { - // means we're in DeviceGray or Unknown. - // assume we're in DeviceGray, because otherwise we're screwed. - - if (fillNotStroke) { - p.append(PDFNumber.doubleOut(this.black) + " g\n"); - } else { - p.append(PDFNumber.doubleOut(this.black) + " G\n"); - } - - } - return (p.toString()); - } - - /** - * Convert the color from CMYK to RGB. - */ - protected void convertCMYKtoRGB() { - // convert CMYK to RGB - this.red = 1.0 - this.cyan; - this.green = 1.0 - this.green; - this.blue = 1.0 - this.yellow; - - this.red = (this.black / PDFColor.blackFactor) + this.red; - this.green = (this.black / PDFColor.blackFactor) + this.green; - this.blue = (this.black / PDFColor.blackFactor) + this.blue; - - } - - /** - * Convert the color from RGB to CMYK. - */ - protected void convertRGBtoCMYK() { - // convert RGB to CMYK - this.cyan = 1.0 - this.red; - this.magenta = 1.0 - this.green; - this.yellow = 1.0 - this.blue; - - this.black = 0.0; - /* - * If you want to calculate black, uncomment this - * //pick the lowest color - * tempDouble = this.red; - * - * if (this.green < tempDouble) - * tempDouble = this.green; - * - * if (this.blue < tempDouble) - * tempDouble = this.blue; - * - * this.black = tempDouble / this.blackFactor; - */ - } - - /** - * Convert the color from Gray to RGB. - */ - protected void convertGRAYtoRGB() { - this.red = 1.0 - this.black; - this.green = 1.0 - this.black; - this.blue = 1.0 - this.black; - } - - /** - * Convert the color from Gray to CMYK. - */ - protected void convertGRAYtoCMYK() { - this.cyan = this.black; - this.magenta = this.black; - this.yellow = this.black; - // this.black=0.0;//? - } - - /** - * Convert the color from CMYK to Gray. - */ - protected void convertCMYKtoGRAY() { - double tempDouble = 0.0; - - // pick the lowest color - tempDouble = this.cyan; - - if (this.magenta < tempDouble) { - tempDouble = this.magenta; - } - - if (this.yellow < tempDouble) { - tempDouble = this.yellow; - } - - this.black = (tempDouble / PDFColor.blackFactor); - - } - - /** - * Convert the color from RGB to Gray. - */ - protected void convertRGBtoGRAY() { - double tempDouble = 0.0; - - // pick the lowest color - tempDouble = this.red; - - if (this.green < tempDouble) { - tempDouble = this.green; - } - - if (this.blue < tempDouble) { - tempDouble = this.blue; - } - - this.black = 1.0 - (tempDouble / PDFColor.blackFactor); - } - - /** - * Create pdf. - * Not used for this object. - * - * @return the bytes for the pdf - */ - public byte[] toPDF() { - return (new byte[0]); - } - - /** - * Check for equality of color with another object. - * - * @param obj the object to compare - * @return true if colors are equal - */ - public boolean equals(Object obj) { - if (!(obj instanceof PDFColor)) { - return false; - } - PDFColor color = (PDFColor)obj; - - if (color.red == this.red && color.green == this.green - && color.blue == this.blue) { - return true; - } - return false; - } - -} - diff --git a/src/org/apache/fop/pdf/PDFColorSpace.java b/src/org/apache/fop/pdf/PDFColorSpace.java deleted file mode 100644 index c7b21c92b..000000000 --- a/src/org/apache/fop/pdf/PDFColorSpace.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -/** - * PDF Color space. - */ -public class PDFColorSpace { - private boolean hasICCProfile; - private byte[] iccProfile; - private int numComponents; - - // Ok... so I had some grand purpose for this, but I can't recall. - // I'm just writing it - - /** - * Unknown colorspace - */ - public static final int DEVICE_UNKNOWN = -1; - - /** - * Gray colorspace - */ - public static final int DEVICE_GRAY = 1; - - /** - * RGB colorspace - */ - public static final int DEVICE_RGB = 2; - - /** - * CMYK colorspace - */ - public static final int DEVICE_CMYK = 3; - - // Are there any others? - - /** - * Current color space value. - */ - protected int currentColorSpace = DEVICE_UNKNOWN; - - /** - * Create a PDF colorspace object. - * - * @param theColorSpace the current colorspace - */ - public PDFColorSpace(int theColorSpace) { - this.currentColorSpace = theColorSpace; - hasICCProfile = false; - numComponents = calculateNumComponents(); - } - - private int calculateNumComponents() { - if (currentColorSpace == DEVICE_GRAY) { - return 1; - } else if (currentColorSpace == DEVICE_RGB) { - return 3; - } else if (currentColorSpace == DEVICE_CMYK) { - return 4; - } else { - return 0; - } - } - - /** - * Set the current colorspace. - * - * @param theColorSpace the new color space value - */ - public void setColorSpace(int theColorSpace) { - this.currentColorSpace = theColorSpace; - numComponents = calculateNumComponents(); - } - - /** - * Check if this colorspace has an ICC profile. - * - * @return true if this has an ICC profile - */ - public boolean hasICCProfile() { - return hasICCProfile; - } - - /** - * Get the ICC profile for this colorspace - * - * @return the byte array containing the ICC profile data - */ - public byte[] getICCProfile() { - if (hasICCProfile) { - return iccProfile; - } else { - return new byte[0]; - } - } - - /** - * Set the ICC profile for this colorspace. - * - * @param iccProfile the ICC profile data - */ - public void setICCProfile(byte[] iccProfile) { - this.iccProfile = iccProfile; - hasICCProfile = true; - } - - /** - * Get the colorspace value - * - * @return the colorspace value - */ - public int getColorSpace() { - return (this.currentColorSpace); - } - - /** - * Get the number of color components for this colorspace - * - * @return the number of components - */ - public int getNumComponents() { - return numComponents; - } - - /** - * Get the PDF string for this colorspace. - * - * @return the PDF string for the colorspace - */ - public String getColorSpacePDFString() { - // shouldn't this be a select-case? I can never remember - // the syntax for that. - switch (currentColorSpace) { - case DEVICE_CMYK: - return "DeviceCMYK"; - //break; - case DEVICE_GRAY: - return "DeviceGray"; - //break; - case DEVICE_RGB: - default: - // unknown... Error. Tell them it's RGB and hope they - // don't notice. - return ("DeviceRGB"); - //break; - } - } - -} diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java deleted file mode 100644 index 1da73145c..000000000 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ /dev/null @@ -1,1926 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.util.StreamUtilities; - -import org.apache.fop.fonts.CIDFont; -import org.apache.fop.fonts.CustomFont; -import org.apache.fop.fonts.FontDescriptor; -import org.apache.fop.fonts.FontMetrics; -import org.apache.fop.fonts.FontType; -import org.apache.fop.fonts.LazyFont; -import org.apache.fop.fonts.MultiByteFont; -import org.apache.fop.fonts.truetype.FontFileReader; -import org.apache.fop.fonts.truetype.TTFSubSetFile; -import org.apache.fop.fonts.type1.PFBData; -import org.apache.fop.fonts.type1.PFBParser; - -// Java -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; -import java.util.Iterator; -import java.awt.geom.Rectangle2D; - -/* image support modified from work of BoBoGi */ -/* font support based on work by Takayuki Takeuchi */ - -/** - * class representing a PDF document. - * - * The document is built up by calling various methods and then finally - * output to given filehandle using output method. - * - * A PDF document consists of a series of numbered objects preceded by a - * header and followed by an xref table and trailer. The xref table - * allows for quick access to objects by listing their character - * positions within the document. For this reason the PDF document must - * keep track of the character position of each object. The document - * also keeps direct track of the /Root, /Info and /Resources objects. - * - * Modified by Mark Lillywhite, mark-fop@inomial.com. The changes - * involve: ability to output pages one-at-a-time in a streaming - * fashion (rather than storing them all for output at the end); - * ability to write the /Pages object after writing the rest - * of the document; ability to write to a stream and flush - * the object list; enhanced trailer output; cleanups. - * - */ -public class PDFDocument { - private static final Integer LOCATION_PLACEHOLDER = new Integer(0); - /** - * the version of PDF supported which is 1.4 - */ - protected static final String PDF_VERSION = "1.4"; - - /** - * the encoding to use when converting strings to PDF commandos. - */ - public static final String ENCODING = "ISO-8859-1"; - - /** - * the current character position - */ - protected int position = 0; - - /** - * the character position of each object - */ - protected List location = new java.util.ArrayList(); - - /** List of objects to write in the trailer */ - private List trailerObjects = new java.util.ArrayList(); - - /** - * the counter for object numbering - */ - protected int objectcount = 0; - - /** - * the objects themselves - */ - protected List objects = new java.util.ArrayList(); - - /** - * character position of xref table - */ - protected int xref; - - /** - * the /Root object - */ - protected PDFRoot root; - - /** The root outline object */ - private PDFOutline outlineRoot = null; - - /** The /Pages object (mark-fop@inomial.com) */ - private PDFPages pages; - - /** - * the /Info object - */ - protected PDFInfo info; - - /** - * the /Resources object - */ - protected PDFResources resources; - - /** - * the colorspace (0=RGB, 1=CMYK) - */ - protected PDFColorSpace colorspace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - - /** - * the counter for Pattern name numbering (e.g. 'Pattern1') - */ - protected int patternCount = 0; - - /** - * the counter for Shading name numbering - */ - protected int shadingCount = 0; - - /** - * the counter for XObject numbering - */ - protected int xObjectCount = 0; - - /** - * the XObjects Map. - * Should be modified (works only for image subtype) - */ - protected Map xObjectsMap = new java.util.HashMap(); - - /** - * the Font Map. - */ - protected Map fontMap = new java.util.HashMap(); - - /** - * The filter map. - */ - protected Map filterMap = new java.util.HashMap(); - - /** - * List of PDFGState objects. - */ - protected List gstates = new java.util.ArrayList(); - - /** - * List of functions. - */ - protected List functions = new java.util.ArrayList(); - - /** - * List of shadings. - */ - protected List shadings = new java.util.ArrayList(); - - /** - * List of patterns. - */ - protected List patterns = new java.util.ArrayList(); - - /** - * List of Links. - */ - protected List links = new java.util.ArrayList(); - - /** - * List of FileSpecs. - */ - protected List filespecs = new java.util.ArrayList(); - - /** - * List of GoToRemotes. - */ - protected List gotoremotes = new java.util.ArrayList(); - - /** - * List of GoTos. - */ - protected List gotos = new java.util.ArrayList(); - - - /** - * creates an empty PDF document <p> - * - * The constructor creates a /Root and /Pages object to - * track the document but does not write these objects until - * the trailer is written. Note that the object ID of the - * pages object is determined now, and the xref table is - * updated later. This allows Pages to refer to their - * Parent before we write it out. - * - * @param prod the name of the producer of this pdf document - */ - public PDFDocument(String prod) { - - /* create the /Root, /Info and /Resources objects */ - this.pages = makePages(); - - // Create the Root object - this.root = makeRoot(pages); - - // Create the Resources object - this.resources = makeResources(); - - // Make the /Info record - this.info = makeInfo(prod); - } - - /** - * set the producer of the document - * - * @param producer string indicating application producing the PDF - */ - public void setProducer(String producer) { - this.info.setProducer(producer); - } - - /** - * set the creator of the document - * - * @param creator string indicating application creating the document - */ - public void setCreator(String creator) { - this.info.setCreator(creator); - } - - /** - * Set the filter map to use for filters in this document. - * - * @param map the map of filter lists for each stream type - */ - public void setFilterMap(Map map) { - filterMap = map; - } - - /** - * Get the filter map used for filters in this document. - * - * @return the map of filters being used - */ - public Map getFilterMap() { - return filterMap; - } - - /** - * Make a /Catalog (Root) object. This object is written in - * the trailer. - * - * @param pages the pages pdf object that the root points to - * @return the new pdf root object for this document - */ - public PDFRoot makeRoot(PDFPages pages) { - - /* - * Make a /Pages object. This object is written in the trailer. - */ - PDFRoot pdfRoot = new PDFRoot(++this.objectcount, pages); - addTrailerObject(pdfRoot); - return pdfRoot; - } - - /** - * Get the PDF root object. - * - * @return the PDFRoot object - */ - public PDFRoot getRoot() { - return this.root; - } - - /** - * Make a /Pages object. This object is written in the trailer. - * - * @return a new PDF Pages object for adding pages to - */ - public PDFPages makePages() { - PDFPages pdfPages = new PDFPages(++this.objectcount); - addTrailerObject(pdfPages); - return pdfPages; - } - - /** - * Make a /Resources object. This object is written in the trailer. - * - * @return a new PDF resources object - */ - public PDFResources makeResources() { - PDFResources pdfResources = new PDFResources(++this.objectcount); - addTrailerObject(pdfResources); - return pdfResources; - } - - /** - * make an /Info object - * - * @param prod string indicating application producing the PDF - * @return the created /Info object - */ - protected PDFInfo makeInfo(String prod) { - - /* - * create a PDFInfo with the next object number and add to - * list of objects - */ - PDFInfo pdfInfo = new PDFInfo(++this.objectcount); - // set the default producer - pdfInfo.setProducer(prod); - this.objects.add(pdfInfo); - return pdfInfo; - } - - /** - * Get the pdf info object for this document. - * - * @return the PDF Info object for this document - */ - public PDFInfo getInfo() { - return info; - } - - /** - * Make a Type 0 sampled function - * - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theSize A List object of Integer objects. - * This is the number of samples in each input dimension. - * I can't imagine there being more or less than two input dimensions, - * so maybe this should be an array of length 2. - * - * See page 265 of the PDF 1.3 Spec. - * @param theBitsPerSample An int specifying the number of bits user - * to represent each sample value. - * Limited to 1,2,4,8,12,16,24 or 32. - * See page 265 of the 1.3 PDF Spec. - * @param theOrder The order of interpolation between samples. - * Default is 1 (one). Limited - * to 1 (one) or 3, which means linear or cubic-spline interpolation. - * - * This attribute is optional. - * - * See page 265 in the PDF 1.3 spec. - * @param theEncode List objects of Double objects. - * This is the linear mapping of input values intop the domain - * of the function's sample table. Default is hard to represent in - * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. - * This attribute is optional. - * - * See page 265 in the PDF 1.3 spec. - * @param theDecode List objects of Double objects. - * This is a linear mapping of sample values into the range. - * The default is just the range. - * - * This attribute is optional. - * Read about it on page 265 of the PDF 1.3 spec. - * @param theFunctionDataStream The sample values that specify - * the function are provided in a stream. - * - * This is optional, but is almost always used. - * - * Page 265 of the PDF 1.3 spec has more. - * @param theFilter This is a vector of String objects which - * are the various filters that have are to be - * applied to the stream to make sense of it. - * Order matters, so watch out. - * - * This is not documented in the Function section of the PDF 1.3 spec, - * it was deduced from samples that this is sometimes used, even if we may never - * use it in FOP. It is added for completeness sake. - * @param theFunctionType This is the type of function (0,2,3, or 4). - * It should be 0 as this is the constructor for sampled functions. - * @return the PDF function that was created - */ - public PDFFunction makeFunction(int theFunctionType, List theDomain, - List theRange, List theSize, - int theBitsPerSample, int theOrder, - List theEncode, List theDecode, - StringBuffer theFunctionDataStream, - List theFilter) { - // Type 0 function - PDFFunction function = new PDFFunction(++this.objectcount, - theFunctionType, theDomain, - theRange, theSize, - theBitsPerSample, theOrder, - theEncode, theDecode, - theFunctionDataStream, - theFilter); - - PDFFunction oldfunc = findFunction(function); - if (oldfunc == null) { - functions.add(function); - this.objects.add(function); - } else { - this.objectcount--; - function = oldfunc; - } - - return (function); - } - - /** - * make a type Exponential interpolation function - * (for shading usually) - * - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List of Doubles that is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theCZero This is a vector of Double objects which defines the function result - * when x=0. - * - * This attribute is optional. - * It's described on page 268 of the PDF 1.3 spec. - * @param theCOne This is a vector of Double objects which defines the function result - * when x=1. - * - * This attribute is optional. - * It's described on page 268 of the PDF 1.3 spec. - * @param theInterpolationExponentN This is the inerpolation exponent. - * - * This attribute is required. - * PDF Spec page 268 - * @param theFunctionType The type of the function, which should be 2. - * @return the PDF function that was created - */ - public PDFFunction makeFunction(int theFunctionType, List theDomain, - List theRange, List theCZero, - List theCOne, - double theInterpolationExponentN) { // type 2 - PDFFunction function = new PDFFunction(++this.objectcount, - theFunctionType, theDomain, - theRange, theCZero, theCOne, - theInterpolationExponentN); - PDFFunction oldfunc = findFunction(function); - if (oldfunc == null) { - functions.add(function); - this.objects.add(function); - } else { - this.objectcount--; - function = oldfunc; - } - - return (function); - } - - private Object findPDFObject(List list, PDFObject compare) { - for (Iterator iter = list.iterator(); iter.hasNext();) { - Object obj = iter.next(); - if (compare.equals(obj)) { - return obj; - } - } - return null; - } - - private PDFFunction findFunction(PDFFunction compare) { - return (PDFFunction)findPDFObject(functions, compare); - } - - private PDFShading findShading(PDFShading compare) { - return (PDFShading)findPDFObject(shadings, compare); - } - - /** - * Find a previous pattern. - * The problem with this is for tiling patterns the pattern - * data stream is stored and may use up memory, usually this - * would only be a small amount of data. - */ - private PDFPattern findPattern(PDFPattern compare) { - return (PDFPattern)findPDFObject(patterns, compare); - } - - /** - * Make a Type 3 Stitching function - * - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theFunctions An List of the PDFFunction objects - * that the stitching function stitches. - * - * This attributed is required. - * It is described on page 269 of the PDF spec. - * @param theBounds This is a vector of Doubles representing - * the numbers that, in conjunction with Domain - * define the intervals to which each function from - * the 'functions' object applies. It must be in - * order of increasing magnitude, and each must be - * within Domain. - * - * It basically sets how much of the gradient each function handles. - * - * This attributed is required. - * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode List objects of Double objects. - * This is the linear mapping of input values intop the domain - * of the function's sample table. Default is hard to represent in - * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. - * This attribute is required. - * - * See page 270 in the PDF 1.3 spec. - * @param theFunctionType This is the function type. It should be 3, - * for a stitching function. - * @return the PDF function that was created - */ - public PDFFunction makeFunction(int theFunctionType, List theDomain, - List theRange, List theFunctions, - List theBounds, - List theEncode) { - // Type 3 - - PDFFunction function = new PDFFunction(++this.objectcount, - theFunctionType, theDomain, - theRange, theFunctions, - theBounds, theEncode); - - PDFFunction oldfunc = findFunction(function); - if (oldfunc == null) { - functions.add(function); - this.objects.add(function); - } else { - this.objectcount--; - function = oldfunc; - } - - return (function); - } - - /** - * make a postscript calculator function - * - * @param theNumber the PDF object number - * @param theFunctionType the type of function to make - * @param theDomain the domain values - * @param theRange the range values of the function - * @param theFunctionDataStream a string containing the pdf drawing - * @return the PDF function that was created - */ - public PDFFunction makeFunction(int theNumber, int theFunctionType, - List theDomain, List theRange, - StringBuffer theFunctionDataStream) { - // Type 4 - PDFFunction function = new PDFFunction(++this.objectcount, - theFunctionType, theDomain, - theRange, - theFunctionDataStream); - - PDFFunction oldfunc = findFunction(function); - if (oldfunc == null) { - functions.add(function); - this.objects.add(function); - } else { - this.objectcount--; - function = oldfunc; - } - - return (function); - - } - - /** - * make a function based shading object - * - * @param res the PDF resource context to add the shading, may be null - * @param theShadingType The type of shading object, which should be 1 for function - * based shading. - * @param theColorSpace The colorspace is 'DeviceRGB' or something similar. - * @param theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Whether or not to anti-alias. - * @param theDomain Optional vector of Doubles specifying the domain. - * @param theMatrix List of Doubles specifying the matrix. - * If it's a pattern, then the matrix maps it to pattern space. - * If it's a shading, then it maps it to current user space. - * It's optional, the default is the identity matrix - * @param theFunction The PDF Function that maps an (x,y) location to a color - * @return the PDF shading that was created - */ - public PDFShading makeShading(PDFResourceContext res, int theShadingType, - PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, List theDomain, - List theMatrix, - PDFFunction theFunction) { - // make Shading of Type 1 - String theShadingName = new String("Sh" + (++this.shadingCount)); - - PDFShading shading = new PDFShading(++this.objectcount, - theShadingName, theShadingType, - theColorSpace, theBackground, - theBBox, theAntiAlias, theDomain, - theMatrix, theFunction); - - PDFShading oldshad = findShading(shading); - if (oldshad == null) { - shadings.add(shading); - this.objects.add(shading); - } else { - this.objectcount--; - this.shadingCount--; - shading = oldshad; - } - - // add this shading to resources - if (res != null) { - res.getPDFResources().addShading(shading); - } else { - this.resources.addShading(shading); - } - - return (shading); - } - - /** - * Make an axial or radial shading object. - * - * @param res the PDF resource context to add the shading, may be null - * @param theShadingType 2 or 3 for axial or radial shading - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theCoords List of four (type 2) or 6 (type 3) Double - * @param theDomain List of Doubles specifying the domain - * @param theFunction the Stitching (PDFfunction type 3) function, - * even if it's stitching a single function - * @param theExtend List of Booleans of whether to extend the - * start and end colors past the start and end points - * The default is [false, false] - * @return the PDF shading that was created - */ - public PDFShading makeShading(PDFResourceContext res, int theShadingType, - PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, List theCoords, - List theDomain, PDFFunction theFunction, - List theExtend) { - // make Shading of Type 2 or 3 - String theShadingName = new String("Sh" + (++this.shadingCount)); - - PDFShading shading = new PDFShading(++this.objectcount, - theShadingName, theShadingType, - theColorSpace, theBackground, - theBBox, theAntiAlias, theCoords, - theDomain, theFunction, - theExtend); - - PDFShading oldshad = findShading(shading); - if (oldshad == null) { - shadings.add(shading); - this.objects.add(shading); - } else { - this.objectcount--; - this.shadingCount--; - shading = oldshad; - } - - if (res != null) { - res.getPDFResources().addShading(shading); - } else { - this.resources.addShading(shading); - } - - return (shading); - } - - /** - * Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh - * shading object - * - * @param res the PDF resource context to add the shading, may be null - * @param theShadingType 4, 6, or 7 depending on whether it's - * Free-form gouraud-shaded triangle meshes, coons patch meshes, - * or tensor product patch meshes, respectively. - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. - * @param theBitsPerComponent 1,2,4,8,12, and 16 - * @param theBitsPerFlag 2,4,8. - * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. - * @param theFunction the PDFFunction - * @return the PDF shading that was created - */ - public PDFShading makeShading(PDFResourceContext res, int theShadingType, - PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, - int theBitsPerCoordinate, - int theBitsPerComponent, - int theBitsPerFlag, List theDecode, - PDFFunction theFunction) { - // make Shading of type 4,6 or 7 - String theShadingName = new String("Sh" + (++this.shadingCount)); - - PDFShading shading = new PDFShading(++this.objectcount, - theShadingName, theShadingType, - theColorSpace, theBackground, - theBBox, theAntiAlias, - theBitsPerCoordinate, - theBitsPerComponent, - theBitsPerFlag, theDecode, - theFunction); - - PDFShading oldshad = findShading(shading); - if (oldshad == null) { - shadings.add(shading); - this.objects.add(shading); - } else { - this.objectcount--; - this.shadingCount--; - shading = oldshad; - } - - if (res != null) { - res.getPDFResources().addShading(shading); - } else { - this.resources.addShading(shading); - } - - return (shading); - } - - /** - * make a Lattice-Form Gouraud mesh shading object - * - * @param res the PDF resource context to add the shading, may be null - * @param theShadingType 5 for lattice-Form Gouraud shaded-triangle mesh - * without spaces. "Shading1" or "Sh1" are good examples. - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 - * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode List of Doubles. See page 305 in PDF 1.3 spec. - * @param theVerticesPerRow number of vertices in each "row" of the lattice. - * @param theFunction The PDFFunction that's mapped on to this shape - * @return the PDF shading that was created - */ - public PDFShading makeShading(PDFResourceContext res, int theShadingType, - PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, - int theBitsPerCoordinate, - int theBitsPerComponent, List theDecode, - int theVerticesPerRow, - PDFFunction theFunction) { - // make shading of Type 5 - String theShadingName = new String("Sh" + (++this.shadingCount)); - - PDFShading shading = new PDFShading(++this.objectcount, - theShadingName, theShadingType, - theColorSpace, theBackground, - theBBox, theAntiAlias, - theBitsPerCoordinate, - theBitsPerComponent, theDecode, - theVerticesPerRow, theFunction); - - PDFShading oldshad = findShading(shading); - if (oldshad == null) { - shadings.add(shading); - this.objects.add(shading); - } else { - this.objectcount--; - this.shadingCount--; - shading = oldshad; - } - - if (res != null) { - res.getPDFResources().addShading(shading); - } else { - this.resources.addShading(shading); - } - - return (shading); - } - - /** - * Make a tiling pattern - * - * @param res the PDF resource context to add the shading, may be null - * @param thePatternType the type of pattern, which is 1 for tiling. - * @param theResources the resources associated with this pattern - * @param thePaintType 1 or 2, colored or uncolored. - * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox List of Doubles: The pattern cell bounding box - * @param theXStep horizontal spacing - * @param theYStep vertical spacing - * @param theMatrix Optional List of Doubles transformation matrix - * @param theXUID Optional vector of Integers that uniquely identify the pattern - * @param thePatternDataStream The stream of pattern data to be tiled. - * @return the PDF pattern that was created - */ - public PDFPattern makePattern(PDFResourceContext res, int thePatternType, // 1 - PDFResources theResources, int thePaintType, int theTilingType, - List theBBox, double theXStep, - double theYStep, List theMatrix, - List theXUID, StringBuffer thePatternDataStream) { - String thePatternName = new String("Pa" + (++this.patternCount)); - // int theNumber, String thePatternName, - // PDFResources theResources - PDFPattern pattern = new PDFPattern(++this.objectcount, - thePatternName, theResources, 1, - thePaintType, theTilingType, - theBBox, theXStep, theYStep, - theMatrix, theXUID, - thePatternDataStream); - - PDFPattern oldpatt = findPattern(pattern); - if (oldpatt == null) { - patterns.add(pattern); - this.objects.add(pattern); - } else { - this.objectcount--; - this.patternCount--; - pattern = oldpatt; - } - - if (res != null) { - res.getPDFResources().addPattern(pattern); - } else { - this.resources.addPattern(pattern); - } - - return (pattern); - } - - /** - * Make a smooth shading pattern - * - * @param res the PDF resource context to add the shading, may be null - * @param thePatternType the type of the pattern, which is 2, smooth shading - * @param theShading the PDF Shading object that comprises this pattern - * @param theXUID optional:the extended unique Identifier if used. - * @param theExtGState optional: the extended graphics state, if used. - * @param theMatrix Optional:List of Doubles that specify the matrix. - * @return the PDF pattern that was created - */ - public PDFPattern makePattern(PDFResourceContext res, - int thePatternType, PDFShading theShading, - List theXUID, StringBuffer theExtGState, - List theMatrix) { - String thePatternName = new String("Pa" + (++this.patternCount)); - - PDFPattern pattern = new PDFPattern(++this.objectcount, - thePatternName, 2, theShading, - theXUID, theExtGState, theMatrix); - - PDFPattern oldpatt = findPattern(pattern); - if (oldpatt == null) { - patterns.add(pattern); - this.objects.add(pattern); - } else { - this.objectcount--; - this.patternCount--; - pattern = oldpatt; - } - - if (res != null) { - res.getPDFResources().addPattern(pattern); - } else { - this.resources.addPattern(pattern); - } - - return (pattern); - } - - /** - * Get the color space. - * - * @return the color space - */ - public int getColorSpace() { - return (this.colorspace.getColorSpace()); - } - - /** - * Set the color space. - * This is used when creating gradients. - * - * @param theColorspace the new color space - */ - public void setColorSpace(int theColorspace) { - this.colorspace.setColorSpace(theColorspace); - return; - } - - /** - * Make a gradient - * - * @param res the PDF resource context to add the shading, may be null - * @param radial if true a radial gradient will be created - * @param theColorspace the colorspace of the gradient - * @param theColors the list of colors for the gradient - * @param theBounds the list of bounds associated with the colors - * @param theCoords the coordinates for the gradient - * @return the PDF pattern that was created - */ - public PDFPattern createGradient(PDFResourceContext res, boolean radial, - PDFColorSpace theColorspace, - List theColors, List theBounds, - List theCoords) { - PDFShading myShad; - PDFFunction myfunky; - PDFFunction myfunc; - List theCzero; - List theCone; - PDFPattern myPattern; - //PDFColorSpace theColorSpace; - double interpolation = (double)1.000; - List theFunctions = new java.util.ArrayList(); - - int currentPosition; - int lastPosition = theColors.size() - 1; - - - // if 5 elements, the penultimate element is 3. - // do not go beyond that, because you always need - // to have a next color when creating the function. - - for (currentPosition = 0; currentPosition < lastPosition; - currentPosition++) { // for every consecutive color pair - PDFColor currentColor = - (PDFColor)theColors.get(currentPosition); - PDFColor nextColor = (PDFColor)theColors.get(currentPosition - + 1); - // colorspace must be consistant - if (this.colorspace.getColorSpace() - != currentColor.getColorSpace()) { - currentColor.setColorSpace(this.colorspace.getColorSpace()); - } - - if (this.colorspace.getColorSpace() != nextColor.getColorSpace()) { - nextColor.setColorSpace(this.colorspace.getColorSpace()); - } - - theCzero = currentColor.getVector(); - theCone = nextColor.getVector(); - - myfunc = this.makeFunction(2, null, null, theCzero, theCone, - interpolation); - - theFunctions.add(myfunc); - - } // end of for every consecutive color pair - - myfunky = this.makeFunction(3, null, null, theFunctions, theBounds, - null); - - if (radial) { - if (theCoords.size() == 6) { - myShad = this.makeShading(res, 3, this.colorspace, null, null, - false, theCoords, null, myfunky, - null); - } else { // if the center x, center y, and radius specifiy - // the gradient, then assume the same center x, center y, - // and radius of zero for the other necessary component - List newCoords = new java.util.ArrayList(); - newCoords.add(theCoords.get(0)); - newCoords.add(theCoords.get(1)); - newCoords.add(theCoords.get(2)); - newCoords.add(theCoords.get(0)); - newCoords.add(theCoords.get(1)); - newCoords.add(new Double(0.0)); - - myShad = this.makeShading(res, 3, this.colorspace, null, null, - false, newCoords, null, myfunky, - null); - - } - } else { - myShad = this.makeShading(res, 2, this.colorspace, null, null, false, - theCoords, null, myfunky, null); - - } - - myPattern = this.makePattern(res, 2, myShad, null, null, null); - - return (myPattern); - } - - - /** - * make a /Encoding object - * - * @param encodingName character encoding scheme name - * @return the created /Encoding object - */ - public PDFEncoding makeEncoding(String encodingName) { - - /* - * create a PDFEncoding with the next object number and add to the - * list of objects - */ - PDFEncoding encoding = new PDFEncoding(++this.objectcount, - encodingName); - this.objects.add(encoding); - return encoding; - } - - /** - * Create a PDFICCStream - * @see PDFXObject - * @see org.apache.fop.image.JpegImage - * @see org.apache.fop.pdf.PDFColorSpace - * @return the new PDF ICC stream object - */ - public PDFICCStream makePDFICCStream() { - PDFICCStream iccStream = new PDFICCStream(++this.objectcount); - this.objects.add(iccStream); - return iccStream; - } - - /** - * Get the font map for this document. - * - * @return the map of fonts used in this document - */ - public Map getFontMap() { - return fontMap; - } - - /** - * make a Type1 /Font object - * - * @param fontname internal name to use for this font (eg "F1") - * @param basefont name of the base font (eg "Helvetica") - * @param encoding character encoding scheme used by the font - * @param metrics additional information about the font - * @param descriptor additional information about the font - * @return the created /Font object - */ - public PDFFont makeFont(String fontname, String basefont, - String encoding, FontMetrics metrics, - FontDescriptor descriptor) { - if (fontMap.containsKey(fontname)) { - return (PDFFont)fontMap.get(fontname); - } - - /* - * create a PDFFont with the next object number and add to the - * list of objects - */ - if (descriptor == null) { - PDFFont font = new PDFFont(++this.objectcount, fontname, - FontType.TYPE1, basefont, encoding); - this.objects.add(font); - fontMap.put(fontname, font); - return font; - } else { - FontType fonttype = metrics.getFontType(); - - PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor); - - PDFFontNonBase14 font = null; - if (fonttype == FontType.TYPE0) { - /* - * Temporary commented out - customized CMaps - * isn't needed until /ToUnicode support is added - * PDFCMap cmap = new PDFCMap(++this.objectcount, - * "fop-ucs-H", - * new PDFCIDSystemInfo("Adobe", - * "Identity", - * 0)); - * cmap.addContents(); - * this.objects.add(cmap); - */ - font = - (PDFFontNonBase14)PDFFont.createFont(++this.objectcount, - fontname, fonttype, - basefont, - "Identity-H"); - } else { - - font = - (PDFFontNonBase14)PDFFont.createFont(++this.objectcount, - fontname, fonttype, - basefont, encoding); - } - this.objects.add(font); - - font.setDescriptor(pdfdesc); - - if (fonttype == FontType.TYPE0) { - CIDFont cidMetrics; - if (metrics instanceof LazyFont) { - cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont(); - } else { - cidMetrics = (CIDFont)metrics; - } - PDFCIDSystemInfo sysInfo = - new PDFCIDSystemInfo(cidMetrics.getRegistry(), - cidMetrics.getOrdering(), - cidMetrics.getSupplement()); - PDFCIDFont cidFont = - new PDFCIDFont(++this.objectcount, basefont, - cidMetrics.getCIDType(), - cidMetrics.getDefaultWidth(), - cidMetrics.getWidths(), sysInfo, - (PDFCIDFontDescriptor)pdfdesc); - this.objects.add(cidFont); - - ((PDFFontType0)font).setDescendantFonts(cidFont); - } else { - int firstChar = 0; - int lastChar = 255; - if (metrics instanceof CustomFont) { - CustomFont cf = (CustomFont)metrics; - firstChar = cf.getFirstChar(); - lastChar = cf.getLastChar(); - } - font.setWidthMetrics(firstChar, - lastChar, - makeArray(metrics.getWidths())); - } - - fontMap.put(fontname, font); - - return font; - } - } - - - /** - * make a /FontDescriptor object - * - * @param desc the font descriptor - * @return the new PDF font descriptor - */ - public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) { - PDFFontDescriptor font = null; - - if (desc.getFontType() == FontType.TYPE0) { - // CID Font - font = new PDFCIDFontDescriptor(++this.objectcount, - desc.getFontName(), - desc.getFontBBox(), - desc.getCapHeight(), desc.getFlags(), - desc.getItalicAngle(), - desc.getStemV(), null); - } else { - // Create normal FontDescriptor - font = new PDFFontDescriptor(++this.objectcount, desc.getFontName(), - desc.getAscender(), - desc.getDescender(), - desc.getCapHeight(), - desc.getFlags(), - new PDFRectangle(desc.getFontBBox()), - desc.getStemV(), - desc.getItalicAngle()); - } - this.objects.add(font); - - // Check if the font is embeddable - if (desc.isEmbeddable()) { - PDFStream stream = makeFontFile(this.objectcount + 1, desc); - if (stream != null) { - this.objectcount++; - font.setFontFile(desc.getFontType(), stream); - this.objects.add(stream); - } - } - return font; - } - - /** - * Resolve a URI. - * - * @param uri the uri to resolve - * @throws java.io.FileNotFoundException if the URI could not be resolved - * @return the InputStream from the URI. - */ - protected InputStream resolveURI(String uri) - throws java.io.FileNotFoundException { - try { - /**@todo Temporary hack to compile, improve later */ - return new java.net.URL(uri).openStream(); - } catch (Exception e) { - throw new java.io.FileNotFoundException( - "URI could not be resolved (" + e.getMessage() + "): " + uri); - } - } - - /** - * Embeds a font. - * @param obj PDF object number to use - * @param desc FontDescriptor of the font. - * @return PDFStream The embedded font file - */ - public PDFStream makeFontFile(int obj, FontDescriptor desc) { - if (desc.getFontType() == FontType.OTHER) { - throw new IllegalArgumentException("Trying to embed unsupported font type: " - + desc.getFontType()); - } - if (!(desc instanceof CustomFont)) { - throw new IllegalArgumentException( - "FontDescriptor must be instance of CustomFont, but is a " - + desc.getClass().getName()); - } - - CustomFont font = (CustomFont)desc; - - InputStream in = null; - try { - // Get file first - if (font.getEmbedFileName() != null) { - try { - in = resolveURI(font.getEmbedFileName()); - } catch (Exception e) { - System.out.println("Failed to embed fontfile: " - + font.getEmbedFileName()); - } - } - - // Get resource - if (in == null && font.getEmbedResourceName() != null) { - try { - in = new java.io.BufferedInputStream( - this.getClass().getResourceAsStream(font.getEmbedResourceName())); - } catch (Exception e) { - System.out.println("Failed to embed fontresource: " - + font.getEmbedResourceName()); - } - } - - if (in == null) { - return null; - } else { - try { - PDFStream embeddedFont; - if (desc.getFontType() == FontType.TYPE0) { - MultiByteFont mbfont = (MultiByteFont)font; - FontFileReader reader = new FontFileReader(in); - - TTFSubSetFile subset = new TTFSubSetFile(); - - byte[] subsetFont = subset.readFont(reader, - mbfont.getTTCName(), mbfont.getUsedGlyphs()); - // Only TrueType CID fonts are supported now - - embeddedFont = new PDFTTFStream(obj, subsetFont.length); - ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length); - } else if (desc.getFontType() == FontType.TYPE1) { - PFBParser parser = new PFBParser(); - PFBData pfb = parser.parsePFB(in); - embeddedFont = new PDFT1Stream(obj); - ((PDFT1Stream)embeddedFont).setData(pfb); - } else { - byte[] file = StreamUtilities.toByteArray(in, 128000); - embeddedFont = new PDFTTFStream(obj, file.length); - ((PDFTTFStream)embeddedFont).setData(file, file.length); - } - embeddedFont.addFilter("flate"); - embeddedFont.addFilter("ascii-85"); - return embeddedFont; - } finally { - in.close(); - } - } - } catch (IOException ioe) { - //log.error("Failed to embed font [" + obj + "] " - // + fontName + ": " + ioe.getMessage()); - return (PDFStream) null; - } - } - -/* - public PDFStream getFontFile(int i) { - PDFStream embeddedFont = null; - - - return (PDFStream)embeddedFont; - } - - - public PDFStream getFontFile(int i) { - } - -*/ - - - /** - * make an Array object (ex. Widths array for a font) - * - * @param values the int array values - * @return the PDF Array with the int values - */ - public PDFArray makeArray(int[] values) { - PDFArray array = new PDFArray(++this.objectcount, values); - this.objects.add(array); - return array; - } - - /** - * make an ExtGState for extra graphics options - * This tries to find a GState that will setup the correct values - * for the current context. If there is no suitable GState it will - * create a new one. - * - * @param settings the settings required by the caller - * @param current the current GState of the current PDF context - * @return a PDF GState, either an existing GState or a new one - */ - public PDFGState makeGState(Map settings, PDFGState current) { - - // try to locate a gstate that has all the settings - // or will inherit from the current gstate - // compare "DEFAULT + settings" with "current + each gstate" - - PDFGState wanted = new PDFGState(0); - wanted.addValues(PDFGState.DEFAULT); - wanted.addValues(settings); - - PDFGState poss; - for (Iterator iter = gstates.iterator(); iter.hasNext();) { - PDFGState avail = (PDFGState)iter.next(); - poss = new PDFGState(0); - poss.addValues(current); - poss.addValues(avail); - if (poss.equals(wanted)) { - return avail; - } - } - - PDFGState gstate = new PDFGState(++this.objectcount); - gstate.addValues(settings); - this.objects.add(gstate); - gstates.add(gstate); - return gstate; - } - - /** - * Get an image from the image map. - * - * @param key the image key to look for - * @return the image or PDFXObject for the key if found - */ - public PDFXObject getImage(String key) { - PDFXObject xObject = (PDFXObject)xObjectsMap.get(key); - return xObject; - } - - /** - * Add an image to the PDF document. - * This adds an image to the PDF objects. - * If an image with the same key already exists it will return the - * old PDFXObject. - * - * @param res the PDF resource context to add to, may be null - * @param img the PDF image to add - * @return the PDF XObject that references the PDF image data - */ - public PDFXObject addImage(PDFResourceContext res, PDFImage img) { - // check if already created - String key = img.getKey(); - PDFXObject xObject = (PDFXObject)xObjectsMap.get(key); - if (xObject != null) { - if (res != null) { - res.getPDFResources().addXObject(xObject); - } - return xObject; - } - - // setup image - img.setup(this); - // create a new XObject - xObject = new PDFXObject(++this.objectcount, ++this.xObjectCount, - img); - this.objects.add(xObject); - this.resources.addXObject(xObject); - if (res != null) { - res.getPDFResources().addXObject(xObject); - } - this.xObjectsMap.put(key, xObject); - return xObject; - } - - /** - * Add a form XObject to the PDF document. - * This adds a Form XObject to the PDF objects. - * If a Form XObject with the same key already exists it will return the - * old PDFFormXObject. - * - * @param res the PDF resource context to add to, may be null - * @param cont the PDF Stream contents of the Form XObject - * @param formres the PDF Resources for the Form XObject data - * @param key the key for the object - * @return the PDF Form XObject that references the PDF data - */ - public PDFFormXObject addFormXObject(PDFResourceContext res, PDFStream cont, - PDFResources formres, String key) { - PDFFormXObject xObject; - xObject = new PDFFormXObject(++this.objectcount, ++this.xObjectCount, - cont, formres.referencePDF()); - this.objects.add(xObject); - this.resources.addXObject(xObject); - if (res != null) { - res.getPDFResources().addXObject(xObject); - } - return xObject; - } - - /** - * make a /Page object - * - * @param resources resources object to use - * @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, - int pagewidth, int pageheight) { - - /* - * create a PDFPage with the next object number, the given - * resources, contents and dimensions - */ - PDFPage page = new PDFPage(this, ++this.objectcount, resources, - pagewidth, pageheight); - - /* add it to the list of objects */ - pages.addPage(page); - return page; - } - - /** - * Add a completed page to the PDF document. - * The page is added to the object list. - * - * @param page the page to add - */ - public void addPage(PDFPage page) { - /* add it to the list of objects */ - this.objects.add(page); - } - - private PDFLink findLink(PDFLink compare) { - return (PDFLink)findPDFObject(links, compare); - } - - private PDFFileSpec findFileSpec(PDFFileSpec compare) { - return (PDFFileSpec)findPDFObject(filespecs, compare); - } - - private PDFGoToRemote findGoToRemote(PDFGoToRemote compare) { - return (PDFGoToRemote)findPDFObject(gotoremotes, compare); - } - - private PDFGoTo findGoTo(PDFGoTo compare) { - return (PDFGoTo)findPDFObject(gotos, compare); - } - - /** - * make a link object - * - * @param rect the clickable rectangle - * @param destination the destination file - * @param linkType the link type - * @param yoffset the yoffset on the page for an internal link - * @return the PDFLink object created - */ - public PDFLink makeLink(Rectangle2D rect, String destination, - int linkType, float yoffset) { - - //PDFLink linkObject; - int index; - - PDFLink link = new PDFLink(++this.objectcount, rect); - - if (linkType == PDFLink.EXTERNAL) { - // check destination - if (destination.startsWith("http://")) { - PDFUri uri = new PDFUri(destination); - link.setAction(uri); - } else if (destination.endsWith(".pdf")) { // FileSpec - PDFGoToRemote remote = getGoToPDFAction(destination, null, -1); - link.setAction(remote); - } else if ((index = destination.indexOf(".pdf#page=")) > 0) { - //String file = destination.substring(0, index + 4); - int page = Integer.parseInt(destination.substring(index + 10)); - PDFGoToRemote remote = getGoToPDFAction(destination, null, page); - link.setAction(remote); - } else if ((index = destination.indexOf(".pdf#dest=")) > 0) { - //String file = destination.substring(0, index + 4); - String dest = destination.substring(index + 10); - PDFGoToRemote remote = getGoToPDFAction(destination, dest, -1); - link.setAction(remote); - } else { // URI - PDFUri uri = new PDFUri(destination); - link.setAction(uri); - } - } else { - // linkType is internal - String goToReference = getGoToReference(destination, yoffset); - PDFInternalLink internalLink = new PDFInternalLink(goToReference); - link.setAction(internalLink); - } - - PDFLink oldlink = findLink(link); - if (oldlink == null) { - links.add(link); - this.objects.add(link); - } else { - this.objectcount--; - link = oldlink; - } - - return link; - } - - /** - * Create and return a goto pdf document action. - * This creates a pdf files spec and pdf goto remote action. - * It also checks available pdf objects so it will not create an - * object if it already exists. - * - * @param file the pdf file name - * @param dest the remote name destination, may be null - * @param page the remote page number, -1 means not specified - * @return the pdf goto remote object - */ - private PDFGoToRemote getGoToPDFAction(String file, String dest, int page) { - PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file); - PDFFileSpec oldspec = findFileSpec(fileSpec); - if (oldspec == null) { - filespecs.add(fileSpec); - this.objects.add(fileSpec); - } else { - this.objectcount--; - fileSpec = oldspec; - } - PDFGoToRemote remote; - - if (dest == null && page == -1) { - remote = new PDFGoToRemote(++this.objectcount, fileSpec); - } else if (dest != null) { - remote = new PDFGoToRemote(++this.objectcount, fileSpec, dest); - } else { - remote = new PDFGoToRemote(++this.objectcount, fileSpec, page); - } - PDFGoToRemote oldremote = findGoToRemote(remote); - if (oldremote == null) { - gotoremotes.add(remote); - this.objects.add(remote); - } else { - this.objectcount--; - remote = oldremote; - } - return remote; - } - - private String getGoToReference(String destination, float yoffset) { - String goToReference = null; - PDFGoTo gt = new PDFGoTo(++this.objectcount, destination); - gt.setYPosition(yoffset); - PDFGoTo oldgt = findGoTo(gt); - if (oldgt == null) { - gotos.add(gt); - addTrailerObject(gt); - } else { - this.objectcount--; - gt = oldgt; - } - - goToReference = gt.referencePDF(); - return goToReference; - } - - /** - * Add trailer object. - * Adds an object to the list of trailer objects. - * - * @param object the PDF object to add - */ - public void addTrailerObject(PDFObject object) { - this.trailerObjects.add(object); - } - - /** - * Make an internal link. - * - * @param rect the hotspot position in absolute coordinates - * @param page the target page reference value - * @param dest the position destination - * @return the new PDF link object - */ - public PDFLink makeLink(Rectangle2D rect, String page, String dest) { - PDFLink link = new PDFLink(++this.objectcount, rect); - this.objects.add(link); - - PDFGoTo gt = new PDFGoTo(++this.objectcount, page); - gt.setDestination(dest); - addTrailerObject(gt); - PDFInternalLink internalLink = new PDFInternalLink(gt.referencePDF()); - link.setAction(internalLink); - - return link; - } - - /** - * Ensure there is room in the locations xref for the number of - * objects that have been created. - */ - private void prepareLocations() { - while (location.size() < objectcount) { - location.add(LOCATION_PLACEHOLDER); - } - } - - /** - * make a stream object - * - * @param type the type of stream to be created - * @param add if true then the stream will be added immediately - * @return the stream object created - */ - public PDFStream makeStream(String type, boolean add) { - - /* - * create a PDFStream with the next object number and add it - * - * to the list of objects - */ - PDFStream obj = new PDFStream(++this.objectcount); - obj.addDefaultFilters(filterMap, type); - - if (add) { - this.objects.add(obj); - } - return obj; - } - - /** - * add a stream object - * - * @param obj the PDF Stream to add to this document - */ - public void addStream(PDFStream obj) { - this.objects.add(obj); - } - - /** - * make an annotation list object - * - * @return the annotation list object created - */ - public PDFAnnotList makeAnnotList() { - - /* - * create a PDFAnnotList with the next object number and add it - * to the list of objects - */ - PDFAnnotList obj = new PDFAnnotList(++this.objectcount); - return obj; - } - - /** - * Add an annotation list object to the pdf document - * - * @param obj the annotation list to add - */ - public void addAnnotList(PDFAnnotList obj) { - this.objects.add(obj); - } - - /** - * Get the root Outlines object. This method does not write - * the outline to the PDF document, it simply creates a - * reference for later. - * - * @return the PDF Outline root object - */ - public PDFOutline getOutlineRoot() { - if (outlineRoot != null) { - return outlineRoot; - } - - outlineRoot = new PDFOutline(++this.objectcount, null, null); - addTrailerObject(outlineRoot); - root.setRootOutline(outlineRoot); - return outlineRoot; - } - - /** - * Make an outline object and add it to the given outline - * - * @param parent parent PDFOutline object which may be null - * @param label the title for the new outline object - * @param destination the reference string for the action to go to - * @param yoffset the yoffset on the destination page - * @return the new PDF outline object - */ - public PDFOutline makeOutline(PDFOutline parent, String label, - String destination, float yoffset) { - String goToRef = getGoToReference(destination, yoffset); - - PDFOutline obj = new PDFOutline(++this.objectcount, label, goToRef); - - if (parent != null) { - parent.addOutline(obj); - } - this.objects.add(obj); - return obj; - } - - /** - * get the /Resources object for the document - * - * @return the /Resources object - */ - public PDFResources getResources() { - return this.resources; - } - - /** - * write the entire document out - * - * @param stream the OutputStream to output the document to - * @throws IOException if there is an exception writing to the output stream - */ - public void output(OutputStream stream) throws IOException { - - prepareLocations(); - - for (int count = 0; count < this.objects.size(); count++) { - /* retrieve the object with the current number */ - PDFObject object = (PDFObject)this.objects.get(count); - - /* - * add the position of this object to the list of object - * locations - */ - location.set(object.getNumber() - 1, - new Integer(this.position)); - - /* - * output the object and increment the character position - * by the object's length - */ - this.position += object.output(stream); - } - - this.objects.clear(); - } - - /** - * write the PDF header <P> - * - * This method must be called prior to formatting - * and outputting AreaTrees. - * - * @param stream the OutputStream to write the header to - * @throws IOException if there is an exception writing to the output stream - */ - public void outputHeader(OutputStream stream) - throws IOException { - this.position = 0; - - byte[] pdf = ("%PDF-" + PDF_VERSION + "\n").getBytes(); - stream.write(pdf); - this.position += pdf.length; - - // output a binary comment as recommended by the PDF spec (3.4.1) - byte[] bin = { - (byte)'%', (byte)0xAA, (byte)0xAB, (byte)0xAC, (byte)0xAD, - (byte)'\n' - }; - stream.write(bin); - this.position += bin.length; - } - - /** - * write the trailer - * - * @param stream the OutputStream to write the trailer to - * @throws IOException if there is an exception writing to the output stream - */ - public void outputTrailer(OutputStream stream) - throws IOException { - output(stream); - for (int count = 0; count < trailerObjects.size(); count++) { - PDFObject o = (PDFObject) trailerObjects.get(count); - this.location.set(o.getNumber() - 1, - new Integer(this.position)); - this.position += o.output(stream); - } - /* output the xref table and increment the character position - by the table's length */ - this.position += outputXref(stream); - - /* construct the trailer */ - String pdf = "trailer\n" + "<<\n" - + "/Size " + (this.objectcount + 1) + "\n" - + "/Root " + this.root.number + " " - + this.root.generation + " R\n" + "/Info " - + this.info.number + " " + this.info.generation - + " R\n" + ">>\n" + "startxref\n" + this.xref - + "\n" + "%%EOF\n"; - - /* write the trailer */ - stream.write(pdf.getBytes()); - } - - /** - * write the xref table - * - * @param stream the OutputStream to write the xref table to - * @return the number of characters written - */ - private int outputXref(OutputStream stream) throws IOException { - - /* remember position of xref table */ - this.xref = this.position; - - /* construct initial part of xref */ - StringBuffer pdf = new StringBuffer("xref\n0 " - + (this.objectcount + 1) - + "\n0000000000 65535 f \n"); - - for (int count = 0; count < this.location.size(); count++) { - String x = this.location.get(count).toString(); - - /* contruct xref entry for object */ - String padding = "0000000000"; - String loc = padding.substring(x.length()) + x; - - /* append to xref table */ - pdf = pdf.append(loc + " 00000 n \n"); - } - - /* write the xref table and return the character length */ - byte[] pdfBytes = pdf.toString().getBytes(); - stream.write(pdfBytes); - return pdfBytes.length; - } - -} - diff --git a/src/org/apache/fop/pdf/PDFEncoding.java b/src/org/apache/fop/pdf/PDFEncoding.java deleted file mode 100644 index d0f9b704f..000000000 --- a/src/org/apache/fop/pdf/PDFEncoding.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; -import java.util.Map; -import java.util.Iterator; -import java.util.HashMap; - -/** - * class representing an /Encoding object. - * - * A small object expressing the base encoding name and - * the differences from the base encoding. - * - * The three base encodings are given by their name. - * - * Encodings are specified in section 5.5.5 of the PDF 1.4 spec. - */ -public class PDFEncoding extends PDFObject { - - /** - * the name for the standard encoding scheme - */ - public static final String MAC_ROMAN_ENCODING = "MacRomanEncoding"; - - /** - * the name for the standard encoding scheme - */ - public static final String MAC_EXPERT_ENCODING = "MacExpertEncoding"; - - /** - * the name for the standard encoding scheme - */ - public static final String WIN_ANSI_ENCODING = "WinAnsiEncoding"; - - /** - * the name for the base encoding. - * One of the three base encoding scheme names or - * the default font's base encoding if null. - */ - protected String basename; - - /** - * the differences from the base encoding - */ - protected Map differences; - - /** - * create the /Encoding object - * - * @param number the object's number - * @param basename the name of the character encoding schema - */ - public PDFEncoding(int number, String basename) { - - /* generic creation of PDF object */ - super(number); - - /* set fields using paramaters */ - this.basename = basename; - this.differences = new HashMap(); - } - - /** - * add differences to the encoding - * - * @param code the first index of the sequence to be changed - * @param sequence the sequence of glyph names (as String) - */ - public void addDifferences(int code, List sequence) { - differences.put(new Integer(code), sequence); - } - - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< /Type /Encoding"); - if ((basename != null) && (!basename.equals(""))) { - p.append("\n/BaseEncoding /" + this.basename); - } - if (!differences.isEmpty()) { - p.append("\n/Differences [ "); - Object code; - Iterator codes = differences.keySet().iterator(); - while (codes.hasNext()) { - code = codes.next(); - p.append(" "); - p.append(code); - List sequence = (List)differences.get(code); - for (int i = 0; i < sequence.size(); i++) { - p.append(" /"); - p.append((String)sequence.get(i)); - } - } - p.append(" ]"); - } - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); - } - - /* - * example (p. 214) - * 25 0 obj - * << - * /Type /Encoding - * /Differences [39 /quotesingle 96 /grave 128 - * /Adieresis /Aring /Ccedilla /Eacute /Ntilde - * /Odieresis /Udieresis /aacute /agrave] - * >> - * endobj - */ -} diff --git a/src/org/apache/fop/pdf/PDFFileSpec.java b/src/org/apache/fop/pdf/PDFFileSpec.java deleted file mode 100644 index e5d61fce8..000000000 --- a/src/org/apache/fop/pdf/PDFFileSpec.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 byte[] toPDF() { - String p = new String(this.number + " " + this.generation - + " obj\n<<\n/Type /FileSpec\n" + "/F (" - + this.filename + ")\n" + ">>\nendobj\n"); - return p.getBytes(); - } - - /* - * example - * 29 0 obj - * << - * /Type /FileSpec - * /F (table1.pdf) - * >> - * endobj - */ - - /** - * Check if this equals another object. - * - * @param obj the object to compare - * @return true if this equals other object - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || !(obj instanceof PDFFileSpec)) { - return false; - } - - PDFFileSpec spec = (PDFFileSpec)obj; - - if (!spec.filename.equals(filename)) { - return false; - } - - return true; - } -} - diff --git a/src/org/apache/fop/pdf/PDFFilter.java b/src/org/apache/fop/pdf/PDFFilter.java deleted file mode 100644 index 18b2641bd..000000000 --- a/src/org/apache/fop/pdf/PDFFilter.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -/** - * PDF Filter class. - * This represents a PDF filter object. - * Filter implementations should extend this class. - * - * @author Eric SCHAEFFER, Kelly A. Campbell - */ -public abstract class PDFFilter { - /* - * These are no longer needed, but are here as a reminder about what - * filters pdf supports. - * public static final int ASCII_HEX_DECODE = 1; - * public static final int ASCII_85_DECODE = 2; - * public static final int LZW_DECODE = 3; - * public static final int RUN_LENGTH_DECODE = 4; - * public static final int CCITT_FAX_DECODE = 5; - * public static final int DCT_DECODE = 6; - * public static final int FLATE_DECODE = 7; - */ - - /** - * Marker to know if this filter has already been applied to the data - */ - private boolean applied = false; - - /** - * Check if this filter has been applied. - * - * @return true if this filter has been applied - */ - public boolean isApplied() { - return applied; - } - - /** - * Set the applied attribute to the given value. This attribute is - * used to determine if this filter is just a placeholder for the - * decodeparms and dictionary entries, or if the filter needs to - * actually encode the data. For example if the raw data is copied - * out of an image file in it's compressed format, then this - * should be set to true and the filter options should be set to - * those which the raw data was encoded with. - * - * @param b set the applied value to this - */ - public void setApplied(boolean b) { - applied = b; - } - - /** - * return a PDF string representation of the filter, e.g. /FlateDecode - * - * @return the filter PDF name - */ - public abstract String getName(); - - /** - * return a parameter dictionary for this filter, or null - * - * @return the decode params for the filter - */ - public abstract String getDecodeParms(); - - /** - * encode the given data with the filter - * - * @param in the input data stream to encode - * @param out the output stream to write the result - * @param length the length of data to read from the input stream - * @throws IOException if there is an error reading or writing the data - */ - public abstract void encode(InputStream in, OutputStream out, int length) throws IOException; - -} diff --git a/src/org/apache/fop/pdf/PDFFilterException.java b/src/org/apache/fop/pdf/PDFFilterException.java deleted file mode 100644 index a59ec7cfb..000000000 --- a/src/org/apache/fop/pdf/PDFFilterException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -/** - * PDF Filter exception. - * This is used for exceptions relating to use a PDF filter. - * - * @author Eric SCHAEFFER - */ -public class PDFFilterException extends Exception { - /** - * Create a basic filter exception. - */ - public PDFFilterException() { - } - - /** - * Create a filter exception with a message. - * - * @param message the error message - */ - public PDFFilterException(String message) { - super(message); - } -} - diff --git a/src/org/apache/fop/pdf/PDFFont.java b/src/org/apache/fop/pdf/PDFFont.java deleted file mode 100644 index e1585c9d1..000000000 --- a/src/org/apache/fop/pdf/PDFFont.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a /Font object. - * <p> - * A more complete object expressing the base font name and encoding of a - * font along with an internal name for the font used within - * streams of content. - * <p> - * Fonts are specified on page 198 and onwards of the PDF 1.3 spec. - */ -public class PDFFont extends PDFObject { - - /** - * the internal name for the font (eg "F1") - */ - protected String fontname; - - /** - * the font's subtype - * (as defined by the constants FontType: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE) - */ - protected FontType subtype; - - /** - * the base font name (eg "Helvetica") - */ - protected String basefont; - - /** - * the character encoding scheme used by the font. - * It can be a String for standard encodings, or - * a PDFEncoding for a more complex scheme, or - * a PDFStream containing a CMap in a Type0 font. - * If <code>null</code> then not written out in the PDF. - */ - protected Object encoding; - - /** - * the Unicode mapping mechanism - */ - // protected PDFToUnicode mapping; - - /** - * create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFont(int number, String fontname, FontType subtype, - String basefont, - Object encoding /* , PDFToUnicode mapping */) { - - /* generic creation of PDF object */ - super(number); - - /* set fields using paramaters */ - this.fontname = fontname; - this.subtype = subtype; - this.basefont = basefont; - this.encoding = encoding; - // this.mapping = mapping; - } - - /** - * factory method with the basic parameters - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @return the generated PDFFont object - */ - public static PDFFont createFont(int number, String fontname, - FontType subtype, String basefont, - Object encoding) { - if (subtype == FontType.TYPE0) { - return new PDFFontType0(number, fontname, basefont, - encoding); - } else if ((subtype == FontType.TYPE1) - || (subtype == FontType.MMTYPE1)) { - return new PDFFontType1(number, fontname, basefont, - encoding); - } else if (subtype == FontType.TYPE3) { - //return new PDFFontType3(number, fontname, basefont, encoding); - return null; //NYI - } else if (subtype == FontType.TRUETYPE) { - return new PDFFontTrueType(number, fontname, basefont, - encoding); - } else { - return null; // should not happend - } - } - - /** - * factory method with the extended parameters - * for Type1, MMType1 and TrueType - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param firstChar the first character code in the font - * @param lastChar the last character code in the font - * @param widths an array of size (lastChar - firstChar +1) - * @param descriptor the descriptor for other font's metrics - * @return the generated PDFFont object - */ - public static PDFFont createFont(int number, String fontname, - FontType subtype, String basefont, - Object encoding, int firstChar, - int lastChar, PDFArray widths, - PDFFontDescriptor descriptor) { - - PDFFontNonBase14 font; - if (subtype == FontType.TYPE0) { - font = new PDFFontType0(number, fontname, basefont, - encoding); - font.setDescriptor(descriptor); - return font; - } else if ((subtype == FontType.TYPE1) - || (subtype == FontType.MMTYPE1)) { - font = new PDFFontType1(number, fontname, basefont, - encoding); - font.setWidthMetrics(firstChar, lastChar, widths); - font.setDescriptor(descriptor); - return font; - } else if (subtype == FontType.TYPE3) { - return null; //NYI, should not happend - } else if (subtype == FontType.TRUETYPE) { - font = new PDFFontTrueType(number, fontname, basefont, - encoding); - font.setWidthMetrics(firstChar, lastChar, widths); - font.setDescriptor(descriptor); - return font; - } else { - return null; // should not happend - } - } - - /** - * get the internal name used for this font - * @return the internal name - */ - public String getName() { - return this.fontname; - } - - /** - * Returns the PDF name for a certain font type. - * @param fontType font type - * @return String corresponding PDF name - */ - protected String getPDFNameForFontType(FontType fontType) { - if (fontType == FontType.TYPE0) { - return fontType.getName(); - } else if (fontType == FontType.TYPE1) { - return fontType.getName(); - } else if (fontType == FontType.MMTYPE1) { - return fontType.getName(); - } else if (fontType == FontType.TYPE3) { - return fontType.getName(); - } else if (fontType == FontType.TRUETYPE) { - return fontType.getName(); - } else { - throw new IllegalArgumentException("Unsupported font type: " + fontType.getName()); - } - } - - /** - * Produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< /Type /Font\n/Subtype /" - + getPDFNameForFontType(this.subtype) + "\n/Name /" + this.fontname - + "\n/BaseFont /" + this.basefont); - if (encoding != null) { - p.append("\n/Encoding "); - if (encoding instanceof PDFEncoding) { - p.append(((PDFEncoding)this.encoding).referencePDF()); - } else if (encoding instanceof PDFStream) { - p.append(((PDFStream)this.encoding).referencePDF()); - } else { - p.append("/").append((String)encoding); - } - } - fillInPDF(p); - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); - } - - /** - * This method is called to receive the specifics for the font's subtype. - * <p> - * The given buffer already contains the fields common to all font types. - * - * @param target the buffer to be completed with the type specific fields - */ - protected void fillInPDF(StringBuffer target) { - //nop - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontDescriptor.java b/src/org/apache/fop/pdf/PDFFontDescriptor.java deleted file mode 100644 index 0cc70c478..000000000 --- a/src/org/apache/fop/pdf/PDFFontDescriptor.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a font descriptor (/FontDescriptor object). - * <p> - * Font descriptors are specified on page 222 and onwards of the PDF 1.3 spec. - */ -public class PDFFontDescriptor extends PDFObject { - - // Required fields - private int ascent; - private int capHeight; - private int descent; - private int flags; - private PDFRectangle fontBBox; - private String basefont; // PDF-spec: FontName - private int italicAngle; - private int stemV; - // Optional fields - private int stemH = 0; - private int xHeight = 0; - private int leading = 0; - private int avgWidth = 0; - private int maxWidth = 0; - private int missingWidth = 0; - private PDFStream fontfile; - // private String charSet = null; - - private FontType subtype; - - /** - * Create the /FontDescriptor object - * - * @param number the object's number - * @param ascent the maximum height above the baseline - * @param descent the maximum depth below the baseline - * @param capHeight height of the capital letters - * @param flags various characteristics of the font - * @param fontBBox the bounding box for the described font - * @param basefont the base font name - * @param italicAngle the angle of the vertical dominant strokes - * @param stemV the width of the dominant vertical stems of glyphs - */ - public PDFFontDescriptor(int number, String basefont, int ascent, - int descent, int capHeight, int flags, - PDFRectangle fontBBox, int italicAngle, - int stemV) { - - /* generic creation of PDF object */ - super(number); - - /* set fields using paramaters */ - this.basefont = basefont; - this.ascent = ascent; - this.descent = descent; - this.capHeight = capHeight; - this.flags = flags; - this.fontBBox = fontBBox; - this.italicAngle = italicAngle; - this.stemV = stemV; - } - - /** - * Set the optional metrics. - * @param avgWidth The average width of characters in this font. - * The default value is 0. - * @param maxWidth The maximum width of characters in this font. - * The default value is 0. - * @param missingWidth missing width - * @param leading the desired spacing between lines of text. - * The default value is 0. - * @param stemH The vertical width of the dominant horizontal stems of - * glyphs in the font. The default value is 0. - * @param xHeight The y-coordinate of the top of flat non-ascending - * lowercase letters, measured from the baseline. The default value is 0. - */ - public void setMetrics(int avgWidth, int maxWidth, int missingWidth, - int leading, int stemH, int xHeight) { - this.avgWidth = avgWidth; - this.maxWidth = maxWidth; - this.missingWidth = missingWidth; - this.leading = leading; - this.stemH = stemH; - this.xHeight = xHeight; - } - - /** - * Set the optional font file stream - * - * @param subtype the font type defined in the font stream - * @param fontfile the stream containing an embedded font - */ - public void setFontFile(FontType subtype, PDFStream fontfile) { - this.subtype = subtype; - this.fontfile = fontfile; - } - - // public void setCharSet(){}//for subset fonts - - /** - * Produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< /Type /FontDescriptor" - + "\n/FontName /" + this.basefont); - - p.append("\n/FontBBox "); - p.append(fontBBox.toPDFString()); - p.append("\n/Flags "); - p.append(flags); - p.append("\n/CapHeight "); - p.append(capHeight); - p.append("\n/Ascent "); - p.append(ascent); - p.append("\n/Descent "); - p.append(descent); - p.append("\n/ItalicAngle "); - p.append(italicAngle); - p.append("\n/StemV "); - p.append(stemV); - // optional fields - if (stemH != 0) { - p.append("\n/StemH "); - p.append(stemH); - } - if (xHeight != 0) { - p.append("\n/XHeight "); - p.append(xHeight); - } - if (avgWidth != 0) { - p.append("\n/AvgWidth "); - p.append(avgWidth); - } - if (maxWidth != 0) { - p.append("\n/MaxWidth "); - p.append(maxWidth); - } - if (missingWidth != 0) { - p.append("\n/MissingWidth "); - p.append(missingWidth); - } - if (leading != 0) { - p.append("\n/Leading "); - p.append(leading); - } - if (fontfile != null) { - if (subtype == FontType.TYPE1) { - p.append("\n/FontFile "); - } else { - p.append("\n/FontFile2 "); - } - p.append(fontfile.referencePDF()); - } - // charSet for subset fonts // not yet implemented - // CID optional field - fillInPDF(p); - p.append("\n >>\nendobj\n"); - return p.toString().getBytes(); - } - - /** - * Fill in the specifics for the font's descriptor. - * <p> - * The given buffer already contains the fields common to all descriptors. - * - * @param begin the buffer to be completed with the specific fields - */ - protected void fillInPDF(StringBuffer begin) { - //nop - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontNonBase14.java b/src/org/apache/fop/pdf/PDFFontNonBase14.java deleted file mode 100644 index 18cc2b743..000000000 --- a/src/org/apache/fop/pdf/PDFFontNonBase14.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * A common ancestor for Type1, TrueType, MMType1 and Type3 fonts - * (all except base 14 fonts). - */ -public abstract class PDFFontNonBase14 extends PDFFont { - - /** - * first character code in the font - */ - protected int firstChar; - - /** - * last character code in the font - */ - protected int lastChar; - - /** - * widths of characters from firstChar to lastChar - */ - protected PDFArray widths; - - /** - * descriptor of font metrics - */ - protected PDFFontDescriptor descriptor; - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFontNonBase14(int number, String fontname, FontType subtype, - String basefont, - Object encoding) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, basefont, encoding); - - this.descriptor = null; - } - - /** - * Set the width metrics for the font - * - * @param firstChar the first character code in the font - * @param lastChar the last character code in the font - * @param widths an array of size (lastChar - firstChar +1) - */ - public void setWidthMetrics(int firstChar, int lastChar, - PDFArray widths) { - /* set fields using paramaters */ - this.firstChar = firstChar; - this.lastChar = lastChar; - this.widths = widths; - } - - /** - * Set the font descriptor (unused for the Type3 fonts) - * - * @param descriptor the descriptor for other font's metrics - */ - public void setDescriptor(PDFFontDescriptor descriptor) { - this.descriptor = descriptor; - } - - /** - * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer) - */ - protected void fillInPDF(StringBuffer target) { - target.append("\n/FirstChar "); - target.append(firstChar); - target.append("\n/LastChar "); - target.append(lastChar); - target.append("\n/Widths "); - target.append(this.widths.referencePDF()); - if (descriptor != null) { - target.append("\n/FontDescriptor "); - target.append(this.descriptor.referencePDF()); - } - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontTrueType.java b/src/org/apache/fop/pdf/PDFFontTrueType.java deleted file mode 100644 index 4509e956a..000000000 --- a/src/org/apache/fop/pdf/PDFFontTrueType.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a TrueType font. - * <p> - * In fact everything already done in the superclass. - * Must only define the not default constructor. - */ -public class PDFFontTrueType extends PDFFontNonBase14 { - - /** - * create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFontTrueType(int number, String fontname, - String basefont, - Object encoding) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */); - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontType0.java b/src/org/apache/fop/pdf/PDFFontType0.java deleted file mode 100644 index bb0984ed0..000000000 --- a/src/org/apache/fop/pdf/PDFFontType0.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a Type0 font. - * <p> - * Type0 fonts are specified on page 208 and onwards of the PDF 1.3 spec. - */ -public class PDFFontType0 extends PDFFontNonBase14 { - - /** - * This should be an array of CIDFont but only the first one is used - */ - protected PDFCIDFont descendantFonts; - - /** - * The character map - */ - protected PDFCMap cmap; - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFontType0(int number, String fontname, - String basefont, - Object encoding) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */); - - /* set fields using paramaters */ - this.descendantFonts = null; - cmap = null; - } - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param descendantFonts the CIDFont upon which this font is based - */ - public PDFFontType0(int number, String fontname, - String basefont, - Object encoding, - PDFCIDFont descendantFonts) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */); - - /* set fields using paramaters */ - this.descendantFonts = descendantFonts; - } - - /** - * Set the descendant font - * @param descendantFonts the CIDFont upon which this font is based - */ - public void setDescendantFonts(PDFCIDFont descendantFonts) { - this.descendantFonts = descendantFonts; - } - - /** - * Sets the character map - * @param cmap the character map - */ - public void setCMAP(PDFCMap cmap) { - this.cmap = cmap; - } - - /** - * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer) - */ - protected void fillInPDF(StringBuffer target) { - if (descendantFonts != null) { - target.append("\n/DescendantFonts [ " - + this.descendantFonts.referencePDF() + " ] "); - } - if (cmap != null) { - target.append("\n/ToUnicode " + cmap.referencePDF()); - } - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontType1.java b/src/org/apache/fop/pdf/PDFFontType1.java deleted file mode 100644 index e4c19d0e6..000000000 --- a/src/org/apache/fop/pdf/PDFFontType1.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a Type1 or MMType1 font (not necessary for the base 14). - * <p> - * Type1 fonts are specified on page 201 and onwards of the PDF 1.3 spec. - * <br> - * MMType1 fonts are specified on page 205 and onwards of the PDF 1.3 spec. - * <p> - * In fact everything already done in the superclass. - * Must only define the not default constructor. - */ -public class PDFFontType1 extends PDFFontNonBase14 { - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFontType1(int number, String fontname, - String basefont, - Object encoding) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE1, basefont, encoding); - } - -} diff --git a/src/org/apache/fop/pdf/PDFFontType3.java b/src/org/apache/fop/pdf/PDFFontType3.java deleted file mode 100644 index 19ac8b1fd..000000000 --- a/src/org/apache/fop/pdf/PDFFontType3.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.fonts.FontType; - -/** - * Class representing a Type3 font. - * <p> - * <b>CAUTION: this is not yet fully implemented!!!!!!!</b> - * the /CharProcs is still missing its <code>toPDF()</code> method. - * <p> - * Type3 fonts are specified on page 206 and onwards of the PDF 1.3 spec. - */ -public class PDFFontType3 extends PDFFontNonBase14 { - - /** - * font's required /FontBBox bounding box - */ - protected PDFRectangle fontBBox; - - /** - * font's required /FontMatrix array - */ - protected PDFArray fontMatrix; - - /** - * font's required /CharProcs dictionary - */ - protected PDFCharProcs charProcs; - - /** - * font's optional /Resources object - */ - protected PDFResources resources; - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - */ - public PDFFontType3(int number, String fontname, - String basefont, - Object encoding) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */); - - this.fontBBox = null; - this.fontMatrix = null; - this.charProcs = null; - } - - /** - * Create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param fontBBox the font's bounding box - * @param fontMatrix the font's transformation matrix - * @param charProcs the glyphs' definitions - */ - public PDFFontType3(int number, String fontname, - String basefont, - Object encoding, - PDFRectangle fontBBox, PDFArray fontMatrix, - PDFCharProcs charProcs) { - - /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */); - - this.fontBBox = fontBBox; - this.fontMatrix = fontMatrix; - this.charProcs = charProcs; - } - - /** - * Set the font's bounding box - * - * @param bbox bounding box for the font - */ - public void setFontBBox(PDFRectangle bbox) { - this.fontBBox = bbox; - } - - /** - * Set the font's transformation matrix - * - * @param matrix the transformation matrix for the font - */ - public void setFontMatrix(PDFArray matrix) { - this.fontMatrix = matrix; - } - - /** - * Set the glyphs' definitions. - * <p> - * The /CharProcs object needs to be registered in the document's resources. - * - * @param chars the glyphs' dictionary - */ - public void setCharProcs(PDFCharProcs chars) { - this.charProcs = chars; - } - - /** - * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer) - */ - protected void fillInPDF(StringBuffer target) { - if (fontBBox != null) { - target.append("\n/FontBBox "); - target.append(fontBBox.toPDF()); - } - if (fontMatrix != null) { - target.append("\n/FontMatrix "); - target.append(fontMatrix.toPDF()); - } - if (charProcs != null) { - target.append("\n/CharProcs "); - target.append(charProcs.referencePDF()); - } - } - -} diff --git a/src/org/apache/fop/pdf/PDFFormXObject.java b/src/org/apache/fop/pdf/PDFFormXObject.java deleted file mode 100644 index d97de0a49..000000000 --- a/src/org/apache/fop/pdf/PDFFormXObject.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.io.IOException; -import java.io.OutputStream; - -/** - * PDF Form XObject - * - * A derivative of the PDFXObject, is a PDF Stream that has not only a - * dictionary but a stream of image data. - */ -public class PDFFormXObject extends PDFXObject { - private PDFStream contents; - private String resRef; - - /** - * create a FormXObject with the given number and name and load the - * image in the object - * - * @param number the pdf object number - * @param xnumber the pdf object X number - * @param cont the pdf stream contents - * @param ref the resource PDF reference - */ - public PDFFormXObject(int number, int xnumber, PDFStream cont, String ref) { - super(number, xnumber, null); - contents = cont; - resRef = ref; - } - - /** - * Output the form stream as PDF. - * This sets up the form XObject dictionary and adds the content - * data stream. - * - * @param stream the output stream to write the data - * @throws IOException if there is an error writing the data - * @return the length of the data written - */ - protected int output(OutputStream stream) throws IOException { - int length = 0; - - String dictEntries = contents.applyFilters(); - - String p = this.number + " " + this.generation + " obj\n"; - p = p + "<</Type /XObject\n"; - p = p + "/Subtype /Form\n"; - p = p + "/FormType 1\n"; - p = p + "/BBox [0 0 1000 1000]\n"; - p = p + "/Matrix [1 0 0 1 0 0]\n"; - p = p + "/Resources " + resRef + "\n"; - p = p + "/Length " + (contents.getDataLength() + 1) + "\n"; - - p = p + dictEntries; - p = p + ">>\n"; - - // push the pdf dictionary on the writer - byte[] pdfBytes = p.getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - // push all the image data on the writer - // and takes care of length for trailer - length += contents.outputStreamData(stream); - - pdfBytes = ("endobj\n").getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - // let it gc - // this object is retained as a reference to inserting - // the same image but the image data is no longer needed - contents = null; - return length; - } -} - diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java deleted file mode 100644 index e9147a3a0..000000000 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ /dev/null @@ -1,845 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; - -/** - * class representing a PDF Function. - * - * PDF Functions represent parameterized mathematical formulas and - * sampled representations with - * arbitrary resolution. Functions are used in two areas: device-dependent - * rasterization information for halftoning and transfer - * functions, and color specification for smooth shading (a PDF 1.3 feature). - * - * All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range. - */ -public class PDFFunction extends PDFObject { - // Guts common to all function types - - /** - * Required: The Type of function (0,2,3,4) default is 0. - */ - protected int functionType = 0; // Default - - /** - * Required: 2 * m Array of Double numbers which are possible inputs to the function - */ - protected List domain = null; - - /** - * Required: 2 * n Array of Double numbers which are possible outputs to the function - */ - protected List range = null; - - /* ********************TYPE 0***************************** */ - // FunctionType 0 specific function guts - - /** - * Required: Array containing the Integer size of the Domain and Range, respectively. - * Note: This is really more like two seperate integers, sizeDomain, and sizeRange, - * but since they're expressed as an array in PDF, my implementation reflects that. - */ - protected List size = null; - - /** - * Required for Type 0: Number of Bits used to represent each sample value. - * Limited to 1,2,4,8,12,16,24, or 32 - */ - protected int bitsPerSample = 1; - - /** - * Optional for Type 0: order of interpolation between samples. - * Limited to linear (1) or cubic (3). Default is 1 - */ - protected int order = 1; - - /** - * Optional for Type 0: A 2 * m array of Doubles which provides a - * linear mapping of input values to the domain. - * - * Required for Type 3: A 2 * k array of Doubles that, taken - * in pairs, map each subset of the domain defined by Domain - * and the Bounds array to the domain of the corresponding function. - * Should be two values per function, usually (0,1), - * as in [0 1 0 1] for 2 functions. - */ - protected List encode = null; - - /** - * Optional for Type 0: A 2 * n array of Doubles which provides - * a linear mapping of sample values to the range. Defaults to Range. - */ - protected List decode = null; - - /** - * Optional For Type 0: A stream of sample values - */ - - /** - * Required For Type 4: Postscript Calculator function - * composed of arithmetic, boolean, and stack operators + boolean constants - */ - protected StringBuffer functionDataStream = null; - - /** - * Required (?) For Type 0: A vector of Strings for the - * various filters to be used to decode the stream. - * These are how the string is compressed. Flate, LZW, etc. - */ - protected List filter = null; - /* *************************TYPE 2************************** */ - - /** - * Required For Type 2: An Array of n Doubles defining - * the function result when x=0. Default is [0]. - */ - protected List cZero = null; - - /** - * Required For Type 2: An Array of n Doubles defining - * the function result when x=1. Default is [1]. - */ - protected List cOne = null; - - /** - * Required for Type 2: The interpolation exponent. - * Each value x will return n results. - * Must be greater than 0. - */ - protected double interpolationExponentN = 1; - - /* *************************TYPE 3************************** */ - - /** - * Required for Type 3: An vector of PDFFunctions which - * form an array of k single input functions making up - * the stitching function. - */ - protected List functions = null; - - /** - * Optional for Type 3: An array of (k-1) Doubles that, - * in combination with Domain, define the intervals to which - * each function from the Functions array apply. Bounds - * elements must be in order of increasing magnitude, - * and each value must be within the value of Domain. - * k is the number of functions. - * If you pass null, it will output (1/k) in an array of k-1 elements. - * This makes each function responsible for an equal amount of the stitching function. - * It makes the gradient even. - */ - protected List bounds = null; - // See encode above, as it's also part of Type 3 Functions. - - /* *************************TYPE 4************************** */ - // See 'data' above. - - /** - * create an complete Function object of Type 0, A Sampled function. - * - * Use null for an optional object parameter if you choose not to use it. - * For optional int parameters, pass the default. - * - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theSize A List object of Integer objects. - * This is the number of samples in each input dimension. - * I can't imagine there being more or less than two input dimensions, - * so maybe this should be an array of length 2. - * - * See page 265 of the PDF 1.3 Spec. - * @param theBitsPerSample An int specifying the number of bits - used to represent each sample value. - * Limited to 1,2,4,8,12,16,24 or 32. - * See page 265 of the 1.3 PDF Spec. - * @param theOrder The order of interpolation between samples. Default is 1 (one). Limited - * to 1 (one) or 3, which means linear or cubic-spline interpolation. - * - * This attribute is optional. - * - * See page 265 in the PDF 1.3 spec. - * @param theEncode List objects of Double objects. - * This is the linear mapping of input values intop the domain - * of the function's sample table. Default is hard to represent in - * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. - * This attribute is optional. - * - * See page 265 in the PDF 1.3 spec. - * @param theDecode List objects of Double objects. - * This is a linear mapping of sample values into the range. - * The default is just the range. - * - * This attribute is optional. - * Read about it on page 265 of the PDF 1.3 spec. - * @param theFunctionDataStream The sample values that specify - * the function are provided in a stream. - * - * This is optional, but is almost always used. - * - * Page 265 of the PDF 1.3 spec has more. - * @param theFilter This is a vector of String objects which are the various filters that - * have are to be applied to the stream to make sense of it. Order matters, - * so watch out. - * - * This is not documented in the Function section of the PDF 1.3 spec, - * it was deduced from samples that this is sometimes used, even if we may never - * use it in FOP. It is added for completeness sake. - * @param theNumber The object number of this PDF object. - * @param theFunctionType This is the type of function (0,2,3, or 4). - * It should be 0 as this is the constructor for sampled functions. - */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, - List theRange, List theSize, int theBitsPerSample, - int theOrder, List theEncode, List theDecode, - StringBuffer theFunctionDataStream, List theFilter) { - super(theNumber); - - this.functionType = 0; // dang well better be 0; - this.size = theSize; - this.bitsPerSample = theBitsPerSample; - this.order = theOrder; // int - this.encode = theEncode; // vector of int - this.decode = theDecode; // vector of int - this.functionDataStream = theFunctionDataStream; - this.filter = theFilter; // vector of Strings - - // the domain and range are actually two dimensional arrays. - // so if there's not an even number of items, bad stuff - // happens. - this.domain = theDomain; - this.range = theRange; - } - - /** - * create an complete Function object of Type 2, an Exponential Interpolation function. - * - * Use null for an optional object parameter if you choose not to use it. - * For optional int parameters, pass the default. - * - * @param theNumber the object's number - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List of Doubles that is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theCZero This is a vector of Double objects which defines the function result - * when x=0. - * - * This attribute is optional. - * It's described on page 268 of the PDF 1.3 spec. - * @param theCOne This is a vector of Double objects which defines the function result - * when x=1. - * - * This attribute is optional. - * It's described on page 268 of the PDF 1.3 spec. - * @param theInterpolationExponentN This is the inerpolation exponent. - * - * This attribute is required. - * PDF Spec page 268 - * @param theFunctionType The type of the function, which should be 2. - */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, - List theRange, List theCZero, List theCOne, - double theInterpolationExponentN) { - super(theNumber); - - this.functionType = 2; // dang well better be 2; - - this.cZero = theCZero; - this.cOne = theCOne; - this.interpolationExponentN = theInterpolationExponentN; - - - this.domain = theDomain; - this.range = theRange; - - } - - /** - * create an complete Function object of Type 3, a Stitching function. - * - * Use null for an optional object parameter if you choose not to use it. - * For optional int parameters, pass the default. - * - * @param theNumber the object's number - * @param theDomain List objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theFunctions A List of the PDFFunction objects that the stitching function stitches. - * - * This attributed is required. - * It is described on page 269 of the PDF spec. - * @param theBounds This is a vector of Doubles representing the numbers that, - * in conjunction with Domain define the intervals to which each function from - * the 'functions' object applies. It must be in order of increasing magnitude, - * and each must be within Domain. - * - * It basically sets how much of the gradient each function handles. - * - * This attributed is required. - * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode List objects of Double objects. - * This is the linear mapping of input values intop the domain - * of the function's sample table. Default is hard to represent in - * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. - * This attribute is required. - * - * See page 270 in the PDF 1.3 spec. - * @param theFunctionType This is the function type. It should be 3, - * for a stitching function. - */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, - List theRange, List theFunctions, - List theBounds, List theEncode) { - super(theNumber); - - this.functionType = 3; // dang well better be 3; - - this.functions = theFunctions; - this.bounds = theBounds; - this.encode = theEncode; - this.domain = theDomain; - this.range = theRange; - - } - - /** - * create an complete Function object of Type 4, a postscript calculator function. - * - * Use null for an optional object parameter if you choose not to use it. - * For optional int parameters, pass the default. - * - * @param theDomain List object of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange List object of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theFunctionDataStream This is a stream of arithmetic, - * boolean, and stack operators and boolean constants. - * I end up enclosing it in the '{' and '}' braces for you, so don't do it - * yourself. - * - * This attribute is required. - * It's described on page 269 of the PDF 1.3 spec. - * @param theNumber The object number of this PDF object. - * @param theFunctionType The type of function which should be 4, as this is - * a Postscript calculator function - */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, - List theRange, StringBuffer theFunctionDataStream) { - super(theNumber); - - this.functionType = 4; // dang well better be 4; - this.functionDataStream = theFunctionDataStream; - - this.domain = theDomain; - - this.range = theRange; - - } - - - /** - * represent as PDF. Whatever the FunctionType is, the correct - * representation spits out. The sets of required and optional - * attributes are different for each type, but if a required - * attribute's object was constructed as null, then no error - * is raised. Instead, the malformed PDF that was requested - * by the construction is dutifully output. - * This policy should be reviewed. - * - * @return the PDF string. - */ - public byte[] toPDF() { - int vectorSize = 0; - int numberOfFunctions = 0; - int tempInt = 0; - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< \n/FunctionType " + this.functionType + " \n"); - - // FunctionType 0 - if (this.functionType == 0) { - if (this.domain != null) { - // DOMAIN - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - // SIZE - if (this.size != null) { - p.append("/Size [ "); - vectorSize = this.size.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.size.get(tempInt)) - + " "); - } - p.append("] \n"); - } - // ENCODE - if (this.encode != null) { - p.append("/Encode [ "); - vectorSize = this.encode.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.encode.get(tempInt)) - + " "); - } - p.append("] \n"); - } else { - p.append("/Encode [ "); - vectorSize = this.functions.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append("0 1 "); - } - p.append("] \n"); - - } - - // BITSPERSAMPLE - p.append("/BitsPerSample " + this.bitsPerSample); - - // ORDER (optional) - if (this.order == 1 || this.order == 3) { - p.append(" \n/Order " + this.order + " \n"); - } - - // RANGE - if (this.range != null) { - p.append("/Range [ "); - vectorSize = this.range.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.range.get(tempInt)) - + " "); - } - - p.append("] \n"); - } - - // DECODE - if (this.decode != null) { - p.append("/Decode [ "); - vectorSize = this.decode.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.decode.get(tempInt)) - + " "); - } - - p.append("] \n"); - } - - // LENGTH - if (this.functionDataStream != null) { - p.append("/Length " + (this.functionDataStream.length() + 1) - + " \n"); - } - - // FILTER? - if (this.filter != null) { // if there's a filter - vectorSize = this.filter.size(); - p.append("/Filter "); - if (vectorSize == 1) { - p.append("/" + ((String)this.filter.get(0)) - + " \n"); - } else { - p.append("[ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append("/" + ((String)this.filter.get(0)) - + " "); - } - p.append("] \n"); - } - } - p.append(">> \n"); - - // stream representing the function - if (this.functionDataStream != null) { - p.append("stream\n" + this.functionDataStream - + "\nendstream\n"); - } - - p.append("endobj\n"); - // end of if FunctionType 0 - - } else if (this.functionType == 2) { - // DOMAIN - if (this.domain != null) { - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - - // RANGE - if (this.range != null) { - p.append("/Range [ "); - vectorSize = this.range.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.range.get(tempInt)) - + " "); - } - - p.append("] \n"); - } - - // FunctionType, C0, C1, N are required in PDF - - // C0 - if (this.cZero != null) { - p.append("/C0 [ "); - vectorSize = this.cZero.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.cZero.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - // C1 - if (this.cOne != null) { - p.append("/C1 [ "); - vectorSize = this.cOne.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.cOne.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - // N: The interpolation Exponent - p.append("/N " - + PDFNumber.doubleOut(new Double(this.interpolationExponentN)) - + " \n"); - - p.append(">> \nendobj\n"); - - } else if (this.functionType - == 3) { // fix this up when my eyes uncross - // DOMAIN - if (this.domain != null) { - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - // RANGE - if (this.range != null) { - p.append("/Range [ "); - vectorSize = this.range.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.range.get(tempInt)) - + " "); - } - - p.append("] \n"); - } - - // FUNCTIONS - if (this.functions != null) { - p.append("/Functions [ "); - numberOfFunctions = this.functions.size(); - for (tempInt = 0; tempInt < numberOfFunctions; tempInt++) { - p.append(((PDFFunction)this.functions.get(tempInt)).referencePDF() - + " "); - - } - p.append("] \n"); - } - - - // ENCODE - if (this.encode != null) { - p.append("/Encode [ "); - vectorSize = this.encode.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.encode.get(tempInt)) - + " "); - } - - p.append("] \n"); - } else { - p.append("/Encode [ "); - vectorSize = this.functions.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append("0 1 "); - } - p.append("] \n"); - - } - - - // BOUNDS, required, but can be empty - p.append("/Bounds [ "); - if (this.bounds != null) { - - vectorSize = this.bounds.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.bounds.get(tempInt)) - + " "); - } - - } else { - if (this.functions != null) { - // if there are n functions, - // there must be n-1 bounds. - // so let each function handle an equal portion - // of the whole. e.g. if there are 4, then [ 0.25 0.25 0.25 ] - - String functionsFraction = PDFNumber.doubleOut(new Double(1.0 - / ((double)numberOfFunctions))); - - for (tempInt = 0; tempInt + 1 < numberOfFunctions; - tempInt++) { - - p.append(functionsFraction + " "); - } - functionsFraction = null; // clean reference. - - } - - } - p.append("] \n"); - - - p.append(">> \nendobj\n"); - } else if (this.functionType - == 4) { // fix this up when my eyes uncross - // DOMAIN - if (this.domain != null) { - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - // RANGE - if (this.range != null) { - p.append("/Range [ "); - vectorSize = this.range.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.range.get(tempInt)) - + " "); - } - - p.append("] \n"); - } - - // LENGTH - if (this.functionDataStream != null) { - p.append("/Length " + (this.functionDataStream.length() + 1) - + " \n"); - } - - p.append(">> \n"); - - // stream representing the function - if (this.functionDataStream != null) { - p.append("stream\n{ " + this.functionDataStream - + " } \nendstream\n"); - } - - p.append("endobj\n"); - - } - - return (p.toString().getBytes()); - - } - - /** - * Check if this function is equal to another object. - * This is used to find if a particular function already exists - * in a document. - * - * @param obj the obj to compare - * @return true if the functions are equal - */ - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(obj instanceof PDFFunction)) { - return false; - } - PDFFunction func = (PDFFunction)obj; - if (functionType != func.functionType) { - return false; - } - if (bitsPerSample != func.bitsPerSample) { - return false; - } - if (order != func.order) { - return false; - } - if (interpolationExponentN != func.interpolationExponentN) { - return false; - } - if (domain != null) { - if (!domain.equals(func.domain)) { - return false; - } - } else if (func.domain != null) { - return false; - } - if (range != null) { - if (!range.equals(func.range)) { - return false; - } - } else if (func.range != null) { - return false; - } - if (size != null) { - if (!size.equals(func.size)) { - return false; - } - } else if (func.size != null) { - return false; - } - if (encode != null) { - if (!encode.equals(func.encode)) { - return false; - } - } else if (func.encode != null) { - return false; - } - if (decode != null) { - if (!decode.equals(func.decode)) { - return false; - } - } else if (func.decode != null) { - return false; - } - if (functionDataStream != null) { - if (!functionDataStream.equals(func.functionDataStream)) { - return false; - } - } else if (func.functionDataStream != null) { - return false; - } - if (filter != null) { - if (!filter.equals(func.filter)) { - return false; - } - } else if (func.filter != null) { - return false; - } - if (cZero != null) { - if (!cZero.equals(func.cZero)) { - return false; - } - } else if (func.cZero != null) { - return false; - } - if (cOne != null) { - if (!cOne.equals(func.cOne)) { - return false; - } - } else if (func.cOne != null) { - return false; - } - if (functions != null) { - if (!functions.equals(func.functions)) { - return false; - } - } else if (func.functions != null) { - return false; - } - if (bounds != null) { - if (!bounds.equals(func.bounds)) { - return false; - } - } else if (func.bounds != null) { - return false; - } - return true; - } - -} diff --git a/src/org/apache/fop/pdf/PDFGState.java b/src/org/apache/fop/pdf/PDFGState.java deleted file mode 100644 index 4da68db54..000000000 --- a/src/org/apache/fop/pdf/PDFGState.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.Map; -import java.util.Iterator; - -/** - * Class representing a /ExtGState object. - */ -public class PDFGState extends PDFObject { - - /** Line width (LW) */ - public static final String GSTATE_LINE_WIDTH = "LW"; - /** Line cap (LC) */ - public static final String GSTATE_LINE_CAP = "LC"; - /** Line join (LJ) */ - public static final String GSTATE_LINE_JOIN = "LJ"; - /** Miter limit (ML) */ - public static final String GSTATE_MITER_LIMIT = "ML"; - /** Dash pattern (D) */ - public static final String GSTATE_DASH_PATTERN = "D"; - /** Rendering intent (RI) */ - public static final String GSTATE_RENDERING_INTENT = "RI"; - /** Overprint for stroke (OP) */ - public static final String GSTATE_OVERPRINT_STROKE = "OP"; - /** Overprint for fill (op) */ - public static final String GSTATE_OVERPRINT_FILL = "op"; - /** Overprint mode (OPM) */ - public static final String GSTATE_OVERPRINT_MODE = "OPM"; - /** Font (Font) */ - public static final String GSTATE_FONT = "Font"; - /** Black generation (BG) */ - public static final String GSTATE_BLACK_GENERATION = "BG"; - /** Black generation with default (BG2) */ - public static final String GSTATE_BLACK_GENERATION2 = "BG2"; - /** Undercolor removal function (UCR) */ - public static final String GSTATE_UNDERCOLOR_REMOVAL = "UCR"; - /** Undercolor removal function with default (UCR2) */ - public static final String GSTATE_UNDERCOLOR_REMOVAL2 = "UCR2"; - /** Transfer function (TR) */ - public static final String GSTATE_TRANSFER_FUNCTION = "TR"; - /** Transfer function with default (TR2) */ - public static final String GSTATE_TRANSFER_FUNCTION2 = "TR2"; - /** Halftone dictionary or stream (HT) */ - public static final String GSTATE_HALFTONE_DICT = "HT"; - /** Halftone phase (HTP, does not show up anymore in PDF 1.4)*/ - public static final String GSTATE_HALFTONE_PHASE = "HTP"; - /** Flatness (FL) */ - public static final String GSTATE_FLATNESS = "FL"; - /** Smoothness (SM) */ - public static final String GSTATE_SMOOTHNESS = "SM"; - /** Strike adjustment (SA) */ - public static final String GSTATE_STRIKE_ADJ = "SA"; - /** Blend mode (BM, PDF 1.4) */ - public static final String GSTATE_BLEND_MODE = "BM"; - /** Soft mask (SMask, PDF 1.4) */ - public static final String GSTATE_SOFT_MASK = "SMask"; - /** Stroking Alpha (CA, PDF 1.4) */ - public static final String GSTATE_ALPHA_STROKE = "CA"; - /** Nonstroking Alpha (ca, PDF 1.4) */ - public static final String GSTATE_ALPHA_NONSTROKE = "ca"; - /** Alpha Source Flag (AIS, PDF 1.4) */ - public static final String GSTATE_ALPHA_SOURCE_FLAG = "AIS"; - /** Text Knockout Flag (TK, PDF 1.4) */ - public static final String GSTATE_TEXT_KNOCKOUT = "TK"; - - - /** Default GState object */ - public static final PDFGState DEFAULT; - - static { - DEFAULT = new PDFGState(0); - Map vals = DEFAULT.values; - /*vals.put(LW, new Float(1.0)); - vals.put(LC, new Integer(0)); - vals.put(LJ, new Integer(0)); - vals.put(ML, new Float(10.0)); - vals.put(D, "0 []"); - vals.put(RI, "RelativeColorimetric"); - vals.put(OP, Boolean.FALSE); - vals.put(op, Boolean.FALSE); - vals.put(OPM, new Integer(1)); - vals.put(Font, "");*/ - - vals.put(GSTATE_ALPHA_STROKE, new Float(1.0)); - vals.put(GSTATE_ALPHA_NONSTROKE, new Float(1.0)); - } - - private Map values = new java.util.HashMap(); - - /** - * Create a /ExtGState object. - * - * @param number the object's number - */ - public PDFGState(int number) { - /* generic creation of object */ - super(number); - } - - /** - * Returns the name of this object - * @return the name - */ - public String getName() { - return "GS" + this.number; - } - - /** - * Sets the alpha value. - * @param val alpha value (0.0 - 1.0) - * @param fill True if alpha should be set for non-stroking operations, - * False if for stroking operations - */ - public void setAlpha(float val, boolean fill) { - if (fill) { - values.put(GSTATE_ALPHA_NONSTROKE, new Float(val)); - } else { - values.put(GSTATE_ALPHA_STROKE, new Float(val)); - } - } - - /** - * Adds all values from another GState object to this one. - * @param state source object to copy from - */ - public void addValues(PDFGState state) { - values.putAll(state.values); - } - - /** - * Adds all values from a Map to this object. - * @param vals source object to copy from - */ - public void addValues(Map vals) { - values.putAll(vals); - } - - /** - * Represent the object in PDF. - * - * @return the PDF string - */ - public byte[] toPDF() { - StringBuffer sb = new StringBuffer(this.number + " " + this.generation - + " obj\n<<\n/Type /ExtGState\n"); - appendVal(sb, GSTATE_ALPHA_NONSTROKE); - appendVal(sb, GSTATE_ALPHA_STROKE); - - sb.append(">>\nendobj\n"); - return sb.toString().getBytes(); - } - - private void appendVal(StringBuffer sb, String name) { - Object val = values.get(name); - if (val != null) { - sb.append("/" + name + " " + val + "\n"); - } - } - - /* - * example - * 29 0 obj - * << - * /Type /ExtGState - * /ca 0.5 - * >> - * endobj - */ - - /** - * @see java.lang.Object#equals(Object) - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof PDFGState)) { - return false; - } - Map vals1 = values; - Map vals2 = ((PDFGState)obj).values; - if (vals1.size() != vals2.size()) { - return false; - } - for (Iterator iter = vals1.keySet().iterator(); iter.hasNext();) { - Object str = iter.next(); - Object obj1 = vals1.get(str); - if (!obj1.equals(vals2.get(str))) { - return false; - } - } - return true; - } -} - diff --git a/src/org/apache/fop/pdf/PDFGoTo.java b/src/org/apache/fop/pdf/PDFGoTo.java deleted file mode 100644 index 4b7f11c2a..000000000 --- a/src/org/apache/fop/pdf/PDFGoTo.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 /GoTo object. - * This can either have a Goto to a page reference and location - * or to a specified PDF reference string. - */ -public class PDFGoTo extends PDFAction { - - /** - * the pageReference - */ - private String pageReference; - private String destination = null; - private float xPosition = 0; - private float yPosition = 0; - - /** - * create a /GoTo object. - * - * @param number the object's number - * @param pageReference the pageReference represented by this object - */ - public PDFGoTo(int number, String pageReference) { - /* generic creation of object */ - super(number); - - this.pageReference = pageReference; - } - - /** - * Sets page reference after object has been created - * - * @param pageReference the new page reference to use - */ - public void setPageReference(String pageReference) { - this.pageReference = pageReference; - } - - /** - * Sets the Y position to jump to - * - * @param yPosition y position - */ - public void setYPosition(float yPosition) { - this.yPosition = yPosition; - } - - /** - * Set the destination string for this Goto. - * - * @param dest the PDF destination string - */ - public void setDestination(String dest) { - destination = dest; - } - - /** - * Sets the x Position to jump to - * - * @param xPosition x position - */ - public void setXPosition(int xPosition) { - this.xPosition = (xPosition / 1000f); - } - - /** - * Get the PDF reference for the GoTo action. - * - * @return the PDF reference for the action - */ - public String getAction() { - return referencePDF(); - } - - /** - * represent the object in PDF - * - * @return the PDF string - */ - public byte[] toPDF() { - String dest; - if (destination == null) { - dest = "/D [" + this.pageReference + " /XYZ " + xPosition - + " " + yPosition + " null]\n"; - } else { - dest = "/D [" + this.pageReference + " " + destination + "]\n"; - } - String p = new String(this.number + " " + this.generation - + " obj\n<<\n/S /GoTo\n" + dest - + ">>\nendobj\n"); - return p.getBytes(); - } - - /* - * example - * 29 0 obj - * << - * /S /GoTo - * /D [23 0 R /FitH 600] - * >> - * endobj - */ - - /** - * Check if this equals another object. - * - * @param obj the object to compare - * @return true if this equals other object - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || !(obj instanceof PDFGoTo)) { - return false; - } - - PDFGoTo gt = (PDFGoTo)obj; - - if (gt.pageReference == null) { - if (pageReference != null) { - return false; - } - } else { - if (!gt.pageReference.equals(pageReference)) { - return false; - } - } - - if (destination == null) { - if (!(gt.destination == null && gt.xPosition == xPosition - && gt.yPosition == yPosition)) { - return false; - } - } else { - if (!destination.equals(gt.destination)) { - return false; - } - } - - return true; - } -} - diff --git a/src/org/apache/fop/pdf/PDFGoToRemote.java b/src/org/apache/fop/pdf/PDFGoToRemote.java deleted file mode 100644 index b7b396e61..000000000 --- a/src/org/apache/fop/pdf/PDFGoToRemote.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 /GoToR object. - */ -public class PDFGoToRemote extends PDFAction { - - /** - * the file specification - */ - private PDFFileSpec pdfFileSpec; - private int pageReference = 0; - private String destination = null; - - /** - * create an GoToR object. - * - * @param number the object's number - * @param pdfFileSpec the fileSpec associated with the action - */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec) { - /* generic creation of object */ - super(number); - - this.pdfFileSpec = pdfFileSpec; - } - - /** - * create an GoToR object. - * - * @param number the object's number - * @param pdfFileSpec the fileSpec associated with the action - * @param page a page reference within the remote document - */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, int page) { - /* generic creation of object */ - super(number); - - this.pdfFileSpec = pdfFileSpec; - this.pageReference = page; - } - - /** - * create an GoToR object. - * - * @param number the object's number - * @param pdfFileSpec the fileSpec associated with the action - * @param dest a named destination within the remote document - */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, String dest) { - /* generic creation of object */ - super(number); - - this.pdfFileSpec = pdfFileSpec; - this.destination = dest; - } - - /** - * return the action string which will reference this object - * - * @return the action String - */ - public String getAction() { - return this.referencePDF(); - } - - /** - * represent the object in PDF - * - * @return the PDF string - */ - public byte[] toPDF() { - String p = new String(this.number + " " + this.generation + " obj\n" - + "<<\n/S /GoToR\n" + "/F " - + pdfFileSpec.referencePDF() + "\n"); - - if (destination != null) { - p += "/D (" + this.destination + ")"; - } else { - p += "/D [ " + this.pageReference + " /XYZ null null null ]"; - } - - p += " \n>>\nendobj\n"; - - return p.getBytes(); - } - - - /* - * example - * 28 0 obj - * << - * /S /GoToR - * /F 29 0 R - * /D [ 0 /XYZ -6 797 null ] - * >> - * endobj - */ - - /** - * Check if this equals another object. - * - * @param obj the object to compare - * @return true if this equals other object - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || !(obj instanceof PDFGoToRemote)) { - return false; - } - - PDFGoToRemote remote = (PDFGoToRemote)obj; - - if (!remote.pdfFileSpec.referencePDF().equals(pdfFileSpec.referencePDF())) { - return false; - } - - if (destination != null) { - if (!destination.equals(remote.destination)) { - return false; - } - } else { - if (pageReference != remote.pageReference) { - return false; - } - } - - return true; - } -} - diff --git a/src/org/apache/fop/pdf/PDFICCStream.java b/src/org/apache/fop/pdf/PDFICCStream.java deleted file mode 100644 index 4bc556d91..000000000 --- a/src/org/apache/fop/pdf/PDFICCStream.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.awt.color.ICC_Profile; - -/** - * Special PDFStream for ICC profiles (color profiles). - */ -public class PDFICCStream extends PDFStream { - - private int origLength; - private int len1, len3; - - private ICC_Profile cp; - private PDFColorSpace pdfColorSpace; - - /** - * @see org.apache.fop.pdf.PDFObject#PDFObject(int) - */ - public PDFICCStream(int num) { - super(num); - cp = null; - } - - /** - * Sets the color space to encode in PDF. - * @param cp the ICC profile - * @param alt the PDF color space - */ - public void setColorSpace(ICC_Profile cp, PDFColorSpace alt) { - this.cp = cp; - pdfColorSpace = alt; - } - - /** - * overload the base object method so we don't have to copy - * byte arrays around so much - * @see org.apache.fop.pdf.PDFObject#output(OutputStream) - */ - protected int output(java.io.OutputStream stream) - throws java.io.IOException { - - setData(cp.getData()); - - int length = 0; - String filterEntry = applyFilters(); - StringBuffer pb = new StringBuffer(); - pb.append(this.number).append(" ").append(this.generation).append(" obj\n<< "); - pb.append("/N ").append(cp.getNumComponents()).append(" "); - - if (pdfColorSpace != null) { - pb.append("/Alternate /").append(pdfColorSpace.getColorSpacePDFString()).append(" "); - } - - pb.append("/Length ").append((data.getSize() + 1)).append(" ").append(filterEntry); - pb.append(" >>\n"); - byte[] p = pb.toString().getBytes(); - stream.write(p); - length += p.length; - length += outputStreamData(stream); - p = "endobj\n".getBytes(); - stream.write(p); - length += p.length; - return length; - } -} diff --git a/src/org/apache/fop/pdf/PDFImage.java b/src/org/apache/fop/pdf/PDFImage.java deleted file mode 100644 index b9ca3b211..000000000 --- a/src/org/apache/fop/pdf/PDFImage.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.IOException; - -/** - * Interface for a PDF image. - * This is used for inserting an image into PDF. - */ -public interface PDFImage { - - /** - * Key to look up XObject. - * This should be a unique key to refer to the image. - * - * @return the key for this image - */ - String getKey(); - - /** - * Setup the PDF image for the current document. - * Some image formats may need to access the document. - * - * @param doc the PDF parent document - */ - void setup(PDFDocument doc); - - /** - * Get the image width in pixels. - * - * @return the image width - */ - int getWidth(); - - /** - * Get the image height in pixels. - * - * @return the image height - */ - int getHeight(); - - /** - * Get the color space for this image. - * Possible results are: DeviceGray, DeviceRGB, or DeviceCMYK - * - * @return the color space - */ - PDFColorSpace getColorSpace(); - - /** - * Get the bits per pixel for this image. - * - * @return the bits per pixel - */ - int getBitsPerPixel(); - - /** - * Check if this image is a PostScript image. - * - * @return true if this is a PostScript image - */ - boolean isPS(); - - /** - * Check if this image has a transparent color transparency. - * - * @return true if it has transparency - */ - boolean isTransparent(); - - /** - * Get the transparent color. - * - * @return the transparent color for this image - */ - PDFColor getTransparentColor(); - - /** - * Get the PDF reference for a bitmap mask. - * - * @return the PDF reference for the mask image - */ - String getMask(); - - /** - * Get the PDF reference for a soft mask. - * - * @return the PDF reference for a soft mask image - */ - String getSoftMask(); - - // get the image bytes, and bytes properties - - /** - * Get the data stream containing the image contents. - * - * @throws IOException if there creating stream - * @return the PDFStream containing the image data - */ - PDFStream getDataStream() throws IOException; - - /** - * Get the ICC stream for this image. - * - * @return the ICC stream for this image if any - */ - PDFICCStream getICCStream(); - -} - diff --git a/src/org/apache/fop/pdf/PDFInfo.java b/src/org/apache/fop/pdf/PDFInfo.java deleted file mode 100644 index d4f0b6335..000000000 --- a/src/org/apache/fop/pdf/PDFInfo.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.Date; -import java.text.SimpleDateFormat; - -/** - * class representing an /Info object - */ -public class PDFInfo extends PDFObject { - - /** - * the application producing the PDF - */ - private String producer; - - private String title = null; - private String author = null; - private String subject = null; - private String keywords = null; - - // the name of the application that created the - // original document before converting to PDF - private String creator; - - /** - * create an Info object - * - * @param number the object's number - */ - public PDFInfo(int number) { - super(number); - } - - /** - * set the producer string - * - * @param producer the producer string - */ - public void setProducer(String producer) { - this.producer = producer; - } - - /** - * set the creator string - * - * @param creator the document creator - */ - public void setCreator(String creator) { - this.creator = creator; - } - - /** - * set the title string - * - * @param t the document title - */ - public void setTitle(String t) { - this.title = t; - } - - /** - * set the author string - * - * @param a the document author - */ - public void setAuthor(String a) { - this.author = a; - } - - /** - * set the subject string - * - * @param s the document subject - */ - public void setSubject(String s) { - this.subject = s; - } - - /** - * set the keywords string - * - * @param k the keywords for this document - */ - public void setKeywords(String k) { - this.keywords = k; - } - - /** - * produce the PDF representation of the object - * - * @return the PDF - */ - public byte[] toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Info\n"; - if (title != null) { - p += "/Title (" + this.title + ")\n"; - } - if (author != null) { - p += "/Author (" + this.author + ")\n"; - } - if (subject != null) { - p += "/Subject (" + this.subject + ")\n"; - } - if (keywords != null) { - p += "/Keywords (" + this.keywords + ")\n"; - } - - if (creator != null) { - p += "/Creator (" + this.creator + ")\n"; - } - - p += "/Producer (" + this.producer + ")\n"; - - // creation date in form (D:YYYYMMDDHHmmSSOHH'mm') - Date date = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); - String str = sdf.format(date) + "+00'00'"; - p += "/CreationDate (D:" + str + ")"; - p += " >>\nendobj\n"; - return p.getBytes(); - } -} - diff --git a/src/org/apache/fop/pdf/PDFInternalLink.java b/src/org/apache/fop/pdf/PDFInternalLink.java deleted file mode 100644 index e6d1bab50..000000000 --- a/src/org/apache/fop/pdf/PDFInternalLink.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 used to create a PDF internal link - */ -public class PDFInternalLink extends PDFAction { - - private String goToReference; - - /** - * create an internal link instance. - * - * @param goToReference the GoTo Reference to which the link should point - */ - public PDFInternalLink(String goToReference) { - - this.goToReference = goToReference; - } - - /** - * returns the action ncecessary for an internal link - * - * @return the action to place next to /A within a Link - */ - public String getAction() { - return goToReference; - } - - /** - * there is nothing to return for the toPDF method, as it should not be called - * - * @return an empty string - */ - public byte[] toPDF() { - return new byte[0]; - } - -} diff --git a/src/org/apache/fop/pdf/PDFLink.java b/src/org/apache/fop/pdf/PDFLink.java deleted file mode 100644 index 889a35780..000000000 --- a/src/org/apache/fop/pdf/PDFLink.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.geom.Rectangle2D; - -/** - * class representing an /Annot object of /Subtype /Link - */ -public class PDFLink extends PDFObject { - /** - * Used to represent an external link. - */ - public static final int EXTERNAL = 0; - - /** - * Used to represent an internal link. - */ - public static final int INTERNAL = 1; - - private float ulx; - private float uly; - private float brx; - private float bry; - private String color; - private PDFAction action; - - /** - * create objects associated with a link annotation (GoToR) - * - * @param number the object's number - * @param r the rectangle of the link hotspot in absolute coordinates - */ - public PDFLink(int number, Rectangle2D r) { - /* generic creation of PDF object */ - super(number); - - this.ulx = (float)r.getX(); - this.uly = (float)r.getY(); - this.brx = (float)(r.getX() + r.getWidth()); - this.bry = (float)(r.getY() + r.getHeight()); - this.color = "0 0 0"; // just for now - - } - - /** - * Set the pdf action for this link. - * @param action the pdf action that is activated for this link - */ - public void setAction(PDFAction action) { - this.action = action; - } - - /** - * produce the PDF representation of the object - * - * @return the PDF - */ - public byte[] toPDF() { - String p = this.number + " " + this.generation + " obj\n" - + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ " - + (ulx) + " " + (uly) + " " - + (brx) + " " + (bry) + " ]\n" + "/C [ " - + this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A " - + this.action.getAction() + "\n" + "/H /I\n>>\nendobj\n"; - return p.getBytes(); - } - - /* - * 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 - */ - - /** - * Check if this equals another object. - * - * @param obj the object to compare - * @return true if this equals other object - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || !(obj instanceof PDFLink)) { - return false; - } - - PDFLink link = (PDFLink)obj; - - if (!((link.ulx == ulx) && (link.uly == uly) - && (link.brx == brx) && (link.bry == bry))) { - return false; - } - - if (!(link.color.equals(color) - && link.action.getAction().equals(action.getAction()))) { - return false; - } - - return true; - } -} - diff --git a/src/org/apache/fop/pdf/PDFNumber.java b/src/org/apache/fop/pdf/PDFNumber.java deleted file mode 100644 index d48c04689..000000000 --- a/src/org/apache/fop/pdf/PDFNumber.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -/** - * This class contains some utility methods for outputing numbers to PDF. - */ -public class PDFNumber { - - /** prevent instantiation */ - private PDFNumber() { } - - /** - * Output a Double value to a string suitable for PDF. - * - * @param doubleDown the Double value - * @return the value as a string - */ - public static String doubleOut(Double doubleDown) { - return doubleOut(doubleDown.doubleValue()); - } - - /** - * Output a double value to a string suitable for PDF. - * - * @param doubleDown the double value - * @return the value as a string - */ - public static String doubleOut(double doubleDown) { - StringBuffer p = new StringBuffer(); - if (doubleDown < 0) { - doubleDown = -doubleDown; - p.append("-"); - } - double trouble = doubleDown % 1; - - if (trouble > 0.950) { - p.append((int)doubleDown + 1); - } else if (trouble < 0.050) { - p.append((int)doubleDown); - } else { - String doubleString = new String(doubleDown + ""); - int decimal = doubleString.indexOf("."); - if (decimal != -1) { - p.append(doubleString.substring(0, decimal)); - - if ((doubleString.length() - decimal) > 6) { - p.append(doubleString.substring(decimal, decimal + 6)); - } else { - p.append(doubleString.substring(decimal)); - } - } else { - p.append(doubleString); - } - } - return (p.toString()); - } - - /** - * Output a double value to a string suitable for PDF. - * In this method it is possible to set the maximum - * number of decimal places to output. - * - * @param doubleDown the Double value - * @param dec the number of decimal places to output - * @return the value as a string - */ - public static String doubleOut(double doubleDown, int dec) { - StringBuffer p = new StringBuffer(); - if (doubleDown < 0) { - doubleDown = -doubleDown; - p.append("-"); - } - double trouble = doubleDown % 1; - - if (trouble > (1.0 - (5.0 / (Math.pow(10.0, dec))))) { - p.append((int)doubleDown + 1); - } else if (trouble < (5.0 / (Math.pow(10.0, dec)))) { - p.append((int)doubleDown); - } else { - String doubleString = new String(doubleDown + ""); - int decimal = doubleString.indexOf("."); - if (decimal != -1) { - p.append(doubleString.substring(0, decimal)); - - if ((doubleString.length() - decimal) > dec) { - p.append(doubleString.substring(decimal, decimal + dec)); - } else { - p.append(doubleString.substring(decimal)); - } - } else { - p.append(doubleString); - } - } - return (p.toString()); - } - -} - diff --git a/src/org/apache/fop/pdf/PDFObject.java b/src/org/apache/fop/pdf/PDFObject.java deleted file mode 100644 index 8a8f053bc..000000000 --- a/src/org/apache/fop/pdf/PDFObject.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.io.IOException; -import java.io.OutputStream; - -/** - * generic PDF object. - * - * A PDF Document is essentially a collection of these objects. A PDF - * Object has a number and a generation (although the generation will always - * be 0 in new documents). - */ -public abstract class PDFObject { - - /** - * the object's number - */ - protected int number; - - /** - * the object's generation (0 in new documents) - */ - protected int generation = 0; - - /** - * create an empty object - * - * @param number the object's number - */ - public PDFObject(int number) { - this.number = number; - } - - /** - * Create a PDFObject - */ - public PDFObject() { - // do nothing - } - - /** - * @return the PDF Object number - */ - public int getNumber() { - return this.number; - } - - /** - * write the PDF represention of this object - * - * @param stream the stream to write the PDF to - * @throws IOException if there is an error writing to the stream - * @return the number of bytes written - */ - protected int output(OutputStream stream) throws IOException { - byte[] pdf = this.toPDF(); - stream.write(pdf); - return pdf.length; - } - - /** - * the PDF representation of a reference to this object - * - * @return the reference string - */ - public String referencePDF() { - String p = this.number + " " + this.generation + " R"; - return p; - } - - /** - * represent object as PDF - * - * @return PDF string - */ - abstract byte[] toPDF(); -} diff --git a/src/org/apache/fop/pdf/PDFOutline.java b/src/org/apache/fop/pdf/PDFOutline.java deleted file mode 100644 index 3024e0922..000000000 --- a/src/org/apache/fop/pdf/PDFOutline.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.List; - -/** - * This represents a single Outline object in a PDF, including the root Outlines - * object. Outlines provide the bookmark bar, usually rendered to the right of - * a PDF document in user agents such as Acrobat Reader - * - * @author Kelly A. Campbell - * - */ -public class PDFOutline extends PDFObject { - - /** - * list of sub-entries (outline objects) - */ - private List subentries; - - /** - * parent outline object. Root Outlines parent is null - */ - private PDFOutline parent; - - private PDFOutline prev; - private PDFOutline next; - - private PDFOutline first; - private PDFOutline last; - - private int count; - - /** - * title to display for the bookmark entry - */ - private String title; - - private String actionRef; - - /** - * Create a PDF outline with the title and action. - * - * @param number the object id number - * @param title the title of the outline entry (can only be null for root Outlines obj) - * @param action the action for this outline - */ - public PDFOutline(int number, String title, String action) { - super(number); - subentries = new java.util.ArrayList(); - count = 0; - parent = null; - prev = null; - next = null; - first = null; - last = null; - this.title = title; - actionRef = action; - } - - /** - * Set the title of this Outline object. - * - * @param t the title of the outline - */ - public void setTitle(String t) { - title = t; - } - - /** - * Add a sub element to this outline. - * - * @param outline a sub outline - */ - public void addOutline(PDFOutline outline) { - if (subentries.size() > 0) { - outline.prev = - (PDFOutline)subentries.get(subentries.size() - 1); - outline.prev.next = outline; - } else { - first = outline; - } - - subentries.add(outline); - outline.parent = this; - - // note: count is not just the immediate children - incrementCount(); - - last = outline; - } - - /** - * Increment the number of subentries and descendants. - */ - private void incrementCount() { - // count is a total of our immediate subentries - // and all descendent subentries - count++; - if (parent != null) { - parent.incrementCount(); - } - } - - /** - * represent the object in PDF - * - * @return the PDF for this outline - */ - protected byte[] toPDF() { - StringBuffer result = new StringBuffer(this.number + " " - + this.generation - + " obj\n<<\n"); - if (parent == null) { - // root Outlines object - if (first != null && last != null) { - result.append(" /First " + first.referencePDF() + "\n"); - result.append(" /Last " + last.referencePDF() + "\n"); - // no count... we start with the outline completely closed for now - } - } else { - // subentry Outline object - result.append(" /Title (" + escapeString(title) + ")\n"); - result.append(" /Parent " + parent.referencePDF() + "\n"); - if (first != null && last != null) { - result.append(" /First " + first.referencePDF() + "\n"); - result.append(" /Last " + last.referencePDF() + "\n"); - } - if (prev != null) { - result.append(" /Prev " + prev.referencePDF() + "\n"); - } - if (next != null) { - result.append(" /Next " + next.referencePDF() + "\n"); - } - if (count > 0) { - result.append(" /Count -" + count + "\n"); - } - - if (actionRef != null) { - result.append(" /A " + actionRef + "\n"); - } - - - } - result.append(">> endobj\n"); - return result.toString().getBytes(); - - } - - /** - * escape string (see 3.8.1 in PDF reference 2nd edition) - */ - private String escapeString(String s) { - StringBuffer result = new StringBuffer(); - if (s != null) { - int l = s.length(); - - // byte order marker (0xfeff) - result.append("\\376\\377"); - - for (int i = 0; i < l; i++) { - char ch = s.charAt(i); - int high = (ch & 0xff00) >>> 8; - int low = ch & 0xff; - result.append("\\"); - result.append(Integer.toOctalString(high)); - result.append("\\"); - result.append(Integer.toOctalString(low)); - } - } - - return result.toString(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java deleted file mode 100644 index 188f312aa..000000000 --- a/src/org/apache/fop/pdf/PDFPage.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 /Page object. - * - * There is one of these for every page in a PDF document. The object - * specifies the dimensions of the page and references a /Resources - * object, a contents stream and the page's parent in the page - * hierarchy. - * - * Modified by Mark Lillywhite, mark-fop@inomial.com. The Parent - * object was being referred to by reference, but all that we - * ever used from the Parent was it's PDF object ID, and according - * to the memory profile this was causing OOM issues. So, we store - * only the object ID of the parent, rather than the parent itself. - */ -public class PDFPage extends PDFResourceContext { - - /** - * the page's parent, a PDF reference object - */ - protected String parent; - - /** - * the contents stream - */ - protected PDFStream contents; - - /** - * the width of the page in points - */ - protected int pagewidth; - - /** - * the height of the page in points - */ - protected int pageheight; - - /** - * Duration to display page - */ - protected int duration = -1; - - /** - * Transition dictionary - */ - protected TransitionDictionary trDictionary = null; - - /** - * create a /Page object - * - * @param doc the PDF document holding this page - * @param number the object's number - * @param resources the /Resources object - * @param contents the content stream - * @param pagewidth the page's width in points - * @param pageheight the page's height in points - */ - public PDFPage(PDFDocument doc, int number, PDFResources resources, PDFStream contents, - int pagewidth, int pageheight) { - - /* generic creation of object */ - super(number, doc, resources); - - /* set fields using parameters */ - this.contents = contents; - this.pagewidth = pagewidth; - this.pageheight = pageheight; - } - - /** - * create a /Page object - * - * @param doc the PDF document holding this page - * @param number the object's number - * @param resources the /Resources object - * @param pagewidth the page's width in points - * @param pageheight the page's height in points - */ - public PDFPage(PDFDocument doc, int number, PDFResources resources, - int pagewidth, int pageheight) { - - /* generic creation of object */ - super(number, doc, resources); - - /* set fields using parameters */ - this.pagewidth = pagewidth; - this.pageheight = pageheight; - } - - /** - * set this page contents - * - * @param contents the contents of the page - */ - public void setContents(PDFStream contents) { - this.contents = contents; - } - - /** - * set this page's parent - * - * @param parent the /Pages object that is this page's parent - */ - public void setParent(PDFPages parent) { - this.parent = parent.referencePDF(); - } - - /** - * Set the transition dictionary and duration. - * This sets the duration of the page and the transition - * dictionary used when going to the next page. - * - * @param dur the duration in seconds - * @param tr the transition dictionary - */ - public void setTransition(int dur, TransitionDictionary tr) { - duration = dur; - trDictionary = tr; - } - - /** - * represent this object as PDF - * - * @return the PDF string - */ - public byte[] toPDF() { - StringBuffer sb = new StringBuffer(); - - sb = sb.append(this.number + " " + this.generation + " obj\n" - + "<< /Type /Page\n" + "/Parent " - + this.parent + "\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"); - } - if (this.duration != -1) { - sb = sb.append("/Dur " + this.duration + "\n"); - } - if (this.trDictionary != null) { - sb = sb.append("/Trans << " + this.trDictionary.getDictionary() + " >>\n"); - } - - sb = sb.append(">>\nendobj\n"); - return sb.toString().getBytes(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFPages.java b/src/org/apache/fop/pdf/PDFPages.java deleted file mode 100644 index 2e53d5d22..000000000 --- a/src/org/apache/fop/pdf/PDFPages.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; -import java.util.ArrayList; - -/** - * class representing a /Pages object. - * - * A /Pages object is an ordered collection of pages (/Page objects) - * (Actually, /Pages can contain further /Pages as well but this - * implementation doesn't allow this) - */ -public class PDFPages extends PDFObject { - - /** - * the /Page objects - */ - protected List kids = new ArrayList(); - - /** - * the number of /Page objects - */ - protected int count = 0; - - // private PDFPages parent; - - /** - * create a /Pages object. NOTE: The PDFPages - * object must be created before the PDF document is - * generated, but it is not written to the stream immediately. - * It must aslo be allocated an object ID (so that the kids - * can refer to the parent) so that the XRef table needs to - * be updated before this object is written. - * - * @param number the object's number - */ - public PDFPages(int number) { - super(number); - } - - /** - * add a /Page object. - * - * @param page the PDFPage to add. - */ - public void addPage(PDFPage page) { - this.kids.add(page.referencePDF()); - page.setParent(this); - this.incrementCount(); - } - - /** - * get the count of /Page objects - * - * @return the number of pages - */ - public int getCount() { - return this.count; - } - - /** - * increment the count of /Page objects - */ - public void incrementCount() { - this.count++; - // log.debug("Incrementing count to " + this.getCount()); - } - - /** - * represent the object in PDF - * - * @return the PDF string - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< /Type /Pages\n/Count " - + this.getCount() + "\n/Kids ["); - for (int i = 0; i < kids.size(); i++) { - p = p.append(kids.get(i) + " "); - } - p = p.append("] >>\nendobj\n"); - return p.toString().getBytes(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFPathPaint.java b/src/org/apache/fop/pdf/PDFPathPaint.java deleted file mode 100644 index 85bfa3865..000000000 --- a/src/org/apache/fop/pdf/PDFPathPaint.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -/** - * Base class for PDF painting operations. - * - */ -public abstract class PDFPathPaint extends PDFObject { - - /** - * The color space for this paint - */ - protected PDFColorSpace colorSpace; - - /** - * Create a path paint with a PDF object number. - * - * @param theNumber the PDF object number - */ - public PDFPathPaint(int theNumber) { - super(theNumber); - } - - /** - * Create an emty path paint. - */ - public PDFPathPaint() { - // do nothing - } - - /** - * Get the PDF string for setting the path paint. - * - * @param fillNotStroke if true fill otherwise stroke - * @return the PDF instruction string - */ - public String getColorSpaceOut(boolean fillNotStroke) { - return (""); - } - - /** - * Set the color space for this paint. - * - * @param theColorSpace the color space value - */ - public void setColorSpace(int theColorSpace) { - this.colorSpace.setColorSpace(theColorSpace); - } - - /** - * Get the current color space value for this paint. - * - * @return the color space value - */ - public int getColorSpace() { - return this.colorSpace.getColorSpace(); - } - -} - diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java deleted file mode 100644 index fb169d8f8..000000000 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ /dev/null @@ -1,453 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; -import java.util.HashMap; -import java.io.OutputStream; -import java.io.IOException; - -/** - * class representing a PDF Function. - * - * PDF Functions represent parameterized mathematical formulas and sampled representations with - * arbitrary resolution. Functions are used in two areas: device-dependent - * rasterization information for halftoning and transfer - * functions, and color specification for smooth shading (a PDF 1.3 feature). - * - * All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range. - */ -public class PDFPattern extends PDFPathPaint { - - /** - * The resources associated with this pattern - */ - protected PDFResources resources = null; - - /** - * Either one (1) for tiling, or two (2) for shading. - */ - protected int patternType = 2; // Default - - /** - * The name of the pattern such as "Pa1" or "Pattern1" - */ - protected String patternName = null; - - /** - * 1 for colored pattern, 2 for uncolored - */ - protected int paintType = 2; - - /** - * 1 for constant spacing, 2 for no distortion, and 3 for fast rendering - */ - protected int tilingType = 1; - - /** - * List of Doubles representing the Bounding box rectangle - */ - protected List bBox = null; - - /** - * Horizontal spacing - */ - protected double xStep = -1; - - /** - * Vertical spacing - */ - protected double yStep = -1; - - /** - * The Shading object comprising the Type 2 pattern - */ - protected PDFShading shading = null; - - /** - * List of Integers represetning the Extended unique Identifier - */ - protected List xUID = null; - - /** - * TODO use PDFGState - * String representing the extended Graphics state. - * Probably will never be used like this. - */ - protected StringBuffer extGState = null; - - /** - * List of Doubles representing the Transformation matrix. - */ - protected List matrix = null; - - /** - * The stream of a pattern - */ - protected StringBuffer patternDataStream = null; - - /** - * Create a tiling pattern (type 1). - * - * @param theNumber The object number of this PDF Object - * @param thePatternName The name of the pattern such as "Pa1" or "Pattern1" - * @param theResources the resources associated with this pattern - * @param thePatternType the type of pattern, which is 1 for tiling. - * @param thePaintType 1 or 2, colored or uncolored. - * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox List of Doubles: The pattern cell bounding box - * @param theXStep horizontal spacing - * @param theYStep vertical spacing - * @param theMatrix Optional List of Doubles transformation matrix - * @param theXUID Optional vector of Integers that uniquely identify the pattern - * @param thePatternDataStream The stream of pattern data to be tiled. - */ - public PDFPattern(int theNumber, String thePatternName, - PDFResources theResources, int thePatternType, // 1 - int thePaintType, int theTilingType, List theBBox, double theXStep, - double theYStep, List theMatrix, List theXUID, - StringBuffer thePatternDataStream) { - super(theNumber); - this.patternName = thePatternName; - - this.resources = theResources; - // This next parameter is implicit to all constructors, and is - // not directly passed. - - this.patternType = 1; // thePatternType; - this.paintType = thePaintType; - this.tilingType = theTilingType; - this.bBox = theBBox; - this.xStep = theXStep; - this.yStep = theYStep; - this.matrix = theMatrix; - this.xUID = theXUID; - this.patternDataStream = thePatternDataStream; - } - - /** - * Create a type 2 pattern (smooth shading) - * - * @param theNumber the object number of this PDF object - * @param thePatternName the name of the pattern - * @param thePatternType the type of the pattern, which is 2, smooth shading - * @param theShading the PDF Shading object that comprises this pattern - * @param theXUID optional:the extended unique Identifier if used. - * @param theExtGState optional: the extended graphics state, if used. - * @param theMatrix Optional:List of Doubles that specify the matrix. - */ - public PDFPattern(int theNumber, String thePatternName, - int thePatternType, PDFShading theShading, - List theXUID, StringBuffer theExtGState, - List theMatrix) { - super(theNumber); - - this.patternName = thePatternName; - - this.patternType = 2; // thePatternType; - this.shading = theShading; - this.xUID = theXUID; - // this isn't really implemented, so it should always be null. - // I just don't want to have to add a new parameter once it is implemented. - this.extGState = theExtGState; // always null - this.matrix = theMatrix; - } - - /** - * Get the name of the pattern - * - * @return String representing the name of the pattern. - */ - public String getName() { - return (this.patternName); - } - - /** - * Get the PDF command for setting to this pattern. - * - * @param fillNotStroke if true fill otherwise stroke - * @return the PDF string for setting the pattern - */ - public String getColorSpaceOut(boolean fillNotStroke) { - if (fillNotStroke) { // fill but no stroke - return ("/Pattern cs /" + this.getName() + " scn \n"); - } else { // stroke (or border) - return ("/Pattern CS /" + this.getName() + " SCN \n"); - } - } - - /** - * represent as PDF. Whatever the FunctionType is, the correct - * representation spits out. The sets of required and optional - * attributes are different for each type, but if a required - * attribute's object was constructed as null, then no error - * is raised. Instead, the malformed PDF that was requested - * by the construction is dutifully output. - * This policy should be reviewed. - * - * @param stream the stream to write to - * @throws IOException if there is an error writing to the stream - * @return the PDF string. - */ - protected int output(OutputStream stream) throws IOException { - - int vectorSize = 0; - int tempInt = 0; - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< \n/Type /Pattern \n"); - - if (this.resources != null) { - p.append("/Resources " + this.resources.referencePDF() + " \n"); - } - - p.append("/PatternType " + this.patternType + " \n"); - - PDFStream dataStream = null; - - if (this.patternType == 1) { - p.append("/PaintType " + this.paintType + " \n"); - p.append("/TilingType " + this.tilingType + " \n"); - - if (this.bBox != null) { - vectorSize = this.bBox.size(); - p.append("/BBox [ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.bBox.get(tempInt))); - p.append(" "); - } - p.append("] \n"); - } - p.append("/XStep " + PDFNumber.doubleOut(new Double(this.xStep)) - + " \n"); - p.append("/YStep " + PDFNumber.doubleOut(new Double(this.yStep)) - + " \n"); - - if (this.matrix != null) { - vectorSize = this.matrix.size(); - p.append("/Matrix [ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt))); - p.append(" "); - } - p.append("] \n"); - } - - if (this.xUID != null) { - vectorSize = this.xUID.size(); - p.append("/XUID [ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(((Integer)this.xUID.get(tempInt)) + " "); - } - p.append("] \n"); - } - - // don't forget the length of the stream. - if (this.patternDataStream != null) { - dataStream = new PDFStream(0); - dataStream.add(this.patternDataStream.toString()); - // TODO get the filters from the doc - dataStream.addDefaultFilters(new HashMap(), PDFStream.CONTENT_FILTER); - p.append(dataStream.applyFilters()); - p.append("/Length " + (dataStream.getDataLength() + 1) - + " \n"); - } - - } else { - // if (this.patternType ==2) - // Smooth Shading... - if (this.shading != null) { - p.append("/Shading " + this.shading.referencePDF() + " \n"); - } - - if (this.xUID != null) { - vectorSize = this.xUID.size(); - p.append("/XUID [ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(((Integer)this.xUID.get(tempInt)) + " "); - } - p.append("] \n"); - } - - if (this.extGState != null) { - p.append("/ExtGState " + this.extGState + " \n"); - } - - if (this.matrix != null) { - vectorSize = this.matrix.size(); - p.append("/Matrix [ "); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt))); - p.append(" "); - } - p.append("] \n"); - } - } // end of if patterntype =1...else 2. - - p.append(">> \n"); - - String dict = p.toString(); - int length = dict.length(); - - stream.write(dict.getBytes()); - - // stream representing the function - if (dataStream != null) { - length += dataStream.outputStreamData(stream); - } - - String end = "endobj\n"; - stream.write(end.getBytes()); - length += end.length(); - - return length; - } - - /** - * Output PDF bytes, not used. - * @return returns null - */ - public byte[] toPDF() { return null; } - - /** - * Check if this pattern is equal to another. - * - * @param obj the object to compare against - * @return true if the patterns are equal - */ - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(obj instanceof PDFPattern)) { - return false; - } - PDFPattern patt = (PDFPattern)obj; - if (patternType != patt.patternType) { - return false; - } - if (paintType != patt.paintType) { - return false; - } - if (tilingType != patt.tilingType) { - return false; - } - if (xStep != patt.xStep) { - return false; - } - if (yStep != patt.yStep) { - return false; - } - if (bBox != null) { - if (!bBox.equals(patt.bBox)) { - return false; - } - } else if (patt.bBox != null) { - return false; - } - if (bBox != null) { - if (!bBox.equals(patt.bBox)) { - return false; - } - } else if (patt.bBox != null) { - return false; - } - if (xUID != null) { - if (!xUID.equals(patt.xUID)) { - return false; - } - } else if (patt.xUID != null) { - return false; - } - if (extGState != null) { - if (!extGState.equals(patt.extGState)) { - return false; - } - } else if (patt.extGState != null) { - return false; - } - if (matrix != null) { - if (!matrix.equals(patt.matrix)) { - return false; - } - } else if (patt.matrix != null) { - return false; - } - if (resources != null) { - if (!resources.equals(patt.resources)) { - return false; - } - } else if (patt.resources != null) { - return false; - } - if (shading != null) { - if (!shading.equals(patt.shading)) { - return false; - } - } else if (patt.shading != null) { - return false; - } - if (patternDataStream != null) { - if (!patternDataStream.equals(patt.patternDataStream)) { - return false; - } - } else if (patt.patternDataStream != null) { - return false; - } - - return true; - } - -} diff --git a/src/org/apache/fop/pdf/PDFRectangle.java b/src/org/apache/fop/pdf/PDFRectangle.java deleted file mode 100644 index 57a3ebbac..000000000 --- a/src/org/apache/fop/pdf/PDFRectangle.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 rectangle - * - * Rectangles are specified on page 183 of the PDF 1.3 spec. - */ -public class PDFRectangle { - - /** - * lower left x coordinate - */ - protected int llx; - - /** - * lower left y coordinate - */ - protected int lly; - - /** - * upper right x coordinate - */ - protected int urx; - - /** - * upper right y coordinate - */ - protected int ury; - - /** - * create a rectangle giving the four separate values - * - * @param llx lower left x coordinate - * @param lly lower left y coordinate - * @param urx upper right x coordinate - * @param ury upper right y coordinate - */ - public PDFRectangle(int llx, int lly, int urx, int ury) { - this.llx = llx; - this.lly = lly; - this.urx = urx; - this.ury = ury; - } - - /** - * create a rectangle giving an array of four values - * - * @param array values in the order llx, lly, urx, ury - */ - public PDFRectangle(int[] array) { - this.llx = array[0]; - this.lly = array[1]; - this.urx = array[2]; - this.ury = array[3]; - } - - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - /** - * Create a PDF string for this rectangle. - * - * @return the pdf string - */ - public String toPDFString() { - return new String(" [" + llx + " " + lly + " " + urx + " " + ury - + "] "); - } - -} diff --git a/src/org/apache/fop/pdf/PDFResourceContext.java b/src/org/apache/fop/pdf/PDFResourceContext.java deleted file mode 100644 index ff0a9bb8e..000000000 --- a/src/org/apache/fop/pdf/PDFResourceContext.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -/** - * The PDF resource context. - * - * There is one of these for every page in a PDF document. The object - * specifies the dimensions of the page and references a /Resources - * object, a contents stream and the page's parent in the page - * hierarchy. - * - * Modified by Mark Lillywhite, mark-fop@inomial.com. The Parent - * object was being referred to by reference, but all that we - * ever used from the Parent was it's PDF object ID, and according - * to the memory profile this was causing OOM issues. So, we store - * only the object ID of the parent, rather than the parent itself. - */ -public class PDFResourceContext extends PDFObject { - - /** - * the page's /Resource object - */ - protected PDFResources resources; - - /** - * the list of annotation objects for this page - */ - protected PDFAnnotList annotList; - - /** - * Reference to document used when creating annotation list - */ - protected PDFDocument document; - - /** - * - * @param number the object's number - * @param doc the PDF document this belongs to - * @param resources the /Resources object - */ - public PDFResourceContext(int number, PDFDocument doc, PDFResources resources) { - /* generic creation of object */ - super(number); - - /* set fields using parameters */ - this.document = doc; - this.resources = resources; - this.annotList = null; - } - - /** - * Get the resources for this resource context. - * - * @return the resources in this resource context - */ - public PDFResources getPDFResources() { - return this.resources; - } - - /** - * set this page's annotation list - * - * @param annot a PDFAnnotList list of annotations - */ - public void addAnnotation(PDFObject annot) { - if (this.annotList == null) { - this.annotList = document.makeAnnotList(); - } - this.annotList.addAnnot(annot); - } - - /** - * Get the current annotations. - * - * @return the current annotation list - */ - public PDFAnnotList getAnnotations() { - return this.annotList; - } - - /** - * A a GState to this resource context. - * - * @param gstate the GState to add - */ - public void addGState(PDFGState gstate) { - this.resources.addGState(gstate); - } - - /** - * Add the shading tot he current resource context. - * - * @param shading the shading to add - */ - public void addShading(PDFShading shading) { - this.resources.addShading(shading); - } - - /** - * Get the PDF, unused. - * - * @return null value - */ - public byte[] toPDF() { - return null; - } -} diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java deleted file mode 100644 index e8292ca9a..000000000 --- a/src/org/apache/fop/pdf/PDFResources.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.HashMap; -import java.util.HashSet; - -/** - * class representing a /Resources object. - * - * /Resources object contain a list of references to the fonts for the - * document - */ -public class PDFResources extends PDFObject { - - /** - * /Font objects keyed by their internal name - */ - protected Map fonts = new HashMap(); - - /** - * Set of XObjects - */ - protected Set xObjects = new HashSet(); - - /** - * Set of patterns - */ - protected Set patterns = new HashSet(); - - /** - * Set of shadings - */ - protected Set shadings = new HashSet(); - - /** - * Set of ExtGStates - */ - protected Set gstates = new HashSet(); - - /** - * create a /Resources object. - * - * @param number the object's number - */ - public PDFResources(int number) { - /* generic creation of object */ - super(number); - } - - /** - * add font object to resources list. - * - * @param font the PDFFont to add - */ - public void addFont(PDFFont font) { - this.fonts.put(font.getName(), font); - } - - /** - * Add a PDFGState to the resources. - * - * @param gs the PDFGState to add - */ - public void addGState(PDFGState gs) { - this.gstates.add(gs); - } - - /** - * Add a Shading to the resources. - * - * @param theShading the shading to add - */ - public void addShading(PDFShading theShading) { - this.shadings.add(theShading); - } - - /** - * Add the pattern to the resources. - * - * @param thePattern the pattern to add - */ - public void addPattern(PDFPattern thePattern) { - this.patterns.add(thePattern); - } - - /** - * Add an XObject to the resources. - * - * @param xObject the XObject to add - */ - public void addXObject(PDFXObject xObject) { - this.xObjects.add(xObject); - } - - /** - * represent the object in PDF - * This adds the references to all the objects in the current - * resource context. - * - * @return the PDF - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< \n"); - if (!this.fonts.isEmpty()) { - p.append("/Font << "); - - /* construct PDF dictionary of font object references */ - Iterator fontIterator = this.fonts.keySet().iterator(); - while (fontIterator.hasNext()) { - String fontName = (String)fontIterator.next(); - p.append("/" + fontName + " " - + ((PDFFont)this.fonts.get(fontName)).referencePDF() - + " "); - } - - p.append(">> \n"); - } - - PDFShading currentShading = null; - if (!this.shadings.isEmpty()) { - p.append("/Shading << "); - - for (Iterator iter = shadings.iterator(); iter.hasNext();) { - currentShading = (PDFShading)iter.next(); - p.append("/" + currentShading.getName() + " " - + currentShading.referencePDF() + " "); // \n ?????? - } - - p.append(">>\n"); - } - // "free" the memory. Sorta. - currentShading = null; - - PDFPattern currentPattern = null; - if (!this.patterns.isEmpty()) { - p.append("/Pattern << "); - - for (Iterator iter = patterns.iterator(); iter.hasNext();) { - currentPattern = (PDFPattern)iter.next(); - p.append("/" + currentPattern.getName() + " " - + currentPattern.referencePDF() + " "); - } - - p.append(">> \n"); - } - // "free" the memory. Sorta. - currentPattern = null; - - p.append("/ProcSet [ /PDF /ImageC /Text ]\n"); - - if (this.xObjects != null && !this.xObjects.isEmpty()) { - p = p.append("/XObject <<"); - for (Iterator iter = xObjects.iterator(); iter.hasNext();) { - PDFXObject xobj = (PDFXObject)iter.next(); - p = p.append("/Im" + xobj.getXNumber() + " " - + xobj.referencePDF() - + "\n"); - } - p = p.append(" >>\n"); - } - - if (!this.gstates.isEmpty()) { - p = p.append("/ExtGState <<"); - for (Iterator iter = gstates.iterator(); iter.hasNext();) { - PDFGState gs = (PDFGState)iter.next(); - p = p.append("/" + gs.getName() + " " - + gs.referencePDF() - + " "); - } - p = p.append(">>\n"); - } - - p = p.append(">>\nendobj\n"); - - return p.toString().getBytes(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFRoot.java b/src/org/apache/fop/pdf/PDFRoot.java deleted file mode 100644 index c759a1090..000000000 --- a/src/org/apache/fop/pdf/PDFRoot.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 Root (/Catalog) object - */ -public class PDFRoot extends PDFObject { - - /** - * Use no page mode setting, default - */ - public static final int PAGEMODE_USENONE = 0; - - /** - * Use outlines page mode to show bookmarks - */ - public static final int PAGEMODE_USEOUTLINES = 1; - - /** - * Use thumbs page mode to show thumbnail images - */ - public static final int PAGEMODE_USETHUMBS = 2; - - /** - * Full screen page mode - */ - public static final int PAGEMODE_FULLSCREEN = 3; - - /** - * the /Pages object that is root of the Pages hierarchy - */ - protected PDFPages rootPages; - - /** - * Root outline object - */ - private PDFOutline outline; - - private int pageMode = PAGEMODE_USENONE; - - /** - * create a Root (/Catalog) object. NOTE: The PDFRoot - * object must be created before the PDF document is - * generated, but it is not assigned an object ID until - * it is about to be written (immediately before the xref - * table as part of the trsailer). (mark-fop@inomial.com) - * - * @param number the object's number - * @param pages the PDFPages object - */ - public PDFRoot(int number, PDFPages pages) { - super(number); - setRootPages(pages); - } - - /** - * Set the page mode for the PDF document. - * - * @param mode the page mode - */ - public void setPageMode(int mode) { - pageMode = mode; - } - - /** - * add a /Page object to the root /Pages object - * - * @param page the /Page object to add - */ - public void addPage(PDFPage page) { - this.rootPages.addPage(page); - } - - /** - * set the root /Pages object - * - * @param pages the /Pages object to set as root - */ - public void setRootPages(PDFPages pages) { - this.rootPages = pages; - } - - /** - * Set the root outline for the PDF document. - * - * @param out the root PDF Outline - */ - public void setRootOutline(PDFOutline out) { - outline = out; - } - - /** - * Get the root PDF outline for the document. - * - * @return the root PDF Outline - */ - public PDFOutline getRootOutline() { - return outline; - } - - /** - * represent the object as PDF. - * - * @return the PDF string - */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< /Type /Catalog\n/Pages " - + this.rootPages.referencePDF() - + "\n"); - if (outline != null) { - p.append(" /Outlines " + outline.referencePDF() + "\n"); - p.append(" /PageMode /UseOutlines\n"); - } else { - switch (pageMode) { - case PAGEMODE_USEOUTLINES: - p.append(" /PageMode /UseOutlines\n"); - break; - case PAGEMODE_USETHUMBS: - p.append(" /PageMode /UseThumbs\n"); - break; - case PAGEMODE_FULLSCREEN: - p.append(" /PageMode /FullScreen\n"); - break; - case PAGEMODE_USENONE: - default: - break; - } - } - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); - } - -} diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java deleted file mode 100644 index 5baa83e9c..000000000 --- a/src/org/apache/fop/pdf/PDFShading.java +++ /dev/null @@ -1,670 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.List; - -/** - * class representing a PDF Smooth Shading object. - * - * PDF Functions represent parameterized mathematical formulas and sampled representations with - * arbitrary resolution. Functions are used in two areas: device-dependent - * rasterization information for halftoning and transfer - * functions, and color specification for smooth shading (a PDF 1.3 feature). - * - * All PDF Functions have a shadingType (0,2,3, or 4), a Domain, and a Range. - */ -public class PDFShading extends PDFObject { - // Guts common to all function types - - /** - * The name of the Shading e.g. "Shading1" - */ - protected String shadingName = null; - - /** - * Required: The Type of shading (1,2,3,4,5,6,7) - */ - protected int shadingType = 3; // Default - - /** - * A ColorSpace representing the colorspace. "DeviceRGB" is an example. - */ - protected PDFColorSpace colorSpace = null; - - /** - * The background color. Since shading is opaque, - * this is very rarely used. - */ - protected List background = null; - - /** - * Optional: A List specifying the clipping rectangle - */ - protected List bBox = null; - - /** - * Optional: A flag whether or not to filter the shading function - * to prevent aliasing artifacts. Default is false. - */ - protected boolean antiAlias = false; - - /** - * Optional for Type 1: Array of four numbers, xmin, xmax, ymin, ymax. - * Default is [0 1 0 1] - * Optional for Type 2: An array of two numbers between which the blend - * varies between start and end points. Default is 0, 1. - * Optional for Type 3: An array of two numbers between which the blend - * varies between start and end points. Default is 0, 1. - */ - protected List domain = null; - - /** - * Optional for Type 1: A transformation matrix - */ - protected List matrix = null; - - /** - * Required for Type 1, 2, and 3: - * The object of the color mapping function (usually type 2 or 3). - * Optional for Type 4,5,6, and 7: When it's nearly the same thing. - */ - protected PDFFunction function = null; - - /** - * Required for Type 2: An Array of four numbers specifying - * the starting and ending coordinate pairs - * Required for Type 3: An Array of six numbers [x0,y0,r0,x1,y1,r1] - * specifying the centers and radii of - * the starting and ending circles. - */ - protected List coords = null; - - /** - * Required for Type 2+3: An Array of two boolean values specifying - * whether to extend the start and end colors past the start - * and end points, respectively. - * Default is false, false. - */ - protected List extend = null; - - /** - * Required for Type 4,5,6, and 7: Specifies the number of bits used - * to represent each vertex coordinate. - * Allowed to be 1,2,4,8,12,16,24, or 32. - */ - protected int bitsPerCoordinate = 0; - - /** - * Required for Type 4,5,6, and 7: Specifies the number of bits used - * to represent the edge flag for each vertex. - * Allowed to be 2,4,or 8, while the Edge flag itself is allowed to - * be 0,1 or 2. - */ - protected int bitsPerFlag = 0; - - /** - * Required for Type 4,5,6, and 7: Array of Doubles which specifies - * how to decode coordinate and color component values. - * Each type has a differing number of decode array members, so check - * the spec. - * Page 303 in PDF Spec 1.3 - */ - protected List decode = null; - - /** - * Required for Type 4,5,6, and 7: Specifies the number of bits used - * to represent each color coordinate. - * Allowed to be 1,2,4,8,12, or 16 - */ - protected int bitsPerComponent = 0; - - /** - * Required for Type 5:The number of vertices in each "row" of - * the lattice; it must be greater than or equal to 2. - */ - protected int verticesPerRow = 0; - - /** - * Constructor for type function based shading - * - * @param theNumber The object number of this PDF object - * @param theShadingName The name of the shading pattern. Can be anything - * without spaces. "Shading1" or "Sh1" are good examples. - * @param theShadingType The type of shading object, which should be 1 for function - * based shading. - * @param theColorSpace The colorspace is 'DeviceRGB' or something similar. - * @param theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Whether or not to anti-alias. - * @param theDomain Optional vector of Doubles specifying the domain. - * @param theMatrix List of Doubles specifying the matrix. - * If it's a pattern, then the matrix maps it to pattern space. - * If it's a shading, then it maps it to current user space. - * It's optional, the default is the identity matrix - * @param theFunction The PDF Function that maps an (x,y) location to a color - */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, List theDomain, - List theMatrix, PDFFunction theFunction) { - super(theNumber); - this.shadingName = theShadingName; - this.shadingType = theShadingType; // 1 - this.colorSpace = theColorSpace; - this.background = theBackground; - this.bBox = theBBox; - this.antiAlias = theAntiAlias; - - this.domain = theDomain; - this.matrix = theMatrix; - this.function = theFunction; - - } - - /** - * Constructor for Type 2 and 3 - * - * @param theNumber The object number of this PDF object. - * @param theShadingName The name of the shading pattern. Can be anything - * without spaces. "Shading1" or "Sh1" are good examples. - * @param theShadingType 2 or 3 for axial or radial shading - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theCoords List of four (type 2) or 6 (type 3) Double - * @param theDomain List of Doubles specifying the domain - * @param theFunction the Stitching (PDFfunction type 3) function, - * even if it's stitching a single function - * @param theExtend List of Booleans of whether to extend the start - * and end colors past the start and end points - * The default is [false, false] - */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, List theCoords, - List theDomain, PDFFunction theFunction, - List theExtend) { - super(theNumber); - this.shadingName = theShadingName; - this.shadingType = theShadingType; // 2 or 3 - this.colorSpace = theColorSpace; - this.background = theBackground; - this.bBox = theBBox; - this.antiAlias = theAntiAlias; - - this.coords = theCoords; - this.domain = theDomain; - this.function = theFunction; - this.extend = theExtend; - - } - - /** - * Constructor for Type 4,6, or 7 - * - * @param theNumber The object number of this PDF object. - * @param theShadingType 4, 6, or 7 depending on whether it's - * Free-form gouraud-shaded triangle meshes, coons patch meshes, - * or tensor product patch meshes, respectively. - * @param theShadingName The name of the shading pattern. Can be anything - * without spaces. "Shading1" or "Sh1" are good examples. - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. - * @param theBitsPerComponent 1,2,4,8,12, and 16 - * @param theBitsPerFlag 2,4,8. - * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. - * @param theFunction the PDFFunction - */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, int theBitsPerFlag, - List theDecode, PDFFunction theFunction) { - super(theNumber); - - this.shadingType = theShadingType; // 4,6 or 7 - this.colorSpace = theColorSpace; - this.background = theBackground; - this.bBox = theBBox; - this.antiAlias = theAntiAlias; - - this.bitsPerCoordinate = theBitsPerCoordinate; - this.bitsPerComponent = theBitsPerComponent; - this.bitsPerFlag = theBitsPerFlag; - this.decode = theDecode; - this.function = theFunction; - } - - /** - * Constructor for type 5 - * - * @param theShadingType 5 for lattice-Form Gouraud shaded-triangle mesh - * @param theShadingName The name of the shading pattern. Can be anything - * without spaces. "Shading1" or "Sh1" are good examples. - * @param theColorSpace "DeviceRGB" or similar. - * @param theBackground theBackground An array of color components appropriate to the - * colorspace key specifying a single color value. - * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox List of double's representing a rectangle - * in the coordinate space that is current at the - * time of shading is imaged. Temporary clipping - * boundary. - * @param theAntiAlias Default is false - * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 - * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode List of Doubles. See page 305 in PDF 1.3 spec. - * @param theVerticesPerRow number of vertices in each "row" of the lattice. - * @param theFunction The PDFFunction that's mapped on to this shape - * @param theNumber the object number of this PDF object. - */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, - List theBackground, List theBBox, - boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, List theDecode, - int theVerticesPerRow, PDFFunction theFunction) { - super(theNumber); - this.shadingName = theShadingName; - this.shadingType = theShadingType; // 5 - this.colorSpace = theColorSpace; - this.background = theBackground; - this.bBox = theBBox; - this.antiAlias = theAntiAlias; - - this.bitsPerCoordinate = theBitsPerCoordinate; - this.bitsPerComponent = theBitsPerComponent; - this.decode = theDecode; - this.verticesPerRow = theVerticesPerRow; - this.function = theFunction; - - } - - /** - * Get the name of this shading. - * - * @return the name of the shading - */ - public String getName() { - return (this.shadingName); - } - - /** - * represent as PDF. Whatever the shadingType is, the correct - * representation spits out. The sets of required and optional - * attributes are different for each type, but if a required - * attribute's object was constructed as null, then no error - * is raised. Instead, the malformed PDF that was requested - * by the construction is dutifully output. - * This policy should be reviewed. - * - * @return the PDF string. - */ - public byte[] toPDF() { - int vectorSize; - int tempInt; - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< \n/ShadingType " + this.shadingType + " \n"); - if (this.colorSpace != null) { - p.append("/ColorSpace /" - + this.colorSpace.getColorSpacePDFString() + " \n"); - } - - if (this.background != null) { - p.append("/Background [ "); - vectorSize = this.background.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.background.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - if (this.bBox - != null) { // I've never seen an example, so I guess this is right. - p.append("/BBox [ "); - vectorSize = this.bBox.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.bBox.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - if (this.antiAlias) { - p.append("/AntiAlias " + this.antiAlias + " \n"); - } - - // Here's where we differentiate based on what type it is. - if (this.shadingType == 1) { // function based shading - if (this.domain != null) { - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - if (this.matrix != null) { - p.append("/Matrix [ "); - vectorSize = this.matrix.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - if (this.function != null) { - p.append("/Function "); - p.append(this.function.referencePDF() + " \n"); - } - } else if ((this.shadingType == 2) - || (this.shadingType - == 3)) { // 2 is axial shading (linear gradient) - // 3 is radial shading (circular gradient) - if (this.coords != null) { - p.append("/Coords [ "); - vectorSize = this.coords.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.coords.get(tempInt)) - + " "); - } - p.append("] \n"); - } - - // DOMAIN - if (this.domain != null) { - p.append("/Domain [ "); - vectorSize = this.domain.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(PDFNumber.doubleOut((Double)this.domain.get(tempInt)) - + " "); - } - p.append("] \n"); - } else { - p.append("/Domain [ 0 1 ] \n"); - } - - if (this.extend != null) { - p.append("/Extend [ "); - vectorSize = this.extend.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(((Boolean)this.extend.get(tempInt)) + " "); - } - - p.append("] \n"); - } else { - p.append("/Extend [ true true ] \n"); - } - - - if (this.function != null) { - p.append("/Function "); - p.append(this.function.referencePDF() + " \n"); - } - - - } else if ((this.shadingType == 4) || (this.shadingType == 6) - || (this.shadingType - == 7)) { // 4:Free-form Gouraud-shaded triangle meshes - // 6:coons patch meshes - // 7://tensor product patch meshes (which no one ever uses) - if (this.bitsPerCoordinate > 0) { - p.append("/BitsPerCoordinate " + this.bitsPerCoordinate - + " \n"); - } else { - p.append("/BitsPerCoordinate 1 \n"); - } - - if (this.bitsPerComponent > 0) { - p.append("/BitsPerComponent " + this.bitsPerComponent - + " \n"); - } else { - p.append("/BitsPerComponent 1 \n"); - } - - if (this.bitsPerFlag > 0) { - p.append("/BitsPerFlag " + this.bitsPerFlag + " \n"); - } else { - p.append("/BitsPerFlag 2 \n"); - } - - if (this.decode != null) { - p.append("/Decode [ "); - vectorSize = this.decode.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(((Boolean)this.decode.get(tempInt)) + " "); - } - - p.append("] \n"); - } - - if (this.function != null) { - p.append("/Function "); - p.append(this.function.referencePDF() + " \n"); - } - - } else if (this.shadingType - == 5) { // Lattice Free form gouraud-shaded triangle mesh - - if (this.bitsPerCoordinate > 0) { - p.append("/BitsPerCoordinate " + this.bitsPerCoordinate - + " \n"); - } else { - p.append("/BitsPerCoordinate 1 \n"); - } - - if (this.bitsPerComponent > 0) { - p.append("/BitsPerComponent " + this.bitsPerComponent - + " \n"); - } else { - p.append("/BitsPerComponent 1 \n"); - } - - if (this.decode != null) { - p.append("/Decode [ "); - vectorSize = this.decode.size(); - for (tempInt = 0; tempInt < vectorSize; tempInt++) { - p.append(((Boolean)this.decode.get(tempInt)) + " "); - } - - p.append("] \n"); - } - - if (this.function != null) { - p.append("/Function "); - p.append(this.function.referencePDF() + " \n"); - } - - if (this.verticesPerRow > 0) { - p.append("/VerticesPerRow " + this.verticesPerRow + " \n"); - } else { - p.append("/VerticesPerRow 2 \n"); - } - - } - - p.append(">> \nendobj\n"); - - return (p.toString().getBytes()); - } - - /** - * Check if this shading is equal to another shading. - * This is used to check if a shading already exists. - * - * @param obj the object to compare against - * @return true if the shadings are equal - */ - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(obj instanceof PDFShading)) { - return false; - } - PDFShading shad = (PDFShading)obj; - if (shadingType != shad.shadingType) { - return false; - } - if (antiAlias != shad.antiAlias) { - return false; - } - if (bitsPerCoordinate != shad.bitsPerCoordinate) { - return false; - } - if (bitsPerFlag != shad.bitsPerFlag) { - return false; - } - if (bitsPerComponent != shad.bitsPerComponent) { - return false; - } - if (verticesPerRow != shad.verticesPerRow) { - return false; - } - if (colorSpace != null) { - if (!colorSpace.equals(shad.colorSpace)) { - return false; - } - } else if (shad.colorSpace != null) { - return false; - } - if (background != null) { - if (!background.equals(shad.background)) { - return false; - } - } else if (shad.background != null) { - return false; - } - if (bBox != null) { - if (!bBox.equals(shad.bBox)) { - return false; - } - } else if (shad.bBox != null) { - return false; - } - if (domain != null) { - if (!domain.equals(shad.domain)) { - return false; - } - } else if (shad.domain != null) { - return false; - } - if (matrix != null) { - if (!matrix.equals(shad.matrix)) { - return false; - } - } else if (shad.matrix != null) { - return false; - } - if (coords != null) { - if (!coords.equals(shad.coords)) { - return false; - } - } else if (shad.coords != null) { - return false; - } - if (extend != null) { - if (!extend.equals(shad.extend)) { - return false; - } - } else if (shad.extend != null) { - return false; - } - if (decode != null) { - if (!decode.equals(shad.decode)) { - return false; - } - } else if (shad.decode != null) { - return false; - } - if (function != null) { - if (!function.equals(shad.function)) { - return false; - } - } else if (shad.function != null) { - return false; - } - return true; - } -} diff --git a/src/org/apache/fop/pdf/PDFState.java b/src/org/apache/fop/pdf/PDFState.java deleted file mode 100644 index 305ff8ffc..000000000 --- a/src/org/apache/fop/pdf/PDFState.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.awt.Shape; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.awt.geom.GeneralPath; -import java.awt.geom.Area; - -import java.awt.Color; -import java.awt.Paint; -import java.awt.geom.AffineTransform; - -/** - * This keeps information about the current state when writing to pdf. - * It allows for creating new graphics states with the q operator. - * This class is only used to store the information about the state - * the caller needs to handle the actual pdf operators. - * - * When setting the state for pdf there are three possible ways of - * handling the situation. - * The values can be set to override previous or default values. - * A new state can be added and then the values set. - * The current state can be popped and values will return to a - * previous state then the necessary values can be overridden. - * The current transform behaves differently to other values as the - * matrix is combined with the current resolved value. - * It is impossible to optimise the result without analysing the all - * the possible combinations after completing. - */ -public class PDFState { - private static final String COLOR = "color"; - private static final String BACKCOLOR = "backcolor"; - private static final String PAINT = "paint"; - private static final String BACKPAINT = "backpaint"; - private static final String LINECAP = "lineCap"; - private static final String LINEJOIN = "lineJoin"; - private static final String LINEWIDTH = "lineWidth"; - private static final String MITERLIMIT = "miterLimit"; - private static final String TEXT = "text"; - private static final String DASHOFFSET = "dashOffset"; - private static final String DASHARRAY = "dashArray"; - private static final String TRANSFORM = "transform"; - private static final String FONTSIZE = "fontSize"; - private static final String FONTNAME = "fontName"; - private static final String CLIP = "clip"; - private static final String GSTATE = "gstate"; - - private Color color = Color.black; - private Color backcolor = Color.white; - private Paint paint = null; - private Paint backPaint = null; - private int lineCap = 0; - private int lineJoin = 0; - private float lineWidth = 1; - private float miterLimit = 0; - private boolean text = false; - private int dashOffset = 0; - private int[] dashArray = new int[0]; - private AffineTransform transform = new AffineTransform(); - private float fontSize = 0; - private String fontName = ""; - private Shape clip = null; - private PDFGState gstate = null; - - private ArrayList stateStack = new ArrayList(); - - /** - * PDF State for storing graphics state. - */ - public PDFState() { - - } - - /** - * Push the current state onto the stack. - * This call should be used when the q operator is used - * so that the state is known when popped. - */ - public void push() { - HashMap saveMap = new HashMap(); - saveMap.put(COLOR, color); - saveMap.put(BACKCOLOR, backcolor); - saveMap.put(PAINT, paint); - saveMap.put(BACKPAINT, backPaint); - saveMap.put(LINECAP, new Integer(lineCap)); - saveMap.put(LINEJOIN, new Integer(lineJoin)); - saveMap.put(LINEWIDTH, new Float(lineWidth)); - saveMap.put(MITERLIMIT, new Float(miterLimit)); - saveMap.put(TEXT, new Boolean(text)); - saveMap.put(DASHOFFSET, new Integer(dashOffset)); - saveMap.put(DASHARRAY, dashArray); - saveMap.put(TRANSFORM, transform); - saveMap.put(FONTSIZE, new Float(fontSize)); - saveMap.put(FONTNAME, fontName); - saveMap.put(CLIP, clip); - saveMap.put(GSTATE, gstate); - - stateStack.add(saveMap); - - transform = new AffineTransform(); - } - - /** - * Pop the state from the stack and set current values to popped state. - * This should be called when a Q operator is used so - * the state is restored to the correct values. - */ - public void pop() { - if (getStackLevel() > 0) { - HashMap saveMap = (HashMap)stateStack.get(stateStack.size() - 1); - stateStack.remove(stateStack.size() - 1); - color = (Color)saveMap.get(COLOR); - backcolor = (Color)saveMap.get(BACKCOLOR); - paint = (Paint)saveMap.get(PAINT); - backPaint = (Paint)saveMap.get(BACKPAINT); - lineCap = ((Integer)saveMap.get(LINECAP)).intValue(); - lineJoin = ((Integer)saveMap.get(LINEJOIN)).intValue(); - lineWidth = ((Float)saveMap.get(LINEWIDTH)).floatValue(); - miterLimit = ((Float)saveMap.get(MITERLIMIT)).floatValue(); - text = ((Boolean)saveMap.get(TEXT)).booleanValue(); - dashOffset = ((Integer)saveMap.get(DASHOFFSET)).intValue(); - dashArray = (int[])saveMap.get(DASHARRAY); - transform = (AffineTransform)saveMap.get(TRANSFORM); - fontSize = ((Float)saveMap.get(FONTSIZE)).floatValue(); - fontName = (String)saveMap.get(FONTNAME); - clip = (Shape)saveMap.get(CLIP); - gstate = (PDFGState)saveMap.get(GSTATE); - } - } - - /** - * Get the current stack level. - * - * @return the current stack level - */ - public int getStackLevel() { - return stateStack.size(); - } - - /** - * Restore the state to a particular level. - * this can be used to restore to a known level without making - * multiple pop calls. - * - * @param stack the level to restore to - */ - public void restoreLevel(int stack) { - int pos = stack; - while (stateStack.size() > pos + 1) { - stateStack.remove(stateStack.size() - 1); - } - if (stateStack.size() > pos) { - pop(); - } - } - - /** - * Set the current line dash. - * Check if setting the line dash to the given values - * will make a change and then set the state to the new values. - * - * @param array the line dash array - * @param offset the line dash start offset - * @return true if the line dash has changed - */ - public boolean setLineDash(int[] array, int offset) { - return false; - } - - /** - * Set the current color. - * Check if the new color is a change and then set the current color. - * - * @param col the color to set - * @return true if the color has changed - */ - public boolean setColor(Color col) { - if (!col.equals(color)) { - color = col; - return true; - } - return false; - } - - /** - * Set the current background color. - * Check if the background color will change and then set the new color. - * - * @param col the new background color - * @return true if the background color has changed - */ - public boolean setBackColor(Color col) { - if (!col.equals(backcolor)) { - backcolor = col; - return true; - } - return false; - } - - /** - * Set the current paint. - * This checks if the paint will change and then sets the current paint. - * - * @param p the new paint - * @return true if the new paint changes the current paint - */ - public boolean setPaint(Paint p) { - if (paint == null) { - if (p != null) { - paint = p; - return true; - } - } else if (!paint.equals(p)) { - paint = p; - return true; - } - return false; - } - - /** - * Check if the clip will change the current state. - * A clip is assumed to be used in a situation where it will add - * to any clip in the current or parent states. - * A clip cannot be cleared, this can only be achieved by going to - * a parent level with the correct clip. - * If the clip is different then it may start a new state so that - * it can return to the previous clip. - * - * @param cl the clip shape to check - * @return true if the clip will change the current clip. - */ - public boolean checkClip(Shape cl) { - if (clip == null) { - if (cl != null) { - return true; - } - } else if (!new Area(clip).equals(new Area(cl))) { - return true; - } - // todo check for clips that are larger than the current - return false; - } - - /** - * Set the current clip. - * This either sets a new clip or sets the clip to the intersect of - * the old clip and the new clip. - * - * @param cl the new clip in the current state - */ - public void setClip(Shape cl) { - if (clip != null) { - Area newClip = new Area(clip); - newClip.intersect(new Area(cl)); - clip = new GeneralPath(newClip); - } else { - clip = cl; - } - } - - /** - * Check the current transform. - * The transform for the current state is the combination of all - * transforms in the current state. The parameter is compared - * against this current transform. - * - * @param tf the transform the check against - * @return true if the new transform is different then the current transform - */ - public boolean checkTransform(AffineTransform tf) { - return !tf.equals(transform); - } - - /** - * Set a new transform. - * This transform is appended to the transform of - * the current graphic state. - * - * @param tf the transform to concatonate to the current level transform - */ - public void setTransform(AffineTransform tf) { - transform.concatenate(tf); - } - - /** - * Get the current transform. - * This gets the combination of all transforms in the - * current state. - * - * @return the calculate combined transform for the current state - */ - public AffineTransform getTransform() { - AffineTransform tf; - AffineTransform at = new AffineTransform(); - for (Iterator iter = stateStack.iterator(); iter.hasNext();) { - HashMap map = (HashMap)iter.next(); - tf = (AffineTransform)map.get(TRANSFORM); - at.concatenate(tf); - } - at.concatenate(transform); - - return at; - } - - /** - * Get the grapics state. - * This gets the combination of all graphic states for - * the current context. - * This is the graphic state set with the gs operator not - * the other graphic state changes. - * - * @return the calculated ExtGState in the current context - */ - public PDFGState getGState() { - PDFGState defaultState = PDFGState.DEFAULT; - - PDFGState state; - PDFGState newstate = new PDFGState(0); - newstate.addValues(defaultState); - for (Iterator iter = stateStack.iterator(); iter.hasNext();) { - HashMap map = (HashMap)iter.next(); - state = (PDFGState)map.get(GSTATE); - if (state != null) { - newstate.addValues(state); - } - } - if (gstate != null) { - newstate.addValues(gstate); - } - - return newstate; - } -} - diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java deleted file mode 100644 index 9fddaafdf..000000000 --- a/src/org/apache/fop/pdf/PDFStream.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.OutputStream; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -/** - * Class representing a PDF stream. - * <p> - * A derivative of the PDF Object, a PDF Stream has not only a dictionary - * but a stream of PDF commands. The stream of commands is where the real - * work is done, the dictionary just provides information like the stream - * length. - */ -public class PDFStream extends PDFObject { - - /** Key for the default filter */ - public static final String DEFAULT_FILTER = "default"; - /** Key for the filter used for normal content*/ - public static final String CONTENT_FILTER = "content"; - /** Key for the filter used for images */ - public static final String IMAGE_FILTER = "image"; - /** Key for the filter used for JPEG images */ - public static final String JPEG_FILTER = "jpeg"; - /** Key for the filter used for fonts */ - public static final String FONT_FILTER = "font"; - - /** - * The stream of PDF commands - */ - protected StreamCache data; - - /** - * The filters that should be applied - */ - private List filters; - - /** - * Create an empty stream object - * - * @param number the object's number - */ - public PDFStream(int number) { - super(number); - try { - data = StreamCache.createStreamCache(); - } catch (IOException ex) { - /**@todo Log with Logger */ - ex.printStackTrace(); - } - filters = new java.util.ArrayList(); - } - - /** - * Append data to the stream - * - * @param s the string of PDF to add - */ - public void add(String s) { - try { - data.getOutputStream().write(s.getBytes()); - } catch (IOException ex) { - /**@todo Log with Logger */ - ex.printStackTrace(); - } - - } - - /** - * Add a filter for compression of the stream. Filters are - * applied in the order they are added. This should always be a - * new instance of the particular filter of choice. The applied - * flag in the filter is marked true after it has been applied to the - * data. - * @param filter filter to add - */ - public void addFilter(PDFFilter filter) { - if (filter != null) { - filters.add(filter); - } - - } - - /** - * Add a filter for compression of the stream by name. - * @param filterType name of the filter to add - */ - public void addFilter(String filterType) { - if (filterType == null) { - return; - } - if (filterType.equals("flate")) { - addFilter(new FlateFilter()); - } else if (filterType.equals("ascii-85")) { - addFilter(new ASCII85Filter()); - } else if (filterType.equals("ascii-hex")) { - addFilter(new ASCIIHexFilter()); - } else if (filterType.equals("")) { - return; - } else { - throw new IllegalArgumentException( - "Unsupported filter type in stream-filter-list: " + filterType); - } - } - - /** - * Adds the default filters to this stream. - * @param filters Map of filters - * @param type which filter list to modify - */ - public void addDefaultFilters(Map filters, String type) { - List filterset = (List)filters.get(type); - if (filterset == null) { - filterset = (List)filters.get(DEFAULT_FILTER); - } - if (filterset == null || filterset.size() == 0) { - // built-in default to flate - //addFilter(new FlateFilter()); - } else { - for (int i = 0; i < filterset.size(); i++) { - String v = (String)filterset.get(i); - addFilter(v); - } - } - } - - /** - * Append an array of xRGB pixels, ASCII Hex Encoding it first - * - * @param pixels the area of pixels - * @param width the width of the image in pixels - * @param height the height of the image in pixels - */ - public void addImageArray(int[] pixels, int width, int height) { - try { - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - int p = pixels[i * width + j]; - int r = (p >> 16) & 0xFF; - int g = (p >> 8) & 0xFF; - int b = (p) & 0xFF; - if (r < 16) { - data.getOutputStream().write('0'); - } - data.getOutputStream().write(Integer.toHexString(r).getBytes()); - if (g < 16) { - data.getOutputStream().write('0'); - } - data.getOutputStream().write(Integer.toHexString(g).getBytes()); - if (b < 16) { - data.getOutputStream().write('0'); - } - data.getOutputStream().write(Integer.toHexString(b).getBytes()); - data.getOutputStream().write(' '); - } - } - data.getOutputStream().write(">\n".getBytes()); - } catch (IOException ex) { - ex.printStackTrace(); - } - - } - - /** - * Used to set the contents of the PDF stream. - * @param data the contents as a byte array - * @throws IOException in case of an I/O problem - */ - public void setData(byte[] data) throws IOException { - this.data.reset(); - this.data.getOutputStream().write(data); - } - - /* - public byte[] getData() { - return _data.toByteArray(); - } - */ - - /** - * Returns the size of the content. - * @return size of the content - */ - public int getDataLength() { - try { - return data.getSize(); - } catch (Exception e) { - e.printStackTrace(); - return 0; - } - } - - /** - * Represent as PDF. - * - * @return the PDF string. - */ - public byte[] toPDF() { - throw new UnsupportedOperationException("Use output(OutputStream) instead"); - /* - * byte[] d = _data.toByteArray(); - * ByteArrayOutputStream s = new ByteArrayOutputStream(); - * String p = this.number + " " + this.generation - * + " obj\n<< /Length " + (d.length+1) - * + " >>\nstream\n"; - * s.write(p.getBytes()); - * s.write(d); - * s.write("\nendstream\nendobj\n".getBytes()); - * return s.toByteArray(); - */ - } - - /** - * Overload the base object method so we don't have to copy - * byte arrays around so much - * @see org.apache.fop.pdf.PDFObject#output(OutputStream) - */ - protected int output(OutputStream stream) throws IOException { - int length = 0; - String filterEntry = applyFilters(); - byte[] p = (this.number + " " + this.generation + " obj\n<< /Length " - + (data.getSize() + 1) + " " + filterEntry - + " >>\n").getBytes(); - - stream.write(p); - length += p.length; - length += outputStreamData(stream); - p = "endobj\n".getBytes(); - stream.write(p); - length += p.length; - return length; - - } - - /** - * Output just the stream data enclosed by stream/endstream markers - * @param stream OutputStream to write to - * @return int number of bytes written - * @throws IOException in case of an I/O problem - */ - protected int outputStreamData(OutputStream stream) throws IOException { - int length = 0; - byte[] p = "stream\n".getBytes(); - stream.write(p); - length += p.length; - data.outputStreamData(stream); - length += data.getSize(); - data.close(); - p = "\nendstream\n".getBytes(); - stream.write(p); - length += p.length; - return length; - - } - - /** - * Apply the filters to the data - * in the order given and return the /Filter and /DecodeParms - * entries for the stream dictionary. If the filters have already - * been applied to the data (either externally, or internally) - * then the dictionary entries are built and returned. - * @return a String representing the filter list - * @throws IOException in case of an I/O problem - */ - protected String applyFilters() throws IOException { - if (filters.size() > 0) { - List names = new java.util.ArrayList(); - List parms = new java.util.ArrayList(); - - // run the filters - for (int count = 0; count < filters.size(); count++) { - PDFFilter filter = (PDFFilter)filters.get(count); - // apply the filter encoding if neccessary - if (!filter.isApplied()) { - data.applyFilter(filter); - filter.setApplied(true); - } - // place the names in our local vector in reverse order - names.add(0, filter.getName()); - parms.add(0, filter.getDecodeParms()); - } - - // now build up the filter entries for the dictionary - return buildFilterEntries(names) + buildDecodeParms(parms); - } - return ""; - - } - - private String buildFilterEntries(List names) { - StringBuffer sb = new StringBuffer(); - sb.append("/Filter "); - if (names.size() > 1) { - sb.append("[ "); - } - for (int count = 0; count < names.size(); count++) { - sb.append((String)names.get(count)); - sb.append(" "); - } - if (names.size() > 1) { - sb.append("]"); - } - sb.append("\n"); - return sb.toString(); - } - - private String buildDecodeParms(List parms) { - StringBuffer sb = new StringBuffer(); - boolean needParmsEntry = false; - sb.append("/DecodeParms "); - - if (parms.size() > 1) { - sb.append("[ "); - } - for (int count = 0; count < parms.size(); count++) { - String s = (String)parms.get(count); - if (s != null) { - sb.append(s); - needParmsEntry = true; - } else { - sb.append("null"); - } - sb.append(" "); - } - if (parms.size() > 1) { - sb.append("]"); - } - sb.append("\n"); - if (needParmsEntry) { - return sb.toString(); - } else { - return ""; - } - } - - -} diff --git a/src/org/apache/fop/pdf/PDFT1Stream.java b/src/org/apache/fop/pdf/PDFT1Stream.java deleted file mode 100644 index d863a708e..000000000 --- a/src/org/apache/fop/pdf/PDFT1Stream.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.io.IOException; -import java.io.UnsupportedEncodingException; - -// FOP -import org.apache.fop.fonts.type1.PFBData; - -/** - * Special PDFStream for embedding Type 1 fonts. - */ -public class PDFT1Stream extends PDFStream { - - private PFBData pfb; - - /** - * @see org.apache.fop.pdf.PDFObject#PDFObject(int) - */ - public PDFT1Stream(int num) { - super(num); - } - - - /** - * Overload the base object method so we don't have to copy - * byte arrays around so much - * @see org.apache.fop.pdf.PDFObject#output(OutputStream) - */ - protected int output(java.io.OutputStream stream) - throws java.io.IOException { - if (pfb == null) { - throw new IllegalStateException("pfb must not be null at this point"); - } - int length = 0; - String filterEntry = applyFilters(); - String preData = this.number + " " + this.generation - + " obj\n<< /Length " + pfb.getLength() + " " - + filterEntry - + " /Length1 " + pfb.getLength1() - + " /Length2 " + pfb.getLength2() - + " /Length3 " + pfb.getLength3() + " >>\n"; - - byte[] p; - try { - p = preData.getBytes(PDFDocument.ENCODING); - } catch (UnsupportedEncodingException ue) { - p = preData.getBytes(); - } - - stream.write(p); - length += p.length; - - length += outputStreamData(stream); - try { - p = "endobj\n".getBytes(PDFDocument.ENCODING); - } catch (UnsupportedEncodingException ue) { - p = "endobj\n".getBytes(); - } - stream.write(p); - length += p.length; - //System.out.println("Embedded Type1 font"); - return length; - } - - /** - * Used to set the PFBData object that represents the embeddable Type 1 - * font. - * @param pfb The PFB file - * @throws IOException in case of an I/O problem - */ - public void setData(PFBData pfb) throws IOException { - data.reset(); - // System.out.println("Writing " + size + " bytes of font data"); - this.pfb = pfb; - pfb.outputAllParts(data.getOutputStream()); - } - -} diff --git a/src/org/apache/fop/pdf/PDFTTFStream.java b/src/org/apache/fop/pdf/PDFTTFStream.java deleted file mode 100644 index 0e292d68f..000000000 --- a/src/org/apache/fop/pdf/PDFTTFStream.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.IOException; - -/** - * Special PDFStream for embeddable TrueType fonts. - */ -public class PDFTTFStream extends PDFStream { - - private int origLength; - - /** - * Main constructor - * @param num PDF object number - * @param len original length - */ - public PDFTTFStream(int num, int len) { - super(num); - origLength = len; - } - - /** - * Overload the base object method so we don't have to copy - * byte arrays around so much - * @see org.apache.fop.pdf.PDFObject#output(OutputStream) - */ - protected int output(java.io.OutputStream stream) - throws java.io.IOException { - int length = 0; - String filterEntry = applyFilters(); - String preData = new String(this.number + " " + this.generation - + " obj\n<< /Length " - + (data.getSize() + 1) + " " + filterEntry - + " " + "/Length1 " + origLength - + " >>\n"); - - byte[] p = preData.getBytes(); - stream.write(p); - length += p.length; - - length += outputStreamData(stream); - p = "endobj\n".getBytes(); - stream.write(p); - length += p.length; - return length; - } - - /** - * Sets the TrueType font data. - * @param data the font payload - * @param size size of the payload - * @throws IOException in case of an I/O problem - */ - public void setData(byte[] data, int size) throws IOException { - this.data.reset(); - /**@todo Log using Logger */ - System.out.println("Writing " + size + " bytes of font data"); - this.data.getOutputStream().write(data, 0, size); - } - -} diff --git a/src/org/apache/fop/pdf/PDFUri.java b/src/org/apache/fop/pdf/PDFUri.java deleted file mode 100644 index 47135c4e9..000000000 --- a/src/org/apache/fop/pdf/PDFUri.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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 used to create a PDF Uri link - */ -public class PDFUri extends PDFAction { - - private String uri; - - /** - * create a Uri instance. - * - * @param uri the uri to which the link should point - */ - public PDFUri(String uri) { - this.uri = uri; - } - - /** - * returns the action ncecessary for a uri - * - * @return the action to place next to /A within a Link - */ - public String getAction() { - return "<< /URI (" + uri + ")\n/S /URI >>"; - } - - /** - * There is nothing to return for the toPDF method - * as it should not be called. - * - * @return an empty array - */ - public byte[] toPDF() { - return new byte[0]; - } - -} diff --git a/src/org/apache/fop/pdf/PDFWArray.java b/src/org/apache/fop/pdf/PDFWArray.java deleted file mode 100644 index f2054e8be..000000000 --- a/src/org/apache/fop/pdf/PDFWArray.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.List; - -/** - * Class representing a <b>W</b> array for CID fonts. - */ -public class PDFWArray { - - /** - * The metrics - */ - private List entries = new java.util.ArrayList(); - - /** - * Default constructor - */ - public PDFWArray() { - } - - /** - * Convenience constructor - * @param metrics the metrics array to initially add - */ - public PDFWArray(int[] metrics) { - addEntry(0, metrics); - } - - /** - * Add an entry for single starting CID. - * i.e. in the form "c [w ...]" - * - * @param start the starting CID value. - * @param metrics the metrics array. - */ - public void addEntry(int start, int[] metrics) { - entries.add(new Entry(start, metrics)); - } - - /** - * Add an entry for a range of CIDs (/W element on p 213) - * - * @param first the first CID in the range - * @param last the last CID in the range - * @param width the width for all CIDs in the range - */ - public void addEntry(int first, int last, int width) { - entries.add(new int[] { - first, last, width - }); - } - - /** - * Add an entry for a range of CIDs (/W2 element on p 210) - * - * @param first the first CID in the range - * @param last the last CID in the range - * @param width the width for all CIDs in the range - * @param posX the x component for the vertical position vector - * @param posY the y component for the vertical position vector - */ - public void addEntry(int first, int last, int width, int posX, int posY) { - entries.add(new int[] { - first, last, width, posX, posY - }); - } - - /** - * Convert this object to PDF code. - * @return byte[] the PDF code - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - /** - * Convert this object to PDF code. - * @return String the PDF code - */ - public String toPDFString() { - StringBuffer p = new StringBuffer(); - p.append("[ "); - int len = entries.size(); - for (int i = 0; i < len; i++) { - Object entry = entries.get(i); - if (entry instanceof int[]) { - int[] line = (int[])entry; - for (int j = 0; j < line.length; j++) { - p.append(line[j]); - p.append(" "); - } - } else { - ((Entry)entry).fillInPDF(p); - } - } - p.append("]"); - return p.toString(); - } - - /** - * Inner class for entries in the form "c [w ...]" - */ - private static class Entry { - private int start; - private int[] metrics; - public Entry(int s, int[] m) { - start = s; - metrics = m; - } - - public void fillInPDF(StringBuffer p) { - // p.setLength(0); - p.append(start); - p.append(" ["); - for (int i = 0; i < metrics.length; i++) { - p.append(this.metrics[i]); - p.append(" "); - } - p.append("] "); - } - - } -} diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java deleted file mode 100644 index a5243332f..000000000 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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.io.IOException; -import java.io.OutputStream; - -/* modified by JKT to integrate with 0.12.0 */ -/* modified by Eric SCHAEFFER to integrate with 0.13.0 */ - -/** - * PDF XObject - * - * A derivative of the PDF Object, is a PDF Stream that has not only a - * dictionary but a stream of image data. - * The dictionary just provides information like the stream length. - * This outputs the image dictionary and the image data. - * This is used as a reference for inserting the same image in the - * document in another place. - */ -public class PDFXObject extends PDFObject { - private PDFImage pdfimage; - private int xnum; - - /** - * create an XObject with the given number and name and load the - * image in the object - * - * @param number the pdf object number - * @param xnumber the pdf object X number - * @param img the pdf image that contains the image data - */ - public PDFXObject(int number, int xnumber, PDFImage img) { - super(number); - this.xnum = xnumber; - pdfimage = img; - } - - /** - * Get the xnumber for this pdf object. - * - * @return the PDF XObject number - */ - public int getXNumber() { - return this.xnum; - } - - /** - * Output the image as PDF. - * This sets up the image dictionary and adds the image data stream. - * - * @param stream the output stream to write the data - * @throws IOException if there is an error writing the data - * @return the length of the data written - */ - protected int output(OutputStream stream) throws IOException { - int length = 0; - int i = 0; - - if (pdfimage.isPS()) { - length = outputEPSImage(stream); - } else { - - PDFStream imgStream = pdfimage.getDataStream(); - - String dictEntries = imgStream.applyFilters(); - - String p = this.number + " " + this.generation + " obj\n"; - p = p + "<</Type /XObject\n"; - p = p + "/Subtype /Image\n"; - p = p + "/Name /Im" + xnum + "\n"; - p = p + "/Length " + (imgStream.getDataLength() + 1) + "\n"; - p = p + "/Width " + pdfimage.getWidth() + "\n"; - p = p + "/Height " + pdfimage.getHeight() + "\n"; - p = p + "/BitsPerComponent " + pdfimage.getBitsPerPixel() - + "\n"; - - PDFICCStream pdfICCStream = pdfimage.getICCStream(); - if (pdfICCStream != null) { - p = p + "/ColorSpace [/ICCBased " - + pdfICCStream.referencePDF() + "]\n"; - } else { - PDFColorSpace cs = pdfimage.getColorSpace(); - p = p + "/ColorSpace /" + cs.getColorSpacePDFString() - + "\n"; - } - - /* PhotoShop generates CMYK values that's inverse, - this will invert the values - too bad if it's not - a PhotoShop image... - */ - if (pdfimage.getColorSpace().getColorSpace() - == PDFColorSpace.DEVICE_CMYK) { - p = p + "/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]\n"; - } - - if (pdfimage.isTransparent()) { - PDFColor transp = pdfimage.getTransparentColor(); - p = p + "/Mask [" + transp.red255() + " " - + transp.red255() + " " + transp.green255() - + " " + transp.green255() + " " - + transp.blue255() + " " + transp.blue255() + "]\n"; - } - String ref = pdfimage.getSoftMask(); - if (ref != null) { - p = p + "/SMask " + ref + "\n"; - } - - p = p + dictEntries; - p = p + ">>\n"; - - // push the pdf dictionary on the writer - byte[] pdfBytes = p.getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - // push all the image data on the writer - // and takes care of length for trailer - length += imgStream.outputStreamData(stream); - - pdfBytes = ("endobj\n").getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - } - // let it gc - // this object is retained as a reference to inserting - // the same image but the image data is no longer needed - pdfimage = null; - return length; - } - - byte[] toPDF() { - return null; - } - - private int outputEPSImage(OutputStream stream) throws IOException { - int length = 0; - int i = 0; - - PDFStream imgStream = pdfimage.getDataStream(); - String dictEntries = imgStream.applyFilters(); - - String p = this.number + " " + this.generation + " obj\n"; - p = p + "<</Type /XObject\n"; - p = p + "/Subtype /PS\n"; - p = p + "/Length " + (imgStream.getDataLength() + 1); - - p = p + dictEntries; - p = p + ">>\n"; - - // push the pdf dictionary on the writer - byte[] pdfBytes = p.getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - // push all the image data on the writer and takes care of length for trailer - length += imgStream.outputStreamData(stream); - - pdfBytes = ("endobj\n").getBytes(); - stream.write(pdfBytes); - length += pdfBytes.length; - - return length; - } - -} diff --git a/src/org/apache/fop/pdf/StreamCache.java b/src/org/apache/fop/pdf/StreamCache.java deleted file mode 100644 index 4234a7f89..000000000 --- a/src/org/apache/fop/pdf/StreamCache.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.io.OutputStream; -import java.io.IOException; - -/** - * class used to store the bytes for a PDFStream. It's actually a generic - * cached byte array, along with a factory that returns either an - * in-memory or tempfile based implementation based on the global - * cacheToFile setting. - */ -public abstract class StreamCache { - - /** - * Global setting; controls whether to use tempfiles or not. - */ - private static boolean cacheToFile = false; - - /** - * Change the global cacheToFile flag. - * - * @param tizit true if cache to file - */ - public static void setCacheToFile(boolean tizit) { - cacheToFile = tizit; - } - - /** - * Get the value of the global cacheToFile flag. - * - * @return the current cache to file flag - */ - public static boolean getCacheToFile() { - return cacheToFile; - } - - /** - * Get the correct implementation (based on cacheToFile) of - * StreamCache. - * - * @throws IOException if there is an IO error - * @return a new StreamCache for caching streams - */ - public static StreamCache createStreamCache() throws IOException { - if (cacheToFile) { - return new TempFileStreamCache(); - } else { - return new InMemoryStreamCache(); - } - } - - /** - * Get the current OutputStream. Do not store it - it may change - * from call to call. - * - * @throws IOException if there is an IO error - * @return an output stream for this cache - */ - public abstract OutputStream getOutputStream() throws IOException; - - /** - * Filter the cache with the supplied PDFFilter. - * - * @param filter the filter to apply - * @throws IOException if there is an IO error - */ - public abstract void applyFilter(PDFFilter filter) throws IOException; - - /** - * Outputs the cached bytes to the given stream. - * - * @param stream the stream to write to - * @throws IOException if there is an IO error - */ - public abstract void outputStreamData(OutputStream stream) throws IOException; - - /** - * Returns the current size of the stream. - * - * @throws IOException if there is an IO error - * @return the size of the cache - */ - public abstract int getSize() throws IOException; - - /** - * Closes the cache and frees resources. - * - * @throws IOException if there is an IO error - */ - public abstract void close() throws IOException; - - /** - * Clears and resets the cache. - * - * @throws IOException if there is an IO error - */ - public abstract void reset() throws IOException; -} - diff --git a/src/org/apache/fop/pdf/TempFileStreamCache.java b/src/org/apache/fop/pdf/TempFileStreamCache.java deleted file mode 100644 index 21a84e143..000000000 --- a/src/org/apache/fop/pdf/TempFileStreamCache.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import org.apache.fop.util.StreamUtilities; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.IOException; -import java.io.File; - -/** - * StreamCache implementation that uses temporary files rather than heap. - */ -public class TempFileStreamCache extends StreamCache { - - /** - * The current output stream. - */ - private BufferedOutputStream output; - - /** - * The temp file. - */ - private File tempFile; - - /** - * Creates a new TempFileStreamCache. - * - * @throws IOException if there is an IO error - */ - public TempFileStreamCache() throws IOException { - tempFile = File.createTempFile("org.apache.fop.pdf.StreamCache-", - ".temp"); - tempFile.deleteOnExit(); - } - - /** - * Get the current OutputStream. Do not store it - it may change - * from call to call. - * - * @throws IOException if there is an IO error - * @return the output stream for this cache - */ - public OutputStream getOutputStream() throws IOException { - if (output == null) { - output = new BufferedOutputStream( - new FileOutputStream(tempFile)); - } - return output; - } - - /** - * Filter the cache with the supplied PDFFilter. - * - * @param filter the filter to apply - * @throws IOException if there is an IO error - */ - public void applyFilter(PDFFilter filter) throws IOException { - if (output == null) { - return; - } - - output.close(); - output = null; - - // need a place to put results - File newTempFile = - File.createTempFile("org.apache.fop.pdf.StreamCache-", - ".temp"); - newTempFile.deleteOnExit(); - - // filter may not be buffered - BufferedInputStream input = - new BufferedInputStream(new FileInputStream(tempFile)); - BufferedOutputStream output = new BufferedOutputStream( - new FileOutputStream(newTempFile)); - filter.encode(input, output, (int) tempFile.length()); - input.close(); - output.close(); - tempFile.delete(); - tempFile = newTempFile; - } - - /** - * Outputs the cached bytes to the given stream. - * - * @param stream the output stream to write to - * @throws IOException if there is an IO error - */ - public void outputStreamData(OutputStream stream) throws IOException { - if (output == null) { - return; - } - - output.close(); - output = null; - - // don't need a buffer because streamCopy is buffered - FileInputStream input = new FileInputStream(tempFile); - StreamUtilities.streamCopy(input, output); - input.close(); - } - - /** - * Returns the current size of the stream. - * - * @throws IOException if there is an IO error - * @return the size of the cache - */ - public int getSize() throws IOException { - if (output != null) { - output.flush(); - } - return (int) tempFile.length(); - } - - /** - * Closes the cache and frees resources. - * - * @throws IOException if there is an IO error - */ - public void close() throws IOException { - if (output != null) { - output.close(); - output = null; - } - if (tempFile.exists()) { - tempFile.delete(); - } - } - - /** - * Clears and resets the cache. - * - * @throws IOException if there is an IO error - */ - public void reset() throws IOException { - if (output != null) { - output.close(); - output = null; - } - if (tempFile.exists()) { - tempFile.delete(); - } - } -} diff --git a/src/org/apache/fop/pdf/TransitionDictionary.java b/src/org/apache/fop/pdf/TransitionDictionary.java deleted file mode 100644 index 63b28003c..000000000 --- a/src/org/apache/fop/pdf/TransitionDictionary.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 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; - -import java.util.Map; -import java.util.Iterator; - -/** - * Transition Dictionary - * This class is used to build a transition dictionary to - * specify the transition between pages. - */ -public class TransitionDictionary extends PDFObject { - - private Map dictionaryValues; - - /** - * Create a Transition Dictionary - * - * @param values the dictionary values to output - */ - public TransitionDictionary(Map values) { - dictionaryValues = values; - } - - /** - * Get the dictionary. - * This returns the string containing the dictionary values. - * - * @return the string with the dictionary values - */ - public String getDictionary() { - StringBuffer sb = new StringBuffer(); - sb.append("/Type /Trans\n"); - for (Iterator iter = dictionaryValues.keySet().iterator(); iter.hasNext();) { - Object key = iter.next(); - sb.append(key + " " + dictionaryValues.get(key) + "\n"); - } - return sb.toString(); - } - - /** - * there is nothing to return for the toPDF method, as it should not be called - * - * @return an empty string - */ - public byte[] toPDF() { - return new byte[0]; - } -} - diff --git a/src/org/apache/fop/pdf/package.html b/src/org/apache/fop/pdf/package.html deleted file mode 100644 index 1fd09411d..000000000 --- a/src/org/apache/fop/pdf/package.html +++ /dev/null @@ -1,8 +0,0 @@ -<HTML> -<TITLE>org.apache.fop.pdf Package</TITLE> -<BODY> -<P>Classes for handling the low-level creation of PDF documents</P> -<P>These classes were developed for FOP, but could be used by other -applications wishing to produce PDF.</P> -</BODY> -</HTML>
\ No newline at end of file |