From 0b8d83a71b7e8699884057742946a3c450e3fb26 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Fri, 22 Nov 2002 10:32:21 +0000 Subject: reuses duplicate link pdf objects bit of a cleanup of collections using interface git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195607 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/pdf/BitmapImage.java | 272 ++++++++++++++++++--------- src/org/apache/fop/pdf/PDFDocument.java | 295 +++++++++++++++++++----------- src/org/apache/fop/pdf/PDFFileSpec.java | 25 +++ src/org/apache/fop/pdf/PDFFunction.java | 70 +++---- src/org/apache/fop/pdf/PDFGoTo.java | 53 +++++- src/org/apache/fop/pdf/PDFGoToRemote.java | 35 ++++ src/org/apache/fop/pdf/PDFLink.java | 31 ++++ src/org/apache/fop/pdf/PDFPattern.java | 28 +-- src/org/apache/fop/pdf/PDFShading.java | 60 +++--- src/org/apache/fop/pdf/PDFStream.java | 19 +- 10 files changed, 596 insertions(+), 292 deletions(-) (limited to 'src/org/apache/fop/pdf') diff --git a/src/org/apache/fop/pdf/BitmapImage.java b/src/org/apache/fop/pdf/BitmapImage.java index cc23f3df1..ab06ea4e1 100644 --- a/src/org/apache/fop/pdf/BitmapImage.java +++ b/src/org/apache/fop/pdf/BitmapImage.java @@ -8,97 +8,189 @@ package org.apache.fop.pdf; import java.io.IOException; -import java.util.HashMap; +import java.util.Map; + +/** + * Bitmap image. + * This is used to create a bitmap image that will be inserted + * into pdf. + */ public class BitmapImage implements PDFImage { - int m_height; - int m_width; - int m_bitsPerPixel; - PDFColorSpace m_colorSpace; - byte[] m_bitmaps; - String maskRef; - PDFColor transparent = null; - String key; - HashMap filters; - - public BitmapImage(String k, int width, int height, byte[] result, + private int height; + private int width; + private int bitsPerPixel; + private PDFColorSpace colorSpace; + private byte[] bitmaps; + private String maskRef; + private PDFColor transparent = null; + private String key; + private Map filters; + + /** + * Create a bitmap image. + * Creates a new bitmap image with the given data. + * + * @param k the key to be used to lookup the image + * @param width the width of the image + * @param height the height of the image + * @param data the bitmap data + * @param mask the transparancy mask reference if any + */ + public BitmapImage(String k, int width, int height, byte[] data, String mask) { - this.key = k; - this.m_height = height; - this.m_width = width; - this.m_bitsPerPixel = 8; - this.m_colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - this.m_bitmaps = result; - maskRef = mask; - } - - public void setup(PDFDocument doc) { - filters = doc.getFilterMap(); - } - - public String getKey() { - return key; - } - - // image size - public int getWidth() { - return m_width; - } - - public int getHeight() { - return m_height; - } - - public void setColorSpace(PDFColorSpace cs) { - m_colorSpace = cs; - } - - // DeviceGray, DeviceRGB, or DeviceCMYK - public PDFColorSpace getColorSpace() { - return m_colorSpace; - } - - // bits per pixel - public int getBitsPerPixel() { - return m_bitsPerPixel; - } - - public void setTransparent(PDFColor t) { - transparent = t; - } - - // For transparent images - public boolean isTransparent() { - return transparent != null; - } - - public PDFColor getTransparentColor() { - return transparent; - } - - public String getMask() { - return null; - } - - public String getSoftMask() { - return maskRef; - } - - public PDFStream getDataStream() throws IOException { - // delegate the stream work to PDFStream - PDFStream imgStream = new PDFStream(0); - - imgStream.setData(m_bitmaps); - - imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); - return imgStream; - } - - public PDFICCStream getICCStream() { - return null; - } - - public boolean isPS() { - return false; - } + this.key = k; + this.height = height; + this.width = width; + this.bitsPerPixel = 8; + this.colorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); + this.bitmaps = data; + maskRef = mask; + } + + /** + * Setup this image with the pdf document. + * + * @param doc the pdf document this will be inserted into + */ + public void setup(PDFDocument doc) { + filters = doc.getFilterMap(); + } + + /** + * Get the key for this image. + * This key is used by the pdf document so that it will only + * insert an image once. All other references to the same image + * will use the same XObject reference. + * + * @return the unique key to identify this image + */ + public String getKey() { + return key; + } + + /** + * Get the width of this image. + * + * @return the width of the image + */ + public int getWidth() { + return width; + } + + /** + * Get the height of this image. + * + * @return the height of the image + */ + public int getHeight() { + return height; + } + + /** + * Set the color space for this image. + * + * @param cs the pdf color space + */ + public void setColorSpace(PDFColorSpace cs) { + colorSpace = cs; + } + + /** + * Get the color space for the image data. + * Possible options are: DeviceGray, DeviceRGB, or DeviceCMYK + * + * @return the pdf doclor space + */ + public PDFColorSpace getColorSpace() { + return colorSpace; + } + + /** + * Get the number of bits per pixel. + * + * @return the number of bits per pixel + */ + public int getBitsPerPixel() { + return bitsPerPixel; + } + + /** + * Set the transparent color for this iamge. + * + * @param t the transparent color + */ + public void setTransparent(PDFColor t) { + transparent = t; } + /** + * Check if this image has a transparent color. + * + * @return true if it has a transparent color + */ + public boolean isTransparent() { + return transparent != null; + } + + /** + * Get the transparent color for this image. + * + * @return the transparent color if any + */ + public PDFColor getTransparentColor() { + return transparent; + } + + /** + * Get the bitmap mask reference for this image. + * Current not supported. + * + * @return the bitmap mask reference + */ + public String getMask() { + return null; + } + + /** + * Get the soft mask reference for this image. + * + * @return the soft mask reference if any + */ + public String getSoftMask() { + return maskRef; + } + + /** + * Get the pdf data stream for the bitmap data. + * + * @return a pdf stream containing the filtered image data + * @throws IOException if there is an error handling the data + */ + public PDFStream getDataStream() throws IOException { + // delegate the stream work to PDFStream + PDFStream imgStream = new PDFStream(0); + + imgStream.setData(bitmaps); + + imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER); + return imgStream; + } + + /** + * Get the ICC stream. + * @return always returns null since this has no icc color space + */ + public PDFICCStream getICCStream() { + return null; + } + + /** + * Check if this is a postscript image. + * @return always returns false + */ + public boolean isPS() { + return false; + } +} + + diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 4c62c85fb..fdd8578bd 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -15,9 +15,12 @@ import org.apache.fop.render.pdf.fonts.LazyFont; import org.apache.fop.layout.FontMetric; import org.apache.fop.layout.FontDescriptor; + // Java import java.io.IOException; import java.io.OutputStream; +import java.util.List; +import java.util.Map; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -59,10 +62,10 @@ public class PDFDocument { /** * the character position of each object */ - protected ArrayList location = new ArrayList(); + protected List location = new ArrayList(); /** List of objects to write in the trailer */ - private ArrayList trailerObjects = new ArrayList(); + private List trailerObjects = new ArrayList(); /** * the counter for object numbering @@ -72,7 +75,7 @@ public class PDFDocument { /** * the objects themselves */ - protected ArrayList objects = new ArrayList(); + protected List objects = new ArrayList(); /** * character position of xref table @@ -124,37 +127,58 @@ public class PDFDocument { * the XObjects Map. * Should be modified (works only for image subtype) */ - protected HashMap xObjectsMap = new HashMap(); + protected Map xObjectsMap = new HashMap(); /** * the Font Map. */ - protected HashMap fontMap = new HashMap(); + protected Map fontMap = new HashMap(); /** * The filter map. */ - protected HashMap filterMap = new HashMap(); + protected Map filterMap = new HashMap(); /** * List of PDFGState objects. */ - protected ArrayList gstates = new ArrayList(); + protected List gstates = new ArrayList(); /** * List of functions. */ - protected ArrayList functions = new ArrayList(); + protected List functions = new ArrayList(); /** * List of shadings. */ - protected ArrayList shadings = new ArrayList(); + protected List shadings = new ArrayList(); /** * List of patterns. */ - protected ArrayList patterns = new ArrayList(); + protected List patterns = new ArrayList(); + + /** + * List of Links. + */ + protected List links = new ArrayList(); + + /** + * List of FileSpecs. + */ + protected List filespecs = new ArrayList(); + + /** + * List of GoToRemotes. + */ + protected List gotoremotes = new ArrayList(); + + /** + * List of GoTos. + */ + protected List gotos = new ArrayList(); + /** * creates an empty PDF document

@@ -215,7 +239,7 @@ public class PDFDocument { * * @return the map of filters being used */ - public HashMap getFilterMap() { + public Map getFilterMap() { return filterMap; } @@ -289,13 +313,13 @@ public class PDFDocument { /** * Make a Type 0 sampled function * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theSize A ArrayList object of Integer objects. + * @param theSize A List object of Integer objects. * This is the number of samples in each input dimension. * I can't imagine there being more or less than two input dimensions, * so maybe this should be an array of length 2. @@ -312,14 +336,14 @@ public class PDFDocument { * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theDecode ArrayList objects of Double objects. + * @param theDecode List objects of Double objects. * This is a linear mapping of sample values into the range. * The default is just the range. * @@ -343,12 +367,12 @@ public class PDFDocument { * @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 makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theSize, + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theSize, int theBitsPerSample, int theOrder, - ArrayList theEncode, ArrayList theDecode, + List theEncode, List theDecode, StringBuffer theFunctionDataStream, - ArrayList theFilter) { + List theFilter) { // Type 0 function PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -374,10 +398,10 @@ public class PDFDocument { * make a type Exponential interpolation function * (for shading usually) * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList of Doubles that is the Range of the function. + * @param theRange List of Doubles that is the Range of the function. * See page 264 of the PDF 1.3 Spec. * @param theCZero This is a vector of Double objects which defines the function result * when x=0. @@ -395,9 +419,9 @@ public class PDFDocument { * PDF Spec page 268 * @param theFunctionType The type of the function, which should be 2. */ - public PDFFunction makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theCZero, - ArrayList theCOne, + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theCZero, + List theCOne, double theInterpolationExponentN) { // type 2 PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -415,24 +439,22 @@ public class PDFDocument { return (function); } - private PDFFunction findFunction(PDFFunction compare) { - for (Iterator iter = functions.iterator(); iter.hasNext();) { - Object func = iter.next(); - if (compare.equals(func)) { - return (PDFFunction)func; + private Object findPDFObject(List list, PDFObject compare) { + for (Iterator iter = list.iterator(); iter.hasNext();) { + Object obj = iter.next(); + if (compare.equals(obj)) { + return obj; } } return null; } + private PDFFunction findFunction(PDFFunction compare) { + return (PDFFunction)findPDFObject(functions, compare); + } + private PDFShading findShading(PDFShading compare) { - for (Iterator iter = shadings.iterator(); iter.hasNext();) { - Object shad = iter.next(); - if (compare.equals(shad)) { - return (PDFShading)shad; - } - } - return null; + return (PDFShading)findPDFObject(shadings, compare); } /** @@ -442,25 +464,19 @@ public class PDFDocument { * would only be a small amount of data. */ private PDFPattern findPattern(PDFPattern compare) { - for (Iterator iter = patterns.iterator(); iter.hasNext();) { - Object patt = iter.next(); - if (compare.equals(patt)) { - return (PDFPattern)patt; - } - } - return null; + return (PDFPattern)findPDFObject(patterns, compare); } /** * Make a Type 3 Stitching function * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theFunctions An ArrayList of the PDFFunction objects + * @param theFunctions An List of the PDFFunction objects * that the stitching function stitches. * * This attributed is required. @@ -476,7 +492,7 @@ public class PDFDocument { * * This attributed is required. * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. @@ -486,10 +502,10 @@ public class PDFDocument { * @param theFunctionType This is the function type. It should be 3, * for a stitching function. */ - public PDFFunction makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theFunctions, - ArrayList theBounds, - ArrayList theEncode) { + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theFunctions, + List theBounds, + List theEncode) { // Type 3 PDFFunction function = new PDFFunction(++this.objectcount, @@ -519,7 +535,7 @@ public class PDFDocument { * @param theFunctionDataStream */ public PDFFunction makeFunction(int theNumber, int theFunctionType, - ArrayList theDomain, ArrayList theRange, + List theDomain, List theRange, StringBuffer theFunctionDataStream) { // Type 4 PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -548,13 +564,13 @@ public class PDFDocument { * @param theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Whether or not to anti-alias. * @param theDomain Optional vector of Doubles specifying the domain. - * @param theMatrix ArrayList of Doubles specifying the matrix. + * @param theMatrix List of Doubles specifying the matrix. * If it's a pattern, then the matrix maps it to pattern space. * If it's a shading, then it maps it to current user space. * It's optional, the default is the identity matrix @@ -562,9 +578,9 @@ public class PDFDocument { */ public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theDomain, - ArrayList theMatrix, + List theBackground, List theBBox, + boolean theAntiAlias, List theDomain, + List theMatrix, PDFFunction theFunction) { // make Shading of Type 1 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -603,25 +619,25 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false - * @param theCoords ArrayList of four (type 2) or 6 (type 3) Double - * @param theDomain ArrayList of Doubles specifying the domain + * @param theCoords List of four (type 2) or 6 (type 3) Double + * @param theDomain List of Doubles specifying the domain * @param theFunction the Stitching (PDFfunction type 3) function, * even if it's stitching a single function - * @param theExtend ArrayList of Booleans of whether to extend the + * @param theExtend List of Booleans of whether to extend the * start and end colors past the start and end points * The default is [false, false] */ public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theCoords, - ArrayList theDomain, PDFFunction theFunction, - ArrayList theExtend) { + List theBackground, List theBBox, + boolean theAntiAlias, List theCoords, + List theDomain, PDFFunction theFunction, + List theExtend) { // make Shading of Type 2 or 3 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -662,7 +678,7 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. @@ -670,16 +686,16 @@ public class PDFDocument { * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. * @param theBitsPerComponent 1,2,4,8,12, and 16 * @param theBitsPerFlag 2,4,8. - * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312. + * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, - int theBitsPerFlag, ArrayList theDecode, + int theBitsPerFlag, List theDecode, PDFFunction theFunction) { // make Shading of type 4,6 or 7 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -721,23 +737,23 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode ArrayList of Doubles. See page 305 in PDF 1.3 spec. + * @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 */ public PDFShading makeShading(PDFResourceContext res, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, ArrayList theDecode, + int theBitsPerComponent, List theDecode, int theVerticesPerRow, PDFFunction theFunction) { // make shading of Type 5 @@ -777,18 +793,18 @@ public class PDFDocument { * @param theResources the resources associated with this pattern * @param thePaintType 1 or 2, colored or uncolored. * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox ArrayList of Doubles: The pattern cell bounding box + * @param theBBox List of Doubles: The pattern cell bounding box * @param theXStep horizontal spacing * @param theYStep vertical spacing - * @param theMatrix Optional ArrayList of Doubles transformation matrix + * @param theMatrix Optional List of Doubles transformation matrix * @param theXUID Optional vector of Integers that uniquely identify the pattern * @param thePatternDataStream The stream of pattern data to be tiled. */ public PDFPattern makePattern(PDFResourceContext res, int thePatternType, // 1 PDFResources theResources, int thePaintType, int theTilingType, - ArrayList theBBox, double theXStep, - double theYStep, ArrayList theMatrix, - ArrayList theXUID, StringBuffer thePatternDataStream) { + List theBBox, double theXStep, + double theYStep, List theMatrix, + List theXUID, StringBuffer thePatternDataStream) { String thePatternName = new String("Pa" + (++this.patternCount)); // int theNumber, String thePatternName, // PDFResources theResources @@ -825,12 +841,12 @@ public class PDFDocument { * @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:ArrayList of Doubles that specify the matrix. + * @param theMatrix Optional:List of Doubles that specify the matrix. */ public PDFPattern makePattern(PDFResourceContext res, int thePatternType, PDFShading theShading, - ArrayList theXUID, StringBuffer theExtGState, - ArrayList theMatrix) { + List theXUID, StringBuffer theExtGState, + List theMatrix) { String thePatternName = new String("Pa" + (++this.patternCount)); PDFPattern pattern = new PDFPattern(++this.objectcount, @@ -867,17 +883,17 @@ public class PDFDocument { public PDFPattern createGradient(PDFResourceContext res, boolean radial, PDFColorSpace theColorspace, - ArrayList theColors, ArrayList theBounds, - ArrayList theCoords) { + List theColors, List theBounds, + List theCoords) { PDFShading myShad; PDFFunction myfunky; PDFFunction myfunc; - ArrayList theCzero; - ArrayList theCone; + List theCzero; + List theCone; PDFPattern myPattern; PDFColorSpace theColorSpace; double interpolation = (double)1.000; - ArrayList theFunctions = new ArrayList(); + List theFunctions = new ArrayList(); int currentPosition; int lastPosition = theColors.size() - 1; @@ -924,7 +940,7 @@ public class PDFDocument { } else { // if the center x, center y, and radius specifiy // the gradient, then assume the same center x, center y, // and radius of zero for the other necessary component - ArrayList newCoords = new ArrayList(); + List newCoords = new ArrayList(); newCoords.add(theCoords.get(0)); newCoords.add(theCoords.get(1)); newCoords.add(theCoords.get(2)); @@ -984,7 +1000,7 @@ public class PDFDocument { * * @return the map of fonts used in this document */ - public HashMap getFontMap() { + public Map getFontMap() { return fontMap; } @@ -1242,6 +1258,22 @@ public class PDFDocument { this.objects.add(page); } + private PDFLink findLink(PDFLink compare) { + return (PDFLink)findPDFObject(links, compare); + } + + private PDFFileSpec findFileSpec(PDFFileSpec compare) { + return (PDFFileSpec)findPDFObject(filespecs, compare); + } + + private PDFGoToRemote findGoToRemote(PDFGoToRemote compare) { + return (PDFGoToRemote)findPDFObject(gotoremotes, compare); + } + + private PDFGoTo findGoTo(PDFGoTo compare) { + return (PDFGoTo)findPDFObject(gotos, compare); + } + /** * make a link object * @@ -1254,11 +1286,9 @@ public class PDFDocument { int linkType, float yoffset) { PDFLink linkObject; - PDFAction action; int index; PDFLink link = new PDFLink(++this.objectcount, rect); - this.objects.add(link); if (linkType == PDFLink.EXTERNAL) { // check destination @@ -1266,28 +1296,18 @@ public class PDFDocument { PDFUri uri = new PDFUri(destination); link.setAction(uri); } else if (destination.endsWith(".pdf")) { // FileSpec - PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, - destination); - this.objects.add(fileSpec); - action = new PDFGoToRemote(++this.objectcount, fileSpec); - this.objects.add(action); - link.setAction(action); + PDFGoToRemote remote = getGoToPDFAction(destination, null, -1); + link.setAction(remote); } else if ((index = destination.indexOf(".pdf#page=")) > 0) { String file = destination.substring(0, index + 4); int page = Integer.parseInt(destination.substring(index + 10)); - PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file); - this.objects.add(fileSpec); - action = new PDFGoToRemote(++this.objectcount, fileSpec, page); - this.objects.add(action); - link.setAction(action); + PDFGoToRemote remote = getGoToPDFAction(destination, null, page); + link.setAction(remote); } else if ((index = destination.indexOf(".pdf#dest=")) > 0) { String file = destination.substring(0, index + 4); String dest = destination.substring(index + 10); - PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file); - this.objects.add(fileSpec); - action = new PDFGoToRemote(++this.objectcount, fileSpec, dest); - this.objects.add(action); - link.setAction(action); + PDFGoToRemote remote = getGoToPDFAction(destination, dest, -1); + link.setAction(remote); } else { // URI PDFUri uri = new PDFUri(destination); link.setAction(uri); @@ -1298,15 +1318,74 @@ public class PDFDocument { PDFInternalLink internalLink = new PDFInternalLink(goToReference); link.setAction(internalLink); } + + PDFLink oldlink = findLink(link); + if (oldlink == null) { + links.add(link); + this.objects.add(link); + } else { + this.objectcount--; + link = oldlink; + } + return link; } + /** + * Create and return a goto pdf document action. + * This creates a pdf files spec and pdf goto remote action. + * It also checks available pdf objects so it will not create an + * object if it already exists. + * + * @param file the pdf file name + * @param dest the remote name destination, may be null + * @param page the remote page number, -1 means not specified + * @return the pdf goto remote object + */ + private PDFGoToRemote getGoToPDFAction(String file, String dest, int page) { + PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file); + PDFFileSpec oldspec = findFileSpec(fileSpec); + if (oldspec == null) { + filespecs.add(fileSpec); + this.objects.add(fileSpec); + } else { + this.objectcount--; + fileSpec = oldspec; + } + PDFGoToRemote remote; + + if (dest == null && page == -1) { + remote = new PDFGoToRemote(++this.objectcount, fileSpec); + } else if (dest != null) { + remote = new PDFGoToRemote(++this.objectcount, fileSpec, dest); + } else { + remote = new PDFGoToRemote(++this.objectcount, fileSpec, page); + } + PDFGoToRemote oldremote = findGoToRemote(remote); + if (oldremote == null) { + gotoremotes.add(remote); + this.objects.add(remote); + } else { + this.objectcount--; + remote = oldremote; + } + return remote; + } + private String getGoToReference(String destination, float yoffset) { String goToReference = null; PDFGoTo gt = new PDFGoTo(++this.objectcount, destination); gt.setYPosition(yoffset); + PDFGoTo oldgt = findGoTo(gt); + if (oldgt == null) { + gotos.add(gt); + addTrailerObject(gt); + } else { + this.objectcount--; + gt = oldgt; + } + goToReference = gt.referencePDF(); - addTrailerObject(gt); return goToReference; } diff --git a/src/org/apache/fop/pdf/PDFFileSpec.java b/src/org/apache/fop/pdf/PDFFileSpec.java index d7c5338d0..2f7b2a141 100644 --- a/src/org/apache/fop/pdf/PDFFileSpec.java +++ b/src/org/apache/fop/pdf/PDFFileSpec.java @@ -53,4 +53,29 @@ public class PDFFileSpec extends PDFObject { * >> * endobj */ + + /** + * Check if this equals another object. + * + * @param obj the object to compare + * @return true if this equals other object + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null || !(obj instanceof PDFFileSpec)) { + return false; + } + + PDFFileSpec spec = (PDFFileSpec)obj; + + if (!spec.filename.equals(filename)) { + return false; + } + + return true; + } } + diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java index 62ecb25bc..32382b955 100644 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ b/src/org/apache/fop/pdf/PDFFunction.java @@ -8,7 +8,7 @@ package org.apache.fop.pdf; // Java... -import java.util.ArrayList; +import java.util.List; /** * class representing a PDF Function. @@ -31,12 +31,12 @@ public class PDFFunction extends PDFObject { /** * Required: 2 * m Array of Double numbers which are possible inputs to the function */ - protected ArrayList domain = null; + protected List domain = null; /** * Required: 2 * n Array of Double numbers which are possible outputs to the function */ - protected ArrayList range = null; + protected List range = null; /* ********************TYPE 0***************************** */ // FunctionType 0 specific function guts @@ -46,7 +46,7 @@ public class PDFFunction extends PDFObject { * Note: This is really more like two seperate integers, sizeDomain, and sizeRange, * but since they're expressed as an array in PDF, my implementation reflects that. */ - protected ArrayList size = null; + protected List size = null; /** * Required for Type 0: Number of Bits used to represent each sample value. Limited to 1,2,4,8,12,16,24, or 32 @@ -64,12 +64,12 @@ public class PDFFunction extends PDFObject { * Required for Type 3: A 2 * k array of Doubles that, taken in pairs, map each subset of the domain defined by Domain and the Bounds array to the domain of the corresponding function. * Should be two values per function, usually (0,1), as in [0 1 0 1] for 2 functions. */ - protected ArrayList encode = null; + protected List encode = null; /** * Optinoal for Type 0: A 2 * n array of Doubles which provides a linear mapping of sample values to the range. Defaults to Range. */ - protected ArrayList decode = null; + protected List decode = null; /** * Optional For Type 0: A stream of sample values @@ -84,18 +84,18 @@ public class PDFFunction extends PDFObject { * Required (?) For Type 0: A vector of Strings for the various filters to be used to decode the stream. * These are how the string is compressed. Flate, LZW, etc. */ - protected ArrayList filter = null; + protected List filter = null; /* *************************TYPE 2************************** */ /** * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0]. */ - protected ArrayList cZero = null; + protected List cZero = null; /** * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1]. */ - protected ArrayList cOne = null; + protected List cOne = null; /** * Required for Type 2: The interpolation exponent. @@ -109,7 +109,7 @@ public class PDFFunction extends PDFObject { /** * Required for Type 3: An vector of PDFFunctions which form an array of k single input functions making up the stitching function. */ - protected ArrayList functions = null; + protected List functions = null; /** * Optional for Type 3: An array of (k-1) Doubles that, in combination with Domain, define the intervals to which each function from the Functions array apply. Bounds elements must be in order of increasing magnitude, and each value must be within the value of Domain. @@ -118,7 +118,7 @@ public class PDFFunction extends PDFObject { * This makes each function responsible for an equal amount of the stitching function. * It makes the gradient even. */ - protected ArrayList bounds = null; + protected List bounds = null; // See encode above, as it's also part of Type 3 Functions. /* *************************TYPE 4************************** */ @@ -130,13 +130,13 @@ 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 theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theSize A ArrayList object of Integer objects. + * @param theSize A List object of Integer objects. * This is the number of samples in each input dimension. * I can't imagine there being more or less than two input dimensions, * so maybe this should be an array of length 2. @@ -151,14 +151,14 @@ public class PDFFunction extends PDFObject { * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theDecode ArrayList objects of Double objects. + * @param theDecode List objects of Double objects. * This is a linear mapping of sample values into the range. * The default is just the range. * @@ -180,10 +180,10 @@ public class PDFFunction extends PDFObject { * @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, ArrayList theDomain, - ArrayList theRange, ArrayList theSize, int theBitsPerSample, - int theOrder, ArrayList theEncode, ArrayList theDecode, - StringBuffer theFunctionDataStream, ArrayList theFilter) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theSize, int theBitsPerSample, + int theOrder, List theEncode, List theDecode, + StringBuffer theFunctionDataStream, List theFilter) { super(theNumber); this.functionType = 0; // dang well better be 0; @@ -209,10 +209,10 @@ public class PDFFunction extends PDFObject { * For optional int parameters, pass the default. * * @param theNumber the object's number - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList of Doubles that is the Range of the function. + * @param theRange List of Doubles that is the Range of the function. * See page 264 of the PDF 1.3 Spec. * @param theCZero This is a vector of Double objects which defines the function result * when x=0. @@ -230,8 +230,8 @@ 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, ArrayList theDomain, - ArrayList theRange, ArrayList theCZero, ArrayList theCOne, + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theCZero, List theCOne, double theInterpolationExponentN) { super(theNumber); @@ -254,13 +254,13 @@ public class PDFFunction extends PDFObject { * For optional int parameters, pass the default. * * @param theNumber the object's number - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theFunctions A ArrayList of the PDFFunction objects that the stitching function stitches. + * @param theFunctions A List of the PDFFunction objects that the stitching function stitches. * * This attributed is required. * It is described on page 269 of the PDF spec. @@ -273,7 +273,7 @@ public class PDFFunction extends PDFObject { * * This attributed is required. * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. @@ -283,9 +283,9 @@ 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, ArrayList theDomain, - ArrayList theRange, ArrayList theFunctions, - ArrayList theBounds, ArrayList theEncode) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theFunctions, + List theBounds, List theEncode) { super(theNumber); this.functionType = 3; // dang well better be 3; @@ -304,10 +304,10 @@ 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 theDomain ArrayList object of Double objects. + * @param theDomain List object of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList object of Double objects. + * @param theRange List object of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. * @param theFunctionDataStream This is a stream of arithmetic, boolean, and stack operators and boolean constants. @@ -320,8 +320,8 @@ public class PDFFunction extends PDFObject { * @param theFunctionType The type of function which should be 4, as this is * a Postscript calculator function */ - public PDFFunction(int theNumber, int theFunctionType, ArrayList theDomain, - ArrayList theRange, StringBuffer theFunctionDataStream) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, StringBuffer theFunctionDataStream) { super(theNumber); this.functionType = 4; // dang well better be 4; diff --git a/src/org/apache/fop/pdf/PDFGoTo.java b/src/org/apache/fop/pdf/PDFGoTo.java index 0a9042b91..43b3204a9 100644 --- a/src/org/apache/fop/pdf/PDFGoTo.java +++ b/src/org/apache/fop/pdf/PDFGoTo.java @@ -80,16 +80,15 @@ public class PDFGoTo extends PDFAction { * @return the PDF string */ public byte[] toPDF() { + String dest; if(destination == null) { - destination = "/D [" - + this.pageReference + " /XYZ " + xPosition - + " " + yPosition + " null]\n"; + dest = "/D [" + this.pageReference + " /XYZ " + xPosition + + " " + yPosition + " null]\n"; } else { - destination = "/D [" - + this.pageReference + " " + destination + "]\n"; + dest = "/D [" + this.pageReference + " " + destination + "]\n"; } String p = new String(this.number + " " + this.generation - + " obj\n<<\n/S /GoTo\n" + destination + + " obj\n<<\n/S /GoTo\n" + dest + ">>\nendobj\n"); return p.getBytes(); } @@ -103,4 +102,46 @@ public class PDFGoTo extends PDFAction { * >> * endobj */ + + /** + * Check if this equals another object. + * + * @param obj the object to compare + * @return true if this equals other object + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null || !(obj instanceof PDFGoTo)) { + return false; + } + + PDFGoTo gt = (PDFGoTo)obj; + + if (gt.pageReference == null) { + if (pageReference != null) { + return false; + } + } else { + if (!gt.pageReference.equals(pageReference)) { + return false; + } + } + + if(destination == null) { + if (!(gt.destination == null && gt.xPosition == xPosition + && gt.yPosition == yPosition)) { + return false; + } + } else { + if (!destination.equals(gt.destination)) { + return false; + } + } + + return true; + } } + diff --git a/src/org/apache/fop/pdf/PDFGoToRemote.java b/src/org/apache/fop/pdf/PDFGoToRemote.java index ad102034c..271eef619 100644 --- a/src/org/apache/fop/pdf/PDFGoToRemote.java +++ b/src/org/apache/fop/pdf/PDFGoToRemote.java @@ -106,4 +106,39 @@ public class PDFGoToRemote extends PDFAction { * >> * endobj */ + + /** + * Check if this equals another object. + * + * @param obj the object to compare + * @return true if this equals other object + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null || !(obj instanceof PDFGoToRemote)) { + return false; + } + + PDFGoToRemote remote = (PDFGoToRemote)obj; + + if (!remote.pdfFileSpec.referencePDF().equals(pdfFileSpec.referencePDF())) { + return false; + } + + if (destination != null) { + if (!destination.equals(remote.destination)) { + return false; + } + } else { + if (pageReference != remote.pageReference) { + return false; + } + } + + return true; + } } + diff --git a/src/org/apache/fop/pdf/PDFLink.java b/src/org/apache/fop/pdf/PDFLink.java index 34d601e59..80c6987fb 100644 --- a/src/org/apache/fop/pdf/PDFLink.java +++ b/src/org/apache/fop/pdf/PDFLink.java @@ -86,4 +86,35 @@ public class PDFLink extends PDFObject { * >> * endobj */ + + /** + * Check if this equals another object. + * + * @param obj the object to compare + * @return true if this equals other object + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null || !(obj instanceof PDFLink)) { + return false; + } + + PDFLink link = (PDFLink)obj; + + if (!((link.ulx == ulx) && (link.uly == uly) + && (link.brx == brx) && (link.bry == bry))) { + return false; + } + + if (!(link.color.equals(color) + && link.action.getAction().equals(action.getAction()))) { + return false; + } + + return true; + } } + diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java index f7363b095..4e4fc1226 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -8,7 +8,7 @@ package org.apache.fop.pdf; // Java... -import java.util.ArrayList; +import java.util.List; import java.util.HashMap; import java.io.OutputStream; import java.io.IOException; @@ -53,9 +53,9 @@ public class PDFPattern extends PDFPathPaint { protected int tilingType = 1; /** - * ArrayList of Doubles representing the Bounding box rectangle + * List of Doubles representing the Bounding box rectangle */ - protected ArrayList bBox = null; + protected List bBox = null; /** * Horizontal spacing @@ -73,9 +73,9 @@ public class PDFPattern extends PDFPathPaint { protected PDFShading shading = null; /** - * ArrayList of Integers represetning the Extended unique Identifier + * List of Integers represetning the Extended unique Identifier */ - protected ArrayList xUID = null; + protected List xUID = null; /** * TODO use PDFGState @@ -85,9 +85,9 @@ public class PDFPattern extends PDFPathPaint { protected StringBuffer extGState = null; /** - * ArrayList of Doubles representing the Transformation matrix. + * List of Doubles representing the Transformation matrix. */ - protected ArrayList matrix = null; + protected List matrix = null; /** * The stream of a pattern @@ -103,17 +103,17 @@ public class PDFPattern extends PDFPathPaint { * @param thePatternType the type of pattern, which is 1 for tiling. * @param thePaintType 1 or 2, colored or uncolored. * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox ArrayList of Doubles: The pattern cell bounding box + * @param theBBox List of Doubles: The pattern cell bounding box * @param theXStep horizontal spacing * @param theYStep vertical spacing - * @param theMatrix Optional ArrayList of Doubles transformation matrix + * @param theMatrix Optional List of Doubles transformation matrix * @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, ArrayList theBBox, double theXStep, - double theYStep, ArrayList theMatrix, ArrayList theXUID, + int thePaintType, int theTilingType, List theBBox, double theXStep, + double theYStep, List theMatrix, List theXUID, StringBuffer thePatternDataStream) { super(theNumber); this.patternName = thePatternName; @@ -142,12 +142,12 @@ public class PDFPattern extends PDFPathPaint { * @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:ArrayList of Doubles that specify the matrix. + * @param theMatrix Optional:List of Doubles that specify the matrix. */ public PDFPattern(int theNumber, String thePatternName, int thePatternType, PDFShading theShading, - ArrayList theXUID, StringBuffer theExtGState, - ArrayList theMatrix) { + List theXUID, StringBuffer theExtGState, + List theMatrix) { super(theNumber); this.patternName = thePatternName; diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java index 07a033702..436ff8447 100644 --- a/src/org/apache/fop/pdf/PDFShading.java +++ b/src/org/apache/fop/pdf/PDFShading.java @@ -8,7 +8,7 @@ package org.apache.fop.pdf; // Java... -import java.util.ArrayList; +import java.util.List; /** * class representing a PDF Smooth Shading object. @@ -43,12 +43,12 @@ public class PDFShading extends PDFObject { * The background color. Since shading is opaque, * this is very rarely used. */ - protected ArrayList background = null; + protected List background = null; /** - * Optional: A ArrayList specifying the clipping rectangle + * Optional: A List specifying the clipping rectangle */ - protected ArrayList bBox = null; + protected List bBox = null; /** * Optional: A flag whether or not to filter the shading function @@ -62,12 +62,12 @@ public class PDFShading extends PDFObject { * Optional for Type 3: An array of two numbers between which the blend varies between start and end points. Default is 0, 1. */ - protected ArrayList domain = null; + protected List domain = null; /** * Optional for Type 1: A transformation matrix */ - protected ArrayList matrix = null; + protected List matrix = null; /** * Required for Type 1, 2, and 3: @@ -81,14 +81,14 @@ public class PDFShading extends PDFObject { * Required for Type 3: An Array of six numbers [x0,y0,r0,x1,y1,r1] specifying the centers and radii of * the starting and ending circles. */ - protected ArrayList coords = null; + protected List coords = null; /** * Required for Type 2+3: An Array of two boolean values specifying whether to extend the * start and end colors past the start and end points, * respectively. Default is false, false. */ - protected ArrayList extend = null; + protected List extend = null; /** * Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each vertex coordinate. @@ -107,7 +107,7 @@ public class PDFShading extends PDFObject { * Each type has a differing number of decode array members, so check the spec. * Page 303 in PDF Spec 1.3 */ - protected ArrayList decode = null; + protected List decode = null; /** * Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each color coordinate. @@ -132,13 +132,13 @@ public class PDFShading extends PDFObject { * @param theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Whether or not to anti-alias. * @param theDomain Optional vector of Doubles specifying the domain. - * @param theMatrix ArrayList of Doubles specifying the matrix. + * @param theMatrix List of Doubles specifying the matrix. * If it's a pattern, then the matrix maps it to pattern space. * If it's a shading, then it maps it to current user space. * It's optional, the default is the identity matrix @@ -146,9 +146,9 @@ public class PDFShading extends PDFObject { */ public PDFShading(int theNumber, String theShadingName, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theDomain, - ArrayList theMatrix, PDFFunction theFunction) { + List theBackground, List theBBox, + boolean theAntiAlias, List theDomain, + List theMatrix, PDFFunction theFunction) { super(theNumber); this.shadingName = theShadingName; this.shadingType = theShadingType; // 1 @@ -174,23 +174,23 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false - * @param theCoords ArrayList of four (type 2) or 6 (type 3) Double - * @param theDomain ArrayList of Doubles specifying the domain + * @param theCoords List of four (type 2) or 6 (type 3) Double + * @param theDomain List of Doubles specifying the domain * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function - * @param theExtend ArrayList of Booleans of whether to extend teh start and end colors past the start and end points + * @param theExtend List of Booleans of whether to extend teh start and end colors past the start and end points * The default is [false, false] */ public PDFShading(int theNumber, String theShadingName, int theShadingType, PDFColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theCoords, - ArrayList theDomain, PDFFunction theFunction, - ArrayList theExtend) { + List theBackground, List theBBox, + boolean theAntiAlias, List theCoords, + List theDomain, PDFFunction theFunction, + List theExtend) { super(theNumber); this.shadingName = theShadingName; this.shadingType = theShadingType; // 2 or 3 @@ -219,7 +219,7 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. @@ -227,15 +227,15 @@ public class PDFShading extends PDFObject { * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. * @param theBitsPerComponent 1,2,4,8,12, and 16 * @param theBitsPerFlag 2,4,8. - * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312. + * @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, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, int theBitsPerFlag, - ArrayList theDecode, PDFFunction theFunction) { + List theDecode, PDFFunction theFunction) { super(theNumber); this.shadingType = theShadingType; // 4,6 or 7 @@ -261,23 +261,23 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode ArrayList of Doubles. See page 305 in PDF 1.3 spec. + * @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, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, ArrayList theDecode, + int theBitsPerComponent, List theDecode, int theVerticesPerRow, PDFFunction theFunction) { super(theNumber); this.shadingName = theShadingName; diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index f0ddaaf5b..2ea9e9f51 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -10,8 +10,9 @@ package org.apache.fop.pdf; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.IOException; +import java.util.List; +import java.util.Map; import java.util.ArrayList; -import java.util.HashMap; import java.util.Enumeration; /** @@ -37,7 +38,7 @@ public class PDFStream extends PDFObject { /** * the filters that should be applied */ - private ArrayList _filters; + private List _filters; /** * create an empty stream object @@ -100,10 +101,10 @@ public class PDFStream extends PDFObject { } } - public void addDefaultFilters(HashMap filters, String type) { - ArrayList filterset = (ArrayList)filters.get(type); + public void addDefaultFilters(Map filters, String type) { + List filterset = (List)filters.get(type); if(filterset == null) { - filterset = (ArrayList)filters.get(DEFAULT_FILTER); + filterset = (List)filters.get(DEFAULT_FILTER); } if(filterset == null || filterset.size() == 0) { // built-in default to flate @@ -241,8 +242,8 @@ public class PDFStream extends PDFObject { */ protected String applyFilters() throws IOException { if (_filters.size() > 0) { - ArrayList names = new ArrayList(); - ArrayList parms = new ArrayList(); + List names = new ArrayList(); + List parms = new ArrayList(); // run the filters for (int count = 0; count < _filters.size(); count++) { @@ -264,7 +265,7 @@ public class PDFStream extends PDFObject { } - private String buildFilterEntries(ArrayList names) { + private String buildFilterEntries(List names) { StringBuffer sb = new StringBuffer(); sb.append("/Filter "); if (names.size() > 1) { @@ -281,7 +282,7 @@ public class PDFStream extends PDFObject { return sb.toString(); } - private String buildDecodeParms(ArrayList parms) { + private String buildDecodeParms(List parms) { StringBuffer sb = new StringBuffer(); boolean needParmsEntry = false; sb.append("/DecodeParms "); -- cgit v1.2.3