protected ArrayList gstates = new ArrayList();
protected ArrayList functions = new ArrayList();
+ protected ArrayList shadings = new ArrayList();
+ protected ArrayList patterns = new ArrayList();
/**
* creates an empty PDF document <p>
return null;
}
+ 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;
+ }
+
+ /**
+ * Find a previous pattern.
+ * The problem with this is for tiling patterns the pattern
+ * data stream is stored and may use up memory, usually this
+ * 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;
+ }
+
/**
* Make a Type 3 Stitching function
*
theColorSpace, theBackground,
theBBox, theAntiAlias, theDomain,
theMatrix, theFunction);
- this.objects.add(shading);
+
+ PDFShading oldshad = findShading(shading);
+ if(oldshad == null) {
+ shadings.add(shading);
+ this.objects.add(shading);
+ } else {
+ this.objectcount--;
+ this.shadingCount--;
+ shading = oldshad;
+ }
// add this shading to resources
if(res != null) {
theDomain, theFunction,
theExtend);
+ PDFShading oldshad = findShading(shading);
+ if(oldshad == null) {
+ shadings.add(shading);
+ this.objects.add(shading);
+ } else {
+ this.objectcount--;
+ this.shadingCount--;
+ shading = oldshad;
+ }
+
if(res != null) {
res.getPDFResources().addShading(shading);
} else {
this.resources.addShading(shading);
}
- this.objects.add(shading);
+
return (shading);
}
theBitsPerFlag, theDecode,
theFunction);
+ PDFShading oldshad = findShading(shading);
+ if(oldshad == null) {
+ shadings.add(shading);
+ this.objects.add(shading);
+ } else {
+ this.objectcount--;
+ this.shadingCount--;
+ shading = oldshad;
+ }
+
if(res != null) {
res.getPDFResources().addShading(shading);
} else {
this.resources.addShading(shading);
}
- this.objects.add(shading);
return (shading);
}
theBitsPerComponent, theDecode,
theVerticesPerRow, theFunction);
+ PDFShading oldshad = findShading(shading);
+ if(oldshad == null) {
+ shadings.add(shading);
+ this.objects.add(shading);
+ } else {
+ this.objectcount--;
+ this.shadingCount--;
+ shading = oldshad;
+ }
+
if(res != null) {
res.getPDFResources().addShading(shading);
} else {
this.resources.addShading(shading);
}
- this.objects.add(shading);
-
return (shading);
}
theMatrix, theXUID,
thePatternDataStream);
+ PDFPattern oldpatt = findPattern(pattern);
+ if(oldpatt == null) {
+ patterns.add(pattern);
+ this.objects.add(pattern);
+ } else {
+ this.objectcount--;
+ this.patternCount--;
+ pattern = oldpatt;
+ }
+
if(res != null) {
res.getPDFResources().addPattern(pattern);
} else {
this.resources.addPattern(pattern);
}
- this.objects.add(pattern);
return (pattern);
}
thePatternName, 2, theShading,
theXUID, theExtGState, theMatrix);
+ PDFPattern oldpatt = findPattern(pattern);
+ if(oldpatt == null) {
+ patterns.add(pattern);
+ this.objects.add(pattern);
+ } else {
+ this.objectcount--;
+ this.patternCount--;
+ pattern = oldpatt;
+ }
+
if(res != null) {
res.getPDFResources().addPattern(pattern);
} else {
this.resources.addPattern(pattern);
}
- this.objects.add(pattern);
return (pattern);
}
if(obj == null) {
return false;
}
+ if(obj == this) {
+ return true;
+ }
if(!(obj instanceof PDFFunction)) {
return false;
}
*/
protected StringBuffer patternDataStream = null;
-
/**
* Create a tiling pattern (type 1).
*
public byte[] toPDF() { return null; }
+ public boolean equals(Object obj) {
+ if(obj == null) {
+ return false;
+ }
+ if(obj == this) {
+ return true;
+ }
+ if(!(obj instanceof PDFPattern)) {
+ return false;
+ }
+ PDFPattern patt = (PDFPattern)obj;
+ if(patternType != patt.patternType) {
+ return false;
+ }
+ if(paintType != patt.paintType) {
+ return false;
+ }
+ if(tilingType != patt.tilingType) {
+ return false;
+ }
+ if(xStep != patt.xStep) {
+ return false;
+ }
+ if(yStep != patt.yStep) {
+ return false;
+ }
+ if(bBox != null) {
+ if(!bBox.equals(patt.bBox)) {
+ return false;
+ }
+ } else if(patt.bBox != null) {
+ return false;
+ }
+ if(bBox != null) {
+ if(!bBox.equals(patt.bBox)) {
+ return false;
+ }
+ } else if(patt.bBox != null) {
+ return false;
+ }
+ if(xUID != null) {
+ if(!xUID.equals(patt.xUID)) {
+ return false;
+ }
+ } else if(patt.xUID != null) {
+ return false;
+ }
+ if(extGState != null) {
+ if(!extGState.equals(patt.extGState)) {
+ return false;
+ }
+ } else if(patt.extGState != null) {
+ return false;
+ }
+ if(matrix != null) {
+ if(!matrix.equals(patt.matrix)) {
+ return false;
+ }
+ } else if(patt.matrix != null) {
+ return false;
+ }
+ if(resources != null) {
+ if(!resources.equals(patt.resources)) {
+ return false;
+ }
+ } else if(patt.resources != null) {
+ return false;
+ }
+ if(shading != null) {
+ if(!shading.equals(patt.shading)) {
+ return false;
+ }
+ } else if(patt.shading != null) {
+ return false;
+ }
+ if(patternDataStream != null) {
+ if(!patternDataStream.equals(patt.patternDataStream)) {
+ return false;
+ }
+ } else if(patt.patternDataStream != null) {
+ return false;
+ }
+
+ return true;
+ }
+
}
protected HashMap fonts = new HashMap();
protected HashSet xObjects = new HashSet();
- protected ArrayList patterns = new ArrayList();
- protected ArrayList shadings = new ArrayList();
+ protected HashSet patterns = new HashSet();
+ protected HashSet shadings = new HashSet();
protected HashSet gstates = new HashSet();
/**
if (!this.shadings.isEmpty()) {
p.append("/Shading << ");
- for (int currentShadingNumber = 0;
- currentShadingNumber < this.shadings.size();
- currentShadingNumber++) {
- currentShading =
- ((PDFShading)this.shadings.get(currentShadingNumber));
-
+ for (Iterator iter = shadings.iterator(); iter.hasNext(); ) {
+ currentShading = (PDFShading)iter.next();
p.append("/" + currentShading.getName() + " "
+ currentShading.referencePDF() + " "); // \n ??????
}
if (!this.patterns.isEmpty()) {
p.append("/Pattern << ");
- for (int currentPatternNumber = 0;
- currentPatternNumber < this.patterns.size();
- currentPatternNumber++) {
- currentPattern =
- ((PDFPattern)this.patterns.get(currentPatternNumber));
-
+ for (Iterator iter = patterns.iterator(); iter.hasNext(); ) {
+ currentPattern = (PDFPattern)iter.next();
p.append("/" + currentPattern.getName() + " "
+ currentPattern.referencePDF() + " ");
}
return (p.toString().getBytes());
}
+ public boolean equals(Object obj) {
+ if(obj == null) {
+ return false;
+ }
+ if(obj == this) {
+ return true;
+ }
+ if(!(obj instanceof PDFShading)) {
+ return false;
+ }
+ PDFShading shad = (PDFShading)obj;
+ if(shadingType != shad.shadingType) {
+ return false;
+ }
+ if(antiAlias != shad.antiAlias) {
+ return false;
+ }
+ if(bitsPerCoordinate != shad.bitsPerCoordinate) {
+ return false;
+ }
+ if(bitsPerFlag != shad.bitsPerFlag) {
+ return false;
+ }
+ if(bitsPerComponent != shad.bitsPerComponent) {
+ return false;
+ }
+ if(verticesPerRow != shad.verticesPerRow) {
+ return false;
+ }
+ if(colorSpace != null) {
+ if(!colorSpace.equals(shad.colorSpace)) {
+ return false;
+ }
+ } else if(shad.colorSpace != null) {
+ return false;
+ }
+ if(background != null) {
+ if(!background.equals(shad.background)) {
+ return false;
+ }
+ } else if(shad.background != null) {
+ return false;
+ }
+ if(bBox != null) {
+ if(!bBox.equals(shad.bBox)) {
+ return false;
+ }
+ } else if(shad.bBox != null) {
+ return false;
+ }
+ if(domain != null) {
+ if(!domain.equals(shad.domain)) {
+ return false;
+ }
+ } else if(shad.domain != null) {
+ return false;
+ }
+ if(matrix != null) {
+ if(!matrix.equals(shad.matrix)) {
+ return false;
+ }
+ } else if(shad.matrix != null) {
+ return false;
+ }
+ if(coords != null) {
+ if(!coords.equals(shad.coords)) {
+ return false;
+ }
+ } else if(shad.coords != null) {
+ return false;
+ }
+ if(extend != null) {
+ if(!extend.equals(shad.extend)) {
+ return false;
+ }
+ } else if(shad.extend != null) {
+ return false;
+ }
+ if(decode != null) {
+ if(!decode.equals(shad.decode)) {
+ return false;
+ }
+ } else if(shad.decode != null) {
+ return false;
+ }
+ if(function != null) {
+ if(!function.equals(shad.function)) {
+ return false;
+ }
+ } else if(shad.function != null) {
+ return false;
+ }
+ return true;
+ }
}