keiron 2002/07/19 00:16:21
Modified: src/org/apache/fop/pdf PDFDocument.java PDFFunction.java
PDFPattern.java PDFResources.java PDFShading.java
Log:
reuse old patterns and shadings to reduce file size
Revision Changes Path
1.47 +90 -8 xml-fop/src/org/apache/fop/pdf/PDFDocument.java
Index: PDFDocument.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- PDFDocument.java 18 Jul 2002 10:59:57 -0000 1.46
+++ PDFDocument.java 19 Jul 2002 07:16:20 -0000 1.47
@@ -139,6 +139,8 @@
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>
@@ -370,6 +372,32 @@
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
*
@@ -488,7 +516,16 @@
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) {
@@ -534,12 +571,22 @@
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);
}
@@ -584,13 +631,22 @@
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);
}
@@ -632,14 +688,22 @@
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);
}
@@ -671,12 +735,21 @@
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);
}
@@ -699,12 +772,21 @@
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);
}
1.10 +4 -1 xml-fop/src/org/apache/fop/pdf/PDFFunction.java
Index: PDFFunction.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFunction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PDFFunction.java 18 Jul 2002 10:59:58 -0000 1.9
+++ PDFFunction.java 19 Jul 2002 07:16:20 -0000 1.10
@@ -671,6 +671,9 @@
if(obj == null) {
return false;
}
+ if(obj == this) {
+ return true;
+ }
if(!(obj instanceof PDFFunction)) {
return false;
}
1.14 +87 -2 xml-fop/src/org/apache/fop/pdf/PDFPattern.java
Index: PDFPattern.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPattern.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PDFPattern.java 1 Jul 2002 10:39:29 -0000 1.13
+++ PDFPattern.java 19 Jul 2002 07:16:20 -0000 1.14
@@ -94,7 +94,6 @@
*/
protected StringBuffer patternDataStream = null;
-
/**
* Create a tiling pattern (type 1).
*
@@ -307,5 +306,91 @@
}
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;
+ }
}
1.15 +7 -15 xml-fop/src/org/apache/fop/pdf/PDFResources.java
Index: PDFResources.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFResources.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- PDFResources.java 4 Jul 2002 14:08:19 -0000 1.14
+++ PDFResources.java 19 Jul 2002 07:16:21 -0000 1.15
@@ -28,8 +28,8 @@
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();
/**
@@ -94,12 +94,8 @@
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 ??????
}
@@ -113,12 +109,8 @@
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() + " ");
}
1.10 +95 -1 xml-fop/src/org/apache/fop/pdf/PDFShading.java
Index: PDFShading.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFShading.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PDFShading.java 27 Jun 2002 11:45:54 -0000 1.9
+++ PDFShading.java 19 Jul 2002 07:16:21 -0000 1.10
@@ -505,4 +505,98 @@
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;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]