diff options
Diffstat (limited to 'src/java/org/apache/fop/pdf')
30 files changed, 312 insertions, 488 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFAction.java b/src/java/org/apache/fop/pdf/PDFAction.java index 28a1954bc..f5f12b664 100644 --- a/src/java/org/apache/fop/pdf/PDFAction.java +++ b/src/java/org/apache/fop/pdf/PDFAction.java @@ -57,25 +57,6 @@ 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 - */ - public PDFAction(int 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() { } - - /** * represent the action to call * this method should be implemented to return the action which gets * called by the Link Object. This could be a reference to another object @@ -86,13 +67,4 @@ public abstract class PDFAction extends PDFObject { public abstract String getAction(); - /** - * represent the object in PDF - * this method should be implemented to return the PDF which is to be - * generated by the Action object - * - * @return the PDF string - */ - public abstract byte[] toPDF(); - } diff --git a/src/java/org/apache/fop/pdf/PDFAnnotList.java b/src/java/org/apache/fop/pdf/PDFAnnotList.java index 1953fc310..50c8bdf88 100644 --- a/src/java/org/apache/fop/pdf/PDFAnnotList.java +++ b/src/java/org/apache/fop/pdf/PDFAnnotList.java @@ -51,7 +51,7 @@ package org.apache.fop.pdf; // Java -import java.util.Vector; +import java.util.List; /** * class representing an object which is a list of annotations. @@ -64,23 +64,7 @@ public class PDFAnnotList extends PDFObject { /** * the /Annot objects */ - protected Vector links = new Vector(); - - /** - * the number of /Annot objects - */ - protected int count = 0; - - /** - * create a /Annots object. - * - * @param number the object's number - */ - public PDFAnnotList(int number) { - - /* generic creation of object */ - super(number); - } + private List links = new java.util.Vector(); /** * add an /Annot object of /Subtype /Link. @@ -88,8 +72,7 @@ public class PDFAnnotList extends PDFObject { * @param link the PDFLink to add. */ public void addAnnot(PDFObject link) { - this.links.addElement(link); - this.count++; + this.links.add(link); } /** @@ -98,23 +81,22 @@ public class PDFAnnotList extends PDFObject { * @return the number of links */ public int getCount() { - return this.count; + return this.links.size(); } /** - * represent the object in PDF - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - 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"); + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID()); + p.append("[\n"); + for (int i = 0; i < getCount(); i++) { + p.append(((PDFObject)links.get(i)).referencePDF()); + p.append("\n"); } - p = p.append("]\nendobj\n"); - return p.toString().getBytes(); + p.append("]\nendobj\n"); + return p.toString(); } /* diff --git a/src/java/org/apache/fop/pdf/PDFArray.java b/src/java/org/apache/fop/pdf/PDFArray.java index 6b60d416f..a97faa2e6 100644 --- a/src/java/org/apache/fop/pdf/PDFArray.java +++ b/src/java/org/apache/fop/pdf/PDFArray.java @@ -62,32 +62,29 @@ public class PDFArray extends PDFObject { /** * 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) { + public PDFArray(int[] values) { /* generic creation of PDF object */ - super(number); + super(); /* set fields using paramaters */ this.values = values; } /** - * produce the PDF representation for the object - * - * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation + " obj\n["); + public String toPDFString() { + StringBuffer p = new StringBuffer(64); + p.append(getObjectID() + "["); for (int i = 0; i < values.length; i++) { p.append(" "); p.append(values[i]); } p.append("]\nendobj\n"); - return p.toString().getBytes(); + return p.toString(); } } diff --git a/src/java/org/apache/fop/pdf/PDFCIDFont.java b/src/java/org/apache/fop/pdf/PDFCIDFont.java index e9f3e1051..4393d6e85 100644 --- a/src/java/org/apache/fop/pdf/PDFCIDFont.java +++ b/src/java/org/apache/fop/pdf/PDFCIDFont.java @@ -78,7 +78,6 @@ public class PDFCIDFont extends PDFObject { /** * Create the /Font object - * @param number PDF object number * @param basefont Name of the basefont * @param cidtype CID type * @param dw default width @@ -88,11 +87,11 @@ public class PDFCIDFont extends PDFObject { * @param supplement Supplement number * @param descriptor CID font descriptor */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, + public PDFCIDFont(String basefont, CIDFontType cidtype, int dw, int[] w, String registry, String ordering, int supplement, PDFCIDFontDescriptor descriptor) { - this(number, basefont, cidtype, dw, + this(basefont, cidtype, dw, new PDFWArray(w), new PDFCIDSystemInfo(registry, ordering, supplement), descriptor); @@ -100,7 +99,6 @@ public class PDFCIDFont extends PDFObject { /** * Create the /Font object - * @param number PDF object number * @param basefont Name of the basefont * @param cidtype CID type * @param dw default width @@ -108,11 +106,11 @@ public class PDFCIDFont extends PDFObject { * @param systemInfo CID system info * @param descriptor CID font descriptor */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, + public PDFCIDFont(String basefont, CIDFontType cidtype, int dw, int[] w, PDFCIDSystemInfo systemInfo, PDFCIDFontDescriptor descriptor) { - this(number, basefont, cidtype, dw, + this(basefont, cidtype, dw, new PDFWArray(w), systemInfo, descriptor); @@ -120,7 +118,6 @@ public class PDFCIDFont extends PDFObject { /** * Create the /Font object - * @param number PDF object number * @param basefont Name of the basefont * @param cidtype CID type * @param dw default width @@ -128,11 +125,11 @@ public class PDFCIDFont extends PDFObject { * @param systemInfo CID system info * @param descriptor CID font descriptor */ - public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw, + public PDFCIDFont(String basefont, CIDFontType cidtype, int dw, PDFWArray w, PDFCIDSystemInfo systemInfo, PDFCIDFontDescriptor descriptor) { - super(number); + super(); this.basefont = basefont; this.cidtype = cidtype; @@ -229,24 +226,12 @@ public class PDFCIDFont extends PDFObject { } /** - * Produce the PDF representation for the object - * - * @return the PDF - */ - public byte[] toPDF() { - return toPDFString().getBytes(); - } - - /** - * Produce the PDF representation for the object - * @return the generated code + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ public String toPDFString() { - StringBuffer p = new StringBuffer(); - p.append(this.number); - p.append(" "); - p.append(this.generation); - p.append(" obj\n<< /Type /Font"); + StringBuffer p = new StringBuffer(128); + p.append(getObjectID()); + p.append("<< /Type /Font"); p.append("\n/BaseFont /"); p.append(this.basefont); if (cidMap != null) { diff --git a/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java b/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java index add7833b4..1b17f31ed 100644 --- a/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java +++ b/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java @@ -72,7 +72,6 @@ public class PDFCIDFontDescriptor extends PDFFontDescriptor { /** * create the /FontDescriptor object * - * @param number the object's number * @param basefont the base font name * @param fontBBox the bounding box for the described font * @param flags various characteristics of the font @@ -81,11 +80,11 @@ 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, + public PDFCIDFontDescriptor(String basefont, int[] fontBBox, int capHeight, int flags, int italicAngle, int stemV, String lang) { - super(number, basefont, fontBBox[3], fontBBox[1], capHeight, flags, + super(basefont, fontBBox[3], fontBBox[1], capHeight, flags, new PDFRectangle(fontBBox), italicAngle, stemV); this.lang = lang; diff --git a/src/java/org/apache/fop/pdf/PDFCIDSystemInfo.java b/src/java/org/apache/fop/pdf/PDFCIDSystemInfo.java index f5037b62f..c8fd2d303 100644 --- a/src/java/org/apache/fop/pdf/PDFCIDSystemInfo.java +++ b/src/java/org/apache/fop/pdf/PDFCIDSystemInfo.java @@ -77,31 +77,19 @@ public class PDFCIDSystemInfo extends PDFObject { } /** - * 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(); - } - - /** * Create a string for the CIDSystemInfo dictionary. * The entries are placed as an inline dictionary. * * @return the string for the CIDSystemInfo entry with the inline dictionary */ public String toPDFString() { - StringBuffer p = new StringBuffer(); + StringBuffer p = new StringBuffer(64); p.setLength(0); p.append("/CIDSystemInfo << /Registry ("); p.append(registry); - p.append(")/Ordering ("); + p.append(") /Ordering ("); p.append(ordering); - p.append(")/Supplement "); + p.append(") /Supplement "); p.append(supplement); p.append(" >>"); return p.toString(); diff --git a/src/java/org/apache/fop/pdf/PDFCMap.java b/src/java/org/apache/fop/pdf/PDFCMap.java index 1cf3ae53d..da3758c12 100644 --- a/src/java/org/apache/fop/pdf/PDFCMap.java +++ b/src/java/org/apache/fop/pdf/PDFCMap.java @@ -402,12 +402,11 @@ public class PDFCMap extends PDFStream { /** * create the /CMap object * - * @param number the pdf object number * @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); + public PDFCMap(String name, PDFCIDSystemInfo sysInfo) { + super(); this.name = name; this.sysInfo = sysInfo; this.base = null; diff --git a/src/java/org/apache/fop/pdf/PDFEncoding.java b/src/java/org/apache/fop/pdf/PDFEncoding.java index b048cd2db..51a4e4769 100644 --- a/src/java/org/apache/fop/pdf/PDFEncoding.java +++ b/src/java/org/apache/fop/pdf/PDFEncoding.java @@ -54,7 +54,6 @@ package org.apache.fop.pdf; import java.util.List; import java.util.Map; import java.util.Iterator; -import java.util.HashMap; /** * class representing an /Encoding object. @@ -98,17 +97,16 @@ public class PDFEncoding extends PDFObject { /** * create the /Encoding object * - * @param number the object's number * @param basename the name of the character encoding schema */ - public PDFEncoding(int number, String basename) { + public PDFEncoding(String basename) { /* generic creation of PDF object */ - super(number); + super(); /* set fields using paramaters */ this.basename = basename; - this.differences = new HashMap(); + this.differences = new java.util.HashMap(); } /** @@ -122,14 +120,12 @@ public class PDFEncoding extends PDFObject { } /** - * produce the PDF representation for the object - * - * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< /Type /Encoding"); + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID() + + "<< /Type /Encoding"); if ((basename != null) && (!basename.equals(""))) { p.append("\n/BaseEncoding /" + this.basename); } @@ -150,7 +146,7 @@ public class PDFEncoding extends PDFObject { p.append(" ]"); } p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + return p.toString(); } /* diff --git a/src/java/org/apache/fop/pdf/PDFFileSpec.java b/src/java/org/apache/fop/pdf/PDFFileSpec.java index b21e45368..3c4ec5f69 100644 --- a/src/java/org/apache/fop/pdf/PDFFileSpec.java +++ b/src/java/org/apache/fop/pdf/PDFFileSpec.java @@ -64,27 +64,24 @@ public class PDFFileSpec extends PDFObject { /** * create a /FileSpec object. * - * @param number the object's number * @param filename the filename represented by this object */ - public PDFFileSpec(int number, String filename) { + public PDFFileSpec(String filename) { /* generic creation of object */ - super(number); + super(); this.filename = filename; } /** - * represent the object in PDF - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - 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(); + public String toPDFString() { + return getObjectID() + + "<<\n/Type /FileSpec\n" + + "/F (" + this.filename + ")\n" + + ">>\nendobj\n"; } /* diff --git a/src/java/org/apache/fop/pdf/PDFFont.java b/src/java/org/apache/fop/pdf/PDFFont.java index 7082ace31..1e1dda141 100644 --- a/src/java/org/apache/fop/pdf/PDFFont.java +++ b/src/java/org/apache/fop/pdf/PDFFont.java @@ -96,18 +96,17 @@ public class PDFFont extends PDFObject { /** * 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 */ - public PDFFont(int number, String fontname, FontType subtype, + public PDFFont(String fontname, FontType subtype, String basefont, Object encoding /* , PDFToUnicode mapping */) { /* generic creation of PDF object */ - super(number); + super(); /* set fields using paramaters */ this.fontname = fontname; @@ -120,28 +119,27 @@ public class PDFFont extends PDFObject { /** * factory method with the basic parameters * - * @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 * @return the generated PDFFont object */ - public static PDFFont createFont(int number, String fontname, + public static PDFFont createFont(String fontname, FontType subtype, String basefont, Object encoding) { if (subtype == FontType.TYPE0) { - return new PDFFontType0(number, fontname, basefont, + return new PDFFontType0(fontname, basefont, encoding); } else if ((subtype == FontType.TYPE1) || (subtype == FontType.MMTYPE1)) { - return new PDFFontType1(number, fontname, basefont, + return new PDFFontType1(fontname, basefont, encoding); } else if (subtype == FontType.TYPE3) { //return new PDFFontType3(number, fontname, basefont, encoding); return null; //NYI } else if (subtype == FontType.TRUETYPE) { - return new PDFFontTrueType(number, fontname, basefont, + return new PDFFontTrueType(fontname, basefont, encoding); } else { return null; // should not happend @@ -152,7 +150,6 @@ public class PDFFont extends PDFObject { * factory method with the extended parameters * for Type1, MMType1 and TrueType * - * @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 @@ -163,7 +160,7 @@ public class PDFFont extends PDFObject { * @param descriptor the descriptor for other font's metrics * @return the generated PDFFont object */ - public static PDFFont createFont(int number, String fontname, + public static PDFFont createFont(String fontname, FontType subtype, String basefont, Object encoding, int firstChar, int lastChar, PDFArray widths, @@ -171,13 +168,13 @@ public class PDFFont extends PDFObject { PDFFontNonBase14 font; if (subtype == FontType.TYPE0) { - font = new PDFFontType0(number, fontname, basefont, + font = new PDFFontType0(fontname, basefont, encoding); font.setDescriptor(descriptor); return font; } else if ((subtype == FontType.TYPE1) || (subtype == FontType.MMTYPE1)) { - font = new PDFFontType1(number, fontname, basefont, + font = new PDFFontType1(fontname, basefont, encoding); font.setWidthMetrics(firstChar, lastChar, widths); font.setDescriptor(descriptor); @@ -185,7 +182,7 @@ public class PDFFont extends PDFObject { } else if (subtype == FontType.TYPE3) { return null; //NYI, should not happend } else if (subtype == FontType.TRUETYPE) { - font = new PDFFontTrueType(number, fontname, basefont, + font = new PDFFontTrueType(fontname, basefont, encoding); font.setWidthMetrics(firstChar, lastChar, widths); font.setDescriptor(descriptor); @@ -225,15 +222,14 @@ public class PDFFont extends PDFObject { } /** - * Produce the PDF representation for the object - * - * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< /Type /Font\n/Subtype /" - + getPDFNameForFontType(this.subtype) + "\n/Name /" + this.fontname + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID()); + p.append("<< /Type /Font\n/Subtype /" + + getPDFNameForFontType(this.subtype) + + "\n/Name /" + this.fontname + "\n/BaseFont /" + this.basefont); if (encoding != null) { p.append("\n/Encoding "); @@ -247,7 +243,7 @@ public class PDFFont extends PDFObject { } fillInPDF(p); p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + return p.toString(); } /** diff --git a/src/java/org/apache/fop/pdf/PDFFontDescriptor.java b/src/java/org/apache/fop/pdf/PDFFontDescriptor.java index c605aaf8a..a91d509c2 100644 --- a/src/java/org/apache/fop/pdf/PDFFontDescriptor.java +++ b/src/java/org/apache/fop/pdf/PDFFontDescriptor.java @@ -83,7 +83,6 @@ public class PDFFontDescriptor extends PDFObject { /** * 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 @@ -93,13 +92,13 @@ public class PDFFontDescriptor extends PDFObject { * @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, + public PDFFontDescriptor(String basefont, int ascent, int descent, int capHeight, int flags, PDFRectangle fontBBox, int italicAngle, int stemV) { /* generic creation of PDF object */ - super(number); + super(); /* set fields using paramaters */ this.basefont = basefont; @@ -150,14 +149,13 @@ public class PDFFontDescriptor extends PDFObject { // public void setCharSet(){}//for subset fonts /** - * Produce the PDF representation for the object - * - * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< /Type /FontDescriptor" - + "\n/FontName /" + this.basefont); + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID() + + "<< /Type /FontDescriptor" + + "\n/FontName /" + this.basefont); p.append("\n/FontBBox "); p.append(fontBBox.toPDFString()); @@ -209,8 +207,8 @@ public class PDFFontDescriptor extends PDFObject { // charSet for subset fonts // not yet implemented // CID optional field fillInPDF(p); - p.append("\n >>\nendobj\n"); - return p.toString().getBytes(); + p.append(" >>\nendobj\n"); + return p.toString(); } /** diff --git a/src/java/org/apache/fop/pdf/PDFFontNonBase14.java b/src/java/org/apache/fop/pdf/PDFFontNonBase14.java index 766e54d45..35b048e04 100644 --- a/src/java/org/apache/fop/pdf/PDFFontNonBase14.java +++ b/src/java/org/apache/fop/pdf/PDFFontNonBase14.java @@ -81,18 +81,17 @@ public abstract class PDFFontNonBase14 extends PDFFont { /** * 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 */ - public PDFFontNonBase14(int number, String fontname, FontType subtype, + public PDFFontNonBase14(String fontname, FontType subtype, String basefont, Object encoding) { /* generic creation of PDF object */ - super(number, fontname, subtype, basefont, encoding); + super(fontname, subtype, basefont, encoding); this.descriptor = null; } diff --git a/src/java/org/apache/fop/pdf/PDFFontTrueType.java b/src/java/org/apache/fop/pdf/PDFFontTrueType.java index ca71f8b80..f8f0657ca 100644 --- a/src/java/org/apache/fop/pdf/PDFFontTrueType.java +++ b/src/java/org/apache/fop/pdf/PDFFontTrueType.java @@ -63,17 +63,16 @@ public class PDFFontTrueType extends PDFFontNonBase14 { /** * create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font */ - public PDFFontTrueType(int number, String fontname, + public PDFFontTrueType(String fontname, String basefont, Object encoding) { /* generic creation of PDF object */ - super(number, fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */); + super(fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */); } } diff --git a/src/java/org/apache/fop/pdf/PDFFontType0.java b/src/java/org/apache/fop/pdf/PDFFontType0.java index 7426a5cbf..4084752ec 100644 --- a/src/java/org/apache/fop/pdf/PDFFontType0.java +++ b/src/java/org/apache/fop/pdf/PDFFontType0.java @@ -72,17 +72,16 @@ public class PDFFontType0 extends PDFFontNonBase14 { /** * Create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font */ - public PDFFontType0(int number, String fontname, + public PDFFontType0(String fontname, String basefont, Object encoding) { /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */); + super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */); /* set fields using paramaters */ this.descendantFonts = null; @@ -92,19 +91,18 @@ public class PDFFontType0 extends PDFFontNonBase14 { /** * Create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font * @param descendantFonts the CIDFont upon which this font is based */ - public PDFFontType0(int number, String fontname, + public PDFFontType0(String fontname, String basefont, Object encoding, PDFCIDFont descendantFonts) { /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */); + super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */); /* set fields using paramaters */ this.descendantFonts = descendantFonts; diff --git a/src/java/org/apache/fop/pdf/PDFFontType1.java b/src/java/org/apache/fop/pdf/PDFFontType1.java index 51382f07b..1204590f4 100644 --- a/src/java/org/apache/fop/pdf/PDFFontType1.java +++ b/src/java/org/apache/fop/pdf/PDFFontType1.java @@ -67,17 +67,16 @@ public class PDFFontType1 extends PDFFontNonBase14 { /** * Create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font */ - public PDFFontType1(int number, String fontname, + public PDFFontType1(String fontname, String basefont, Object encoding) { /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE1, basefont, encoding); + super(fontname, FontType.TYPE1, basefont, encoding); } } diff --git a/src/java/org/apache/fop/pdf/PDFFontType3.java b/src/java/org/apache/fop/pdf/PDFFontType3.java index 5c837aded..d4e0303f9 100644 --- a/src/java/org/apache/fop/pdf/PDFFontType3.java +++ b/src/java/org/apache/fop/pdf/PDFFontType3.java @@ -85,17 +85,16 @@ public class PDFFontType3 extends PDFFontNonBase14 { /** * Create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font */ - public PDFFontType3(int number, String fontname, + public PDFFontType3(String fontname, String basefont, Object encoding) { /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */); + super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */); this.fontBBox = null; this.fontMatrix = null; @@ -105,7 +104,6 @@ public class PDFFontType3 extends PDFFontNonBase14 { /** * Create the /Font object * - * @param number the object's number * @param fontname the internal name for the font * @param basefont the base font name * @param encoding the character encoding schema used by the font @@ -113,14 +111,14 @@ public class PDFFontType3 extends PDFFontNonBase14 { * @param fontMatrix the font's transformation matrix * @param charProcs the glyphs' definitions */ - public PDFFontType3(int number, String fontname, + public PDFFontType3(String fontname, String basefont, Object encoding, PDFRectangle fontBBox, PDFArray fontMatrix, PDFCharProcs charProcs) { /* generic creation of PDF object */ - super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */); + super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */); this.fontBBox = fontBBox; this.fontMatrix = fontMatrix; diff --git a/src/java/org/apache/fop/pdf/PDFFunction.java b/src/java/org/apache/fop/pdf/PDFFunction.java index 38af4ba90..bf05508d1 100644 --- a/src/java/org/apache/fop/pdf/PDFFunction.java +++ b/src/java/org/apache/fop/pdf/PDFFunction.java @@ -239,15 +239,14 @@ public class PDFFunction extends PDFObject { * 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, List theDomain, + public PDFFunction(int theFunctionType, List theDomain, List theRange, List theSize, int theBitsPerSample, int theOrder, List theEncode, List theDecode, StringBuffer theFunctionDataStream, List theFilter) { - super(theNumber); + super(); this.functionType = 0; // dang well better be 0; this.size = theSize; @@ -271,7 +270,6 @@ public class PDFFunction extends PDFObject { * 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 List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. @@ -293,10 +291,10 @@ public class PDFFunction extends PDFObject { * PDF Spec page 268 * @param theFunctionType The type of the function, which should be 2. */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, + public PDFFunction(int theFunctionType, List theDomain, List theRange, List theCZero, List theCOne, double theInterpolationExponentN) { - super(theNumber); + super(); this.functionType = 2; // dang well better be 2; @@ -316,7 +314,6 @@ public class PDFFunction extends PDFObject { * 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 List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. @@ -346,10 +343,10 @@ public class PDFFunction extends PDFObject { * @param theFunctionType This is the function type. It should be 3, * for a stitching function. */ - public PDFFunction(int theNumber, int theFunctionType, List theDomain, + public PDFFunction(int theFunctionType, List theDomain, List theRange, List theFunctions, List theBounds, List theEncode) { - super(theNumber); + super(); this.functionType = 3; // dang well better be 3; @@ -380,13 +377,12 @@ public class PDFFunction extends PDFObject { * * 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, List theDomain, + public PDFFunction(int theFunctionType, List theDomain, List theRange, StringBuffer theFunctionDataStream) { - super(theNumber); + super(); this.functionType = 4; // dang well better be 4; this.functionDataStream = theFunctionDataStream; @@ -413,9 +409,9 @@ public class PDFFunction extends PDFObject { 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"); + StringBuffer p = new StringBuffer(256); + p.append(getObjectID() + + "<< \n/FunctionType " + this.functionType + " \n"); // FunctionType 0 if (this.functionType == 0) { @@ -727,7 +723,7 @@ public class PDFFunction extends PDFObject { } - return (p.toString().getBytes()); + return encode(p.toString()); } diff --git a/src/java/org/apache/fop/pdf/PDFGState.java b/src/java/org/apache/fop/pdf/PDFGState.java index 5b7c20dc1..c599884a7 100644 --- a/src/java/org/apache/fop/pdf/PDFGState.java +++ b/src/java/org/apache/fop/pdf/PDFGState.java @@ -118,7 +118,7 @@ public class PDFGState extends PDFObject { public static final PDFGState DEFAULT; static { - DEFAULT = new PDFGState(0); + DEFAULT = new PDFGState(); Map vals = DEFAULT.values; /*vals.put(LW, new Float(1.0)); vals.put(LC, new Integer(0)); @@ -138,21 +138,11 @@ public class PDFGState extends PDFObject { private Map values = new java.util.HashMap(); /** - * Create a /ExtGState object. - * - * @param number the object's number - */ - public PDFGState(int number) { - /* generic creation of object */ - super(number); - } - - /** * Returns the name of this object * @return the name */ public String getName() { - return "GS" + this.number; + return "GS" + getObjectNumber(); } /** @@ -186,18 +176,17 @@ public class PDFGState extends PDFObject { } /** - * Represent the object in PDF. - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer sb = new StringBuffer(this.number + " " + this.generation - + " obj\n<<\n/Type /ExtGState\n"); + public String toPDFString() { + StringBuffer sb = new StringBuffer(64); + sb.append(getObjectID()); + sb.append("<<\n/Type /ExtGState\n"); appendVal(sb, GSTATE_ALPHA_NONSTROKE); appendVal(sb, GSTATE_ALPHA_STROKE); sb.append(">>\nendobj\n"); - return sb.toString().getBytes(); + return sb.toString(); } private void appendVal(StringBuffer sb, String name) { diff --git a/src/java/org/apache/fop/pdf/PDFGoTo.java b/src/java/org/apache/fop/pdf/PDFGoTo.java index 2011520de..22df2c87f 100644 --- a/src/java/org/apache/fop/pdf/PDFGoTo.java +++ b/src/java/org/apache/fop/pdf/PDFGoTo.java @@ -68,12 +68,11 @@ public class PDFGoTo extends PDFAction { /** * create a /GoTo object. * - * @param number the object's number * @param pageReference the pageReference represented by this object */ - public PDFGoTo(int number, String pageReference) { + public PDFGoTo(String pageReference) { /* generic creation of object */ - super(number); + super(); this.pageReference = pageReference; } @@ -124,11 +123,9 @@ public class PDFGoTo extends PDFAction { } /** - * represent the object in PDF - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { + public String toPDFString() { String dest; if (destination == null) { dest = "/D [" + this.pageReference + " /XYZ " + xPosition @@ -136,10 +133,9 @@ public class PDFGoTo extends PDFAction { } else { dest = "/D [" + this.pageReference + " " + destination + "]\n"; } - String p = new String(this.number + " " + this.generation - + " obj\n<<\n/S /GoTo\n" + dest - + ">>\nendobj\n"); - return p.getBytes(); + return getObjectID() + + "<< /Type /Action\n/S /GoTo\n" + dest + + ">>\nendobj\n"; } /* diff --git a/src/java/org/apache/fop/pdf/PDFGoToRemote.java b/src/java/org/apache/fop/pdf/PDFGoToRemote.java index e0019c8c0..9f5171563 100644 --- a/src/java/org/apache/fop/pdf/PDFGoToRemote.java +++ b/src/java/org/apache/fop/pdf/PDFGoToRemote.java @@ -65,12 +65,11 @@ public class PDFGoToRemote extends PDFAction { /** * create an GoToR object. * - * @param number the object's number * @param pdfFileSpec the fileSpec associated with the action */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec) { + public PDFGoToRemote(PDFFileSpec pdfFileSpec) { /* generic creation of object */ - super(number); + super(); this.pdfFileSpec = pdfFileSpec; } @@ -78,13 +77,12 @@ public class PDFGoToRemote extends PDFAction { /** * create an GoToR object. * - * @param number the object's number * @param pdfFileSpec the fileSpec associated with the action * @param page a page reference within the remote document */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, int page) { + public PDFGoToRemote(PDFFileSpec pdfFileSpec, int page) { /* generic creation of object */ - super(number); + super(); this.pdfFileSpec = pdfFileSpec; this.pageReference = page; @@ -93,13 +91,12 @@ public class PDFGoToRemote extends PDFAction { /** * create an GoToR object. * - * @param number the object's number * @param pdfFileSpec the fileSpec associated with the action * @param dest a named destination within the remote document */ - public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, String dest) { + public PDFGoToRemote(PDFFileSpec pdfFileSpec, String dest) { /* generic creation of object */ - super(number); + super(); this.pdfFileSpec = pdfFileSpec; this.destination = dest; @@ -115,24 +112,22 @@ public class PDFGoToRemote extends PDFAction { } /** - * represent the object in PDF - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - String p = new String(this.number + " " + this.generation + " obj\n" - + "<<\n/S /GoToR\n" + "/F " - + pdfFileSpec.referencePDF() + "\n"); + public String toPDFString() { + StringBuffer sb = new StringBuffer(64); + sb.append(getObjectID()); + sb.append("<<\n/S /GoToR\n/F " + pdfFileSpec.referencePDF() + "\n"); if (destination != null) { - p += "/D (" + this.destination + ")"; + sb.append("/D (" + this.destination + ")"); } else { - p += "/D [ " + this.pageReference + " /XYZ null null null ]"; + sb.append("/D [ " + this.pageReference + " /XYZ null null null ]"); } - p += " \n>>\nendobj\n"; + sb.append(" \n>>\nendobj\n"); - return p.getBytes(); + return sb.toString(); } diff --git a/src/java/org/apache/fop/pdf/PDFInternalLink.java b/src/java/org/apache/fop/pdf/PDFInternalLink.java index 812c974cd..fd2e5969a 100644 --- a/src/java/org/apache/fop/pdf/PDFInternalLink.java +++ b/src/java/org/apache/fop/pdf/PDFInternalLink.java @@ -77,12 +77,10 @@ public class PDFInternalLink extends PDFAction { } /** - * there is nothing to return for the toPDF method, as it should not be called - * - * @return an empty string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - return new byte[0]; + protected String toPDFString() { + throw new UnsupportedOperationException("This method should not be called"); } } diff --git a/src/java/org/apache/fop/pdf/PDFLink.java b/src/java/org/apache/fop/pdf/PDFLink.java index 23e36e41d..78da2d867 100644 --- a/src/java/org/apache/fop/pdf/PDFLink.java +++ b/src/java/org/apache/fop/pdf/PDFLink.java @@ -77,12 +77,11 @@ public class PDFLink extends PDFObject { /** * create objects associated with a link annotation (GoToR) * - * @param number the object's number * @param r the rectangle of the link hotspot in absolute coordinates */ - public PDFLink(int number, Rectangle2D r) { + public PDFLink(Rectangle2D r) { /* generic creation of PDF object */ - super(number); + super(); this.ulx = (float)r.getX(); this.uly = (float)r.getY(); @@ -101,18 +100,16 @@ public class PDFLink extends PDFObject { } /** - * produce the PDF representation of the object - * - * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - String p = this.number + " " + this.generation + " obj\n" + public String toPDFString() { + String s = getObjectID() + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ " + (ulx) + " " + (uly) + " " + (brx) + " " + (bry) + " ]\n" + "/C [ " + this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A " + this.action.getAction() + "\n" + "/H /I\n>>\nendobj\n"; - return p.getBytes(); + return s; } /* diff --git a/src/java/org/apache/fop/pdf/PDFOutline.java b/src/java/org/apache/fop/pdf/PDFOutline.java index 48e54a981..1c2810b7d 100644 --- a/src/java/org/apache/fop/pdf/PDFOutline.java +++ b/src/java/org/apache/fop/pdf/PDFOutline.java @@ -50,6 +50,8 @@ */ package org.apache.fop.pdf; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.List; /** @@ -90,12 +92,11 @@ public class PDFOutline extends PDFObject { /** * Create a PDF outline with the title and action. * - * @param number the object id number * @param title the title of the outline entry (can only be null for root Outlines obj) * @param action the action for this outline */ - public PDFOutline(int number, String title, String action) { - super(number); + public PDFOutline(String title, String action) { + super(); subentries = new java.util.ArrayList(); count = 0; parent = null; @@ -152,73 +153,51 @@ public class PDFOutline extends PDFObject { } /** - * represent the object in PDF - * - * @return the PDF for this outline + * @see org.apache.fop.pdf.PDFObject#toPDF() */ 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 string (see 3.8.1 in PDF reference 2nd edition) - */ - private String escapeString(String s) { - StringBuffer result = new StringBuffer(); - if (s != null) { - int l = s.length(); - - // byte order marker (0xfeff) - result.append("\\376\\377"); - - for (int i = 0; i < l; i++) { - char ch = s.charAt(i); - int high = (ch & 0xff00) >>> 8; - int low = ch & 0xff; - result.append("\\"); - result.append(Integer.toOctalString(high)); - result.append("\\"); - result.append(Integer.toOctalString(low)); + ByteArrayOutputStream bout = new ByteArrayOutputStream(128); + try { + bout.write(encode(getObjectID())); + bout.write(encode("<<")); + if (parent == null) { + // root Outlines object + if (first != null && last != null) { + bout.write(encode(" /First " + first.referencePDF() + "\n")); + bout.write(encode(" /Last " + last.referencePDF() + "\n")); + // no count... we start with the outline completely closed for now + } + } else { + // subentry Outline object + bout.write(encode(" /Title ")); + bout.write(encodeText(this.title)); + bout.write(encode("\n")); + bout.write(encode(" /Parent " + parent.referencePDF() + "\n")); + if (first != null && last != null) { + bout.write(encode(" /First " + first.referencePDF() + "\n")); + bout.write(encode(" /Last " + last.referencePDF() + "\n")); + } + if (prev != null) { + bout.write(encode(" /Prev " + prev.referencePDF() + "\n")); + } + if (next != null) { + bout.write(encode(" /Next " + next.referencePDF() + "\n")); + } + if (count > 0) { + bout.write(encode(" /Count -" + count + "\n")); + } + + if (actionRef != null) { + bout.write(encode(" /A " + actionRef + "\n")); + } + + } + bout.write(encode(">> endobj\n")); + } catch (IOException ioe) { + getDocumentSafely().getLogger().error("Ignored I/O exception", ioe); } - - return result.toString(); + return bout.toByteArray(); } } diff --git a/src/java/org/apache/fop/pdf/PDFPathPaint.java b/src/java/org/apache/fop/pdf/PDFPathPaint.java index dc5170c26..f6c17ae17 100644 --- a/src/java/org/apache/fop/pdf/PDFPathPaint.java +++ b/src/java/org/apache/fop/pdf/PDFPathPaint.java @@ -62,22 +62,6 @@ public abstract class PDFPathPaint extends PDFObject { protected PDFColorSpace colorSpace; /** - * Create a path paint with a PDF object number. - * - * @param theNumber the PDF object number - */ - public PDFPathPaint(int theNumber) { - super(theNumber); - } - - /** - * Create an emty path paint. - */ - public PDFPathPaint() { - // do nothing - } - - /** * Get the PDF string for setting the path paint. * * @param fillNotStroke if true fill otherwise stroke diff --git a/src/java/org/apache/fop/pdf/PDFPattern.java b/src/java/org/apache/fop/pdf/PDFPattern.java index 44de1b8d2..12b465519 100644 --- a/src/java/org/apache/fop/pdf/PDFPattern.java +++ b/src/java/org/apache/fop/pdf/PDFPattern.java @@ -50,9 +50,8 @@ */ package org.apache.fop.pdf; -// Java... +// Java import java.util.List; -import java.util.HashMap; import java.io.OutputStream; import java.io.IOException; @@ -138,8 +137,6 @@ public class PDFPattern extends PDFPathPaint { /** * 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. @@ -151,14 +148,12 @@ public class PDFPattern extends PDFPathPaint { * @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, List theBBox, double theXStep, - double theYStep, List theMatrix, List theXUID, - StringBuffer thePatternDataStream) { - super(theNumber); - this.patternName = thePatternName; - + public PDFPattern(PDFResources theResources, int thePatternType, // 1 + int thePaintType, int theTilingType, List theBBox, + double theXStep, double theYStep, + List theMatrix, List theXUID, + StringBuffer thePatternDataStream) { + super(); this.resources = theResources; // This next parameter is implicit to all constructors, and is // not directly passed. @@ -177,21 +172,16 @@ public class PDFPattern extends PDFPathPaint { /** * 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:List of Doubles that specify the matrix. */ - public PDFPattern(int theNumber, String thePatternName, - int thePatternType, PDFShading theShading, + public PDFPattern(int thePatternType, PDFShading theShading, List theXUID, StringBuffer theExtGState, List theMatrix) { - super(theNumber); - - this.patternName = thePatternName; + super(); this.patternType = 2; // thePatternType; this.shading = theShading; @@ -212,6 +202,19 @@ public class PDFPattern extends PDFPathPaint { } /** + * Sets the name of the pattern. + * @param name the name of the pattern. Can be anything + * without spaces. "Pattern1" or "Pa1" are good examples. + */ + public void setName(String name) { + if (name.indexOf(" ") >= 0) { + throw new IllegalArgumentException( + "Pattern name must not contain any spaces"); + } + this.patternName = name; + } + + /** * Get the PDF command for setting to this pattern. * * @param fillNotStroke if true fill otherwise stroke @@ -242,9 +245,10 @@ public class PDFPattern extends PDFPathPaint { int vectorSize = 0; int tempInt = 0; - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< \n/Type /Pattern \n"); + byte[] buffer; + StringBuffer p = new StringBuffer(64); + p.append(getObjectID()); + p.append("<< \n/Type /Pattern \n"); if (this.resources != null) { p.append("/Resources " + this.resources.referencePDF() + " \n"); @@ -252,7 +256,8 @@ public class PDFPattern extends PDFPathPaint { p.append("/PatternType " + this.patternType + " \n"); - PDFStream dataStream = null; + PDFStream pdfStream = null; + StreamCache encodedStream = null; if (this.patternType == 1) { p.append("/PaintType " + this.paintType + " \n"); @@ -293,12 +298,15 @@ public class PDFPattern extends PDFPathPaint { // don't forget the length of the stream. if (this.patternDataStream != null) { - dataStream = new PDFStream(0); - dataStream.add(this.patternDataStream.toString()); - // TODO get the filters from the doc - dataStream.addDefaultFilters(new HashMap(), PDFStream.CONTENT_FILTER); - p.append(dataStream.applyFilters()); - p.append("/Length " + (dataStream.getDataLength() + 1) + pdfStream = new PDFStream(); + pdfStream.setDocument(getDocumentSafely()); + pdfStream.add(this.patternDataStream.toString()); + pdfStream.getFilterList().addDefaultFilters( + getDocument().getFilterMap(), + PDFFilterList.CONTENT_FILTER); + encodedStream = pdfStream.encodeStream(); + p.append(pdfStream.getFilterList().buildFilterDictEntries()); + p.append("/Length " + (encodedStream.getSize() + 1) + " \n"); } @@ -335,19 +343,18 @@ public class PDFPattern extends PDFPathPaint { p.append(">> \n"); - String dict = p.toString(); - int length = dict.length(); - - stream.write(dict.getBytes()); + buffer = encode(p.toString()); + int length = buffer.length; + stream.write(buffer); // stream representing the function - if (dataStream != null) { - length += dataStream.outputStreamData(stream); + if (pdfStream != null) { + length += pdfStream.outputStreamData(encodedStream, stream); } - String end = "endobj\n"; - stream.write(end.getBytes()); - length += end.length(); + buffer = encode("\nendobj\n"); + stream.write(buffer); + length += buffer.length; return length; } diff --git a/src/java/org/apache/fop/pdf/PDFResourceContext.java b/src/java/org/apache/fop/pdf/PDFResourceContext.java index f82ed26a1..7886d7ce8 100644 --- a/src/java/org/apache/fop/pdf/PDFResourceContext.java +++ b/src/java/org/apache/fop/pdf/PDFResourceContext.java @@ -60,7 +60,7 @@ package org.apache.fop.pdf; * * Modified by Mark Lillywhite, mark-fop@inomial.com. The Parent * object was being referred to by reference, but all that we - * ever used from the Parent was it's PDF object ID, and according + * ever used from the Parent was its PDF object ID, and according * to the memory profile this was causing OOM issues. So, we store * only the object ID of the parent, rather than the parent itself. */ @@ -77,22 +77,15 @@ public class PDFResourceContext extends PDFObject { protected PDFAnnotList annotList; /** - * Reference to document used when creating annotation list - */ - protected PDFDocument document; - - /** - * - * @param number the object's number - * @param doc the PDF document this belongs to + * Creates a new ResourceContext. * @param resources the /Resources object */ - public PDFResourceContext(int number, PDFDocument doc, PDFResources resources) { + public PDFResourceContext(PDFResources resources) { /* generic creation of object */ - super(number); + super(); /* set fields using parameters */ - this.document = doc; + //this.document = doc; this.resources = resources; this.annotList = null; } @@ -113,7 +106,7 @@ public class PDFResourceContext extends PDFObject { */ public void addAnnotation(PDFObject annot) { if (this.annotList == null) { - this.annotList = document.makeAnnotList(); + this.annotList = getDocument().getFactory().makeAnnotList(); } this.annotList.addAnnot(annot); } @@ -133,24 +126,16 @@ public class PDFResourceContext extends PDFObject { * @param gstate the GState to add */ public void addGState(PDFGState gstate) { - this.resources.addGState(gstate); + getPDFResources().addGState(gstate); } /** - * Add the shading tot he current resource context. + * Add the shading to the current resource context. * * @param shading the shading to add */ public void addShading(PDFShading shading) { - this.resources.addShading(shading); + getPDFResources().addShading(shading); } - /** - * Get the PDF, unused. - * - * @return null value - */ - public byte[] toPDF() { - return null; - } } diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java index ffc7c5b0a..76f303113 100644 --- a/src/java/org/apache/fop/pdf/PDFResources.java +++ b/src/java/org/apache/fop/pdf/PDFResources.java @@ -93,11 +93,12 @@ public class PDFResources extends PDFObject { /** * create a /Resources object. * - * @param number the object's number + * @param objnum the object's number */ - public PDFResources(int number) { + public PDFResources(int objnum) { /* generic creation of object */ - super(number); + super(); + setObjectNumber(objnum); } /** @@ -151,32 +152,33 @@ public class PDFResources extends PDFObject { * resource context. * * @return the PDF + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< \n"); + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID() + "<<\n"); if (!this.fonts.isEmpty()) { - p.append("/Font << "); + p.append("/Font <<\n"); /* construct PDF dictionary of font object references */ Iterator fontIterator = this.fonts.keySet().iterator(); while (fontIterator.hasNext()) { String fontName = (String)fontIterator.next(); - p.append("/" + fontName + " " + p.append(" /" + fontName + " " + ((PDFFont)this.fonts.get(fontName)).referencePDF() - + " "); + + "\n"); } - p.append(">> \n"); + p.append(">>\n"); } PDFShading currentShading = null; if (!this.shadings.isEmpty()) { - p.append("/Shading << "); + p.append("/Shading <<\n"); for (Iterator iter = shadings.iterator(); iter.hasNext();) { currentShading = (PDFShading)iter.next(); - p.append("/" + currentShading.getName() + " " + p.append(" /" + currentShading.getName() + " " + currentShading.referencePDF() + " "); // \n ?????? } @@ -187,46 +189,46 @@ public class PDFResources extends PDFObject { PDFPattern currentPattern = null; if (!this.patterns.isEmpty()) { - p.append("/Pattern << "); + p.append("/Pattern <<\n"); for (Iterator iter = patterns.iterator(); iter.hasNext();) { currentPattern = (PDFPattern)iter.next(); - p.append("/" + currentPattern.getName() + " " + p.append(" /" + currentPattern.getName() + " " + currentPattern.referencePDF() + " "); } - p.append(">> \n"); + p.append(">>\n"); } // "free" the memory. Sorta. currentPattern = null; - p.append("/ProcSet [ /PDF /ImageC /Text ]\n"); + p.append("/ProcSet [ /PDF /ImageB /ImageC /Text ]\n"); if (this.xObjects != null && !this.xObjects.isEmpty()) { - p = p.append("/XObject <<"); + p = p.append("/XObject <<\n"); for (Iterator iter = xObjects.iterator(); iter.hasNext();) { PDFXObject xobj = (PDFXObject)iter.next(); - p = p.append("/Im" + xobj.getXNumber() + " " + p = p.append(" /Im" + xobj.getXNumber() + " " + xobj.referencePDF() + "\n"); } - p = p.append(" >>\n"); + p = p.append(">>\n"); } if (!this.gstates.isEmpty()) { - p = p.append("/ExtGState <<"); + p = p.append("/ExtGState <<\n"); for (Iterator iter = gstates.iterator(); iter.hasNext();) { PDFGState gs = (PDFGState)iter.next(); - p = p.append("/" + gs.getName() + " " + p = p.append(" /" + gs.getName() + " " + gs.referencePDF() - + " "); + + "\n"); } p = p.append(">>\n"); } p = p.append(">>\nendobj\n"); - return p.toString().getBytes(); + return p.toString(); } } diff --git a/src/java/org/apache/fop/pdf/PDFRoot.java b/src/java/org/apache/fop/pdf/PDFRoot.java index a803ea0b7..9b0105418 100644 --- a/src/java/org/apache/fop/pdf/PDFRoot.java +++ b/src/java/org/apache/fop/pdf/PDFRoot.java @@ -94,11 +94,12 @@ public class PDFRoot extends PDFObject { * it is about to be written (immediately before the xref * table as part of the trsailer). (mark-fop@inomial.com) * - * @param number the object's number + * @param objnum the object's number * @param pages the PDFPages object */ - public PDFRoot(int number, PDFPages pages) { - super(number); + public PDFRoot(int objnum, PDFPages pages) { + super(); + setObjectNumber(objnum); setRootPages(pages); } @@ -148,15 +149,14 @@ public class PDFRoot extends PDFObject { } /** - * represent the object as PDF. - * - * @return the PDF string + * @see org.apache.fop.pdf.PDFObject#toPDFString() */ - public byte[] toPDF() { - StringBuffer p = new StringBuffer(this.number + " " + this.generation - + " obj\n<< /Type /Catalog\n/Pages " - + this.rootPages.referencePDF() - + "\n"); + public String toPDFString() { + StringBuffer p = new StringBuffer(128); + p.append(getObjectID()); + p.append("<< /Type /Catalog\n/Pages " + + this.rootPages.referencePDF() + + "\n"); if (outline != null) { p.append(" /Outlines " + outline.referencePDF() + "\n"); p.append(" /PageMode /UseOutlines\n"); @@ -176,8 +176,8 @@ public class PDFRoot extends PDFObject { break; } } - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + p.append(">>\nendobj\n"); + return p.toString(); } } diff --git a/src/java/org/apache/fop/pdf/PDFShading.java b/src/java/org/apache/fop/pdf/PDFShading.java index 13220f22c..5f2cc294c 100644 --- a/src/java/org/apache/fop/pdf/PDFShading.java +++ b/src/java/org/apache/fop/pdf/PDFShading.java @@ -177,9 +177,6 @@ public class PDFShading extends PDFObject { /** * 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. @@ -198,13 +195,11 @@ public class PDFShading extends PDFObject { * 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, PDFColorSpace theColorSpace, + public PDFShading(int theShadingType, PDFColorSpace theColorSpace, List theBackground, List theBBox, boolean theAntiAlias, List theDomain, List theMatrix, PDFFunction theFunction) { - super(theNumber); - this.shadingName = theShadingName; + super(); this.shadingType = theShadingType; // 1 this.colorSpace = theColorSpace; this.background = theBackground; @@ -220,9 +215,6 @@ public class PDFShading extends PDFObject { /** * 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 @@ -241,14 +233,12 @@ public class PDFShading extends PDFObject { * and end colors past the start and end points * The default is [false, false] */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, + public PDFShading(int theShadingType, PDFColorSpace theColorSpace, List theBackground, List theBBox, boolean theAntiAlias, List theCoords, List theDomain, PDFFunction theFunction, List theExtend) { - super(theNumber); - this.shadingName = theShadingName; + super(); this.shadingType = theShadingType; // 2 or 3 this.colorSpace = theColorSpace; this.background = theBackground; @@ -265,12 +255,9 @@ public class PDFShading extends PDFObject { /** * 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. @@ -286,13 +273,12 @@ public class PDFShading extends PDFObject { * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ - public PDFShading(int theNumber, String theShadingName, - int theShadingType, PDFColorSpace theColorSpace, + public PDFShading(int theShadingType, PDFColorSpace theColorSpace, List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, int theBitsPerFlag, List theDecode, PDFFunction theFunction) { - super(theNumber); + super(); this.shadingType = theShadingType; // 4,6 or 7 this.colorSpace = theColorSpace; @@ -311,8 +297,6 @@ public class PDFShading extends PDFObject { * 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. @@ -327,16 +311,13 @@ public class PDFShading extends PDFObject { * @param theDecode List 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, PDFColorSpace theColorSpace, + public PDFShading(int theShadingType, PDFColorSpace theColorSpace, List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, List theDecode, int theVerticesPerRow, PDFFunction theFunction) { - super(theNumber); - this.shadingName = theShadingName; + super(); this.shadingType = theShadingType; // 5 this.colorSpace = theColorSpace; this.background = theBackground; @@ -361,6 +342,19 @@ public class PDFShading extends PDFObject { } /** + * Sets the name of the shading + * @param name the name of the shading pattern. Can be anything + * without spaces. "Shading1" or "Sh1" are good examples. + */ + public void setName(String name) { + if (name.indexOf(" ") >= 0) { + throw new IllegalArgumentException( + "Shading name must not contain any spaces"); + } + this.shadingName = name; + } + + /** * 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 @@ -371,12 +365,12 @@ public class PDFShading extends PDFObject { * * @return the PDF string. */ - public byte[] toPDF() { + public String toPDFString() { int vectorSize; int tempInt; - StringBuffer p = new StringBuffer(); - p.append(this.number + " " + this.generation - + " obj\n<< \n/ShadingType " + this.shadingType + " \n"); + StringBuffer p = new StringBuffer(128); + p.append(getObjectID() + + "<< \n/ShadingType " + this.shadingType + " \n"); if (this.colorSpace != null) { p.append("/ColorSpace /" + this.colorSpace.getColorSpacePDFString() + " \n"); @@ -563,7 +557,7 @@ public class PDFShading extends PDFObject { p.append(">> \nendobj\n"); - return (p.toString().getBytes()); + return (p.toString()); } /** diff --git a/src/java/org/apache/fop/pdf/PDFState.java b/src/java/org/apache/fop/pdf/PDFState.java index 289d20292..0d754979e 100644 --- a/src/java/org/apache/fop/pdf/PDFState.java +++ b/src/java/org/apache/fop/pdf/PDFState.java @@ -366,7 +366,7 @@ public class PDFState { PDFGState defaultState = PDFGState.DEFAULT; PDFGState state; - PDFGState newstate = new PDFGState(0); + PDFGState newstate = new PDFGState(); newstate.addValues(defaultState); for (Iterator iter = stateStack.iterator(); iter.hasNext();) { HashMap map = (HashMap)iter.next(); |