Submitted by: Michal Buchtik <BuchtikM@dlsystem.cz>
- Added support for background-image
Submitted by: Michael Gratton <mjg@recalldesign.com>
+- Fixed PDF-Renderer to work on EBCDIC systems
+ (Actually on systems where file.encoding != ASCII/ISO-8859)
+ Submitted by: Jason West <Jason.West@mail.state.ky.us>
+
==============================================================================
Done since 0.20.2 release
*** General
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
public class ASCII85Filter extends PDFFilter {
private static final char ASCII85_ZERO = 'z';
}
// finally write the two character end of data marker
- buffer.write(ASCII85_EOD.getBytes(), 0,
- ASCII85_EOD.getBytes().length);
-
-
+ byte[] eod;
+ try {
+ eod = ASCII85_EOD.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ eod = ASCII85_EOD.getBytes();
+ }
+ buffer.write(eod, 0, eod.length);
byte[] result = buffer.toByteArray();
-
// assert that we have the correct outgoing length
/*
* int in = (data.length % 4);
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
public class ASCIIHexFilter extends PDFFilter {
private static final String ASCIIHEX_EOD = ">";
}
buffer.append(ASCIIHEX_EOD);
- return buffer.toString().getBytes();
-
+ try {
+ return buffer.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return buffer.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
// Java
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
/**
+ "\n");
}
p = p.append("]\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
/*
package org.apache.fop.pdf;
+//Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing an array object
*/
p.append(values[i]);
}
p.append("]\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
// based on work by Takayuki Takeuchi
/**
* @return the PDF
*/
public byte[] toPDF() {
- return toPDFString().getBytes();
+ try {
+ return toPDFString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return toPDFString().getBytes();
+ }
}
public String toPDFString() {
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
// based on work by Takayuki Takeuchi
/**
* @return the PDF
*/
public byte[] toPDF() {
- return toPDFString().getBytes();
+ try {
+ return toPDFString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return toPDFString().getBytes();
+ }
}
public String toPDFString() {
// Java
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
*/
protected Vector pendingLinks = null;
+ /**
+ * Encoding of the PDF
+ */
+ public static final String ENCODING = "ISO-8859-1";
+
/**
* creates an empty PDF document <p>
*
throws IOException {
this.position=0;
- byte[] pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes();
+ byte[] pdf;
+ try {
+ pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes();
+ }
stream.write(pdf);
this.position += pdf.length;
"%%EOF\n";
/* write the trailer */
- stream.write(pdf.getBytes());
+ byte[] trailer;
+ try {
+ trailer = pdf.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ trailer = pdf.getBytes();
+ }
+ stream.write(trailer);
}
/**
}
/* write the xref table and return the character length */
- byte[] pdfBytes = pdf.toString().getBytes();
+ byte[] pdfBytes;
+ try {
+ pdfBytes = pdf.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ pdfBytes = pdf.toString().getBytes();
+ }
stream.write(pdfBytes);
return pdfBytes.length;
}
package org.apache.fop.pdf;
// Java
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
p.append(" ]");
}
p.append(" >>\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
/*
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a /FileSpec object.
*
String p = new String(this.number + " " + this.generation
+ " obj\n<<\n/Type /FileSpec\n" + "/F ("
+ this.filename + ")\n" + ">>\nendobj\n");
- return p.getBytes();
+
+ try {
+ return p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.getBytes();
+ }
}
/*
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a /Font object.
*
}
fillInPDF(p);
p.append(" >>\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
/**
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a font descriptor.
*
// CID optional field
fillInPDF(p);
p.append("\n >>\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
/**
// Java...
import java.util.Vector;
+import java.io.UnsupportedEncodingException;
/**
* class representing a PDF Function.
}
- return (p.toString().getBytes());
-
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a /GoTo object.
*
String p = new String(this.number + " " + this.generation
+ " obj\n<<\n/S /GoTo\n" + destination
+ ">>\nendobj\n");
- return p.getBytes();
+
+ try {
+ return p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.getBytes();
+ }
}
/*
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a /GoToR object.
*/
+ pdfFileSpec.referencePDF() + "\n"
+ "/D [ 0 /XYZ null null null ]"
+ " \n>>\nendobj\n");
- return p.getBytes();
+
+ try {
+ return p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.getBytes();
+ }
}
*/
package org.apache.fop.pdf;
+
+// Java
+import java.io.UnsupportedEncodingException;
+// Fop
import org.apache.fop.datatypes.ColorSpace;
public class PDFICCStream extends PDFStream {
pb.append("/Length ").append((_data.size() + 1)).append(" ").append(filterEntry);
pb.append(" >>\n");
- byte[] p = pb.toString().getBytes();
+ byte[] p;
+ try {
+ p = pb.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = pb.toString().getBytes();
+ }
stream.write(p);
length += p.length;
length += outputStreamData(stream);
- p = "endobj\n".getBytes();
+ try {
+ p = "endobj\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "endobj\n".getBytes();
+ }
stream.write(p);
length += p.length;
return length;
// Java
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.io.PrintWriter;
/**
String p = this.number + " " + this.generation
+ " obj\n<< /Type /Info\n/Producer (" + this.producer
+ ") >>\nendobj\n";
- return p.getBytes();
+ try {
+ return p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.getBytes();
+ }
}
}
// Java
import java.awt.Rectangle;
+import java.io.UnsupportedEncodingException;
/**
* class representing an /Annot object of /Subtype /Link
+ (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();
+
+ try {
+ return p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.getBytes();
+ }
}
/*
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
}
result.append(">> endobj\n");
- return result.toString().getBytes();
+ try {
+ return result.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return result.toString().getBytes();
+ }
}
/**
package org.apache.fop.pdf;
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a /Page object.
*
sb = sb.append(">>\nendobj\n");
- return sb.toString().getBytes();
+ try {
+ return sb.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return sb.toString().getBytes();
+ }
}
}
// Java
import java.io.PrintWriter;
-import org.apache.fop.messaging.MessageHandler;
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
+// Fop
+import org.apache.fop.messaging.MessageHandler;
/**
* class representing a /Pages object.
p = p.append(kids.elementAt(i) + " ");
}
p = p.append("] >>\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
// Java...
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
// FOP...
p.append("endobj\n");
-
-
- return (p.toString().getBytes());
-
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
/**
* class representing a rectangle
*
* @return the PDF
*/
public byte[] toPDF() {
- return toPDFString().getBytes();
+ try {
+ return toPDFString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return toPDFString().getBytes();
+ }
}
public String toPDFString() {
// Java
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Hashtable;
p = p.append(">> \nendobj\n");
- return p.toString().getBytes();
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
// Java
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.io.PrintWriter;
/**
}
p.append(" >>\nendobj\n");
- return p.toString().getBytes();
+
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
// Java...
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
// FOP
p.append(">> \nendobj\n");
- return (p.toString().getBytes());
+ try {
+ return p.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return p.toString().getBytes();
+ }
}
}
package org.apache.fop.pdf;
+// Java
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
import java.util.Enumeration;
+// Fop
import org.apache.fop.configuration.Configuration;
import org.apache.fop.messaging.MessageHandler;
*/
public void add(String s) {
try {
- _data.write(s.getBytes());
+ try {
+ _data.write(s.getBytes(PDFDocument.ENCODING));
+ } catch (UnsupportedEncodingException ue) {
+ _data.write(s.getBytes());
+ }
} catch (IOException ex) {
ex.printStackTrace();
}
if (r < 16) {
_data.write('0');
}
- _data.write(Integer.toHexString(r).getBytes());
+ try {
+ _data.write(Integer.toHexString(r).getBytes(PDFDocument.ENCODING));
+ } catch (UnsupportedEncodingException ue) {
+ _data.write(Integer.toHexString(r).getBytes());
+ }
if (g < 16) {
_data.write('0');
}
- _data.write(Integer.toHexString(g).getBytes());
+ try {
+ _data.write(Integer.toHexString(g).getBytes(PDFDocument.ENCODING));
+ } catch (UnsupportedEncodingException ue) {
+ _data.write(Integer.toHexString(g).getBytes());
+ }
if (b < 16) {
_data.write('0');
}
- _data.write(Integer.toHexString(b).getBytes());
+ try {
+ _data.write(Integer.toHexString(b).getBytes(PDFDocument.ENCODING));
+ } catch (UnsupportedEncodingException ue) {
+ _data.write(Integer.toHexString(b).getBytes());
+ }
_data.write(' ');
}
}
- _data.write(">\n".getBytes());
+ try {
+ _data.write(">\n".getBytes(PDFDocument.ENCODING));
+ } catch (UnsupportedEncodingException ue) {
+ _data.write(">\n".getBytes());
+ }
} catch (IOException ex) {
ex.printStackTrace();
}
protected int output(OutputStream stream) throws IOException {
int length = 0;
String filterEntry = applyFilters();
- byte[] p = (this.number + " " + this.generation + " obj\n<< /Length "
+ String s = this.number + " " + this.generation + " obj\n<< /Length "
+ (_data.size() + 1) + " " + filterEntry
- + " >>\n").getBytes();
-
+ + " >>\n";
+ byte[] p;
+ try {
+ p = s.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = s.getBytes();
+ }
stream.write(p);
length += p.length;
length += outputStreamData(stream);
- p = "endobj\n".getBytes();
+ try {
+ p = "endobj\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "endobj\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();
+ byte[] p;
+ try {
+ p = "stream\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "stream\n".getBytes();
+ }
stream.write(p);
length += p.length;
_data.writeTo(stream);
length += _data.size();
- p = "\nendstream\n".getBytes();
+ try {
+ p = "\nendstream\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "\nendstream\n".getBytes();
+ }
stream.write(p);
length += p.length;
return length;
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
public class PDFT1Stream extends PDFStream {
private int origLength;
private int len1, len3;
// Get the first binary number and search backwards for "eexec"
len1 = 30;
- byte[] eexec = (new String("currentfile eexec")).getBytes();
+ byte[] eexec;
+ try {
+ eexec = "currentfile eexec".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ eexec = "currentfile eexec".getBytes();
+ }
// System.out.println("Length1="+len1);
while (!byteCmp(originalData, len1 - eexec.length, eexec))
len1++;
// Length3 is length of the last portion of the file
len3 = 0;
- byte[] cltom = (new String("cleartomark")).getBytes();
+ byte[] cltom;
+ try {
+ cltom = "cleartomark".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ cltom = "cleartomark".getBytes();
+ }
+
len3 -= cltom.length;
while (!byteCmp(originalData, origLength + len3, cltom)) {
len3--;
len3++;
// Eat 512 zeroes
int numZeroes = 0;
- byte[] ws1 = "\n".getBytes();
- byte[] ws2 = "\r".getBytes();
- byte[] ws3 = "0".getBytes();
+ byte[] ws1;
+ try {
+ ws1 = "\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ ws1 = "\n".getBytes();
+ }
+ byte[] ws2;
+ try {
+ ws2 = "\r".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ ws2 = "\r".getBytes();
+ }
+ byte[] ws3;
+ try {
+ ws3 = "0".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ ws3 = "0".getBytes();
+ }
while ((originalData[origLength - len3] == ws1[0] || originalData[origLength - len3] == ws2[0] || originalData[origLength - len3] == ws3[0])
&& numZeroes < 512) {
len3++;
+ (origLength - len3 - len1)
+ " /Length3 " + len3 + " >>\n");
- byte[] p = preData.getBytes();
+ byte[] p;
+ try {
+ p = preData.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = preData.getBytes();
+ }
+
stream.write(p);
length += p.length;
length += outputStreamData(stream);
- p = "endobj\n".getBytes();
+ try {
+ p = "endobj\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "endobj\n".getBytes();
+ }
stream.write(p);
length += p.length;
//System.out.println("Embedded Type1 font");
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
+
public class PDFTTFStream extends PDFStream {
private int origLength;
+ " " + "/Length1 " + origLength
+ " >>\n");
- byte[] p = preData.getBytes();
+ byte[] p;
+ try {
+ p = preData.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = preData.getBytes();
+ }
+
stream.write(p);
length += p.length;
length += outputStreamData(stream);
- p = "endobj\n".getBytes();
+ try {
+ p = "endobj\n".getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ p = "endobj\n".getBytes();
+ }
stream.write(p);
length += p.length;
return length;
package org.apache.fop.pdf;
+// Java
+import java.io.UnsupportedEncodingException;
import java.util.Vector;
/**
}
public byte[] toPDF() {
- return toPDFString().getBytes();
+ try {
+ return toPDFString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ return toPDFString().getBytes();
+ }
}
public String toPDFString() {
// Java
import java.io.IOException;
-import org.apache.fop.messaging.MessageHandler;
+import java.io.UnsupportedEncodingException;
import java.io.OutputStream;
// FOP
import org.apache.fop.datatypes.ColorSpace;
+import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFICCStream;
import org.apache.fop.image.FopImage;
post.append("PreEPS_state restore\n");
post.append("end % userdict\n");
- byte[] preBytes = preamble.toString().getBytes();
- byte[] postBytes = post.toString().getBytes();
+ byte[] preBytes;
+ try {
+ preBytes = preamble.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ preBytes = preamble.toString().getBytes();
+ }
+ byte[] postBytes;
+ try {
+ postBytes = post.toString().getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ postBytes = post.toString().getBytes();
+ }
byte[] imgData = new byte[preBytes.length + postBytes.length + fopimage.getBitmaps().length];
System.arraycopy (preBytes, 0, imgData, 0, preBytes.length);
p = p + ">>\n";
// push the pdf dictionary on the writer
- byte[] pdfBytes = p.getBytes();
+ byte[] pdfBytes;
+ try {
+ pdfBytes = p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ 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();
+ try {
+ pdfBytes = ("endobj\n").getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ pdfBytes = ("endobj\n").getBytes();
+ }
stream.write(pdfBytes);
length += pdfBytes.length;
fopimage.close();
// push the pdf dictionary on the writer
- byte[] pdfBytes = p.getBytes();
+ byte[] pdfBytes;
+ try {
+ pdfBytes = p.getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ 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();
+ try {
+ pdfBytes = ("endobj\n").getBytes(PDFDocument.ENCODING);
+ } catch (UnsupportedEncodingException ue) {
+ pdfBytes = ("endobj\n").getBytes();
+ }
stream.write(pdfBytes);
length += pdfBytes.length;
}