]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
reuse functions to reduce file size
authorKeiron Liddle <keiron@apache.org>
Thu, 18 Jul 2002 10:59:58 +0000 (10:59 +0000)
committerKeiron Liddle <keiron@apache.org>
Thu, 18 Jul 2002 10:59:58 +0000 (10:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195006 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/pdf/PDFDocument.java
src/org/apache/fop/pdf/PDFFunction.java

index 259ec8d69c465f19985db726a4602deab93a02ca..afc1014f1433c33f4ba3e095e1b799d4d16df1fa 100644 (file)
@@ -138,6 +138,7 @@ public class PDFDocument {
     protected HashMap filterMap = new HashMap();
 
     protected ArrayList gstates = new ArrayList();
+    protected ArrayList functions = new ArrayList();
 
     /**
      * creates an empty PDF document <p>
@@ -302,7 +303,15 @@ public class PDFDocument {
                                                theFunctionDataStream,
                                                theFilter);
 
-        this.objects.add(function);
+        PDFFunction oldfunc = findFunction(function);
+        if(oldfunc == null) {
+            functions.add(function);
+            this.objects.add(function);
+        } else {
+            this.objectcount--;
+            function = oldfunc;
+        }
+
         return (function);
     }
 
@@ -339,11 +348,28 @@ public class PDFDocument {
                                                theFunctionType, theDomain,
                                                theRange, theCZero, theCOne,
                                                theInterpolationExponentN);
+        PDFFunction oldfunc = findFunction(function);
+        if(oldfunc == null) {
+            functions.add(function);
+            this.objects.add(function);
+        } else {
+            this.objectcount--;
+            function = oldfunc;
+        }
 
-        this.objects.add(function);
         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;
+            }
+        }
+        return null;
+    }
+
     /**
      * Make a Type 3 Stitching function
      *
@@ -386,7 +412,15 @@ public class PDFDocument {
                                                theRange, theFunctions,
                                                theBounds, theEncode);
 
-        this.objects.add(function);
+        PDFFunction oldfunc = findFunction(function);
+        if(oldfunc == null) {
+            functions.add(function);
+            this.objects.add(function);
+        } else {
+            this.objectcount--;
+            function = oldfunc;
+        }
+
         return (function);
     }
 
@@ -407,7 +441,15 @@ public class PDFDocument {
                                                theRange,
                                                theFunctionDataStream);
 
-        this.objects.add(function);
+        PDFFunction oldfunc = findFunction(function);
+        if(oldfunc == null) {
+            functions.add(function);
+            this.objects.add(function);
+        } else {
+            this.objectcount--;
+            function = oldfunc;
+        }
+
         return (function);
 
     }
index 3f57df16bd78d0977b8d68195f7c30e786780c4c..35d1480a553ffaafa63b91b52ddaea41046d519f 100644 (file)
@@ -667,4 +667,104 @@ public class PDFFunction extends PDFObject {
 
     }
 
+    public boolean equals(Object obj) {
+        if(obj == null) {
+            return false;
+        }
+        if(!(obj instanceof PDFFunction)) {
+            return false;
+        }
+        PDFFunction func = (PDFFunction)obj;
+        if(functionType != func.functionType) {
+            return false;
+        }
+        if(bitsPerSample != func.bitsPerSample) {
+            return false;
+        }
+        if(order != func.order) {
+            return false;
+        }
+        if(interpolationExponentN != func.interpolationExponentN) {
+            return false;
+        }
+        if(domain != null) {
+            if(!domain.equals(func.domain)) {
+                return false;
+            }
+        } else if(func.domain != null) {
+            return false;
+        }
+        if(range != null) {
+            if(!range.equals(func.range)) {
+                return false; 
+            }
+        } else if(func.range != null) {
+            return false;
+        }
+        if(size != null) {
+            if(!size.equals(func.size)) {
+                return false; 
+            }
+        } else if(func.size != null) {
+            return false;
+        }
+        if(encode != null) {
+            if(!encode.equals(func.encode)) {
+                return false; 
+            }
+        } else if(func.encode != null) {
+            return false;
+        }
+        if(decode != null) {
+            if(!decode.equals(func.decode)) {
+                return false; 
+            }
+        } else if(func.decode != null) {
+            return false;
+        }
+        if(functionDataStream != null) {
+            if(!functionDataStream.equals(func.functionDataStream)) {
+                return false; 
+            }
+        } else if(func.functionDataStream != null) {
+            return false;
+        }
+        if(filter != null) {
+            if(!filter.equals(func.filter)) {
+                return false;
+            }
+        } else if(func.filter != null) {
+            return false;
+        }
+        if(cZero != null) {
+            if(!cZero.equals(func.cZero)) {
+                return false;
+            }
+        } else if(func.cZero != null) {
+            return false;
+        }
+        if(cOne != null) {
+            if(!cOne.equals(func.cOne)) {
+                return false;
+            }
+        } else if(func.cOne != null) {
+            return false;
+        }
+        if(functions != null) {
+            if(!functions.equals(func.functions)) {
+                return false;
+            }
+        } else if(func.functions != null) {
+            return false;
+        }
+        if(bounds != null) {
+            if(!bounds.equals(func.bounds)) {
+                return false;
+            }
+        } else if(func.bounds != null) {
+            return false;
+        }
+        return true;
+    }
+
 }