diff options
author | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
---|---|---|
committer | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
commit | e0edd215721150e6c04ac49706622d6189cb0b42 (patch) | |
tree | 6b59b872d9c0e93f99316ea2f421209b71a97755 /src/org/apache/fop/pdf | |
parent | eb57915dec9bcd907e495595efac60dbf3579ad8 (diff) | |
download | xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.tar.gz xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.zip |
Formatted code according to code standards.
Changed license to use short license.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194380 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/pdf')
47 files changed, 5068 insertions, 6731 deletions
diff --git a/src/org/apache/fop/pdf/ASCII85Filter.java b/src/org/apache/fop/pdf/ASCII85Filter.java index 7ef711c45..40706e968 100644 --- a/src/org/apache/fop/pdf/ASCII85Filter.java +++ b/src/org/apache/fop/pdf/ASCII85Filter.java @@ -1,159 +1,112 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.IOException; -public class ASCII85Filter extends PDFFilter -{ +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 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; - - - public String getName() - { - return "/ASCII85Decode"; + + + public String getName() { + return "/ASCII85Decode"; } - - public String getDecodeParms() - { - return null; + + public String getDecodeParms() { + return null; } - public byte[] encode(byte[] data) - { - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - 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 < data.length; i+=4) { - - long val = ((data[i] << 24) & 0xff000000L) // note: must have the L at the - + ((data[i+1] << 16) & 0xff0000L) // end, otherwise you get into - + ((data[i+2] << 8) & 0xff00L) // weird signed value problems - + (data[i+3] & 0xffL); // cause we're using a full 32 bits - byte[] conv = convertWord(val); - - buffer.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 + public byte[] encode(byte[] data) { + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + + 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 < data.length; i += 4) { + + long val = ((data[i] << 24) + & 0xff000000L) // note: must have the L at the + + ((data[i + 1] << 16) & 0xff0000L) // end, otherwise you get into + + ((data[i + 2] << 8) & 0xff00L) // weird signed value problems + + (data[i + 3] & 0xffL); // cause we're using a full 32 bits + byte[] conv = convertWord(val); + + buffer.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 < data.length) { - int n = data.length - i; - byte[] lastdata = new byte[4]; - for (int j=0; j<4; j++) { - if (j<n) { - lastdata[j] = data[i++]; - } - 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 - buffer.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 - buffer.write(ASCII85_EOD.getBytes(),0,ASCII85_EOD.getBytes().length); - - - byte[] result = buffer.toByteArray(); - - - // 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)); - } - */ - return result; - + // and write out the first n+1 bytes from the result + if (i < data.length) { + int n = data.length - i; + byte[] lastdata = new byte[4]; + for (int j = 0; j < 4; j++) { + if (j < n) { + lastdata[j] = data[i++]; + } 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 + buffer.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 + buffer.write(ASCII85_EOD.getBytes(), 0, + ASCII85_EOD.getBytes().length); + + + byte[] result = buffer.toByteArray(); + + + // 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)); + * } + */ + return result; + } - + /** * 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 @@ -161,52 +114,48 @@ public class ASCII85Filter extends PDFFilter * * @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) + * 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)}; - 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; - - - } + 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) + }; + 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 index e1a103127..775a7fcb4 100644 --- a/src/org/apache/fop/pdf/ASCIIHexFilter.java +++ b/src/org/apache/fop/pdf/ASCIIHexFilter.java @@ -1,86 +1,39 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.IOException; -public class ASCIIHexFilter extends PDFFilter -{ +public class ASCIIHexFilter extends PDFFilter { private static final String ASCIIHEX_EOD = ">"; - - public String getName() - { - return "/ASCIIHexDecode"; + + public String getName() { + return "/ASCIIHexDecode"; } - - public String getDecodeParms() - { - return null; + + public String getDecodeParms() { + return null; } - public byte[] encode(byte[] data) - { - - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < data.length; i++) { - int val = (int) (data[i] & 0xFF); - if (val < 16) buffer.append("0"); - buffer.append(Integer.toHexString(val)); - } - buffer.append(ASCIIHEX_EOD); - - return buffer.toString().getBytes(); - + public byte[] encode(byte[] data) { + + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < data.length; i++) { + int val = (int)(data[i] & 0xFF); + if (val < 16) + buffer.append("0"); + buffer.append(Integer.toHexString(val)); + } + buffer.append(ASCIIHEX_EOD); + + return buffer.toString().getBytes(); + } - + } diff --git a/src/org/apache/fop/pdf/FlateFilter.java b/src/org/apache/fop/pdf/FlateFilter.java index d3994aecf..b10aa78f4 100644 --- a/src/org/apache/fop/pdf/FlateFilter.java +++ b/src/org/apache/fop/pdf/FlateFilter.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; @@ -59,143 +16,121 @@ import java.util.zip.DeflaterOutputStream; * 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. + * file. */ public class FlateFilter extends PDFFilter { public static final int PREDICTION_NONE = 1; public static final int PREDICTION_TIFF2 = 2; public static final int PREDICTION_PNG_NONE = 10; - public static final int PREDICTION_PNG_SUB = 11; - public static final int PREDICTION_PNG_UP = 12; - public static final int PREDICTION_PNG_AVG = 13; - public static final int PREDICTION_PNG_PAETH= 14; - public static final int PREDICTION_PNG_OPT = 15; - - + public static final int PREDICTION_PNG_SUB = 11; + public static final int PREDICTION_PNG_UP = 12; + public static final int PREDICTION_PNG_AVG = 13; + public static final int PREDICTION_PNG_PAETH = 14; + public static final int PREDICTION_PNG_OPT = 15; + + private int _predictor = PREDICTION_NONE; private int _colors; private int _bitsPerComponent; private int _columns; - - public String getName() - { - return "/FlateDecode"; + + public String getName() { + return "/FlateDecode"; } - - 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; + + 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. + * should be retrieved after calling this method. */ - public byte[] encode(byte[] data) - { - ByteArrayOutputStream outArrayStream = new ByteArrayOutputStream(); - _predictor = PREDICTION_NONE; - try { - DeflaterOutputStream compressedStream = - new DeflaterOutputStream(outArrayStream); - compressedStream.write(data, 0, data.length); - compressedStream.flush(); - compressedStream.close(); - } - catch (IOException e) { - org.apache.fop.messaging.MessageHandler.error("Fatal error: "+ - e.getMessage()); - e.printStackTrace(); - } - - return outArrayStream.toByteArray(); + public byte[] encode(byte[] data) { + ByteArrayOutputStream outArrayStream = new ByteArrayOutputStream(); + _predictor = PREDICTION_NONE; + try { + DeflaterOutputStream compressedStream = + new DeflaterOutputStream(outArrayStream); + compressedStream.write(data, 0, data.length); + compressedStream.flush(); + compressedStream.close(); + } catch (IOException e) { + org.apache.fop.messaging.MessageHandler.error("Fatal error: " + + e.getMessage()); + e.printStackTrace(); + } + + return outArrayStream.toByteArray(); } - - public void setPredictor(int predictor) - throws PDFFilterException - { - _predictor = predictor; - + + public void setPredictor(int predictor) throws PDFFilterException { + _predictor = predictor; + } - public int getPredictor() - { - return _predictor; + public int getPredictor() { + return _predictor; } - - - public void setColors(int colors) - throws PDFFilterException - { - if (_predictor != PREDICTION_NONE) { - _colors = colors; - } - else { - throw new PDFFilterException - ("Prediction must not be PREDICTION_NONE in order to set Colors"); - } + + + public void setColors(int colors) throws PDFFilterException { + if (_predictor != PREDICTION_NONE) { + _colors = colors; + } else { + throw new PDFFilterException("Prediction must not be PREDICTION_NONE in order to set Colors"); + } } - public int getColors() - { - return _colors; + public int getColors() { + return _colors; } - - - 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"); - } + + + 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"); + } } - public int getBitsPerComponent() - { - return _bitsPerComponent; + public int getBitsPerComponent() { + return _bitsPerComponent; } - - - public void setColumns(int columns) - throws PDFFilterException - { - if (_predictor != PREDICTION_NONE) { - _columns = columns; - } - else { - throw new PDFFilterException - ("Prediction must not be PREDICTION_NONE in order to set Columns"); - } + + + public void setColumns(int columns) throws PDFFilterException { + if (_predictor != PREDICTION_NONE) { + _columns = columns; + } else { + throw new PDFFilterException("Prediction must not be PREDICTION_NONE in order to set Columns"); + } } - public int getColumns() - { - return _columns; + public int getColumns() { + return _columns; } - + } diff --git a/src/org/apache/fop/pdf/PDFAction.java b/src/org/apache/fop/pdf/PDFAction.java index cd6e83bde..2749a221f 100644 --- a/src/org/apache/fop/pdf/PDFAction.java +++ b/src/org/apache/fop/pdf/PDFAction.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -56,27 +12,25 @@ package org.apache.fop.pdf; */ 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 + * @param number the object's number */ public PDFAction(int number) { - /* generic creation of object */ - super(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() - { - } + public PDFAction() {} /** * represent the action to call @@ -87,7 +41,7 @@ public abstract class PDFAction extends PDFObject { * @return the action to place next to /A within a Link */ abstract public String getAction(); - + /** * represent the object in PDF @@ -98,4 +52,4 @@ public abstract class PDFAction extends PDFObject { */ abstract public byte[] toPDF(); - } +} diff --git a/src/org/apache/fop/pdf/PDFAnnotList.java b/src/org/apache/fop/pdf/PDFAnnotList.java index 058fd0cc6..1a23d85d5 100644 --- a/src/org/apache/fop/pdf/PDFAnnotList.java +++ b/src/org/apache/fop/pdf/PDFAnnotList.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -62,10 +18,14 @@ import java.util.Vector; */ public class PDFAnnotList extends PDFObject { - /** the /Annot objects */ + /** + * the /Annot objects + */ protected Vector links = new Vector(); - /** the number of /Annot objects */ + /** + * the number of /Annot objects + */ protected int count = 0; /** @@ -75,8 +35,8 @@ public class PDFAnnotList extends PDFObject { */ public PDFAnnotList(int number) { - /* generic creation of object */ - super(number); + /* generic creation of object */ + super(number); } /** @@ -85,8 +45,8 @@ public class PDFAnnotList extends PDFObject { * @param link the PDFLink to add. */ public void addLink(PDFLink link) { - this.links.addElement(link); - this.count++; + this.links.addElement(link); + this.count++; } /** @@ -95,7 +55,7 @@ public class PDFAnnotList extends PDFObject { * @return the number of links */ public int getCount() { - return this.count; + return this.count; } /** @@ -104,22 +64,22 @@ public class PDFAnnotList extends PDFObject { * @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(); + 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 - */ + /* + * 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 index da9a19381..243c19f09 100644 --- a/src/org/apache/fop/pdf/PDFArray.java +++ b/src/org/apache/fop/pdf/PDFArray.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -55,36 +12,37 @@ package org.apache.fop.pdf; */ public class PDFArray extends PDFObject { - 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; - } + 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(); + } - /** - * 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 index 65588c6a6..5323996bb 100644 --- a/src/org/apache/fop/pdf/PDFCIDFont.java +++ b/src/org/apache/fop/pdf/PDFCIDFont.java @@ -1,216 +1,200 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // based on work by Takayuki Takeuchi + /** * class representing a "character identifier" font (p 210 and onwards). */ public class PDFCIDFont extends PDFObject { - public static final byte CID_TYPE0 = 0; - public static final byte CID_TYPE2 = 1; - protected static final String[] TYPE_NAMES = {"CIDFontType0", "CIDFontType2"}; - - protected String basefont; - - protected String cidtype; - protected Integer dw; - protected PDFWArray w; - protected int[] dw2; - protected PDFWArray w2; - protected PDFCIDSystemInfo systemInfo; - protected PDFCIDFontDescriptor descriptor; - protected PDFCMap cmap; - /** - * /CIDToGIDMap (only for CIDFontType2, see p 212) - * can be either "Identity" (default) or a PDFStream - */ - protected PDFStream cidMap; - - // compatibility with Takayuki Takeuchi - /** - * create the /Font object - */ - public PDFCIDFont(int number, String basefont, byte cidtype, - int dw, int[] w, - String registry, String ordering, int supplement, - PDFCIDFontDescriptor descriptor) { - - super(number); - - this.basefont = basefont; - this.cidtype = TYPE_NAMES[(int)cidtype]; - this.dw = new Integer(dw); - this.w = new PDFWArray(); - this.w.addEntry(0, w); - this.dw2 = null; - this.w2 = null; - this.systemInfo = new PDFCIDSystemInfo(registry, ordering, supplement); - this.descriptor = descriptor; - this.cidMap = null; - this.cmap = null; - } - - /** - * create the /Font object - */ - public PDFCIDFont(int number, String basefont, byte cidtype, - int dw, PDFWArray w, PDFCIDSystemInfo systemInfo, - PDFCIDFontDescriptor descriptor) { - - super(number); - - this.basefont = basefont; - this.cidtype = TYPE_NAMES[(int)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 */ - public void setDW(int dw) { - this.dw = new Integer(dw); - } - - /** set the /W array */ - public void setW(PDFWArray w) { - this.w = w; - } - - /** set the (two elements) /DW2 array */ - public void setDW2(int[] dw2) { - this.dw2 = dw2; - } - - /** set the two elements of the /DW2 array */ - public void setDW2(int posY, int displacementY) { - this.dw2 = new int[] {posY, displacementY}; - } - - /** - * Set the CMap used as /ToUnicode cmap - */ + public static final byte CID_TYPE0 = 0; + public static final byte CID_TYPE2 = 1; + protected static final String[] TYPE_NAMES = { + "CIDFontType0", "CIDFontType2" + }; + + protected String basefont; + + protected String cidtype; + protected Integer dw; + protected PDFWArray w; + protected int[] dw2; + protected PDFWArray w2; + protected PDFCIDSystemInfo systemInfo; + protected PDFCIDFontDescriptor descriptor; + protected PDFCMap cmap; + + /** + * /CIDToGIDMap (only for CIDFontType2, see p 212) + * can be either "Identity" (default) or a PDFStream + */ + protected PDFStream cidMap; + + // compatibility with Takayuki Takeuchi + + /** + * create the /Font object + */ + public PDFCIDFont(int number, String basefont, byte cidtype, int dw, + int[] w, String registry, String ordering, + int supplement, PDFCIDFontDescriptor descriptor) { + + super(number); + + this.basefont = basefont; + this.cidtype = TYPE_NAMES[(int)cidtype]; + this.dw = new Integer(dw); + this.w = new PDFWArray(); + this.w.addEntry(0, w); + this.dw2 = null; + this.w2 = null; + this.systemInfo = new PDFCIDSystemInfo(registry, ordering, + supplement); + this.descriptor = descriptor; + this.cidMap = null; + this.cmap = null; + } + + /** + * create the /Font object + */ + public PDFCIDFont(int number, String basefont, byte cidtype, int dw, + PDFWArray w, PDFCIDSystemInfo systemInfo, + PDFCIDFontDescriptor descriptor) { + + super(number); + + this.basefont = basefont; + this.cidtype = TYPE_NAMES[(int)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 + */ + public void setDW(int dw) { + this.dw = new Integer(dw); + } + + /** + * set the /W array + */ + public void setW(PDFWArray w) { + this.w = w; + } + + /** + * set the (two elements) /DW2 array + */ + public void setDW2(int[] dw2) { + this.dw2 = dw2; + } + + /** + * set the two elements of the /DW2 array + */ + public void setDW2(int posY, int displacementY) { + this.dw2 = new int[] { + posY, displacementY + }; + } + + /** + * Set the CMap used as /ToUnicode cmap + */ public void setCMAP(PDFCMap cmap) { this.cmap = cmap; } - - /** set the /W2 array */ - public void setW2(PDFWArray w2) { - this.w2 = w2; - } - - /** set the /CIDToGIDMap (to be used only for CIDFontType2) */ - 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 - } - - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - 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(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(); - } + + /** + * set the /W2 array + */ + public void setW2(PDFWArray w2) { + this.w2 = w2; + } + + /** + * set the /CIDToGIDMap (to be used only for CIDFontType2) + */ + 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 + } + + /** + * produce the PDF representation for the object + * + * @return the PDF + */ + public byte[] toPDF() { + return toPDFString().getBytes(); + } + + 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(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 index eabc818e6..a1a6dca6a 100644 --- a/src/org/apache/fop/pdf/PDFCIDFontDescriptor.java +++ b/src/org/apache/fop/pdf/PDFCIDFontDescriptor.java @@ -1,56 +1,14 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // based on work by Takayuki Takeuchi + /** * class representing a font descriptor for CID fonts. * @@ -73,31 +31,30 @@ public class PDFCIDFontDescriptor extends PDFFontDescriptor { * @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) { + 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); + super(number, basefont, fontBBox[3], fontBBox[1], capHeight, flags, + new PDFRectangle(fontBBox), italicAngle, stemV); - this.lang = lang; + this.lang = lang; } public void setCIDSet(PDFStream cidSet) { - this.cidSet = cidSet; + this.cidSet = cidSet; } 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 /"); this.cidSet.referencePDF(); - } + if (lang != null) { + p.append("\n/Lang /"); + p.append(lang); + } + if (cidSet != null) { + p.append("\n/CIDSet /"); + this.cidSet.referencePDF(); + } } + } diff --git a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java b/src/org/apache/fop/pdf/PDFCIDSystemInfo.java index c8b87bde4..7104fd9d7 100644 --- a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java +++ b/src/org/apache/fop/pdf/PDFCIDSystemInfo.java @@ -1,92 +1,55 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + 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 static final StringBuffer p = new StringBuffer(); - protected String registry; - protected String ordering; - protected int supplement; - - 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(); - } + private static final StringBuffer p = new StringBuffer(); + protected String registry; + protected String ordering; + protected int supplement; + + 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(); + } + + public String toPDFString() { + 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(); + } - public String toPDFString() { - 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 index de0292fb0..4e339f162 100644 --- a/src/org/apache/fop/pdf/PDFCMap.java +++ b/src/org/apache/fop/pdf/PDFCMap.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -58,176 +15,206 @@ package org.apache.fop.pdf; * on pages 215, 216 and 217 . */ public class PDFCMap extends PDFStream { - /** Chinese (simplified) */ - public static final String GB_EUC_H= "GB-EUC-H"; - public static final String GB_EUC_V= "GB_EUC_V"; - public static final String GBpc_EUC_H= "GBpc-EUC-H"; - public static final String GBpc_EUC_V= "GBpc-EUC-V"; - public static final String GBK_EUC_H= "GBK-EUC-H"; - public static final String GBK_EUC_V= "GBK-EUC-V"; - public static final String UniGB_UCS2_H= "UniGB-UCS2-H"; - public static final String UniGB_UCS2_V= "UniGB-UCS2-V"; - /** Chinese (traditional) */ - public static final String B5pc_H= "B5pc-H"; - public static final String B5pc_V= "B5pc-V"; - public static final String ETen_B5_H= "ETen-B5-H"; - public static final String ETen_B5_V= "ETen-B5-V"; - public static final String ETenms_B5_H= "ETenms-B5-H"; - public static final String ETenms_B5_V= "ETenms-B5-V"; - public static final String CNS_EUC_H= "CNS-EUC-H"; - public static final String CNS_EUC_V= "CNS-EUC-V"; - public static final String UniCNS_UCS2_H= "UniCNS-UCS2-H"; - public static final String UniCNS_UCS2_V= "UniCNS-UCS2-V"; - /** Japanese */ - public static final String _83pv_RKSJ_H= "83pv-RKSJ-H"; // no V version - public static final String _90ms_RKSJ_H= "90ms-RKSJ-H"; - public static final String _90ms_RKSJ_V= "90ms-RKSJ-V"; - public static final String _90msp_RKSJ_H= "90msp-RKSJ-H"; - public static final String _90msp_RKSJ_V= "90msp-RKSJ-V"; - public static final String _90pv_RKSJ_H= "90pv-RKSJ-H"; // no V version - public static final String Add_RKSJ_H= "Add-RKSJ-H"; - public static final String Add_RKSJ_V= "Add-RKSJ-V"; - public static final String EUC_H= "EUC-H"; - public static final String EUC_V= "EUC-V"; - public static final String Ext_RKSJ_H= "Ext-RKSJ-H"; - public static final String Ext_RKSJ_V= "Ext-RKSJ-V"; - public static final String H= "H"; - public static final String V= "V"; - public static final String UniJIS_UCS2_H= "UniJIS-UCS2-H"; - public static final String UniJIS_UCS2_V= "UniJIS-UCS2-V"; - public static final String UniJIS_UCS2_HW_H= "UniJIS-UCS2-HW-H"; - public static final String UniJIS_UCS2_HW_V= "UniJIS-UCS2-HW-V"; - /** Korean */ - public static final String KSC_EUC_H= "KSC-EUC-H"; - public static final String KSC_EUC_V= "KSC-EUC-V"; - public static final String KSCms_UHC_H= "KSCms-UHC-H"; - public static final String KSCms_UHC_V= "KSCms-UHC-V"; - public static final String KSCms_UHC_HW_H= "KSCms-UHC-HW-H"; - public static final String KSCms_UHC_HW_V= "KSCms-UHC-HW-V"; - public static final String KSCpc_EUC_H= "KSCpc-EUC-H"; // no V version - public static final String UniKSC_UCS2_H= "UniKSC-UCS2-H"; - public static final String UniKSC_UCS2_V= "UniKSC-UCS2-V"; - /** Generic */ - public static final String Identity_H= "Identity-H"; - public static final String Identity_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 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; - } + + /** + * Chinese (simplified) + */ + public static final String GB_EUC_H = "GB-EUC-H"; + public static final String GB_EUC_V = "GB_EUC_V"; + public static final String GBpc_EUC_H = "GBpc-EUC-H"; + public static final String GBpc_EUC_V = "GBpc-EUC-V"; + public static final String GBK_EUC_H = "GBK-EUC-H"; + public static final String GBK_EUC_V = "GBK-EUC-V"; + public static final String UniGB_UCS2_H = "UniGB-UCS2-H"; + public static final String UniGB_UCS2_V = "UniGB-UCS2-V"; + + /** + * Chinese (traditional) + */ + public static final String B5pc_H = "B5pc-H"; + public static final String B5pc_V = "B5pc-V"; + public static final String ETen_B5_H = "ETen-B5-H"; + public static final String ETen_B5_V = "ETen-B5-V"; + public static final String ETenms_B5_H = "ETenms-B5-H"; + public static final String ETenms_B5_V = "ETenms-B5-V"; + public static final String CNS_EUC_H = "CNS-EUC-H"; + public static final String CNS_EUC_V = "CNS-EUC-V"; + public static final String UniCNS_UCS2_H = "UniCNS-UCS2-H"; + public static final String UniCNS_UCS2_V = "UniCNS-UCS2-V"; + + /** + * Japanese + */ + public static final String _83pv_RKSJ_H = "83pv-RKSJ-H"; // no V version + public static final String _90ms_RKSJ_H = "90ms-RKSJ-H"; + public static final String _90ms_RKSJ_V = "90ms-RKSJ-V"; + public static final String _90msp_RKSJ_H = "90msp-RKSJ-H"; + public static final String _90msp_RKSJ_V = "90msp-RKSJ-V"; + public static final String _90pv_RKSJ_H = "90pv-RKSJ-H"; // no V version + public static final String Add_RKSJ_H = "Add-RKSJ-H"; + public static final String Add_RKSJ_V = "Add-RKSJ-V"; + public static final String EUC_H = "EUC-H"; + public static final String EUC_V = "EUC-V"; + public static final String Ext_RKSJ_H = "Ext-RKSJ-H"; + public static final String Ext_RKSJ_V = "Ext-RKSJ-V"; + public static final String H = "H"; + public static final String V = "V"; + public static final String UniJIS_UCS2_H = "UniJIS-UCS2-H"; + public static final String UniJIS_UCS2_V = "UniJIS-UCS2-V"; + public static final String UniJIS_UCS2_HW_H = "UniJIS-UCS2-HW-H"; + public static final String UniJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V"; + + /** + * Korean + */ + public static final String KSC_EUC_H = "KSC-EUC-H"; + public static final String KSC_EUC_V = "KSC-EUC-V"; + public static final String KSCms_UHC_H = "KSCms-UHC-H"; + public static final String KSCms_UHC_V = "KSCms-UHC-V"; + public static final String KSCms_UHC_HW_H = "KSCms-UHC-HW-H"; + public static final String KSCms_UHC_HW_V = "KSCms-UHC-HW-V"; + public static final String KSCpc_EUC_H = "KSCpc-EUC-H"; // no V version + public static final String UniKSC_UCS2_H = "UniKSC-UCS2-H"; + public static final String UniKSC_UCS2_V = "UniKSC-UCS2-V"; + + /** + * Generic + */ + public static final String Identity_H = "Identity-H"; + public static final String Identity_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 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; + } public void addContents() { - StringBuffer p=new StringBuffer(); + StringBuffer p = new StringBuffer(); fillInPDF(p); add(p.toString()); } - - /** - * set the base CMap - * - * @param base the name of the base CMap (see Table 7.20) - */ - 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; - } - - 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()); - } - } - */ - } + + /** + * set the base CMap + * + * @param base the name of the base CMap (see Table 7.20) + */ + 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; + } + + 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 index 2ba96f277..33c493841 100644 --- a/src/org/apache/fop/pdf/PDFCharProcs.java +++ b/src/org/apache/fop/pdf/PDFCharProcs.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import java.util.Hashtable; @@ -63,26 +20,31 @@ import java.util.Hashtable; */ public class PDFCharProcs extends PDFObject { - /** the (character name, drawing stream) pairs for a Type3 font */ - protected Hashtable keys; - - public PDFCharProcs() { - keys = new Hashtable(); - } - - /** - * 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); - } + /** + * the (character name, drawing stream) pairs for a Type3 font + */ + protected Hashtable keys; + + public PDFCharProcs() { + keys = new Hashtable(); + } + + /** + * 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 + */ + public byte[] toPDF() { + // TODO: implement this org.apache.fop.pdf.PDFObject abstract method + return new byte[0]; + } - /** not done yet */ - 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 index f98dcc267..45279a852 100644 --- a/src/org/apache/fop/pdf/PDFColor.java +++ b/src/org/apache/fop/pdf/PDFColor.java @@ -1,8 +1,10 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -10,343 +12,310 @@ import java.util.Vector; import java.io.IOException; import java.io.PrintWriter; -//FOP +// FOP import org.apache.fop.datatypes.ColorType; import org.apache.fop.datatypes.ColorSpace; public class PDFColor extends PDFPathPaint { - protected static double blackFactor = 2.0;//could be 3.0 as well. - protected double red = -1.0; - protected double green= -1.0; - protected double blue = -1.0; - - protected double cyan = -1.0; - protected double magenta= -1.0; - protected double yellow = -1.0; - protected double black = -1.0; - - public PDFColor(org.apache.fop.datatypes.ColorType theColor) - { - this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - //super(theNumber) - this.red = (double)theColor.red(); - this.green = (double)theColor.green(); - this.blue = (double)theColor.blue(); - - } - - public PDFColor(double theRed, double theGreen, double theBlue) { - //super(theNumber); - this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); - - this.red = theRed; - this.green = theGreen; - this.blue = theBlue; - } - - // components from 0 to 255 - public PDFColor(int theRed, int theGreen, int theBlue) { - this(((double) theRed) / 255d, ((double) theGreen) / 255d, ((double) theBlue) / 255d ); - - } - - public PDFColor(double theCyan, double theMagenta, double theYellow, double theBlack) { - //super(theNumber);//? - - this.colorSpace = new ColorSpace(ColorSpace.DEVICE_CMYK); - - this.cyan = theCyan; - this.magenta = theMagenta; - this.yellow = theYellow; - this.black = theBlack; - } - - - public Vector getVector() - {//return a vector representation of the color - //in the appropriate colorspace. - Vector theColorVector= new Vector(); - if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_RGB) - {//RGB - theColorVector.addElement(new Double(this.red)); - theColorVector.addElement(new Double(this.green)); - theColorVector.addElement(new Double(this.blue)); - } - else if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_CMYK) - {//CMYK - theColorVector.addElement(new Double(this.cyan)); - theColorVector.addElement(new Double(this.magenta)); - theColorVector.addElement(new Double(this.yellow)); - theColorVector.addElement(new Double(this.black)); - } - else - {//GRAY - theColorVector.addElement(new Double(this.black)); - } - return(theColorVector); - } - - public double red() - { - return(this.red); - } - public double green() - { - return(this.green); - } - public double blue() - { - return(this.blue); - } - public int red255() - { - return (int) (this.red * 255d); - } - public int green255() - { - return (int) (this.green * 255d); - } - public int blue255() - { - return (int) (this.blue * 255d); - } - public double cyan() - { - return(this.cyan); - } - public double magenta() - { - return(this.magenta); - } - public double yellow() - { - return(this.yellow); - } - public double black() - { - return(this.black); - } - - public void setColorSpace(int theColorSpace) - { - int theOldColorSpace = this.colorSpace.getColorSpace(); - if(theOldColorSpace!=theColorSpace) - { - if (theOldColorSpace==ColorSpace.DEVICE_RGB) - { - if(theColorSpace==ColorSpace.DEVICE_CMYK) - { - this.convertRGBtoCMYK(); - } - else //convert to Gray? - { - this.convertRGBtoGRAY(); - } - - } else if(theOldColorSpace==ColorSpace.DEVICE_CMYK) - { - if(theColorSpace == ColorSpace.DEVICE_RGB) - { - this.convertCMYKtoRGB(); - } - else //convert to Gray? - { - this.convertCMYKtoGRAY(); - } - } else //used to be Gray - { - if(theColorSpace == ColorSpace.DEVICE_RGB) - { - this.convertGRAYtoRGB(); - } - else //convert to CMYK? - { - this.convertGRAYtoCMYK(); - } - } - this.colorSpace.setColorSpace(theColorSpace); - } - } - - public String getColorSpaceOut(boolean fillNotStroke) - { - StringBuffer p = new StringBuffer(""); - - double tempDouble; - - if(this.colorSpace.getColorSpace()==ColorSpace.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"); - } - } - }//end of output RGB - else if (this.colorSpace.getColorSpace() == ColorSpace.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 - { //fill - p.append(PDFNumber.doubleOut(this.cyan) + " " - + PDFNumber.doubleOut(this.magenta) + " " - + PDFNumber.doubleOut(this.yellow) + " " - + PDFNumber.doubleOut(this.black) + " K \n"); - } - - }//end of if CMYK - 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()); - } - - - - - 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 / this.blackFactor) + this.red; - this.green = (this.black / this.blackFactor) + this.green; - this.blue = (this.black / this.blackFactor) + this.blue; - - } - - 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; - */ - } - - protected void convertGRAYtoRGB() - { - this.red = 1.0 - this.black; - this.green= 1.0 - this.black; - this.blue = 1.0 - this.black; - } - - protected void convertGRAYtoCMYK() - { - this.cyan = this.black; - this.magenta= this.black; - this.yellow = this.black; - //this.black=0.0;//? - } - - 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 / this.blackFactor); - - } - - 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 / this.blackFactor); - - } - - byte[] toPDF() - { - return (new byte[0]); - - } //end of toPDF - - 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; + protected static double blackFactor = 2.0; // could be 3.0 as well. + protected double red = -1.0; + protected double green = -1.0; + protected double blue = -1.0; + + protected double cyan = -1.0; + protected double magenta = -1.0; + protected double yellow = -1.0; + protected double black = -1.0; + + public PDFColor(org.apache.fop.datatypes.ColorType theColor) { + this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); + // super(theNumber) + this.red = (double)theColor.red(); + this.green = (double)theColor.green(); + this.blue = (double)theColor.blue(); + + } + + public PDFColor(double theRed, double theGreen, double theBlue) { + // super(theNumber); + this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); + + this.red = theRed; + this.green = theGreen; + this.blue = theBlue; + } + + // components from 0 to 255 + public PDFColor(int theRed, int theGreen, int theBlue) { + this(((double)theRed) / 255d, ((double)theGreen) / 255d, + ((double)theBlue) / 255d); + + } + + public PDFColor(double theCyan, double theMagenta, double theYellow, + double theBlack) { + // super(theNumber);//? + + this.colorSpace = new ColorSpace(ColorSpace.DEVICE_CMYK); + + this.cyan = theCyan; + this.magenta = theMagenta; + this.yellow = theYellow; + this.black = theBlack; + } + + + public Vector getVector() { // return a vector representation of the color + // in the appropriate colorspace. + Vector theColorVector = new Vector(); + if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_RGB) { // RGB + theColorVector.addElement(new Double(this.red)); + theColorVector.addElement(new Double(this.green)); + theColorVector.addElement(new Double(this.blue)); + } else if (this.colorSpace.getColorSpace() + == ColorSpace.DEVICE_CMYK) { // CMYK + theColorVector.addElement(new Double(this.cyan)); + theColorVector.addElement(new Double(this.magenta)); + theColorVector.addElement(new Double(this.yellow)); + theColorVector.addElement(new Double(this.black)); + } else { // GRAY + theColorVector.addElement(new Double(this.black)); + } + return (theColorVector); + } + + public double red() { + return (this.red); + } + + public double green() { + return (this.green); + } + + public double blue() { + return (this.blue); + } + + public int red255() { + return (int)(this.red * 255d); + } + + public int green255() { + return (int)(this.green * 255d); + } + + public int blue255() { + return (int)(this.blue * 255d); + } + + public double cyan() { + return (this.cyan); + } + + public double magenta() { + return (this.magenta); + } + + public double yellow() { + return (this.yellow); + } + + public double black() { + return (this.black); + } + + public void setColorSpace(int theColorSpace) { + int theOldColorSpace = this.colorSpace.getColorSpace(); + if (theOldColorSpace != theColorSpace) { + if (theOldColorSpace == ColorSpace.DEVICE_RGB) { + if (theColorSpace == ColorSpace.DEVICE_CMYK) { + this.convertRGBtoCMYK(); + } else // convert to Gray? + { + this.convertRGBtoGRAY(); + } + + } else if (theOldColorSpace == ColorSpace.DEVICE_CMYK) { + if (theColorSpace == ColorSpace.DEVICE_RGB) { + this.convertCMYKtoRGB(); + } else // convert to Gray? + { + this.convertCMYKtoGRAY(); + } + } else // used to be Gray + { + if (theColorSpace == ColorSpace.DEVICE_RGB) { + this.convertGRAYtoRGB(); + } else // convert to CMYK? + { + this.convertGRAYtoCMYK(); + } + } + this.colorSpace.setColorSpace(theColorSpace); + } + } + + public String getColorSpaceOut(boolean fillNotStroke) { + StringBuffer p = new StringBuffer(""); + + double tempDouble; + + if (this.colorSpace.getColorSpace() + == ColorSpace.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"); + } + } + } // end of output RGB + else if (this.colorSpace.getColorSpace() + == ColorSpace.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 { // fill + p.append(PDFNumber.doubleOut(this.cyan) + " " + + PDFNumber.doubleOut(this.magenta) + " " + + PDFNumber.doubleOut(this.yellow) + " " + + PDFNumber.doubleOut(this.black) + " K \n"); + } + + } // end of if CMYK + 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()); + } + + + + + 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 / this.blackFactor) + this.red; + this.green = (this.black / this.blackFactor) + this.green; + this.blue = (this.black / this.blackFactor) + this.blue; + + } + + 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; + */ + } + + protected void convertGRAYtoRGB() { + this.red = 1.0 - this.black; + this.green = 1.0 - this.black; + this.blue = 1.0 - this.black; + } + + protected void convertGRAYtoCMYK() { + this.cyan = this.black; + this.magenta = this.black; + this.yellow = this.black; + // this.black=0.0;//? } - + + 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 / this.blackFactor); + + } + + 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 / this.blackFactor); + + } + + byte[] toPDF() { + return (new byte[0]); + + } // end of toPDF + + 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/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 542107a6a..e26c59982 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ /* image support modified from work of BoBoGi */ @@ -61,7 +17,7 @@ import org.apache.fop.image.FopImage; import org.apache.fop.layout.LinkSet; import org.apache.fop.datatypes.ColorSpace; -import org.apache.fop.render.pdf.CIDFont; +import org.apache.fop.render.pdf.CIDFont; import org.apache.fop.datatypes.IDReferences; import org.apache.fop.layout.Page; @@ -90,54 +46,86 @@ import java.awt.Rectangle; */ public class PDFDocument { - /** the version of PDF supported */ + /** + * the version of PDF supported + */ protected static final String pdfVersion = "1.3"; - /** the current character position */ + /** + * the current character position + */ protected int position = 0; - /** the character position of each object */ + /** + * the character position of each object + */ protected Vector location = new Vector(); - /** the counter for object numbering */ + /** + * the counter for object numbering + */ protected int objectcount = 0; - /** the objects themselves */ + /** + * the objects themselves + */ protected Vector objects = new Vector(); - /** character position of xref table */ + /** + * character position of xref table + */ protected int xref; - /** the /Root object */ + /** + * the /Root object + */ protected PDFRoot root; - /** the /Info object */ + /** + * the /Info object + */ protected PDFInfo info; - /** the /Resources object */ + /** + * the /Resources object + */ protected PDFResources resources; - /** the documents idReferences */ + /** + * the documents idReferences + */ protected IDReferences idReferences; - /** the colorspace (0=RGB, 1=CMYK) **/ - //protected int colorspace = 0; + /** + * the colorspace (0=RGB, 1=CMYK) + */ + // protected int colorspace = 0; protected ColorSpace colorspace = new ColorSpace(ColorSpace.DEVICE_RGB); - /** the counter for Pattern name numbering (e.g. 'Pattern1')*/ + /** + * the counter for Pattern name numbering (e.g. 'Pattern1') + */ protected int patternCount = 0; - /** the counter for Shading name numbering */ + /** + * the counter for Shading name numbering + */ protected int shadingCount = 0; - /** the counter for XObject numbering */ + /** + * the counter for XObject numbering + */ protected int xObjectCount = 0; - /** the XObjects */ + /** + * the XObjects + */ protected Vector xObjects = new Vector(); - /** the XObjects Map. - Should be modified (works only for image subtype) */ + /** + * the XObjects Map. + * Should be modified (works only for image subtype) + */ protected Hashtable xObjectsMap = new Hashtable(); /** @@ -167,13 +155,17 @@ public class PDFDocument { */ protected PDFRoot makeRoot() { - /* create a PDFRoot with the next object number and add to - list of objects */ + /* + * create a PDFRoot with the next object number and add to + * list of objects + */ PDFRoot pdfRoot = new PDFRoot(++this.objectcount); this.objects.addElement(pdfRoot); - /* create a new /Pages object to be root of Pages hierarchy - and add to list of objects */ + /* + * create a new /Pages object to be root of Pages hierarchy + * and add to list of objects + */ PDFPages rootPages = new PDFPages(++this.objectcount); this.objects.addElement(rootPages); @@ -190,12 +182,14 @@ public class PDFDocument { */ protected PDFInfo makeInfo() { - /* create a PDFInfo with the next object number and add to - list of objects */ + /* + * 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(org.apache.fop.apps.Version.getVersion()); - this.objects.addElement(pdfInfo); + // set the default producer + pdfInfo.setProducer(org.apache.fop.apps.Version.getVersion()); + this.objects.addElement(pdfInfo); return pdfInfo; } @@ -206,8 +200,10 @@ public class PDFDocument { */ private PDFResources makeResources() { - /* create a PDFResources with the next object number and add - to list of objects */ + /* + * create a PDFResources with the next object number and add + * to list of objects + */ PDFResources pdfResources = new PDFResources(++this.objectcount); this.objects.addElement(pdfResources); return pdfResources; @@ -215,7 +211,7 @@ public class PDFDocument { /** * Make a Type 0 sampled function - * + * * @param theDomain Vector objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. @@ -226,39 +222,39 @@ public class PDFDocument { * 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 Vector 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 Vector 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. @@ -266,27 +262,28 @@ public class PDFDocument { * @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 makeFunction(int theFunctionType, - Vector theDomain, Vector theRange, - Vector theSize,int theBitsPerSample, - int theOrder,Vector theEncode,Vector theDecode, - StringBuffer theFunctionDataStream, Vector theFilter) - {//Type 0 function - PDFFunction function = new PDFFunction( - ++this.objectcount, theFunctionType, - theDomain, theRange, theSize, - theBitsPerSample, theOrder, - theEncode, theDecode, - theFunctionDataStream, theFilter); + public PDFFunction makeFunction(int theFunctionType, Vector theDomain, + Vector theRange, Vector theSize, + int theBitsPerSample, int theOrder, + Vector theEncode, Vector theDecode, + StringBuffer theFunctionDataStream, + Vector theFilter) { // Type 0 function + PDFFunction function = new PDFFunction(++this.objectcount, + theFunctionType, theDomain, + theRange, theSize, + theBitsPerSample, theOrder, + theEncode, theDecode, + theFunctionDataStream, + theFilter); this.objects.addElement(function); - return(function); + return (function); } /** * make a type Exponential interpolation function * (for shading usually) - * + * * @param theDomain Vector objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. @@ -294,40 +291,36 @@ public class PDFDocument { * 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 makeFunction(int theFunctionType, - Vector theDomain, Vector theRange, - Vector theCZero, Vector theCOne, - double theInterpolationExponentN) - - {//type 2 - PDFFunction function = new PDFFunction( - ++this.objectcount, - theFunctionType, - theDomain, theRange, - theCZero, theCOne, - theInterpolationExponentN); + public PDFFunction makeFunction(int theFunctionType, Vector theDomain, + Vector theRange, Vector theCZero, + Vector theCOne, + double theInterpolationExponentN) { // type 2 + PDFFunction function = new PDFFunction(++this.objectcount, + theFunctionType, theDomain, + theRange, theCZero, theCOne, + theInterpolationExponentN); this.objects.addElement(function); - return(function); + return (function); } /** * Make a Type 3 Stitching function - * + * * @param theDomain Vector objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. @@ -335,16 +328,16 @@ public class PDFDocument { * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. * @param theFunctions A Vector 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 Vector objects of Double objects. @@ -352,31 +345,28 @@ public class PDFDocument { * 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 makeFunction(int theFunctionType, - Vector theDomain, Vector theRange, - Vector theFunctions, Vector theBounds, - Vector theEncode) - {//Type 3 - - PDFFunction function = new PDFFunction( - ++this.objectcount, - theFunctionType, - theDomain, theRange, - theFunctions, theBounds, - theEncode); + public PDFFunction makeFunction(int theFunctionType, Vector theDomain, + Vector theRange, Vector theFunctions, + Vector theBounds, + Vector theEncode) { // Type 3 + + PDFFunction function = new PDFFunction(++this.objectcount, + theFunctionType, theDomain, + theRange, theFunctions, + theBounds, theEncode); this.objects.addElement(function); - return(function); + return (function); } /** * make a postscript calculator function - * + * * @param theNumber * @param theFunctionType * @param theDomain @@ -384,23 +374,21 @@ public class PDFDocument { * @param theFunctionDataStream */ public PDFFunction makeFunction(int theNumber, int theFunctionType, - Vector theDomain, Vector theRange, - StringBuffer theFunctionDataStream) - { //Type 4 - PDFFunction function = new PDFFunction( - ++this.objectcount, - theFunctionType, - theDomain, theRange, - theFunctionDataStream); + Vector theDomain, Vector theRange, + StringBuffer theFunctionDataStream) { // Type 4 + PDFFunction function = new PDFFunction(++this.objectcount, + theFunctionType, theDomain, + theRange, + theFunctionDataStream); this.objects.addElement(function); - return(function); + return (function); } /** * make a function based shading object - * + * * @param theShadingType The type of shading object, which should be 1 for function * based shading. * @param theColorSpace The colorspace is 'DeviceRGB' or something similar. @@ -419,67 +407,73 @@ public class PDFDocument { * 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 makeShading(int theShadingType, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - Vector theDomain, Vector 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); + public PDFShading makeShading(int theShadingType, + ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, Vector theDomain, + Vector 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); this.objects.addElement(shading); - //add this shading to resources + // add this shading to resources this.resources.addShading(shading); - return(shading); + return (shading); } /** * Make an axial or radial shading object. - * - * @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 Vector 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 Vector of four (type 2) or 6 (type 3) Double - * @param theDomain Vector of Doubles specifying the domain - * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function - * @param theExtend Vector of Booleans of whether to extend teh start and end colors past the start and end points - * The default is [false, false] + * + * @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 Vector 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 Vector of four (type 2) or 6 (type 3) Double + * @param theDomain Vector of Doubles specifying the domain + * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function + * @param theExtend Vector of Booleans of whether to extend teh start and end colors past the start and end points + * The default is [false, false] */ public PDFShading makeShading(int theShadingType, - ColorSpace theColorSpace, Vector theBackground, - Vector theBBox, boolean theAntiAlias, - Vector theCoords, Vector theDomain, - PDFFunction theFunction, Vector 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); + ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, Vector theCoords, + Vector theDomain, PDFFunction theFunction, + Vector 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); this.resources.addShading(shading); this.objects.addElement(shading); - return(shading); + return (shading); } /** - * Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh + * Make a free-form gouraud shaded triangle mesh, coons patch mesh, or tensor patch mesh * shading object - * + * * @param theShadingType 4, 6, or 7 depending on whether it's - * Free-form gouraud-shaded triangle meshes, coons patch meshes, + * 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 @@ -496,28 +490,34 @@ public class PDFDocument { * @param theDecode Vector of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ - public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - int theBitsPerCoordinate, int theBitsPerComponent, - int theBitsPerFlag, Vector 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); + public PDFShading makeShading(int theShadingType, + ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, + int theBitsPerCoordinate, + int theBitsPerComponent, + int theBitsPerFlag, Vector 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); this.resources.addShading(shading); this.objects.addElement(shading); - return(shading); + return (shading); } /** * make a Lattice-Form Gouraud mesh shading object - * + * * @param theShadingType 5 for lattice-Form Gouraud shaded-triangle mesh * without spaces. "Shading1" or "Sh1" are good examples. * @param theColorSpace "DeviceRGB" or similar. @@ -535,30 +535,35 @@ public class PDFDocument { * @param theVerticesPerRow number of vertices in each "row" of the lattice. * @param theFunction The PDFFunction that's mapped on to this shape */ - public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - int theBitsPerCoordinate, int theBitsPerComponent, - Vector 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); + public PDFShading makeShading(int theShadingType, + ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, + int theBitsPerCoordinate, + int theBitsPerComponent, Vector 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); this.resources.addShading(shading); this.objects.addElement(shading); - return(shading); + return (shading); } /** * Make a tiling pattern - * - * @param thePatternType the type of pattern, which is 1 for tiling. + * + * @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 @@ -569,71 +574,63 @@ public class PDFDocument { * @param theXUID Optional vector of Integers that uniquely identify the pattern * @param thePatternDataStream The stream of pattern data to be tiled. */ - public PDFPattern makePattern( - int thePatternType, //1 - PDFResources theResources, - int thePaintType, int theTilingType, - Vector theBBox, double theXStep, double theYStep, - Vector theMatrix, Vector theXUID, StringBuffer thePatternDataStream) - { - String thePatternName = new String("Pa"+(++this.patternCount)); - //int theNumber, String thePatternName, - //PDFResources theResources + public PDFPattern makePattern(int thePatternType, // 1 + PDFResources theResources, int thePaintType, int theTilingType, + Vector theBBox, double theXStep, double theYStep, Vector theMatrix, + Vector 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); + thePatternName, theResources, 1, + thePaintType, theTilingType, + theBBox, theXStep, theYStep, + theMatrix, theXUID, + thePatternDataStream); this.resources.addPattern(pattern); this.objects.addElement(pattern); - return(pattern); + return (pattern); } /** * Make a smooth shading 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:Vector of Doubles that specify the matrix. */ - public PDFPattern makePattern(int thePatternType, - PDFShading theShading, Vector theXUID, - StringBuffer theExtGState,Vector theMatrix) - { - String thePatternName = new String("Pa"+(++this.patternCount)); + public PDFPattern makePattern(int thePatternType, PDFShading theShading, + Vector theXUID, StringBuffer theExtGState, + Vector theMatrix) { + String thePatternName = new String("Pa" + (++this.patternCount)); PDFPattern pattern = new PDFPattern(++this.objectcount, - thePatternName, 2, theShading, theXUID, - theExtGState, theMatrix); + thePatternName, 2, theShading, + theXUID, theExtGState, theMatrix); this.resources.addPattern(pattern); this.objects.addElement(pattern); - return(pattern); + return (pattern); } - public int getColorSpace() - { - return(this.colorspace.getColorSpace()); + public int getColorSpace() { + return (this.colorspace.getColorSpace()); } - public void setColorSpace(int theColorspace) - { + public void setColorSpace(int theColorspace) { this.colorspace.setColorSpace(theColorspace); return; } public PDFPattern createGradient(boolean radial, - ColorSpace theColorspace, - Vector theColors, - Vector theBounds, - Vector theCoords) - { + ColorSpace theColorspace, + Vector theColors, Vector theBounds, + Vector theCoords) { PDFShading myShad; PDFFunction myfunky; PDFFunction myfunc; @@ -641,58 +638,52 @@ public class PDFDocument { Vector theCone; PDFPattern myPattern; ColorSpace theColorSpace; - double interpolation = (double) 1.000; + double interpolation = (double)1.000; Vector theFunctions = new Vector(); 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.elementAt(currentPosition); - PDFColor nextColor = - (PDFColor)theColors.elementAt(currentPosition+1); - //colorspace must be consistant - if ( this.colorspace.getColorSpace() != currentColor.getColorSpace() ) + 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.elementAt(currentPosition); + PDFColor nextColor = (PDFColor)theColors.elementAt(currentPosition + + 1); + // colorspace must be consistant + if (this.colorspace.getColorSpace() + != currentColor.getColorSpace()) currentColor.setColorSpace(this.colorspace.getColorSpace()); - if ( this.colorspace.getColorSpace() != nextColor.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); + myfunc = this.makeFunction(2, null, null, theCzero, theCone, + interpolation); theFunctions.addElement(myfunc); - }//end of for every consecutive color pair + } // end of for every consecutive color pair - myfunky = this.makeFunction(3, - null, null, - theFunctions, theBounds, - null); + myfunky = this.makeFunction(3, null, null, theFunctions, theBounds, + null); - if ( radial ) { - if ( theCoords.size() ==6 ) { - myShad = this.makeShading( - 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 + if (radial) { + if (theCoords.size() == 6) { + myShad = this.makeShading(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 Vector newCoords = new Vector(); newCoords.addElement(theCoords.elementAt(0)); newCoords.addElement(theCoords.elementAt(1)); @@ -701,42 +692,40 @@ public class PDFDocument { newCoords.addElement(theCoords.elementAt(1)); newCoords.addElement(new Double(0.0)); - myShad = this.makeShading( - 3, this.colorspace, - null, null, false, - newCoords, null, myfunky, null); + myShad = this.makeShading(3, this.colorspace, null, null, + false, newCoords, null, myfunky, + null); } - } - else { - myShad = this.makeShading( - 2, this.colorspace, - null, null, false, - theCoords, null, myfunky, null); + } else { + myShad = this.makeShading(2, this.colorspace, null, null, false, + theCoords, null, myfunky, null); } - myPattern = this.makePattern( - 2, myShad, null, null, null); + myPattern = this.makePattern(2, myShad, null, null, null); - return(myPattern); + 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.addElement(encoding); - return encoding; - } + /** + * 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.addElement(encoding); + return encoding; + } /** @@ -750,50 +739,56 @@ public class PDFDocument { * @return the created /Font object */ public PDFFont makeFont(String fontname, String basefont, - String encoding, FontMetric metrics, FontDescriptor descriptor) { + String encoding, FontMetric metrics, + FontDescriptor descriptor) { - /* create a PDFFont with the next object number and add to the - list of objects */ + /* + * 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, - PDFFont.TYPE1, - basefont, encoding); + PDFFont.TYPE1, basefont, encoding); this.objects.addElement(font); return font; } else { - byte subtype=PDFFont.TYPE1; + byte subtype = PDFFont.TYPE1; if (metrics instanceof org.apache.fop.render.pdf.Font) - subtype=((org.apache.fop.render.pdf.Font)metrics).getSubType(); - + subtype = + ((org.apache.fop.render.pdf.Font)metrics).getSubType(); + PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor, - subtype); - + subtype); + PDFFontNonBase14 font = null; if (subtype == PDFFont.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.addElement(cmap); - */ - font = (PDFFontNonBase14)PDFFont.createFont( - ++this.objectcount, fontname, - subtype, basefont, "Identity-H"); + /* + * 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.addElement(cmap); + */ + font = + (PDFFontNonBase14)PDFFont.createFont(++this.objectcount, + fontname, subtype, + basefont, + "Identity-H"); } else { - - font = (PDFFontNonBase14)PDFFont.createFont( - ++this.objectcount, fontname, - subtype, basefont, encoding); + + font = + (PDFFontNonBase14)PDFFont.createFont(++this.objectcount, + fontname, subtype, + basefont, encoding); } this.objects.addElement(font); - + font.setDescriptor(pdfdesc); - + if (subtype == PDFFont.TYPE0) { CIDFont cidMetrics = (CIDFont)metrics; PDFCIDSystemInfo sysInfo = @@ -804,93 +799,88 @@ public class PDFDocument { new PDFCIDFont(++this.objectcount, basefont, cidMetrics.getCidType(), cidMetrics.getDefaultWidth(), - cidMetrics.getWidths(), - sysInfo, (PDFCIDFontDescriptor)pdfdesc); + cidMetrics.getWidths(), sysInfo, + (PDFCIDFontDescriptor)pdfdesc); this.objects.addElement(cidFont); - - //((PDFFontType0)font).setCMAP(cmap); - + + // ((PDFFontType0)font).setCMAP(cmap); + ((PDFFontType0)font).setDescendantFonts(cidFont); } else { font.setWidthMetrics(metrics.getFirstChar(), metrics.getLastChar(), makeArray(metrics.getWidths(1))); } - + return font; } } - /** - * make a /FontDescriptor object - */ + /** + * make a /FontDescriptor object + */ public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc, byte subtype) { PDFFontDescriptor font = null; - + if (subtype == PDFFont.TYPE0) { - // CID Font - font = - new PDFCIDFontDescriptor(++this.objectcount, - desc.fontName(), - desc.getFontBBox(), - //desc.getAscender(), - //desc.getDescender(), + // CID Font + font = new PDFCIDFontDescriptor(++this.objectcount, + desc.fontName(), + desc.getFontBBox(), + // desc.getAscender(), + // desc.getDescender(), + desc.getCapHeight(), desc.getFlags(), + // new PDFRectangle(desc.getFontBBox()), + desc.getItalicAngle(), desc.getStemV(), null); // desc.getLang(), + // null);//desc.getPanose()); + } else { + // Create normal FontDescriptor + font = new PDFFontDescriptor(++this.objectcount, desc.fontName(), + desc.getAscender(), + desc.getDescender(), desc.getCapHeight(), desc.getFlags(), - //new PDFRectangle(desc.getFontBBox()), - desc.getItalicAngle(), + new PDFRectangle(desc.getFontBBox()), desc.getStemV(), - null); //desc.getLang(), - //null);//desc.getPanose()); - } else { - // Create normal FontDescriptor - font = - new PDFFontDescriptor(++this.objectcount, - desc.fontName(), - desc.getAscender(), - desc.getDescender(), - desc.getCapHeight(), - desc.getFlags(), - new PDFRectangle(desc.getFontBBox()), - desc.getStemV(), - desc.getItalicAngle()); + desc.getItalicAngle()); } - this.objects.addElement(font); - - // Check if the font is embeddable + this.objects.addElement(font); + + // Check if the font is embeddable if (desc.isEmbeddable()) { - PDFStream stream=desc.getFontFile(this.objectcount+1); - if (stream!=null) { + PDFStream stream = desc.getFontFile(this.objectcount + 1); + if (stream != null) { this.objectcount++; font.setFontFile(desc.getSubType(), stream); this.objects.addElement(stream); } } - return font; + return font; } - /** - * make an Array object (ex. Widths array for a font) - */ - public PDFArray makeArray(int[] values) { + /** + * make an Array object (ex. Widths array for a font) + */ + public PDFArray makeArray(int[] values) { PDFArray array = new PDFArray(++this.objectcount, values); - this.objects.addElement(array); - return array; - } + this.objects.addElement(array); + return array; + } public int addImage(FopImage img) { // check if already created String url = img.getURL(); - PDFXObject xObject = (PDFXObject) this.xObjectsMap.get(url); - if ( xObject != null ) return xObject.getXNumber(); - // else, create a new one - xObject = new PDFXObject(++this.objectcount, - ++this.xObjectCount, img); + PDFXObject xObject = (PDFXObject)this.xObjectsMap.get(url); + if (xObject != null) + return xObject.getXNumber(); + // else, create a new one + xObject = new PDFXObject(++this.objectcount, ++this.xObjectCount, + img); this.objects.addElement(xObject); this.xObjects.addElement(xObject); this.xObjectsMap.put(url, xObject); @@ -907,25 +897,24 @@ public class PDFDocument { * * @return the created /Page object */ - public PDFPage makePage(PDFResources resources, - PDFStream contents, - int pagewidth, - int pageheight, - Page currentPage) { - - /* create a PDFPage with the next object number, the given - resources, contents and dimensions */ - PDFPage page = new PDFPage(++this.objectcount, resources, - contents, - pagewidth, pageheight); - - if(currentPage != null) { - Enumeration enum=currentPage.getIDList().elements(); - while ( enum.hasMoreElements() ) { - String id=enum.nextElement().toString(); - idReferences.setInternalGoToPageReference(id,page.referencePDF()); + public PDFPage makePage(PDFResources resources, PDFStream contents, + int pagewidth, int pageheight, Page currentPage) { + + /* + * create a PDFPage with the next object number, the given + * resources, contents and dimensions + */ + PDFPage page = new PDFPage(++this.objectcount, resources, contents, + pagewidth, pageheight); + + if (currentPage != null) { + Enumeration enum = currentPage.getIDList().elements(); + while (enum.hasMoreElements()) { + String id = enum.nextElement().toString(); + idReferences.setInternalGoToPageReference(id, + page.referencePDF()); + } } - } /* add it to the list of objects */ this.objects.addElement(page); @@ -938,35 +927,35 @@ public class PDFDocument { /** * make a link object - * + * * @param rect the clickable rectangle * @param destination the destination file * @param linkType the link type * @return the PDFLink object created */ - public PDFLink makeLink(Rectangle rect, String destination, int linkType) { + public PDFLink makeLink(Rectangle rect, String destination, + int linkType) { PDFLink linkObject; PDFAction action; PDFLink link = new PDFLink(++this.objectcount, rect); - this.objects.addElement(link); + this.objects.addElement(link); - if ( linkType == LinkSet.EXTERNAL ) { - //check destination - if ( destination.endsWith(".pdf") ) { //FileSpec - PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount,destination); + if (linkType == LinkSet.EXTERNAL) { + // check destination + if (destination.endsWith(".pdf")) { // FileSpec + PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, + destination); this.objects.addElement(fileSpec); - action = new PDFGoToRemote(++this.objectcount,fileSpec); + action = new PDFGoToRemote(++this.objectcount, fileSpec); this.objects.addElement(action); - link.setAction(action); - } - else { //URI - PDFUri uri = new PDFUri(destination); - link.setAction(uri); + link.setAction(action); + } else { // URI + PDFUri uri = new PDFUri(destination); + link.setAction(uri); } - } - else { // linkType is internal + } else { // linkType is internal String goToReference = getGoToReference(destination); PDFInternalLink internalLink = new PDFInternalLink(goToReference); link.setAction(internalLink); @@ -974,28 +963,29 @@ public class PDFDocument { return link; } - private String getGoToReference(String destination) - { - String goToReference; - if ( idReferences.doesIDExist(destination) ) { - if ( idReferences.doesGoToReferenceExist(destination) ) { - goToReference = idReferences.getInternalLinkGoToReference(destination); - } - else { //assign Internal Link GoTo object - goToReference = idReferences.createInternalLinkGoTo(destination,++this.objectcount); - this.objects.addElement(idReferences.getPDFGoTo(destination)); - } - } - else { //id was not found, so create it - idReferences.createNewId(destination); - idReferences.addToIdValidationList(destination); - goToReference = idReferences.createInternalLinkGoTo(destination,++this.objectcount); - this.objects.addElement(idReferences.getPDFGoTo(destination)); - } - return goToReference; + private String getGoToReference(String destination) { + String goToReference; + if (idReferences.doesIDExist(destination)) { + if (idReferences.doesGoToReferenceExist(destination)) { + goToReference = + idReferences.getInternalLinkGoToReference(destination); + } else { // assign Internal Link GoTo object + goToReference = + idReferences.createInternalLinkGoTo(destination, + ++this.objectcount); + this.objects.addElement(idReferences.getPDFGoTo(destination)); + } + } else { // id was not found, so create it + idReferences.createNewId(destination); + idReferences.addToIdValidationList(destination); + goToReference = idReferences.createInternalLinkGoTo(destination, + ++this.objectcount); + this.objects.addElement(idReferences.getPDFGoTo(destination)); + } + return goToReference; } - - + + /** * make a stream object * @@ -1003,16 +993,18 @@ public class PDFDocument { */ public PDFStream makeStream() { - /* create a PDFStream with the next object number and add it - - to the list of objects */ - PDFStream obj = new PDFStream(++this.objectcount); - obj.addDefaultFilters(); - + /* + * create a PDFStream with the next object number and add it + * + * to the list of objects + */ + PDFStream obj = new PDFStream(++this.objectcount); + obj.addDefaultFilters(); + this.objects.addElement(obj); return obj; } - + /** * make an annotation list object @@ -1021,8 +1013,10 @@ public class PDFDocument { */ public PDFAnnotList makeAnnotList() { - /* create a PDFAnnotList with the next object number and add it - to the list of objects */ + /* + * create a PDFAnnotList with the next object number and add it + * to the list of objects + */ PDFAnnotList obj = new PDFAnnotList(++this.objectcount); this.objects.addElement(obj); return obj; @@ -1031,35 +1025,33 @@ public class PDFDocument { /** * Make the root Outlines object */ - public PDFOutline makeOutlineRoot() - { - PDFOutline obj = new PDFOutline(++this.objectcount, null, null); - this.objects.addElement(obj); - root.setRootOutline(obj); - - return obj; + public PDFOutline makeOutlineRoot() { + PDFOutline obj = new PDFOutline(++this.objectcount, null, null); + this.objects.addElement(obj); + root.setRootOutline(obj); + + return obj; } - - /** Make an outline object and add it to the given outline + + /** + * Make an outline object and add it to the given outline * @param parent parent PDFOutline object * @param label the title for the new outline object * @param action the PDFAction to reference */ - public PDFOutline makeOutline(PDFOutline parent, - String label, - String destination) - { - String goToRef = getGoToReference(destination); - - PDFOutline obj = new PDFOutline(++this.objectcount, label, goToRef); - // System.out.println("created new outline object"); - - if (parent != null) { - parent.addOutline(obj); - } - this.objects.addElement(obj); - return obj; - + public PDFOutline makeOutline(PDFOutline parent, String label, + String destination) { + String goToRef = getGoToReference(destination); + + PDFOutline obj = new PDFOutline(++this.objectcount, label, goToRef); + // System.out.println("created new outline object"); + + if (parent != null) { + parent.addOutline(obj); + } + this.objects.addElement(obj); + return obj; + } /** @@ -1078,28 +1070,36 @@ public class PDFDocument { */ public void output(OutputStream stream) throws IOException { - /* output the header and increment the character position by - the header's length */ + /* + * output the header and increment the character position by + * the header's length + */ this.position += outputHeader(stream); this.resources.setXObjects(xObjects); - Enumeration en = this.objects.elements(); - while (en.hasMoreElements()) { + Enumeration en = this.objects.elements(); + while (en.hasMoreElements()) { /* retrieve the object with the current number */ PDFObject object = (PDFObject)en.nextElement(); - /* add the position of this object to the list of object - locations */ + /* + * add the position of this object to the list of object + * locations + */ this.location.addElement(new Integer(this.position)); - - /* output the object and increment the character position - by the object's length */ + + /* + * output the object and increment the character position + * by the object's length + */ this.position += object.output(stream); - } - - /* output the xref table and increment the character position - by the table's length */ + } + + /* + * output the xref table and increment the character position + * by the table's length + */ this.position += outputXref(stream); /* output the trailer and flush the Stream */ @@ -1114,17 +1114,20 @@ public class PDFDocument { * @return the number of bytes written */ protected int outputHeader(OutputStream stream) throws IOException { - int length = 0; - byte[] pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(); - stream.write(pdf); - length += 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); - length += bin.length; - - return length; + int length = 0; + byte[] pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(); + stream.write(pdf); + length += 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); + length += bin.length; + + return length; } /** @@ -1135,11 +1138,11 @@ public class PDFDocument { protected void outputTrailer(OutputStream stream) throws IOException { /* 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>>\nstartxref\n" + this.xref - + "\n%%EOF\n"; + 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>>\nstartxref\n" + + this.xref + "\n%%EOF\n"; /* write the trailer */ stream.write(pdf.getBytes()); @@ -1157,13 +1160,14 @@ public class PDFDocument { this.xref = this.position; /* construct initial part of xref */ - StringBuffer pdf = new StringBuffer("xref\n0 " + (this.objectcount+1) - + "\n0000000000 65535 f \n"); + StringBuffer pdf = new StringBuffer("xref\n0 " + + (this.objectcount + 1) + + "\n0000000000 65535 f \n"); + + Enumeration en = this.location.elements(); + while (en.hasMoreElements()) { + String x = en.nextElement().toString(); - Enumeration en = this.location.elements(); - while (en.hasMoreElements()) { - String x = en.nextElement().toString(); - /* contruct xref entry for object */ String padding = "0000000000"; String loc = padding.substring(x.length()) + x; @@ -1173,12 +1177,13 @@ public class PDFDocument { } /* write the xref table and return the character length */ - byte[] pdfBytes = pdf.toString().getBytes(); - stream.write(pdfBytes); + byte[] pdfBytes = pdf.toString().getBytes(); + stream.write(pdfBytes); return pdfBytes.length; - } + } - public void setIDReferences(IDReferences idReferences){ - this.idReferences= idReferences; + public void setIDReferences(IDReferences idReferences) { + this.idReferences = idReferences; } + } diff --git a/src/org/apache/fop/pdf/PDFEncoding.java b/src/org/apache/fop/pdf/PDFEncoding.java index ad937f417..68151bdfd 100644 --- a/src/org/apache/fop/pdf/PDFEncoding.java +++ b/src/org/apache/fop/pdf/PDFEncoding.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -67,22 +24,32 @@ import java.util.Vector; */ public class PDFEncoding extends PDFObject { - /** the name for the standard encoding scheme */ - public static final String MacRomanEncoding = "MacRomanEncoding"; - /** the name for the standard encoding scheme */ - public static final String MacExpertEncoding = "MacExpertEncoding"; - /** the name for the standard encoding scheme */ - public static final String WinAnsiEncoding = "WinAnsiEncoding"; + /** + * the name for the standard encoding scheme + */ + public static final String MacRomanEncoding = "MacRomanEncoding"; + + /** + * the name for the standard encoding scheme + */ + public static final String MacExpertEncoding = "MacExpertEncoding"; + + /** + * the name for the standard encoding scheme + */ + public static final String WinAnsiEncoding = "WinAnsiEncoding"; /** - * the name for the base encoding. - * One of the three base encoding scheme names or - * the default font's base encoding if null. - */ + * 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 Hashtable differences; + /** + * the differences from the base encoding + */ + protected Hashtable differences; /** * create the /Encoding object @@ -92,61 +59,65 @@ public class PDFEncoding extends PDFObject { */ public PDFEncoding(int number, String basename) { - /* generic creation of PDF object */ - super(number); + /* generic creation of PDF object */ + super(number); - /* set fields using paramaters */ - this.basename = basename; - this.differences = new Hashtable(); - } + /* set fields using paramaters */ + this.basename = basename; + this.differences = new Hashtable(); + } - /** - * 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, Vector sequence) { - differences.put(new Integer(code), sequence); - } + /** + * 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, Vector 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; - Enumeration codes = differences.keys(); - while (codes.hasMoreElements()) { - code = codes.nextElement(); - p.append(" "); p.append(code); - Vector sequence = (Vector)differences.get(code); - for (int i = 0; i < sequence.size(); i++) { - p.append(" /"); p.append((String)sequence.elementAt(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 - */ + /** + * 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; + Enumeration codes = differences.keys(); + while (codes.hasMoreElements()) { + code = codes.nextElement(); + p.append(" "); + p.append(code); + Vector sequence = (Vector)differences.get(code); + for (int i = 0; i < sequence.size(); i++) { + p.append(" /"); + p.append((String)sequence.elementAt(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 index fdfd0ea1c..d7c5338d0 100644 --- a/src/org/apache/fop/pdf/PDFFileSpec.java +++ b/src/org/apache/fop/pdf/PDFFileSpec.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -57,7 +13,9 @@ package org.apache.fop.pdf; */ public class PDFFileSpec extends PDFObject { - /** the filename */ + /** + * the filename + */ protected String filename; /** @@ -68,10 +26,10 @@ public class PDFFileSpec extends PDFObject { */ public PDFFileSpec(int number, String filename) { - /* generic creation of object */ - super(number); - - this.filename = filename; + /* generic creation of object */ + super(number); + + this.filename = filename; } /** @@ -80,19 +38,19 @@ public class PDFFileSpec extends PDFObject { * @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(); + 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 - */ + /* + * example + * 29 0 obj + * << + * /Type /FileSpec + * /F (table1.pdf) + * >> + * endobj + */ } diff --git a/src/org/apache/fop/pdf/PDFFilter.java b/src/org/apache/fop/pdf/PDFFilter.java index 5783b829b..1cb6ce18c 100644 --- a/src/org/apache/fop/pdf/PDFFilter.java +++ b/src/org/apache/fop/pdf/PDFFilter.java @@ -1,83 +1,38 @@ -/*-- $Id$ -- +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - -*/ - - -//Author: Eric SCHAEFFER, Kelly A. Campbell -//Description: represent a PDF filter object +// Author: Eric SCHAEFFER, Kelly A. Campbell +// Description: represent a PDF filter object package org.apache.fop.pdf; 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; - - */ + /* + * 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 */ + /** + * Marker to know if this filter has already been applied to the data + */ private boolean _applied = false; - - public boolean isApplied() - { - return _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 @@ -85,23 +40,28 @@ public abstract class PDFFilter { * 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. + * those which the raw data was encoded with. */ - public void setApplied(boolean b) - { - _applied = b; + public void setApplied(boolean b) { + _applied = b; } - - - /** return a PDF string representation of the filter, e.g. /FlateDecode */ + + + /** + * return a PDF string representation of the filter, e.g. /FlateDecode + */ public abstract String getName(); - - /** return a parameter dictionary for this filter, or null */ + + /** + * return a parameter dictionary for this filter, or null + */ public abstract String getDecodeParms(); - - /** encode the given data with the filter */ + + /** + * encode the given data with the filter + */ public abstract byte[] encode(byte[] data); - - - + + + } diff --git a/src/org/apache/fop/pdf/PDFFilterException.java b/src/org/apache/fop/pdf/PDFFilterException.java index cb39e554c..06cd038f8 100644 --- a/src/org/apache/fop/pdf/PDFFilterException.java +++ b/src/org/apache/fop/pdf/PDFFilterException.java @@ -1,11 +1,12 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ -//Author: Eric SCHAEFFER -//Description: Filter Exception +// Author: Eric SCHAEFFER +// Description: Filter Exception package org.apache.fop.pdf; @@ -18,4 +19,5 @@ public class PDFFilterException extends Exception { public PDFFilterException(String message) { super(message); } + } diff --git a/src/org/apache/fop/pdf/PDFFont.java b/src/org/apache/fop/pdf/PDFFont.java index ed43a8017..3d1c2ec05 100644 --- a/src/org/apache/fop/pdf/PDFFont.java +++ b/src/org/apache/fop/pdf/PDFFont.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -61,22 +18,43 @@ package org.apache.fop.pdf; */ public class PDFFont extends PDFObject { - /** font subtype to be used as parameter to createFont() */ + /** + * font subtype to be used as parameter to createFont() + */ public static final byte TYPE0 = 0; - /** font subtype to be used as parameter to createFont() */ + + /** + * font subtype to be used as parameter to createFont() + */ public static final byte TYPE1 = 1; - /** font subtype to be used as parameter to createFont() */ + + /** + * font subtype to be used as parameter to createFont() + */ public static final byte MMTYPE1 = 2; - /** font subtype to be used as parameter to createFont() */ + + /** + * font subtype to be used as parameter to createFont() + */ public static final byte TYPE3 = 3; - /** font subtype to be used as parameter to createFont() */ + + /** + * font subtype to be used as parameter to createFont() + */ public static final byte TRUETYPE = 4; - /** font subtype names as output in the PDF */ - protected static final String[] TYPE_NAMES = new String[] // take care of the order - {"Type0", "Type1", "MMType1", "Type3", "TrueType"}; + /** + * font subtype names as output in the PDF + */ + protected static final String[] TYPE_NAMES = + new String[] // take care of the order + { + "Type0", "Type1", "MMType1", "Type3", "TrueType" + }; - /** the internal name for the font (eg "F1") */ + /** + * the internal name for the font (eg "F1") + */ protected String fontname; /** @@ -85,7 +63,9 @@ public class PDFFont extends PDFObject { */ protected byte subtype; - /** the base font name (eg "Helvetica") */ + /** + * the base font name (eg "Helvetica") + */ protected String basefont; /** @@ -97,8 +77,10 @@ public class PDFFont extends PDFObject { */ protected Object encoding; - /** the Unicode mapping mechanism */ - //protected PDFToUnicode mapping; + /** + * the Unicode mapping mechanism + */ + // protected PDFToUnicode mapping; /** * create the /Font object @@ -110,8 +92,9 @@ public class PDFFont extends PDFObject { * @param encoding the character encoding schema used by the font * @param mapping the Unicode mapping mechanism */ - public PDFFont(int number, String fontname, byte subtype, String basefont, - Object encoding/*, PDFToUnicode mapping*/) { + public PDFFont(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { /* generic creation of PDF object */ super(number); @@ -121,7 +104,7 @@ public class PDFFont extends PDFObject { this.subtype = subtype; this.basefont = basefont; this.encoding = encoding; - //this.mapping = mapping; + // this.mapping = mapping; } /** @@ -134,20 +117,23 @@ public class PDFFont extends PDFObject { * @param encoding the character encoding schema used by the font */ public static PDFFont createFont(int number, String fontname, - byte subtype, String basefont, Object encoding) { + byte subtype, String basefont, + Object encoding) { switch (subtype) { - case TYPE0 : - return new PDFFontType0(number, fontname, subtype, - basefont, encoding); - case TYPE1 : - case MMTYPE1 : - return new PDFFontType1(number, fontname, subtype, basefont, encoding); - /* - case TYPE3 : - return new PDFFontType3(number, fontname, subtype, basefont, encoding); - */ - case TRUETYPE : - return new PDFFontTrueType(number, fontname, subtype, basefont, encoding); + case TYPE0: + return new PDFFontType0(number, fontname, subtype, basefont, + encoding); + case TYPE1: + case MMTYPE1: + return new PDFFontType1(number, fontname, subtype, basefont, + encoding); + /* + * case TYPE3 : + * return new PDFFontType3(number, fontname, subtype, basefont, encoding); + */ + case TRUETYPE: + return new PDFFontTrueType(number, fontname, subtype, basefont, + encoding); } return null; // should not happend } @@ -167,31 +153,34 @@ public class PDFFont extends PDFObject { * @param descriptor the descriptor for other font's metrics */ public static PDFFont createFont(int number, String fontname, - byte subtype, String basefont, Object encoding, - int firstChar, int lastChar, PDFArray widths, - PDFFontDescriptor descriptor) { + byte subtype, String basefont, + Object encoding, int firstChar, + int lastChar, PDFArray widths, + PDFFontDescriptor descriptor) { PDFFontNonBase14 font; switch (subtype) { - case TYPE0 : - font = new PDFFontType0(number, fontname, subtype, - basefont, encoding); - font.setDescriptor(descriptor); - return font; - case TYPE1 : - case MMTYPE1 : - font = new PDFFontType1(number, fontname, subtype, basefont, encoding); - font.setWidthMetrics(firstChar, lastChar, widths); - font.setDescriptor(descriptor); - return font; - case TYPE3 : - return null; // should not happend - - case TRUETYPE : - font = new PDFFontTrueType(number, fontname, subtype, basefont, encoding); - font.setWidthMetrics(firstChar, lastChar, widths); - font.setDescriptor(descriptor); - return font; + case TYPE0: + font = new PDFFontType0(number, fontname, subtype, basefont, + encoding); + font.setDescriptor(descriptor); + return font; + case TYPE1: + case MMTYPE1: + font = new PDFFontType1(number, fontname, subtype, basefont, + encoding); + font.setWidthMetrics(firstChar, lastChar, widths); + font.setDescriptor(descriptor); + return font; + case TYPE3: + return null; // should not happend + + case TRUETYPE: + font = new PDFFontTrueType(number, fontname, subtype, basefont, + encoding); + font.setWidthMetrics(firstChar, lastChar, widths); + font.setDescriptor(descriptor); + return font; } return null; // should not happend @@ -214,8 +203,9 @@ public class PDFFont extends PDFObject { public byte[] toPDF() { StringBuffer p = new StringBuffer(); p.append(this.number + " " + this.generation - + " obj\n<< /Type /Font\n/Subtype /" + TYPE_NAMES[this.subtype] - + "\n/Name /" + this.fontname + "\n/BaseFont /" + this.basefont); + + " obj\n<< /Type /Font\n/Subtype /" + + TYPE_NAMES[this.subtype] + "\n/Name /" + this.fontname + + "\n/BaseFont /" + this.basefont); if (encoding != null) { p.append("\n/Encoding "); if (encoding instanceof PDFEncoding) { @@ -238,6 +228,6 @@ public class PDFFont extends PDFObject { * * @param begin the buffer to be completed with the type specific fields */ - protected void fillInPDF(StringBuffer begin) { - } + protected void fillInPDF(StringBuffer begin) {} + } diff --git a/src/org/apache/fop/pdf/PDFFontDescriptor.java b/src/org/apache/fop/pdf/PDFFontDescriptor.java index b13030d24..203879b35 100644 --- a/src/org/apache/fop/pdf/PDFFontDescriptor.java +++ b/src/org/apache/fop/pdf/PDFFontDescriptor.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -57,153 +14,164 @@ package org.apache.fop.pdf; */ public class PDFFontDescriptor extends PDFObject { - // Required fields - protected int ascent; + // Required fields + protected int ascent; protected int capHeight; - protected int descent; + protected int descent; protected int flags; protected PDFRectangle fontBBox; - protected String basefont; //PDF-spec: FontName + protected String basefont; // PDF-spec: FontName protected int italicAngle; protected int stemV; - // Optional fields - protected int stemH = 0; - protected int xHeight = 0; - protected int leading = 0; - protected int avgWidth = 0; - protected int maxWidth = 0; - protected int missingWidth = 0; - protected PDFStream fontfile; - //protected String charSet = null; - - protected byte 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; - } + // Optional fields + protected int stemH = 0; + protected int xHeight = 0; + protected int leading = 0; + protected int avgWidth = 0; + protected int maxWidth = 0; + protected int missingWidth = 0; + protected PDFStream fontfile; + // protected String charSet = null; + + protected byte 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 - */ - 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 metrics + */ + 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(byte subtype, PDFStream fontfile) { - this.subtype = subtype; - this.fontfile = fontfile; - } + /** + * 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(byte subtype, PDFStream fontfile) { + this.subtype = subtype; + this.fontfile = fontfile; + } - //public void setCharSet(){}//for subset fonts + // public void setCharSet(){}//for subset fonts - /** - * produce the PDF representation for the object - * - * @return the PDF - */ + /** + * 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) { - switch (subtype) { - case PDFFont.TYPE1: - p.append("\n/FontFile "); - break; - case PDFFont.TRUETYPE: - p.append("\n/FontFile2 "); - break; - case PDFFont.TYPE0: - p.append("\n/FontFile2 "); - break; - default: - 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(); + 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) { + switch (subtype) { + case PDFFont.TYPE1: + p.append("\n/FontFile "); + break; + case PDFFont.TRUETYPE: + p.append("\n/FontFile2 "); + break; + case PDFFont.TYPE0: + p.append("\n/FontFile2 "); + break; + default: + 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. - * - * 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) { - } + /** + * fill in the specifics for the font's descriptor. + * + * 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) {} + } diff --git a/src/org/apache/fop/pdf/PDFFontNonBase14.java b/src/org/apache/fop/pdf/PDFFontNonBase14.java index 583af810d..ac4abb261 100644 --- a/src/org/apache/fop/pdf/PDFFontNonBase14.java +++ b/src/org/apache/fop/pdf/PDFFontNonBase14.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -58,67 +15,84 @@ package org.apache.fop.pdf; */ 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 - * @param mapping the Unicode mapping mechanism - */ - public PDFFontNonBase14(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/) { - - /* 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; - } + /** + * 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 + * @param mapping the Unicode mapping mechanism + */ + public PDFFontNonBase14(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { + + /* 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; + } + + /** + * fill in the specifics for the font's subtype + */ + protected void fillInPDF(StringBuffer p) { + p.append("\n/FirstChar "); + p.append(firstChar); + p.append("\n/LastChar "); + p.append(lastChar); + p.append("\n/Widths "); + p.append(this.widths.referencePDF()); + if (descriptor != null) { + p.append("\n/FontDescriptor "); + p.append(this.descriptor.referencePDF()); + } + } - /** - * fill in the specifics for the font's subtype - */ - protected void fillInPDF(StringBuffer p) { - p.append("\n/FirstChar "); p.append(firstChar); - p.append("\n/LastChar "); p.append(lastChar); - p.append("\n/Widths "); p.append(this.widths.referencePDF()); - if (descriptor != null) { - p.append("\n/FontDescriptor "); - p.append(this.descriptor.referencePDF()); - } - } } diff --git a/src/org/apache/fop/pdf/PDFFontTrueType.java b/src/org/apache/fop/pdf/PDFFontTrueType.java index be1f37131..444670d38 100644 --- a/src/org/apache/fop/pdf/PDFFontTrueType.java +++ b/src/org/apache/fop/pdf/PDFFontTrueType.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -58,21 +15,22 @@ package org.apache.fop.pdf; */ public class PDFFontTrueType extends PDFFontNonBase14 { - /** - * create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype (PDFFont.TRUETYPE) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - */ - public PDFFontTrueType(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, basefont, encoding/*, 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 (PDFFont.TRUETYPE) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontTrueType(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, basefont, encoding /* , mapping */); + } } diff --git a/src/org/apache/fop/pdf/PDFFontType0.java b/src/org/apache/fop/pdf/PDFFontType0.java index 7ca15647c..1044ade09 100644 --- a/src/org/apache/fop/pdf/PDFFontType0.java +++ b/src/org/apache/fop/pdf/PDFFontType0.java @@ -1,54 +1,12 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; + /** * class representing a Type0 font. * @@ -56,76 +14,82 @@ package org.apache.fop.pdf; */ public class PDFFontType0 extends PDFFontNonBase14 { - /** this should be an array of CIDFont but only the first one is used */ - protected PDFCIDFont descendantFonts; + /** + * this should be an array of CIDFont but only the first one is used + */ + protected PDFCIDFont descendantFonts; protected PDFCMap cmap; - - /** - * create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype (PDFFont.TYPE0) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - */ - public PDFFontType0(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, 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 subtype the font's subtype (PDFFont.TYPE0) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - * @param descendantFonts the CIDFont upon which this font is based - */ - public PDFFontType0(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/, - PDFCIDFont descendantFonts) { - /* generic creation of PDF object */ - super(number, fontname, subtype, basefont, encoding/*, 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 (PDFFont.TYPE0) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontType0(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, basefont, encoding /* , mapping */); + + /* set fields using paramaters */ + this.descendantFonts = null; + cmap = null; + } - /* set fields using paramaters */ - this.descendantFonts = descendantFonts; - } + /** + * create the /Font object + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype (PDFFont.TYPE0) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + * @param descendantFonts the CIDFont upon which this font is based + */ + public PDFFontType0(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */, + PDFCIDFont descendantFonts) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, 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; - } + /** + * set the descendant font + * + * @param descendantFonts the CIDFont upon which this font is based + */ + public void setDescendantFonts(PDFCIDFont descendantFonts) { + this.descendantFonts = descendantFonts; + } public void setCMAP(PDFCMap cmap) { - this.cmap=cmap; + this.cmap = cmap; } - /** - * fill in the specifics for the font's subtype - */ + + /** + * fill in the specifics for the font's subtype + */ protected void fillInPDF(StringBuffer p) { if (descendantFonts != null) { - p.append("\n/DescendantFonts [ " + - this.descendantFonts.referencePDF() + " ] "); + p.append("\n/DescendantFonts [ " + + this.descendantFonts.referencePDF() + " ] "); } if (cmap != null) { - p.append("\n/ToUnicode "+cmap.referencePDF()); + p.append("\n/ToUnicode " + cmap.referencePDF()); } } + } diff --git a/src/org/apache/fop/pdf/PDFFontType1.java b/src/org/apache/fop/pdf/PDFFontType1.java index 3516b670b..2a98c131d 100644 --- a/src/org/apache/fop/pdf/PDFFontType1.java +++ b/src/org/apache/fop/pdf/PDFFontType1.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -61,21 +18,22 @@ package org.apache.fop.pdf; */ public class PDFFontType1 extends PDFFontNonBase14 { - /** - * create the /Font object - * - * @param number the object's number - * @param fontname the internal name for the font - * @param subtype the font's subtype (PDFFont.TYPE1 or PDFFont.MMTYPE1) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - */ - public PDFFontType1(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, basefont, encoding); - } + /** + * create the /Font object + * + * @param number the object's number + * @param fontname the internal name for the font + * @param subtype the font's subtype (PDFFont.TYPE1 or PDFFont.MMTYPE1) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontType1(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, basefont, encoding); + } } diff --git a/src/org/apache/fop/pdf/PDFFontType3.java b/src/org/apache/fop/pdf/PDFFontType3.java index 0461228d2..dc1173d46 100644 --- a/src/org/apache/fop/pdf/PDFFontType3.java +++ b/src/org/apache/fop/pdf/PDFFontType3.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -61,108 +18,123 @@ package org.apache.fop.pdf; */ 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 subtype the font's subtype (PDFFont.TYPE3) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - */ - public PDFFontType3(int number, String fontname, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, 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 subtype the font's subtype (PDFFont.TYPE3) - * @param basefont the base font name - * @param encoding the character encoding schema used by the font - * @param mapping the Unicode mapping mechanism - * @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, byte subtype, - String basefont, Object encoding/*, PDFToUnicode mapping*/, - PDFRectangle fontBBox, PDFArray fontMatrix, PDFCharProcs charProcs) { - - /* generic creation of PDF object */ - super(number, fontname, subtype, 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. - * 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; - } - - /** - * fill in the specifics for the font's subtype. - * - * the given buffer already contains the fields common to all font types. - * - * @param p the buffer to be completed with the type specific fields - */ - protected void fillInPDF(StringBuffer p) { - if (fontBBox != null) { - p.append("\n/FontBBox "); p.append(fontBBox.toPDF()); - } - if (fontMatrix != null) { - p.append("\n/FontMatrix "); p.append(fontMatrix.toPDF()); - } - if (charProcs != null) { - p.append("\n/CharProcs "); p.append(charProcs.referencePDF()); - } - } + /** + * 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 subtype the font's subtype (PDFFont.TYPE3) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + */ + public PDFFontType3(int number, String fontname, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, 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 subtype the font's subtype (PDFFont.TYPE3) + * @param basefont the base font name + * @param encoding the character encoding schema used by the font + * @param mapping the Unicode mapping mechanism + * @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, byte subtype, + String basefont, + Object encoding /* , PDFToUnicode mapping */, + PDFRectangle fontBBox, PDFArray fontMatrix, + PDFCharProcs charProcs) { + + /* generic creation of PDF object */ + super(number, fontname, subtype, 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. + * 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; + } + + /** + * fill in the specifics for the font's subtype. + * + * the given buffer already contains the fields common to all font types. + * + * @param p the buffer to be completed with the type specific fields + */ + protected void fillInPDF(StringBuffer p) { + if (fontBBox != null) { + p.append("\n/FontBBox "); + p.append(fontBBox.toPDF()); + } + if (fontMatrix != null) { + p.append("\n/FontMatrix "); + p.append(fontMatrix.toPDF()); + } + if (charProcs != null) { + p.append("\n/CharProcs "); + p.append(charProcs.referencePDF()); + } + } + } diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java index 18213e5fd..185addc9e 100644 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ b/src/org/apache/fop/pdf/PDFFunction.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,707 +7,664 @@ package org.apache.fop.pdf; -//Java... +// Java... import java.util.Vector; /** * 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 Vector domain = null; - - /** - * Required: 2 * n Array of Double numbers which are possible outputs to the function - */ - protected Vector 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 Vector 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 Vector encode = null; - /** - * Optinoal for Type 0: A 2 * n array of Doubles which provides a linear mapping of sample values to the range. Defaults to Range. - */ - protected Vector 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 Vector filter = null; - /* *************************TYPE 2************************** */ - /** - * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0]. - */ - protected Vector cZero = null; - /** - * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1]. - */ - protected Vector 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 Vector 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 Vector 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 Vector objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange Vector objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theSize A Vector 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 Vector 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 Vector 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, - Vector theDomain, Vector theRange, - Vector theSize,int theBitsPerSample, - int theOrder,Vector theEncode,Vector theDecode, - StringBuffer theFunctionDataStream, Vector 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 Vector objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange Vector 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, - Vector theDomain, Vector theRange, - Vector theCZero, Vector 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 Vector objects of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange Vector objects of Double objects. - * This is the Range of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theFunctions A Vector 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 Vector 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, - Vector theDomain, Vector theRange, - Vector theFunctions, Vector theBounds, - Vector 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 Vector object of Double objects. - * This is the domain of the function. - * See page 264 of the PDF 1.3 Spec. - * @param theRange Vector 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, - Vector theDomain, Vector 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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(0))+" \n"); - } - else - { - p.append("[ "); - for(tempInt=0; tempInt <vectorSize; tempInt++) - { - p.append("/"+((String)this.filter.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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()); - - } + // 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 Vector domain = null; + + /** + * Required: 2 * n Array of Double numbers which are possible outputs to the function + */ + protected Vector 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 Vector 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 Vector encode = null; + + /** + * Optinoal for Type 0: A 2 * n array of Doubles which provides a linear mapping of sample values to the range. Defaults to Range. + */ + protected Vector 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 Vector filter = null; + /* *************************TYPE 2************************** */ + + /** + * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0]. + */ + protected Vector cZero = null; + + /** + * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1]. + */ + protected Vector 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 Vector 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 Vector 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 Vector objects of Double objects. + * This is the domain of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theRange Vector objects of Double objects. + * This is the Range of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theSize A Vector 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 Vector 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 Vector 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, Vector theDomain, + Vector theRange, Vector theSize, int theBitsPerSample, + int theOrder, Vector theEncode, Vector theDecode, + StringBuffer theFunctionDataStream, Vector 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 Vector objects of Double objects. + * This is the domain of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theRange Vector 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, Vector theDomain, + Vector theRange, Vector theCZero, Vector 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 Vector objects of Double objects. + * This is the domain of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theRange Vector objects of Double objects. + * This is the Range of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theFunctions A Vector 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 Vector 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, Vector theDomain, + Vector theRange, Vector theFunctions, + Vector theBounds, Vector 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 Vector object of Double objects. + * This is the domain of the function. + * See page 264 of the PDF 1.3 Spec. + * @param theRange Vector 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, Vector theDomain, + Vector 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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(0)) + + " \n"); + } else { + p.append("[ "); + for (tempInt = 0; tempInt < vectorSize; tempInt++) { + p.append("/" + ((String)this.filter.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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()); + + } + } diff --git a/src/org/apache/fop/pdf/PDFGoTo.java b/src/org/apache/fop/pdf/PDFGoTo.java index e88658fd5..bd32c58d5 100644 --- a/src/org/apache/fop/pdf/PDFGoTo.java +++ b/src/org/apache/fop/pdf/PDFGoTo.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -57,11 +13,11 @@ package org.apache.fop.pdf; */ public class PDFGoTo extends PDFAction { - /** the pageReference */ + /** + * the pageReference + */ protected String pageReference; - protected float - xPosition=0, - yPosition=0; + protected float xPosition = 0, yPosition = 0; /** * create a /GoTo object. @@ -71,21 +27,20 @@ public class PDFGoTo extends PDFAction { */ public PDFGoTo(int number, String pageReference) { - /* generic creation of object */ - super(number); - - this.pageReference = 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 + * the new page reference to use */ - public void setPageReference(String pageReference) - { + public void setPageReference(String pageReference) { this.pageReference = pageReference; } @@ -93,31 +48,28 @@ public class PDFGoTo extends PDFAction { /** * Sets the Y position to jump to - * + * * @param yPosition y position */ - public void setYPosition(int yPosition) - { - this.yPosition = (yPosition/1000f); + public void setYPosition(int yPosition) { + this.yPosition = (yPosition / 1000f); } - + /** * Sets the x Position to jump to - * + * * @param xPosition x position */ - public void setXPosition(int xPosition) - { - this.xPosition = (xPosition/1000f); + public void setXPosition(int xPosition) { + this.xPosition = (xPosition / 1000f); } - public String getAction() - { - return referencePDF(); + public String getAction() { + return referencePDF(); } - + /** * represent the object in PDF @@ -125,19 +77,21 @@ public class PDFGoTo extends PDFAction { * @return the PDF string */ public byte[] toPDF() { - String p = new String(this.number + " " + this.generation + - " obj\n<<\n/S /GoTo\n" + - "/D [" + this.pageReference + " /XYZ "+xPosition+" "+yPosition+" null]\n" + - ">>\nendobj\n"); - return p.getBytes(); + String p = new String(this.number + " " + this.generation + + " obj\n<<\n/S /GoTo\n" + "/D [" + + this.pageReference + " /XYZ " + xPosition + + " " + yPosition + " null]\n" + + ">>\nendobj\n"); + return p.getBytes(); } - /* example - 29 0 obj - << - /S /GoTo - /D [23 0 R /FitH 600] - >> - endobj - */ + /* + * example + * 29 0 obj + * << + * /S /GoTo + * /D [23 0 R /FitH 600] + * >> + * endobj + */ } diff --git a/src/org/apache/fop/pdf/PDFGoToRemote.java b/src/org/apache/fop/pdf/PDFGoToRemote.java index 9164186f2..aa8ef5afa 100644 --- a/src/org/apache/fop/pdf/PDFGoToRemote.java +++ b/src/org/apache/fop/pdf/PDFGoToRemote.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -56,7 +12,9 @@ package org.apache.fop.pdf; */ public class PDFGoToRemote extends PDFAction { - /** the file specification */ + /** + * the file specification + */ protected PDFFileSpec pdfFileSpec; /** @@ -67,10 +25,10 @@ public class PDFGoToRemote extends PDFAction { */ public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec) { - /* generic creation of object */ - super(number); - - this.pdfFileSpec = pdfFileSpec; + /* generic creation of object */ + super(number); + + this.pdfFileSpec = pdfFileSpec; } /** @@ -78,8 +36,7 @@ public class PDFGoToRemote extends PDFAction { * * @return the action String */ - public String getAction() - { + public String getAction() { return this.referencePDF(); } @@ -89,23 +46,23 @@ public class PDFGoToRemote extends PDFAction { * @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" + - "/D [ 0 /XYZ null null null ]" + - " \n>>\nendobj\n"); - return p.getBytes(); + String p = new String(this.number + " " + this.generation + " obj\n" + + "<<\n/S /GoToR\n" + "/F " + + pdfFileSpec.referencePDF() + "\n" + + "/D [ 0 /XYZ null null null ]" + + " \n>>\nendobj\n"); + return p.getBytes(); } - - /* example - 28 0 obj - << - /S /GoToR - /F 29 0 R - /D [ 0 /XYZ -6 797 null ] - >> - endobj - */ + + /* + * example + * 28 0 obj + * << + * /S /GoToR + * /F 29 0 R + * /D [ 0 /XYZ -6 797 null ] + * >> + * endobj + */ } diff --git a/src/org/apache/fop/pdf/PDFInfo.java b/src/org/apache/fop/pdf/PDFInfo.java index ad9aba808..a8215fcea 100644 --- a/src/org/apache/fop/pdf/PDFInfo.java +++ b/src/org/apache/fop/pdf/PDFInfo.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -59,7 +16,9 @@ import java.io.PrintWriter; */ public class PDFInfo extends PDFObject { - /** the application producing the PDF */ + /** + * the application producing the PDF + */ protected String producer; /** @@ -68,7 +27,7 @@ public class PDFInfo extends PDFObject { * @param number the object's number */ public PDFInfo(int number) { - super(number); + super(number); } /** @@ -77,7 +36,7 @@ public class PDFInfo extends PDFObject { * @param producer the producer string */ public void setProducer(String producer) { - this.producer = producer; + this.producer = producer; } /** @@ -86,9 +45,10 @@ public class PDFInfo extends PDFObject { * @return the PDF */ public byte[] toPDF() { - String p = this.number + " " + this.generation - + " obj\n<< /Type /Info\n/Producer (" + this.producer - + ") >>\nendobj\n"; - return p.getBytes(); + String p = this.number + " " + this.generation + + " obj\n<< /Type /Info\n/Producer (" + this.producer + + ") >>\nendobj\n"; + return p.getBytes(); } + } diff --git a/src/org/apache/fop/pdf/PDFInternalLink.java b/src/org/apache/fop/pdf/PDFInternalLink.java index d715b91c3..f365b0544 100644 --- a/src/org/apache/fop/pdf/PDFInternalLink.java +++ b/src/org/apache/fop/pdf/PDFInternalLink.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -56,36 +12,35 @@ package org.apache.fop.pdf; */ public class PDFInternalLink extends PDFAction { - + String goToReference; /** * create an internal link instance. * - * @param goToReference the GoTo Reference to which the link should point + * @param goToReference the GoTo Reference to which the link should point */ public PDFInternalLink(String goToReference) { - this.goToReference=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() - { + public String getAction() { return goToReference; } /** - * there is nothing to return for the toPDF method, as it should not be called + * 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]; - } - + 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 index b8caaae86..6af94f1d8 100644 --- a/src/org/apache/fop/pdf/PDFLink.java +++ b/src/org/apache/fop/pdf/PDFLink.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -65,7 +21,7 @@ public class PDFLink extends PDFObject { float bry; String color; PDFAction action; - + /** * create objects associated with a link annotation (GoToR) * @@ -73,50 +29,48 @@ public class PDFLink extends PDFObject { * @param producer the application producing the PDF */ public PDFLink(int number, Rectangle r) { - /* generic creation of PDF object */ - super(number); - - this.ulx = r.x; - this.uly = r.y; - this.brx = r.x + r.width; - this.bry = r.y - r.height; - this.color = "0 0 0"; // just for now - + /* generic creation of PDF object */ + super(number); + + this.ulx = r.x; + this.uly = r.y; + this.brx = r.x + r.width; + this.bry = r.y - r.height; + this.color = "0 0 0"; // just for now + } public void setAction(PDFAction action) { - this.action = 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/1000f) + " " + (uly/1000f) + " " + - (brx/1000f) + " " + (bry/1000f) + " ]\n" - + "/C [ " + this.color + " ]\n" + - "/Border [ 0 0 0 ]\n" + - "/A " + this.action.getAction() + "\n" + - "/H /I\n>>\nendobj\n"; - return p.getBytes(); + String p = this.number + " " + this.generation + " obj\n" + + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ " + + (ulx / 1000f) + " " + (uly / 1000f) + " " + + (brx / 1000f) + " " + (bry / 1000f) + " ]\n" + "/C [ " + + 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 - */ + /* + * example + * 19 0 obj + * << + * /Type /Annot + * /Subtype /Link + * /Rect [ 176.032 678.48412 228.73579 692.356 ] + * /C [ 0.86491 0.03421 0.02591 ] + * /Border [ 0 0 1 ] + * /A 28 0 R + * /H /I + * >> + * endobj + */ } diff --git a/src/org/apache/fop/pdf/PDFNumber.java b/src/org/apache/fop/pdf/PDFNumber.java index c13e00ad4..deed898ac 100644 --- a/src/org/apache/fop/pdf/PDFNumber.java +++ b/src/org/apache/fop/pdf/PDFNumber.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -7,127 +8,99 @@ package org.apache.fop.pdf; public class PDFNumber { - - private PDFNumber() - { - } - - public static String doubleOut(Double doubleDown) - { - StringBuffer p = new StringBuffer(); - if(doubleDown.doubleValue() < 0) { - doubleDown = new Double(-doubleDown.doubleValue()); - p.append("-"); - } - double trouble = doubleDown.doubleValue() % 1; - if(trouble > 0.950) - { - p.append(doubleDown.intValue()+1); - } - else if (trouble < 0.050) - { - p.append(doubleDown.intValue()); - } - 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()); - } - - 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)); + private PDFNumber() {} - 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()); - } + public static String doubleOut(Double doubleDown) { + StringBuffer p = new StringBuffer(); + if (doubleDown.doubleValue() < 0) { + doubleDown = new Double(-doubleDown.doubleValue()); + p.append("-"); + } + double trouble = doubleDown.doubleValue() % 1; + if (trouble > 0.950) { + p.append(doubleDown.intValue() + 1); + } else if (trouble < 0.050) { + p.append(doubleDown.intValue()); + } else { + String doubleString = new String(doubleDown + ""); + int decimal = doubleString.indexOf("."); + if (decimal != -1) { + p.append(doubleString.substring(0, decimal)); - 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) > 6) { + p.append(doubleString.substring(decimal, decimal + 6)); + } else { + p.append(doubleString.substring(decimal)); + } + } else { + p.append(doubleString); + } + } + return (p.toString()); + } + + 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()); + } + + 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()); + } - 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 index 573923a6f..a20f358f0 100644 --- a/src/org/apache/fop/pdf/PDFObject.java +++ b/src/org/apache/fop/pdf/PDFObject.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -56,17 +13,21 @@ 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 */ + /** + * the object's number + */ protected int number; - /** the object's generation (0 in new documents) */ + /** + * the object's generation (0 in new documents) + */ protected int generation = 0; /** @@ -75,17 +36,20 @@ public abstract class PDFObject { * @param number the object's number */ public PDFObject(int number) { - this.number = number; + this.number = number; } - public PDFObject() { - //do nothing - } - /** - * @return the PDF Object number - */ - public int getNumber() { - return this.number; - } + + public PDFObject() { + // do nothing + } + + /** + * @return the PDF Object number + */ + public int getNumber() { + return this.number; + } + /** * write the PDF represention of this object * @@ -93,9 +57,9 @@ public abstract class PDFObject { * @return the number of bytes written */ protected int output(OutputStream stream) throws IOException { - byte[] pdf = this.toPDF(); - stream.write(pdf); - return pdf.length; + byte[] pdf = this.toPDF(); + stream.write(pdf); + return pdf.length; } /** @@ -104,8 +68,8 @@ public abstract class PDFObject { * @return the reference string */ public String referencePDF() { - String p = this.number + " " + this.generation + " R"; - return p; + String p = this.number + " " + this.generation + " R"; + return p; } /** diff --git a/src/org/apache/fop/pdf/PDFOutline.java b/src/org/apache/fop/pdf/PDFOutline.java index 0f4e8a1e6..ee5f3bc59 100644 --- a/src/org/apache/fop/pdf/PDFOutline.java +++ b/src/org/apache/fop/pdf/PDFOutline.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -63,156 +19,160 @@ import java.util.Vector; * */ -public class PDFOutline extends PDFObject -{ - - /** list of sub-entries (outline objects) */ +public class PDFOutline extends PDFObject { + + /** + * list of sub-entries (outline objects) + */ private Vector _subentries; - - /** parent outline object. Root Outlines parent is null */ + + /** + * 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 */ + + /** + * title to display for the bookmark entry + */ private String _title; - + String _actionRef; - - - + + + /** * @param number the object id number * @param title the title of the outline entry (can only be null for root Outlines obj) * @param page the page which this outline refers to. */ - public PDFOutline(int number, String title, String action) - { - super(number); - _subentries = new Vector(); - _count = 0; - _parent = null; - _prev = null; - _next = null; - _first = null; - _last = null; - _title = title; - _actionRef = action; - - + public PDFOutline(int number, String title, String action) { + super(number); + _subentries = new Vector(); + _count = 0; + _parent = null; + _prev = null; + _next = null; + _first = null; + _last = null; + _title = title; + _actionRef = action; + + } - - public void setTitle(String title) - { - _title = title; + + public void setTitle(String title) { + _title = title; } /** * Add a sub element to this outline */ - public void addOutline(PDFOutline outline) - { - if (_subentries.size() > 0) { - outline._prev = (PDFOutline)_subentries.elementAt(_subentries.size() - 1); - outline._prev._next = outline; - } - else { - _first = outline; - } - - _subentries.addElement(outline); - outline._parent = this; - - incrementCount(); // note: count is not just the immediate children - - _last = outline; + public void addOutline(PDFOutline outline) { + if (_subentries.size() > 0) { + outline._prev = + (PDFOutline)_subentries.elementAt(_subentries.size() - 1); + outline._prev._next = outline; + } else { + _first = outline; + } + + _subentries.addElement(outline); + outline._parent = this; + + incrementCount(); // note: count is not just the immediate children + + _last = outline; } - - private void incrementCount() - { - // count is a total of our immediate subentries and all descendent subentries - _count++; - if (_parent != null) { - _parent.incrementCount(); - } + + 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 */ - 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(); - + + + /** + * represent the object in PDF + */ + 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 parens, and other special chars for PDF */ - private String escapeString(String s) - { - StringBuffer result = new StringBuffer(); - if (s != null) { - int l = s.length(); - - for (int i = 0; i < l; i++) { - char ch = s.charAt(i); - if (ch > 127) { - result.append("\\"); - result.append(Integer.toOctalString((int) ch)); - } else { - switch (ch) { - case '(' : - case ')' : - case '\\' : - result.append('\\'); - break; - } - result.append(ch); - } - } - } - - return result.toString(); + + /** + * escape parens, and other special chars for PDF + */ + private String escapeString(String s) { + StringBuffer result = new StringBuffer(); + if (s != null) { + int l = s.length(); + + for (int i = 0; i < l; i++) { + char ch = s.charAt(i); + if (ch > 127) { + result.append("\\"); + result.append(Integer.toOctalString((int)ch)); + } else { + switch (ch) { + case '(': + case ')': + case '\\': + result.append('\\'); + break; + } + result.append(ch); + } + } + } + + return result.toString(); } - + } diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index e6838c1fd..4f9ae9d24 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -60,22 +17,34 @@ package org.apache.fop.pdf; */ public class PDFPage extends PDFObject { - /** the page's parent, a /Pages object */ + /** + * the page's parent, a /Pages object + */ protected PDFPages parent; - /** the page's /Resource object */ + /** + * the page's /Resource object + */ protected PDFResources resources; - /** the contents stream */ + /** + * the contents stream + */ protected PDFStream contents; - /** the width of the page in points */ + /** + * the width of the page in points + */ protected int pagewidth; - /** the height of the page in points */ + /** + * the height of the page in points + */ protected int pageheight; - /** the list of annotation objects for this page */ + /** + * the list of annotation objects for this page + */ protected PDFAnnotList annotList; /** @@ -87,20 +56,19 @@ public class PDFPage extends PDFObject { * @param pagewidth the page's width in points * @param pageheight the page's height in points */ - public PDFPage(int number, PDFResources resources, - PDFStream contents, int pagewidth, - int pageheight) { + public PDFPage(int number, PDFResources resources, PDFStream contents, + int pagewidth, int pageheight) { - /* generic creation of object */ - super(number); + /* generic creation of object */ + super(number); - /* set fields using parameters */ - this.resources = resources; - this.contents = contents; - this.pagewidth = pagewidth; - this.pageheight = pageheight; + /* set fields using parameters */ + this.resources = resources; + this.contents = contents; + this.pagewidth = pagewidth; + this.pageheight = pageheight; - this.annotList = null; + this.annotList = null; } /** @@ -109,16 +77,16 @@ public class PDFPage extends PDFObject { * @param parent the /Pages object that is this page's parent */ public void setParent(PDFPages parent) { - this.parent = parent; + this.parent = parent; } - + /** * set this page's annotation list * * @param annotList a PDFAnnotList list of annotations */ public void setAnnotList(PDFAnnotList annotList) { - this.annotList = annotList; + this.annotList = annotList; } /** @@ -127,34 +95,35 @@ public class PDFPage extends PDFObject { * @return annotList a PDFAnnotList list of annotations */ public PDFAnnotList getAnnotList() { - return this.annotList; + return this.annotList; + } + + public void addShading(PDFShading shading) { + this.resources.addShading(shading); } - public void addShading(PDFShading shading) { - this.resources.addShading(shading); - } /** * 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.referencePDF() + "\n" + - "/MediaBox [ 0 0 " + this.pagewidth + " " + - this.pageheight + " ]\n" + - "/Resources " + this.resources.referencePDF() + "\n" + - "/Contents " + this.contents.referencePDF() + "\n"); - if (this.annotList != null) { - sb = sb.append("/Annots " + - this.annotList.referencePDF() + "\n"); - } - - sb = sb.append(">>\nendobj\n"); - - return sb.toString().getBytes(); + StringBuffer sb = new StringBuffer(); + + sb = sb.append(this.number + " " + this.generation + " obj\n" + + "<< /Type /Page\n" + "/Parent " + + this.parent.referencePDF() + "\n" + + "/MediaBox [ 0 0 " + this.pagewidth + " " + + this.pageheight + " ]\n" + "/Resources " + + this.resources.referencePDF() + "\n" + "/Contents " + + this.contents.referencePDF() + "\n"); + if (this.annotList != null) { + sb = sb.append("/Annots " + this.annotList.referencePDF() + "\n"); + } + + sb = sb.append(">>\nendobj\n"); + + return sb.toString().getBytes(); } + } diff --git a/src/org/apache/fop/pdf/PDFPages.java b/src/org/apache/fop/pdf/PDFPages.java index 3c099dacb..cef40f1d3 100644 --- a/src/org/apache/fop/pdf/PDFPages.java +++ b/src/org/apache/fop/pdf/PDFPages.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -64,14 +21,18 @@ import java.util.Vector; */ public class PDFPages extends PDFObject { - /** the /Page objects */ + /** + * the /Page objects + */ protected Vector kids = new Vector(); - /** the number of /Page objects */ + /** + * the number of /Page objects + */ protected int count = 0; - // private PDFPages parent; - + // private PDFPages parent; + /** * create a /Pages object. * @@ -79,8 +40,8 @@ public class PDFPages extends PDFObject { */ public PDFPages(int number) { - /* generic creation of object */ - super(number); + /* generic creation of object */ + super(number); } /** @@ -89,8 +50,8 @@ public class PDFPages extends PDFObject { * @param page the PDFPage to add. */ public void addPage(PDFPage page) { - this.kids.addElement(page); - page.setParent(this); + this.kids.addElement(page); + page.setParent(this); this.incrementCount(); } @@ -100,14 +61,14 @@ public class PDFPages extends PDFObject { * @return the number of pages */ public int getCount() { - return this.count; + return this.count; } /** * increment the count of /Page objects */ public void incrementCount() { - this.count++; + this.count++; // MessageHandler.logln("Incrementing count to " + this.getCount()); } @@ -117,14 +78,14 @@ public class PDFPages extends PDFObject { * @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(((PDFObject)kids.elementAt(i)).referencePDF() + " "); - } - p = p.append("] >>\nendobj\n"); - return p.toString().getBytes(); + 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(((PDFObject)kids.elementAt(i)).referencePDF() + " "); + } + 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 index fd9c3eed8..2c2292823 100644 --- a/src/org/apache/fop/pdf/PDFPathPaint.java +++ b/src/org/apache/fop/pdf/PDFPathPaint.java @@ -1,86 +1,39 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import org.apache.fop.datatypes.ColorSpace; -public abstract class PDFPathPaint extends PDFObject -{ +public abstract class PDFPathPaint extends PDFObject { + + // protected int colorspace = 0; //default is 0:RGB, not 1:CMYK + protected ColorSpace colorSpace; + + public PDFPathPaint(int theNumber) { + super(theNumber); + + } + + public PDFPathPaint() { + // do nothing + } + + public String getColorSpaceOut(boolean fillNotStroke) { + return (""); + } + + public void setColorSpace(int theColorSpace) { + this.colorSpace.setColorSpace(theColorSpace); + } + + public int getColorSpace() { + return (this.colorSpace.getColorSpace()); + } - //protected int colorspace = 0; //default is 0:RGB, not 1:CMYK - protected ColorSpace colorSpace; - - public PDFPathPaint(int theNumber) { - super(theNumber); - - } - - public PDFPathPaint(){ - //do nothing - } - - public String getColorSpaceOut(boolean fillNotStroke) - { - return(""); - } - - public void setColorSpace(int theColorSpace) - { - this.colorSpace.setColorSpace(theColorSpace); - } - - 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 index 8e76e5fcc..3fa15d59b 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,10 +7,10 @@ package org.apache.fop.pdf; -//Java... +// Java... import java.util.Vector; -//FOP... +// FOP... import org.apache.fop.datatypes.ColorSpace; /** @@ -23,294 +24,274 @@ import org.apache.fop.datatypes.ColorSpace; * 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 - */ - //Guts common to all function types - - 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; - - /** - * Vector of Doubles representing the Bounding box rectangle - */ - protected Vector 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; - - /** - * Vector of Integers represetning the Extended unique Identifier - */ - protected Vector xUID=null; - - /** - * String representing the extended Graphics state. - * Probably will never be used like this. - */ - protected StringBuffer extGState = null; //eventually, need a PDFExtGSState object... but not now. - - /** - * Vector of Doubles representing the Transformation matrix. - */ - protected Vector 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 Vector of Doubles: The pattern cell bounding box - * @param theXStep horizontal spacing - * @param theYStep vertical spacing - * @param theMatrix Optional Vector 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, - Vector theBBox, double theXStep, double theYStep, - Vector theMatrix, Vector 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:Vector of Doubles that specify the matrix. - */ - public PDFPattern(int theNumber, String thePatternName, - int thePatternType, PDFShading theShading, Vector theXUID, - StringBuffer theExtGState,Vector 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); - } - - 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. - * - * @return the PDF string. - */ - public byte[] toPDF() { - - - 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"); - - 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.elementAt(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.elementAt(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.elementAt(tempInt))+" "); - } - p.append("] \n"); - } - //don't forget the length of the stream. - if(this.patternDataStream != null) - { - p.append("/Length "+(this.patternDataStream.length()+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.elementAt(tempInt))+" "); - } - p.append("] \n"); - } - - if(this.extGState != null) - {//will probably have to change this if it's used. - 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.elementAt(tempInt))); - p.append(" "); - } - p.append("] \n"); - } - }//end of if patterntype =1...else 2. - - p.append(">> \n"); - - //stream representing the function - if(this.patternDataStream != null) - { - p.append("stream\n"+this.patternDataStream +"\nendstream\n"); - } - - p.append("endobj\n"); - - - - return (p.toString().getBytes()); - - } + + /** + * The resources associated with this pattern + */ + // Guts common to all function types + + 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; + + /** + * Vector of Doubles representing the Bounding box rectangle + */ + protected Vector 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; + + /** + * Vector of Integers represetning the Extended unique Identifier + */ + protected Vector xUID = null; + + /** + * String representing the extended Graphics state. + * Probably will never be used like this. + */ + protected StringBuffer extGState = + null; // eventually, need a PDFExtGSState object... but not now. + + /** + * Vector of Doubles representing the Transformation matrix. + */ + protected Vector 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 Vector of Doubles: The pattern cell bounding box + * @param theXStep horizontal spacing + * @param theYStep vertical spacing + * @param theMatrix Optional Vector 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, Vector theBBox, double theXStep, + double theYStep, Vector theMatrix, Vector 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:Vector of Doubles that specify the matrix. + */ + public PDFPattern(int theNumber, String thePatternName, + int thePatternType, PDFShading theShading, + Vector theXUID, StringBuffer theExtGState, + Vector 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); + } + + 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. + * + * @return the PDF string. + */ + public byte[] toPDF() { + + + 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"); + + 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.elementAt(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.elementAt(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.elementAt(tempInt)) + " "); + } + p.append("] \n"); + } + // don't forget the length of the stream. + if (this.patternDataStream != null) { + p.append("/Length " + (this.patternDataStream.length() + 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.elementAt(tempInt)) + " "); + } + p.append("] \n"); + } + + if (this.extGState + != null) { // will probably have to change this if it's used. + 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.elementAt(tempInt))); + p.append(" "); + } + p.append("] \n"); + } + } // end of if patterntype =1...else 2. + + p.append(">> \n"); + + // stream representing the function + if (this.patternDataStream != null) { + p.append("stream\n" + this.patternDataStream + "\nendstream\n"); + } + + p.append("endobj\n"); + + + + return (p.toString().getBytes()); + + } + } diff --git a/src/org/apache/fop/pdf/PDFRectangle.java b/src/org/apache/fop/pdf/PDFRectangle.java index 24809d241..2dc04fb74 100644 --- a/src/org/apache/fop/pdf/PDFRectangle.java +++ b/src/org/apache/fop/pdf/PDFRectangle.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; /** @@ -56,52 +13,66 @@ package org.apache.fop.pdf; * 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; - } + /** + * 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 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]; - } + public String toPDFString() { + return new String(" [" + llx + " " + lly + " " + urx + " " + ury + + "] "); + } - /** - * produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - public String toPDFString() { - return new String(" [" + llx + " " + lly + " " + urx + " " + ury + "] "); - } } diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index b4612b704..d51b716e4 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -61,15 +18,18 @@ import java.util.Hashtable; * * /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 */ + /** + * /Font objects keyed by their internal name + */ protected Hashtable fonts = new Hashtable(); - protected Vector xObjects=null; - protected Vector patterns= new Vector(); - protected Vector shadings=new Vector(); + protected Vector xObjects = null; + protected Vector patterns = new Vector(); + protected Vector shadings = new Vector(); + /** * create a /Resources object. * @@ -77,9 +37,9 @@ public class PDFResources extends PDFObject { */ public PDFResources(int number) { - /* generic creation of object */ - super(number); - + /* generic creation of object */ + super(number); + } /** @@ -88,18 +48,19 @@ public class PDFResources extends PDFObject { * @param font the PDFFont to add */ public void addFont(PDFFont font) { - this.fonts.put(font.getName(),font); + this.fonts.put(font.getName(), font); } - - public void addShading(PDFShading theShading){ - this.shadings.addElement(theShading); - } - - public void addPattern(PDFPattern thePattern){ - this.patterns.addElement(thePattern); - } + + public void addShading(PDFShading theShading) { + this.shadings.addElement(theShading); + } + + public void addPattern(PDFPattern thePattern) { + this.patterns.addElement(thePattern); + } + public void setXObjects(Vector xObjects) { - this.xObjects = xObjects; + this.xObjects = xObjects; } /** @@ -107,86 +68,77 @@ public class PDFResources extends PDFObject { * * @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 */ - Enumeration fontEnumeration = this.fonts.keys(); - while (fontEnumeration.hasMoreElements()) { - String fontName = (String) fontEnumeration.nextElement(); - p.append("/" + fontName + " " - + ((PDFFont) this.fonts.get(fontName)).referencePDF() - + " "); - } - - p.append(">> \n"); - } - - PDFShading currentShading = null; - if(!this.shadings.isEmpty()) - { - p.append("/Shading << "); - - for(int currentShadingNumber=0; - currentShadingNumber < this.shadings.size(); - currentShadingNumber++) - { - currentShading = ((PDFShading)this.shadings.elementAt(currentShadingNumber)); - - 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(int currentPatternNumber=0; - currentPatternNumber < this.patterns.size(); - currentPatternNumber++) - { - currentPattern = ((PDFPattern)this.patterns.elementAt(currentPatternNumber)); - - p.append("/" + currentPattern.getName() + " " - + currentPattern.referencePDF() - + " "); - } - - p.append(">> \n"); - } - //"free" the memory. Sorta. - currentPattern = null; - - p.append("/ProcSet [ /PDF /ImageC /Text ] "); - - if (!this.xObjects.isEmpty()) - { - p = p.append("/XObject <<"); - for (int i = 1; i <= this.xObjects.size(); i++) { - p = p.append("/Im" + i + " " + - ((PDFXObject) - this.xObjects.elementAt(i - - 1)).referencePDF() - + - " \n"); - } - p = p.append(" >>\n"); - } - - p = p.append(">> \nendobj\n"); - - return p.toString().getBytes(); - } + 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 */ + Enumeration fontEnumeration = this.fonts.keys(); + while (fontEnumeration.hasMoreElements()) { + String fontName = (String)fontEnumeration.nextElement(); + p.append("/" + fontName + " " + + ((PDFFont)this.fonts.get(fontName)).referencePDF() + + " "); + } + + p.append(">> \n"); + } + + PDFShading currentShading = null; + if (!this.shadings.isEmpty()) { + p.append("/Shading << "); + + for (int currentShadingNumber = 0; + currentShadingNumber < this.shadings.size(); + currentShadingNumber++) { + currentShading = + ((PDFShading)this.shadings.elementAt(currentShadingNumber)); + + 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 (int currentPatternNumber = 0; + currentPatternNumber < this.patterns.size(); + currentPatternNumber++) { + currentPattern = + ((PDFPattern)this.patterns.elementAt(currentPatternNumber)); + + p.append("/" + currentPattern.getName() + " " + + currentPattern.referencePDF() + " "); + } + + p.append(">> \n"); + } + // "free" the memory. Sorta. + currentPattern = null; + + p.append("/ProcSet [ /PDF /ImageC /Text ] "); + + if (!this.xObjects.isEmpty()) { + p = p.append("/XObject <<"); + for (int i = 1; i <= this.xObjects.size(); i++) { + p = p.append("/Im" + i + " " + + ((PDFXObject)this.xObjects.elementAt(i - 1)).referencePDF() + + " \n"); + } + 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 index f31543eab..1850fbf94 100644 --- a/src/org/apache/fop/pdf/PDFRoot.java +++ b/src/org/apache/fop/pdf/PDFRoot.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; // Java @@ -59,10 +16,14 @@ import java.io.PrintWriter; */ public class PDFRoot extends PDFObject { - /** the /Pages object that is root of the Pages hierarchy */ + /** + * the /Pages object that is root of the Pages hierarchy + */ protected PDFPages rootPages; - /** Root outline object */ + /** + * Root outline object + */ private PDFOutline _outline; /** @@ -71,7 +32,7 @@ public class PDFRoot extends PDFObject { * @param number the object's number */ public PDFRoot(int number) { - super(number); + super(number); } /** @@ -80,7 +41,7 @@ public class PDFRoot extends PDFObject { * @param page the /Page object to add */ public void addPage(PDFPage page) { - this.rootPages.addPage(page); + this.rootPages.addPage(page); } /** @@ -89,12 +50,11 @@ public class PDFRoot extends PDFObject { * @param pages the /Pages object to set as root */ public void setRootPages(PDFPages pages) { - this.rootPages = pages; + this.rootPages = pages; } - public void setRootOutline(PDFOutline outline) - { - _outline = outline; + public void setRootOutline(PDFOutline outline) { + _outline = outline; } @@ -104,15 +64,17 @@ public class PDFRoot extends PDFObject { * @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"); - - } - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + 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"); + + } + 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 index 47ff4cd17..a1a1a9be0 100644 --- a/src/org/apache/fop/pdf/PDFShading.java +++ b/src/org/apache/fop/pdf/PDFShading.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,543 +7,505 @@ package org.apache.fop.pdf; -//Java... +// Java... import java.util.Vector; -//FOP +// FOP import org.apache.fop.datatypes.ColorSpace; /** * 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 StringBuffer colorSpace = null; - protected ColorSpace colorSpace=null; - /** - * The background color. Since shading is opaque, - * this is very rarely used. - */ - protected Vector background = null; - /** - * Optional: A Vector specifying the clipping rectangle - */ - protected Vector 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 Vector domain = null; - - /** Optional for Type 1: A transformation matrix */ - protected Vector 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 Vector 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 Vector 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 Vector 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 Vector 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 Vector 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, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - Vector theDomain, Vector 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 Vector 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 Vector of four (type 2) or 6 (type 3) Double - * @param theDomain Vector of Doubles specifying the domain - * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function - * @param theExtend Vector of Booleans of whether to extend teh start and end colors past the start and end points - * The default is [false, false] - */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - Vector theCoords, Vector theDomain, PDFFunction theFunction, - Vector 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 Vector 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 Vector of Doubles see PDF 1.3 spec pages 303 to 312. - * @param theFunction the PDFFunction - */ - public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - int theBitsPerCoordinate, int theBitsPerComponent, - int theBitsPerFlag, Vector 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 Vector 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 Vector 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, ColorSpace theColorSpace, - Vector theBackground, Vector theBBox, boolean theAntiAlias, - int theBitsPerCoordinate, int theBitsPerComponent, - Vector 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; - - } - - 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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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()); - } + // 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 StringBuffer colorSpace = null; + protected ColorSpace colorSpace = null; + + /** + * The background color. Since shading is opaque, + * this is very rarely used. + */ + protected Vector background = null; + + /** + * Optional: A Vector specifying the clipping rectangle + */ + protected Vector 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 Vector domain = null; + + /** + * Optional for Type 1: A transformation matrix + */ + protected Vector 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 Vector 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 Vector 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 Vector 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 Vector 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 Vector 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, ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, Vector theDomain, + Vector 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 Vector 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 Vector of four (type 2) or 6 (type 3) Double + * @param theDomain Vector of Doubles specifying the domain + * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function + * @param theExtend Vector of Booleans of whether to extend teh start and end colors past the start and end points + * The default is [false, false] + */ + public PDFShading(int theNumber, String theShadingName, + int theShadingType, ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, Vector theCoords, + Vector theDomain, PDFFunction theFunction, + Vector 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 Vector 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 Vector of Doubles see PDF 1.3 spec pages 303 to 312. + * @param theFunction the PDFFunction + */ + public PDFShading(int theNumber, String theShadingName, + int theShadingType, ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, int theBitsPerCoordinate, + int theBitsPerComponent, int theBitsPerFlag, + Vector 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 Vector 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 Vector 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, ColorSpace theColorSpace, + Vector theBackground, Vector theBBox, + boolean theAntiAlias, int theBitsPerCoordinate, + int theBitsPerComponent, Vector 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; + + } + + 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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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.elementAt(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()); + } + } diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index ccf22db75..01b87b9d6 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; @@ -60,7 +17,7 @@ import org.apache.fop.messaging.MessageHandler; /** * class representing a PDF stream. - * + * * 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 @@ -68,21 +25,25 @@ import org.apache.fop.messaging.MessageHandler; */ public class PDFStream extends PDFObject { - /** the stream of PDF commands */ + /** + * the stream of PDF commands + */ protected ByteArrayOutputStream _data; - /** the filters that should be applied */ + /** + * the filters that should be applied + */ private Vector _filters; - + /** * create an empty stream object * * @param number the object's number */ public PDFStream(int number) { - super(number); - _data = new ByteArrayOutputStream(); - _filters = new Vector(); + super(number); + _data = new ByteArrayOutputStream(); + _filters = new Vector(); } /** @@ -91,77 +52,68 @@ public class PDFStream extends PDFObject { * @param s the string of PDF to add */ public void add(String s) { - try { - _data.write(s.getBytes()); - } - catch (IOException ex) { - ex.printStackTrace(); - } - + try { + _data.write(s.getBytes()); + } catch (IOException ex) { + ex.printStackTrace(); + } + } /** * Add a filter for compression of the stream. Filters are - * applied in the order they are added. This should always be a + * 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. */ - public void addFilter(PDFFilter filter) - { - if (filter != null) { - _filters.addElement(filter); - } + public void addFilter(PDFFilter filter) { + if (filter != null) { + _filters.addElement(filter); + } } - 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 { - MessageHandler.errorln("Unsupported filter type in stream-filter-list: "+filterType); - } + 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 { + MessageHandler.errorln("Unsupported filter type in stream-filter-list: " + + filterType); + } } - - - protected void addDefaultFilters() - { - Vector filters = Configuration.getListValue("stream-filter-list", - Configuration.PDF); - if (filters == null) { - // try getting it as a String - String filter = Configuration.getStringValue("stream-filter-list", - Configuration.PDF); - if (filter == null) { - // built-in default to flate - addFilter(new FlateFilter()); - } - else { - addFilter(filter); - } - } - else { - for (int i=0; i < filters.size(); i++) { - String v = (String)filters.elementAt(i); - addFilter(v); - } - } + + + protected void addDefaultFilters() { + Vector filters = Configuration.getListValue("stream-filter-list", + Configuration.PDF); + if (filters == null) { + // try getting it as a String + String filter = Configuration.getStringValue("stream-filter-list", + Configuration.PDF); + if (filter == null) { + // built-in default to flate + addFilter(new FlateFilter()); + } else { + addFilter(filter); + } + } else { + for (int i = 0; i < filters.size(); i++) { + String v = (String)filters.elementAt(i); + addFilter(v); + } + } } - + /** * append an array of xRGB pixels, ASCII Hex Encoding it first @@ -171,117 +123,110 @@ public class PDFStream extends PDFObject { * @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.write('0'); - } - _data.write(Integer.toHexString(r).getBytes()); - if (g < 16) { - _data.write('0'); - } - _data.write(Integer.toHexString(g).getBytes()); - if (b < 16) { - _data.write('0'); - } - _data.write(Integer.toHexString(b).getBytes()); - _data.write(' '); - } - } - _data.write(">\n".getBytes()); - } - catch (IOException ex) { - ex.printStackTrace(); - } - + 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.write('0'); + } + _data.write(Integer.toHexString(r).getBytes()); + if (g < 16) { + _data.write('0'); + } + _data.write(Integer.toHexString(g).getBytes()); + if (b < 16) { + _data.write('0'); + } + _data.write(Integer.toHexString(b).getBytes()); + _data.write(' '); + } + } + _data.write(">\n".getBytes()); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void setData(byte[] data) - throws IOException - { - _data.reset(); - _data.write(data); + public void setData(byte[] data) throws IOException { + _data.reset(); + _data.write(data); } - - public byte[] getData() - { - return _data.toByteArray(); + + public byte[] getData() { + return _data.toByteArray(); } - - public int getDataLength() - { - return _data.size(); + + public int getDataLength() { + return _data.size(); } - - + + /** * represent as PDF. * * @return the PDF string. - */ + */ /* + * public byte[] toPDF() { + * 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(); + * } + */ public byte[] toPDF() { - 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(); - } - */ - public byte[] toPDF() { - throw new RuntimeException(); + throw new RuntimeException(); } - - // overload the base object method so we don't have to copy + + // overload the base object method so we don't have to copy // byte arrays around so much - protected int output(OutputStream stream) throws IOException - { - int length = 0; - String filterEntry = applyFilters(); - byte[] p = (this.number + " " + this.generation - + " obj\n<< /Length " + (_data.size()+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; - + protected int output(OutputStream stream) throws IOException { + int length = 0; + String filterEntry = applyFilters(); + byte[] p = (this.number + " " + this.generation + " obj\n<< /Length " + + (_data.size() + 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 */ - protected int outputStreamData(OutputStream stream) throws IOException - { - int length = 0; - byte[] p ="stream\n".getBytes(); - stream.write(p); - length += p.length; - _data.writeTo(stream); - length += _data.size(); - p = "\nendstream\n".getBytes(); - stream.write(p); - length += p.length; - return length; - + protected int outputStreamData(OutputStream stream) throws IOException { + int length = 0; + byte[] p = "stream\n".getBytes(); + stream.write(p); + length += p.length; + _data.writeTo(stream); + length += _data.size(); + 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 @@ -289,86 +234,81 @@ public class PDFStream extends PDFObject { * been applied to the data (either externally, or internally) * then the dictionary entries are built and returned. */ - protected String applyFilters() throws IOException - { - if (_filters.size() > 0) { - Vector names = new Vector(); - Vector parms = new Vector(); - - // run the filters - Enumeration e = _filters.elements(); - while (e.hasMoreElements()) { - PDFFilter filter = (PDFFilter)e.nextElement(); - // apply the filter encoding if neccessary - if (!filter.isApplied()) { - byte[] tmp = filter.encode(_data.toByteArray()); - _data.reset(); - _data.write(tmp); - filter.setApplied(true); - } - // place the names in our local vector in reverse order - names.insertElementAt(filter.getName(), 0); - parms.insertElementAt(filter.getDecodeParms(), 0); - } - - // now build up the filter entries for the dictionary - return buildFilterEntries(names) + buildDecodeParms(parms); - } - return ""; - + protected String applyFilters() throws IOException { + if (_filters.size() > 0) { + Vector names = new Vector(); + Vector parms = new Vector(); + + // run the filters + Enumeration e = _filters.elements(); + while (e.hasMoreElements()) { + PDFFilter filter = (PDFFilter)e.nextElement(); + // apply the filter encoding if neccessary + if (!filter.isApplied()) { + byte[] tmp = filter.encode(_data.toByteArray()); + _data.reset(); + _data.write(tmp); + filter.setApplied(true); + } + // place the names in our local vector in reverse order + names.insertElementAt(filter.getName(), 0); + parms.insertElementAt(filter.getDecodeParms(), 0); + } + + // now build up the filter entries for the dictionary + return buildFilterEntries(names) + buildDecodeParms(parms); + } + return ""; + } - - private String buildFilterEntries(Vector names) - { - StringBuffer sb = new StringBuffer(); - sb.append("/Filter "); - if (names.size() > 1) { - sb.append("[ "); - } - Enumeration e = names.elements(); - while (e.hasMoreElements()) { - sb.append((String)e.nextElement()); - sb.append(" "); - } - if (names.size() > 1) { - sb.append("]"); - } - sb.append("\n"); - return sb.toString(); + + private String buildFilterEntries(Vector names) { + StringBuffer sb = new StringBuffer(); + sb.append("/Filter "); + if (names.size() > 1) { + sb.append("[ "); + } + Enumeration e = names.elements(); + while (e.hasMoreElements()) { + sb.append((String)e.nextElement()); + sb.append(" "); + } + if (names.size() > 1) { + sb.append("]"); + } + sb.append("\n"); + return sb.toString(); } - private String buildDecodeParms(Vector parms) - { - StringBuffer sb = new StringBuffer(); - boolean needParmsEntry = false; - sb.append("/DecodeParms "); - - if (parms.size() > 1) { - sb.append("[ "); - } - Enumeration e = parms.elements(); - while (e.hasMoreElements()) { - String s = (String)e.nextElement(); - 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 ""; - } + private String buildDecodeParms(Vector parms) { + StringBuffer sb = new StringBuffer(); + boolean needParmsEntry = false; + sb.append("/DecodeParms "); + + if (parms.size() > 1) { + sb.append("[ "); + } + Enumeration e = parms.elements(); + while (e.hasMoreElements()) { + String s = (String)e.nextElement(); + 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 index 644831370..8de99f260 100644 --- a/src/org/apache/fop/pdf/PDFT1Stream.java +++ b/src/org/apache/fop/pdf/PDFT1Stream.java @@ -1,154 +1,107 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; public class PDFT1Stream extends PDFStream { - private int origLength; - private int len1, len3; - private byte[] originalData=null; - - public PDFT1Stream(int num, int len) { - super(num); - origLength=len; - } + private int origLength; + private int len1, len3; + private byte[] originalData = null; - private final static boolean byteCmp(byte[] src, int offset, byte[] cmp) { - boolean ret=true; - for (int i=0; ret==true && i < cmp.length; i++) { - //System.out.println("Compare: "); - //System.out.println(" "+src[offset+i]+" "+cmp[i]); - if (src[offset+i]!=cmp[i]) - ret=false; - } - return ret; - } + public PDFT1Stream(int num, int len) { + super(num); + origLength = len; + } - /** - * calculates the Length1 and Length3 PDFStream attributes for type1 - * font embedding - */ - private void calcLengths(byte[] originalData) { - // Calculate length 1 and 3 - //System.out.println ("Checking font, size = "+originalData.length); - - // Length1 is the size of the initial ascii portion - // search for "currentfile eexec" - // Get the first binary number and search backwards for "eexec" - len1=30; + private final static boolean byteCmp(byte[] src, int offset, byte[] cmp) { + boolean ret = true; + for (int i = 0; ret == true && i < cmp.length; i++) { + // System.out.println("Compare: "); + // System.out.println(" "+src[offset+i]+" "+cmp[i]); + if (src[offset + i] != cmp[i]) + ret = false; + } + return ret; + } - byte[] eexec=(new String("currentfile eexec")).getBytes(); - //System.out.println("Length1="+len1); - while (!byteCmp(originalData, len1-eexec.length, eexec)) - len1++; - // Skip newline - len1++; + /** + * calculates the Length1 and Length3 PDFStream attributes for type1 + * font embedding + */ + private void calcLengths(byte[] originalData) { + // Calculate length 1 and 3 + // System.out.println ("Checking font, size = "+originalData.length); + + // Length1 is the size of the initial ascii portion + // search for "currentfile eexec" + // Get the first binary number and search backwards for "eexec" + len1 = 30; + + byte[] eexec = (new String("currentfile eexec")).getBytes(); + // System.out.println("Length1="+len1); + while (!byteCmp(originalData, len1 - eexec.length, eexec)) + len1++; + // Skip newline + len1++; + + // Length3 is length of the last portion of the file + len3 = 0; + byte[] cltom = (new String("cleartomark")).getBytes(); + len3 -= cltom.length; + while (!byteCmp(originalData, origLength + len3, cltom)) { + len3--; + // System.out.println("Len3="+len3); + } + len3 = -len3; + len3++; + // Eat 512 zeroes + int numZeroes = 0; + byte[] ws1 = "\n".getBytes(); + byte[] ws2 = "\r".getBytes(); + byte[] ws3 = "0".getBytes(); + while ((originalData[origLength - len3] == ws1[0] || originalData[origLength - len3] == ws2[0] || originalData[origLength - len3] == ws3[0]) + && numZeroes < 512) { + len3++; + if (originalData[origLength - len3] == ws3[0]) + numZeroes++; + } + // System.out.println("Length3="+len3); + } + + // overload the base object method so we don't have to copy + // byte arrays around so much + 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.size() + 1) + " " + filterEntry + + " " + "/Length1 " + len1 + " /Length2 " + + (origLength - len3 - len1) + + " /Length3 " + len3 + " >>\n"); - // Length3 is length of the last portion of the file - len3=0; - byte[] cltom=(new String("cleartomark")).getBytes(); - len3 -= cltom.length; - while (!byteCmp(originalData, origLength+len3, cltom)) { - len3--; - //System.out.println("Len3="+len3); - } - len3 = -len3; - len3++; - // Eat 512 zeroes - int numZeroes=0; - byte[] ws1="\n".getBytes(); - byte[] ws2="\r".getBytes(); - byte[] ws3="0".getBytes(); - while ((originalData[origLength-len3]==ws1[0] || - originalData[origLength-len3]==ws2[0] || - originalData[origLength-len3]==ws3[0]) && numZeroes < 512) { - len3++; - if (originalData[origLength-len3]==ws3[0]) - numZeroes++; - } - //System.out.println("Length3="+len3); - } - - // overload the base object method so we don't have to copy - // byte arrays around so much - 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.size()+1) + " " - + filterEntry + " " + - "/Length1 " + len1 + - " /Length2 " + (origLength-len3 -len1) + - " /Length3 " + len3 + - " >>\n"); - byte[] p = preData.getBytes(); stream.write(p); length += p.length; - length += outputStreamData(stream); - p = "endobj\n".getBytes(); - stream.write(p); - length += p.length; + length += outputStreamData(stream); + p = "endobj\n".getBytes(); + stream.write(p); + length += p.length; System.out.println("Embedded Type1 font"); - return length; + return length; + } + + public void setData(byte[] data, int size) throws java.io.IOException { + calcLengths(data); + _data.reset(); + // System.out.println("Writing " + size + " bytes of font data"); + _data.write(data, 0, size); } - public void setData(byte[] data, int size) - throws java.io.IOException { - calcLengths(data); - _data.reset(); - //System.out.println("Writing " + size + " bytes of font data"); - _data.write(data, 0, size); - } } diff --git a/src/org/apache/fop/pdf/PDFTTFStream.java b/src/org/apache/fop/pdf/PDFTTFStream.java index 1b17e02f8..f56e5f587 100644 --- a/src/org/apache/fop/pdf/PDFTTFStream.java +++ b/src/org/apache/fop/pdf/PDFTTFStream.java @@ -1,91 +1,47 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; public class PDFTTFStream extends PDFStream { - private int origLength; - - 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 - 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.size()+1) + " " - + filterEntry + " " + - "/Length1 " + origLength + - " >>\n"); - + private int origLength; + + 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 + 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.size() + 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; + length += outputStreamData(stream); + p = "endobj\n".getBytes(); + stream.write(p); + length += p.length; + return length; + } + + public void setData(byte[] data, int size) throws java.io.IOException { + _data.reset(); + System.out.println("Writing " + size + " bytes of font data"); + _data.write(data, 0, size); } - public void setData(byte[] data, int size) - throws java.io.IOException { - _data.reset(); - System.out.println("Writing " + size + " bytes of font data"); - _data.write(data, 0, size); - } } diff --git a/src/org/apache/fop/pdf/PDFUri.java b/src/org/apache/fop/pdf/PDFUri.java index 9709fa684..85c1838b8 100644 --- a/src/org/apache/fop/pdf/PDFUri.java +++ b/src/org/apache/fop/pdf/PDFUri.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.pdf; @@ -56,36 +12,35 @@ package org.apache.fop.pdf; */ public class PDFUri extends PDFAction { - + String uri; /** * create a Uri instance. * - * @param uri the uri to which the link should point + * @param uri the uri to which the link should point */ public PDFUri(String uri) { - this.uri=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 >>"; + public String getAction() { + return "<< /URI (" + uri + ")\n/S /URI >>"; } /** - * there is nothing to return for the toPDF method, as it should not be called + * 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]; - } - + 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 index be1ed8b8e..a391f45f3 100644 --- a/src/org/apache/fop/pdf/PDFWArray.java +++ b/src/org/apache/fop/pdf/PDFWArray.java @@ -1,53 +1,10 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.pdf; import java.util.Vector; @@ -57,88 +14,100 @@ import java.util.Vector; */ public class PDFWArray { - /** the metrics */ - private Vector entries; - - public PDFWArray() { - entries = new Vector(); - } - - /** - * 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.addElement(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.addElement(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.addElement(new int[] {first, last, width, posX, posY}); - } - - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - public String toPDFString() { - StringBuffer p = new StringBuffer(); - p.append("[ "); - int len = entries.size(); - for (int i = 0; i<len; i++) { - Object entry = entries.elementAt(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 static final StringBuffer p = new StringBuffer(); - 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("] "); - } - } + /** + * the metrics + */ + private Vector entries; + + public PDFWArray() { + entries = new Vector(); + } + + /** + * 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.addElement(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.addElement(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.addElement(new int[] { + first, last, width, posX, posY + }); + } + + public byte[] toPDF() { + return toPDFString().getBytes(); + } + + public String toPDFString() { + StringBuffer p = new StringBuffer(); + p.append("[ "); + int len = entries.size(); + for (int i = 0; i < len; i++) { + Object entry = entries.elementAt(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 static final StringBuffer p = new StringBuffer(); + 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 index 372468cf7..62e964afd 100644 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ b/src/org/apache/fop/pdf/PDFXObject.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -34,95 +35,100 @@ public class PDFXObject extends PDFObject { /** * create an Xobject with the given number and name and load the - * image in the object + * image in the object */ - public PDFXObject(int number,int Xnumber,FopImage img) { - super(number); - this.Xnum=Xnumber; - if (img == null) - MessageHandler.errorln("FISH"); - fopimage=img; + public PDFXObject(int number, int Xnumber, FopImage img) { + super(number); + this.Xnum = Xnumber; + if (img == null) + MessageHandler.errorln("FISH"); + fopimage = img; } - /** - * @return the PDF XObject number - */ - public int getXNumber() { - return this.Xnum; - } + /** + * @return the PDF XObject number + */ + public int getXNumber() { + return this.Xnum; + } /** * represent as PDF */ protected int output(OutputStream stream) throws IOException { - int length=0; - int i=0; - int x,y; - - try { - // delegate the stream work to PDFStream - PDFStream imgStream = new PDFStream(0); - - imgStream.setData(fopimage.getBitmaps()); - // imgStream.addFilter(new FlateFilter()); - imgStream.addDefaultFilters(); - - 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(); - p = p + "/Width " + fopimage.getWidth() + "\n"; - p = p + "/Height " + fopimage.getHeight() + "\n"; - p = p + "/BitsPerComponent " + fopimage.getBitsPerPixel() + "\n"; - ColorSpace cs = fopimage.getColorSpace(); - p = p + "/ColorSpace /" + cs.getColorSpacePDFString() + "\n"; - if (fopimage.isTransparent()) { - PDFColor transp = fopimage.getTransparentColor(); - p = p + "/Mask [" + transp.red255() + " " + transp.red255() + " " + transp.green255() + " " + transp.green255() + " " + transp.blue255() + " " + transp.blue255() + "]\n"; + int length = 0; + int i = 0; + int x, y; + + try { + // delegate the stream work to PDFStream + PDFStream imgStream = new PDFStream(0); + + imgStream.setData(fopimage.getBitmaps()); + // imgStream.addFilter(new FlateFilter()); + imgStream.addDefaultFilters(); + + 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(); + p = p + "/Width " + fopimage.getWidth() + "\n"; + p = p + "/Height " + fopimage.getHeight() + "\n"; + p = p + "/BitsPerComponent " + fopimage.getBitsPerPixel() + "\n"; + ColorSpace cs = fopimage.getColorSpace(); + p = p + "/ColorSpace /" + cs.getColorSpacePDFString() + "\n"; + if (fopimage.isTransparent()) { + PDFColor transp = fopimage.getTransparentColor(); + p = p + "/Mask [" + transp.red255() + " " + transp.red255() + + " " + transp.green255() + " " + transp.green255() + " " + + transp.blue255() + " " + transp.blue255() + "]\n"; + } + p = p + dictEntries; + p = p + ">>\n"; + + // don't know if it's the good place (other objects can have references to it) + fopimage.close(); + + // 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; + } catch (FopImageException imgex) { + MessageHandler.errorln("Error in XObject : " + + imgex.getMessage()); + } + + return length; } - p = p + dictEntries; - p = p + ">>\n"; - - // don't know if it's the good place (other objects can have references to it) - fopimage.close(); - - // 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; - } catch (FopImageException imgex) { - MessageHandler.errorln("Error in XObject : " + imgex.getMessage()); - } - - return length; - } - + byte[] toPDF() { -/* Not used any more - 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 + "/Width "+fopimage.getpixelwidth()+"\n"; - p = p + "/Height "+fopimage.getpixelheight()+"\n"; - p = p + "/BitsPerComponent 8\n"; - if (fopimage.getcolor()) - p = p + "/ColorSpace /DeviceRGB\n"; - else - p = p + "/ColorSpace /DeviceGray\n"; - p = p + "/Filter /ASCIIHexDecode\n"; - p = p + "/Length "; - return p; -*/ - return null; + /* + * Not used any more + * 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 + "/Width "+fopimage.getpixelwidth()+"\n"; + * p = p + "/Height "+fopimage.getpixelheight()+"\n"; + * p = p + "/BitsPerComponent 8\n"; + * if (fopimage.getcolor()) + * p = p + "/ColorSpace /DeviceRGB\n"; + * else + * p = p + "/ColorSpace /DeviceGray\n"; + * p = p + "/Filter /ASCIIHexDecode\n"; + * p = p + "/Length "; + * return p; + */ + return null; } + } |