From: Christian Geisert Date: Fri, 31 May 2002 00:17:16 +0000 (+0000) Subject: Fixed PDF-Renderer to work on EBCDIC systems X-Git-Tag: fop-0_20_5rc~169 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1cfa23ef00a1e3325636858261fd5d12ba944973;p=xmlgraphics-fop.git Fixed PDF-Renderer to work on EBCDIC systems (Actually on systems where file.encoding != ASCII/ISO-8859) Submitted by: Jason West git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@194846 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 0e0df6420..e6243242b 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,10 @@ Done since 0.20.3 release Submitted by: Michal Buchtik - Added support for background-image Submitted by: Michael Gratton +- Fixed PDF-Renderer to work on EBCDIC systems + (Actually on systems where file.encoding != ASCII/ISO-8859) + Submitted by: Jason West + ============================================================================== Done since 0.20.2 release *** General diff --git a/src/org/apache/fop/pdf/ASCII85Filter.java b/src/org/apache/fop/pdf/ASCII85Filter.java index 40706e968..7c8e43cb8 100644 --- a/src/org/apache/fop/pdf/ASCII85Filter.java +++ b/src/org/apache/fop/pdf/ASCII85Filter.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; public class ASCII85Filter extends PDFFilter { private static final char ASCII85_ZERO = 'z'; @@ -87,13 +88,15 @@ public class ASCII85Filter extends PDFFilter { } // 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); diff --git a/src/org/apache/fop/pdf/ASCIIHexFilter.java b/src/org/apache/fop/pdf/ASCIIHexFilter.java index 775a7fcb4..d7c93674e 100644 --- a/src/org/apache/fop/pdf/ASCIIHexFilter.java +++ b/src/org/apache/fop/pdf/ASCIIHexFilter.java @@ -8,6 +8,7 @@ package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; public class ASCIIHexFilter extends PDFFilter { private static final String ASCIIHEX_EOD = ">"; @@ -32,8 +33,11 @@ public class ASCIIHexFilter extends PDFFilter { } buffer.append(ASCIIHEX_EOD); - return buffer.toString().getBytes(); - + try { + return buffer.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return buffer.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFAnnotList.java b/src/org/apache/fop/pdf/PDFAnnotList.java index 1a23d85d5..3c509073b 100644 --- a/src/org/apache/fop/pdf/PDFAnnotList.java +++ b/src/org/apache/fop/pdf/PDFAnnotList.java @@ -8,6 +8,7 @@ package org.apache.fop.pdf; // Java +import java.io.UnsupportedEncodingException; import java.util.Vector; /** @@ -71,7 +72,12 @@ public class PDFAnnotList extends PDFObject { + "\n"); } p = p.append("]\nendobj\n"); - return p.toString().getBytes(); + + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } /* diff --git a/src/org/apache/fop/pdf/PDFArray.java b/src/org/apache/fop/pdf/PDFArray.java index 243c19f09..ad0240248 100644 --- a/src/org/apache/fop/pdf/PDFArray.java +++ b/src/org/apache/fop/pdf/PDFArray.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +//Java +import java.io.UnsupportedEncodingException; + /** * class representing an array object */ @@ -42,7 +45,12 @@ public class PDFArray extends PDFObject { 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(); + } } } diff --git a/src/org/apache/fop/pdf/PDFCIDFont.java b/src/org/apache/fop/pdf/PDFCIDFont.java index 5323996bb..b97bf97d3 100644 --- a/src/org/apache/fop/pdf/PDFCIDFont.java +++ b/src/org/apache/fop/pdf/PDFCIDFont.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + // based on work by Takayuki Takeuchi /** @@ -147,7 +150,11 @@ public class PDFCIDFont extends PDFObject { * @return the PDF */ public byte[] toPDF() { - return toPDFString().getBytes(); + try { + return toPDFString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return toPDFString().getBytes(); + } } public String toPDFString() { diff --git a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java b/src/org/apache/fop/pdf/PDFCIDSystemInfo.java index 7104fd9d7..dc538c01f 100644 --- a/src/org/apache/fop/pdf/PDFCIDSystemInfo.java +++ b/src/org/apache/fop/pdf/PDFCIDSystemInfo.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + // based on work by Takayuki Takeuchi /** @@ -36,7 +39,11 @@ public class PDFCIDSystemInfo extends PDFObject { * @return the PDF */ public byte[] toPDF() { - return toPDFString().getBytes(); + try { + return toPDFString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return toPDFString().getBytes(); + } } public String toPDFString() { diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 380ab3b01..13cc5fdea 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -27,6 +27,7 @@ import org.apache.fop.layout.FontDescriptor; // 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; @@ -154,6 +155,11 @@ public class PDFDocument { */ protected Vector pendingLinks = null; + /** + * Encoding of the PDF + */ + public static final String ENCODING = "ISO-8859-1"; + /** * creates an empty PDF document

* @@ -1218,7 +1224,12 @@ public class PDFDocument { 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; @@ -1265,7 +1276,13 @@ public class PDFDocument { "%%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); } /** @@ -1297,7 +1314,12 @@ public class PDFDocument { } /* 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; } diff --git a/src/org/apache/fop/pdf/PDFEncoding.java b/src/org/apache/fop/pdf/PDFEncoding.java index 68151bdfd..933896960 100644 --- a/src/org/apache/fop/pdf/PDFEncoding.java +++ b/src/org/apache/fop/pdf/PDFEncoding.java @@ -8,6 +8,7 @@ package org.apache.fop.pdf; // Java +import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; @@ -106,7 +107,12 @@ public class PDFEncoding extends PDFObject { p.append(" ]"); } p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } /* diff --git a/src/org/apache/fop/pdf/PDFFileSpec.java b/src/org/apache/fop/pdf/PDFFileSpec.java index d7c5338d0..3ea5a38b9 100644 --- a/src/org/apache/fop/pdf/PDFFileSpec.java +++ b/src/org/apache/fop/pdf/PDFFileSpec.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a /FileSpec object. * @@ -41,7 +44,12 @@ public class PDFFileSpec extends PDFObject { 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(); + } } /* diff --git a/src/org/apache/fop/pdf/PDFFont.java b/src/org/apache/fop/pdf/PDFFont.java index 3d1c2ec05..360f7e2f8 100644 --- a/src/org/apache/fop/pdf/PDFFont.java +++ b/src/org/apache/fop/pdf/PDFFont.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a /Font object. * @@ -218,7 +221,12 @@ public class PDFFont extends PDFObject { } fillInPDF(p); p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } /** diff --git a/src/org/apache/fop/pdf/PDFFontDescriptor.java b/src/org/apache/fop/pdf/PDFFontDescriptor.java index 203879b35..c99de0581 100644 --- a/src/org/apache/fop/pdf/PDFFontDescriptor.java +++ b/src/org/apache/fop/pdf/PDFFontDescriptor.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a font descriptor. * @@ -162,7 +165,12 @@ public class PDFFontDescriptor extends PDFObject { // 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(); + } } /** diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java index 185addc9e..b17320f47 100644 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ b/src/org/apache/fop/pdf/PDFFunction.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; // Java... import java.util.Vector; +import java.io.UnsupportedEncodingException; /** * class representing a PDF Function. @@ -663,8 +664,11 @@ public class PDFFunction extends PDFObject { } - return (p.toString().getBytes()); - + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFGoTo.java b/src/org/apache/fop/pdf/PDFGoTo.java index f8dd65a8e..8bcb5a0b7 100644 --- a/src/org/apache/fop/pdf/PDFGoTo.java +++ b/src/org/apache/fop/pdf/PDFGoTo.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a /GoTo object. * @@ -91,7 +94,12 @@ public class PDFGoTo extends PDFAction { 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(); + } } /* diff --git a/src/org/apache/fop/pdf/PDFGoToRemote.java b/src/org/apache/fop/pdf/PDFGoToRemote.java index aa8ef5afa..c23862602 100644 --- a/src/org/apache/fop/pdf/PDFGoToRemote.java +++ b/src/org/apache/fop/pdf/PDFGoToRemote.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a /GoToR object. */ @@ -51,7 +54,12 @@ public class PDFGoToRemote extends PDFAction { + 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(); + } } diff --git a/src/org/apache/fop/pdf/PDFICCStream.java b/src/org/apache/fop/pdf/PDFICCStream.java index 5d96be0cd..9462eb8dc 100644 --- a/src/org/apache/fop/pdf/PDFICCStream.java +++ b/src/org/apache/fop/pdf/PDFICCStream.java @@ -6,6 +6,10 @@ */ package org.apache.fop.pdf; + +// Java +import java.io.UnsupportedEncodingException; +// Fop import org.apache.fop.datatypes.ColorSpace; public class PDFICCStream extends PDFStream { @@ -45,11 +49,20 @@ 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; diff --git a/src/org/apache/fop/pdf/PDFInfo.java b/src/org/apache/fop/pdf/PDFInfo.java index a8215fcea..8e346d80a 100644 --- a/src/org/apache/fop/pdf/PDFInfo.java +++ b/src/org/apache/fop/pdf/PDFInfo.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; // Java import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.io.PrintWriter; /** @@ -48,7 +49,11 @@ public class PDFInfo extends PDFObject { 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(); + } } } diff --git a/src/org/apache/fop/pdf/PDFLink.java b/src/org/apache/fop/pdf/PDFLink.java index 6af94f1d8..f839a9a0a 100644 --- a/src/org/apache/fop/pdf/PDFLink.java +++ b/src/org/apache/fop/pdf/PDFLink.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; // Java import java.awt.Rectangle; +import java.io.UnsupportedEncodingException; /** * class representing an /Annot object of /Subtype /Link @@ -56,7 +57,12 @@ public class PDFLink extends PDFObject { + (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(); + } } /* diff --git a/src/org/apache/fop/pdf/PDFOutline.java b/src/org/apache/fop/pdf/PDFOutline.java index 48e281b81..1d280fedb 100644 --- a/src/org/apache/fop/pdf/PDFOutline.java +++ b/src/org/apache/fop/pdf/PDFOutline.java @@ -7,6 +7,8 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; import java.util.Vector; @@ -142,8 +144,12 @@ public class PDFOutline extends PDFObject { } result.append(">> endobj\n"); - return result.toString().getBytes(); + try { + return result.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return result.toString().getBytes(); + } } /** diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index 8fce26098..19e3ab135 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -7,6 +7,8 @@ package org.apache.fop.pdf; +import java.io.UnsupportedEncodingException; + /** * class representing a /Page object. * @@ -129,7 +131,11 @@ public class PDFPage extends PDFObject { sb = sb.append(">>\nendobj\n"); - return sb.toString().getBytes(); + try { + return sb.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return sb.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFPages.java b/src/org/apache/fop/pdf/PDFPages.java index 4035fc2eb..9274fdda6 100644 --- a/src/org/apache/fop/pdf/PDFPages.java +++ b/src/org/apache/fop/pdf/PDFPages.java @@ -9,8 +9,10 @@ package org.apache.fop.pdf; // 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. @@ -88,7 +90,12 @@ public class PDFPages extends PDFObject { 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(); + } } } diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java index 3fa15d59b..cc1c5dbcf 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -8,6 +8,7 @@ package org.apache.fop.pdf; // Java... +import java.io.UnsupportedEncodingException; import java.util.Vector; // FOP... @@ -288,10 +289,11 @@ public class PDFPattern extends PDFPathPaint { p.append("endobj\n"); - - - return (p.toString().getBytes()); - + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFRectangle.java b/src/org/apache/fop/pdf/PDFRectangle.java index 2dc04fb74..b89e9a451 100644 --- a/src/org/apache/fop/pdf/PDFRectangle.java +++ b/src/org/apache/fop/pdf/PDFRectangle.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + /** * class representing a rectangle * @@ -67,7 +70,11 @@ public class PDFRectangle { * @return the PDF */ public byte[] toPDF() { - return toPDFString().getBytes(); + try { + return toPDFString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return toPDFString().getBytes(); + } } public String toPDFString() { diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index d51b716e4..45602cb22 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; // Java import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Vector; import java.util.Hashtable; @@ -138,7 +139,11 @@ public class PDFResources extends PDFObject { p = p.append(">> \nendobj\n"); - return p.toString().getBytes(); + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFRoot.java b/src/org/apache/fop/pdf/PDFRoot.java index 8741bd519..edd6bdda3 100644 --- a/src/org/apache/fop/pdf/PDFRoot.java +++ b/src/org/apache/fop/pdf/PDFRoot.java @@ -9,6 +9,7 @@ package org.apache.fop.pdf; // Java import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.io.PrintWriter; /** @@ -96,7 +97,12 @@ public class PDFRoot extends PDFObject { } p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java index a1a1a9be0..8d5b1f208 100644 --- a/src/org/apache/fop/pdf/PDFShading.java +++ b/src/org/apache/fop/pdf/PDFShading.java @@ -8,6 +8,7 @@ package org.apache.fop.pdf; // Java... +import java.io.UnsupportedEncodingException; import java.util.Vector; // FOP @@ -505,7 +506,11 @@ public class PDFShading extends PDFObject { p.append(">> \nendobj\n"); - return (p.toString().getBytes()); + try { + return p.toString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return p.toString().getBytes(); + } } } diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index 01b87b9d6..56d1e3af5 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -7,11 +7,14 @@ 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; @@ -53,7 +56,11 @@ public class PDFStream extends PDFObject { */ 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(); } @@ -133,19 +140,35 @@ public class PDFStream extends PDFObject { 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(); } @@ -195,14 +218,23 @@ public class PDFStream extends PDFObject { 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; @@ -214,12 +246,21 @@ public class PDFStream extends PDFObject { */ 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; diff --git a/src/org/apache/fop/pdf/PDFT1Stream.java b/src/org/apache/fop/pdf/PDFT1Stream.java index a651a0637..5588a0c01 100644 --- a/src/org/apache/fop/pdf/PDFT1Stream.java +++ b/src/org/apache/fop/pdf/PDFT1Stream.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + public class PDFT1Stream extends PDFStream { private int origLength; private int len1, len3; @@ -41,7 +44,12 @@ public class PDFT1Stream extends PDFStream { // 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++; @@ -50,7 +58,13 @@ public class PDFT1Stream extends PDFStream { // 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--; @@ -60,9 +74,24 @@ public class PDFT1Stream extends PDFStream { 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++; @@ -85,12 +114,22 @@ public class PDFT1Stream extends PDFStream { + (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"); diff --git a/src/org/apache/fop/pdf/PDFTTFStream.java b/src/org/apache/fop/pdf/PDFTTFStream.java index ac0a7bf8d..a6e894349 100644 --- a/src/org/apache/fop/pdf/PDFTTFStream.java +++ b/src/org/apache/fop/pdf/PDFTTFStream.java @@ -7,6 +7,9 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; + public class PDFTTFStream extends PDFStream { private int origLength; @@ -27,12 +30,22 @@ public class PDFTTFStream extends PDFStream { + " " + "/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; diff --git a/src/org/apache/fop/pdf/PDFWArray.java b/src/org/apache/fop/pdf/PDFWArray.java index a391f45f3..da86f7d48 100644 --- a/src/org/apache/fop/pdf/PDFWArray.java +++ b/src/org/apache/fop/pdf/PDFWArray.java @@ -7,6 +7,8 @@ package org.apache.fop.pdf; +// Java +import java.io.UnsupportedEncodingException; import java.util.Vector; /** @@ -63,7 +65,11 @@ public class PDFWArray { } public byte[] toPDF() { - return toPDFString().getBytes(); + try { + return toPDFString().getBytes(PDFDocument.ENCODING); + } catch (UnsupportedEncodingException ue) { + return toPDFString().getBytes(); + } } public String toPDFString() { diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java index ef859f807..db2ec8cb4 100644 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ b/src/org/apache/fop/pdf/PDFXObject.java @@ -12,11 +12,12 @@ package org.apache.fop.pdf; // 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; @@ -119,8 +120,18 @@ public class PDFXObject extends PDFObject { 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); @@ -145,13 +156,22 @@ public class PDFXObject extends PDFObject { 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; @@ -210,13 +230,22 @@ public class PDFXObject extends PDFObject { 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; }