diff options
Diffstat (limited to 'src/java/org/apache/fop/pdf/PDFArray.java')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFArray.java | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFArray.java b/src/java/org/apache/fop/pdf/PDFArray.java index 2dd68ad8b..2cb2adb1d 100644 --- a/src/java/org/apache/fop/pdf/PDFArray.java +++ b/src/java/org/apache/fop/pdf/PDFArray.java @@ -19,9 +19,14 @@ package org.apache.fop.pdf; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; import java.util.Collection; import java.util.List; +import org.apache.commons.io.output.CountingOutputStream; + /** * Class representing an array object. */ @@ -33,20 +38,21 @@ public class PDFArray extends PDFObject { /** * Create a new, empty array object + * @param parent the array's parent if any */ - public PDFArray() { + public PDFArray(PDFObject parent) { /* generic creation of PDF object */ - super(); + super(parent); } /** - * Create the array object - * + * Create an array object. + * @param parent the array's parent if any * @param values the actual array wrapped by this object */ - public PDFArray(int[] values) { + public PDFArray(PDFObject parent, int[] values) { /* generic creation of PDF object */ - super(); + super(parent); for (int i = 0, c = values.length; i < c; i++) { this.values.add(new Integer(values[i])); @@ -54,25 +60,25 @@ public class PDFArray extends PDFObject { } /** - * Create the array object - * + * Create an array object. + * @param parent the array's parent if any * @param values the actual values wrapped by this object */ - public PDFArray(Collection values) { + public PDFArray(PDFObject parent, Collection values) { /* generic creation of PDF object */ - super(); + super(parent); this.values.addAll(values); } /** * Create the array object - * + * @param parent the array's parent if any * @param values the actual array wrapped by this object */ - public PDFArray(Object[] values) { + public PDFArray(PDFObject parent, Object[] values) { /* generic creation of PDF object */ - super(); + super(parent); for (int i = 0, c = values.length; i < c; i++) { this.values.add(values[i]); @@ -118,6 +124,17 @@ public class PDFArray extends PDFObject { * Adds a new value to the array. * @param obj the value */ + public void add(PDFObject obj) { + if (obj != null) { + obj.setParent(this); + } + this.values.add(obj); + } + + /** + * Adds a new value to the array. + * @param obj the value + */ public void add(Object obj) { this.values.add(obj); } @@ -130,27 +147,30 @@ public class PDFArray extends PDFObject { this.values.add(new Double(value)); } - /** - * {@inheritDoc} - */ - public String toPDFString() { - StringBuffer p = new StringBuffer(64); + /** {@inheritDoc} */ + protected int output(OutputStream stream) throws IOException { + CountingOutputStream cout = new CountingOutputStream(stream); + Writer writer = PDFDocument.getWriterFor(cout); if (hasObjectNumber()) { - p.append(getObjectID()); + writer.write(getObjectID()); } - p.append("["); + + writer.write('['); for (int i = 0; i < values.size(); i++) { if (i > 0) { - p.append(" "); + writer.write(' '); } Object obj = this.values.get(i); - formatObject(obj, p); + formatObject(obj, cout, writer); } - p.append("]"); + writer.write(']'); + if (hasObjectNumber()) { - p.append("\nendobj\n"); + writer.write("\nendobj\n"); } - return p.toString(); + + writer.flush(); + return cout.getCount(); } - + } |