From ec59ecf8a78788e07c53c0791cb54e6f5c0e7084 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 21 Jan 2008 10:33:10 +0000 Subject: [PATCH] A name object can be encoded as a stand-along PDF object with object number and all, so extend from PDFObject. Fixes a possible ClassCastException with the PDF-in-PDF extension. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@613831 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFName.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/fop/pdf/PDFName.java b/src/java/org/apache/fop/pdf/PDFName.java index 8c626d53f..6ad6ff9eb 100644 --- a/src/java/org/apache/fop/pdf/PDFName.java +++ b/src/java/org/apache/fop/pdf/PDFName.java @@ -23,10 +23,12 @@ import java.io.IOException; import java.io.OutputStream; import java.io.Writer; +import org.apache.commons.io.output.CountingOutputStream; + /** * Class representing a PDF name object. */ -public class PDFName implements PDFWritable { +public class PDFName extends PDFObject { private String name; @@ -35,6 +37,7 @@ public class PDFName implements PDFWritable { * @param name the name value */ public PDFName(String name) { + super(); this.name = escapeName(name); } @@ -74,6 +77,24 @@ public class PDFName implements PDFWritable { return this.name; } + /** {@inheritDoc} */ + protected int output(OutputStream stream) throws IOException { + CountingOutputStream cout = new CountingOutputStream(stream); + Writer writer = PDFDocument.getWriterFor(cout); + if (hasObjectNumber()) { + writer.write(getObjectID()); + } + + outputInline(stream, writer); + + if (hasObjectNumber()) { + writer.write("\nendobj\n"); + } + + writer.flush(); + return cout.getCount(); + } + /** {@inheritDoc} */ public void outputInline(OutputStream out, Writer writer) throws IOException { writer.write(toString()); -- 2.39.5