jeremias 2003/03/27 02:44:05 Modified: src/java/org/apache/fop/pdf PDFResourceContext.java PDFRoot.java PDFPathPaint.java PDFResources.java PDFPattern.java Log: The PDF object number doesn't get passed to the constructor anymore. Adjust for that. Use the toPDFString() (returns String) method instead of toPDF() (returns byte[]) where appropriate. String to byte[] conversion is done in PDFObject in a well-defined location instead of scattered around the codebase. Revision Changes Path 1.2 +9 -24 xml-fop/src/java/org/apache/fop/pdf/PDFResourceContext.java Index: PDFResourceContext.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFResourceContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PDFResourceContext.java 11 Mar 2003 13:05:09 -0000 1.1 +++ PDFResourceContext.java 27 Mar 2003 10:44:04 -0000 1.2 @@ -60,7 +60,7 @@ * * Modified by Mark Lillywhite, [EMAIL PROTECTED] 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 @@ 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 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 @@ * @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; - } } 1.2 +13 -13 xml-fop/src/java/org/apache/fop/pdf/PDFRoot.java Index: PDFRoot.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFRoot.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PDFRoot.java 11 Mar 2003 13:05:09 -0000 1.1 +++ PDFRoot.java 27 Mar 2003 10:44:05 -0000 1.2 @@ -94,11 +94,12 @@ * it is about to be written (immediately before the xref * table as part of the trsailer). ([EMAIL PROTECTED]) * - * @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 @@ } /** - * 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 @@ break; } } - p.append(" >>\nendobj\n"); - return p.toString().getBytes(); + p.append(">>\nendobj\n"); + return p.toString(); } } 1.2 +0 -16 xml-fop/src/java/org/apache/fop/pdf/PDFPathPaint.java Index: PDFPathPaint.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFPathPaint.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PDFPathPaint.java 11 Mar 2003 13:05:09 -0000 1.1 +++ PDFPathPaint.java 27 Mar 2003 10:44:05 -0000 1.2 @@ -62,22 +62,6 @@ 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 1.2 +25 -23 xml-fop/src/java/org/apache/fop/pdf/PDFResources.java Index: PDFResources.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFResources.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PDFResources.java 11 Mar 2003 13:05:09 -0000 1.1 +++ PDFResources.java 27 Mar 2003 10:44:05 -0000 1.2 @@ -93,11 +93,12 @@ /** * 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 @@ * 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 @@ 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(); } } 1.2 +45 -38 xml-fop/src/java/org/apache/fop/pdf/PDFPattern.java Index: PDFPattern.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFPattern.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PDFPattern.java 11 Mar 2003 13:05:09 -0000 1.1 +++ PDFPattern.java 27 Mar 2003 10:44:05 -0000 1.2 @@ -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 @@ /** * 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 @@ * @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 @@ /** * 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 @@ } /** + * 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 @@ 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 @@ 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 @@ // 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 @@ 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; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]