From: Keiron Liddle Date: Thu, 18 Jul 2002 10:59:58 +0000 (+0000) Subject: reuse functions to reduce file size X-Git-Tag: Alt-Design-integration-base~500 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9b11e0803f88a158cdd70ae561c40aaf63d0fc89;p=xmlgraphics-fop.git reuse functions to reduce file size git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195006 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 259ec8d69..afc1014f1 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -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

@@ -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); } diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java index 3f57df16b..35d1480a5 100644 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ b/src/org/apache/fop/pdf/PDFFunction.java @@ -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; + } + }