From 77e0508bb36a6c5e547857f2bea17e1def2a2abc Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Tue, 24 Feb 2015 11:23:44 +0000 Subject: FOP-2445: Merge PDF Linearization branch git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1661887 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFResources.java | 67 +++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 8 deletions(-) (limited to 'src/java/org/apache/fop/pdf/PDFResources.java') diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java index f351b23be..9ba9c7f8f 100644 --- a/src/java/org/apache/fop/pdf/PDFResources.java +++ b/src/java/org/apache/fop/pdf/PDFResources.java @@ -52,7 +52,7 @@ public class PDFResources extends PDFDictionary { */ protected Set xObjects = new LinkedHashSet(); /** Map of color spaces (key: color space name) */ - protected Map colorSpaces = new LinkedHashMap(); + protected Map colorSpaces = new LinkedHashMap(); /** Map of ICC color spaces (key: ICC profile description) */ protected Map iccColorSpaces = new LinkedHashMap(); @@ -68,13 +68,11 @@ public class PDFResources extends PDFDictionary { /** * create a /Resources object. - * - * @param objnum the object's number */ - public PDFResources(int objnum) { + public PDFResources(PDFDocument doc) { /* generic creation of object */ super(); - setObjectNumber(objnum); + setObjectNumber(doc); } public void addContext(PDFResourceContext c) { @@ -156,7 +154,7 @@ public class PDFResources extends PDFDictionary { * @param colorSpace the color space */ public void addColorSpace(PDFColorSpace colorSpace) { - this.colorSpaces.put(new PDFName(colorSpace.getName()), colorSpace); + this.colorSpaces.put(new LazyName(colorSpace), colorSpace); if (colorSpace instanceof PDFICCBasedColorSpace) { PDFICCBasedColorSpace icc = (PDFICCBasedColorSpace)colorSpace; String desc = ColorProfileUtil.getICCProfileDescription( @@ -165,6 +163,16 @@ public class PDFResources extends PDFDictionary { } } + static class LazyName { + private PDFColorSpace colorSpace; + public LazyName(PDFColorSpace colorSpace) { + this.colorSpace = colorSpace; + } + public PDFName getName() { + return new PDFName(colorSpace.getName()); + } + } + /** * Returns a ICCBased color space by profile name. * @param desc the name of the color space @@ -181,8 +189,12 @@ public class PDFResources extends PDFDictionary { * @return the requested color space or null if it wasn't found */ public PDFColorSpace getColorSpace(PDFName name) { - PDFColorSpace cs = this.colorSpaces.get(name); - return cs; + for (Map.Entry x : colorSpaces.entrySet()) { + if (x.getKey().getName().equals(name)) { + return x.getValue(); + } + } + return null; } /** @@ -303,4 +315,43 @@ public class PDFResources extends PDFDictionary { } } + @Override + public void getChildren(Set children) { + getChildren(children, false); + } + + private void getChildren(Set children, boolean isParent) { + super.getChildren(children); + for (PDFDictionary f : fonts.values()) { + children.add(f); + f.getChildren(children); + } + for (PDFResourceContext c : contexts) { + for (PDFXObject x : c.getXObjects()) { + children.add(x); + x.getChildren(children); + } + for (PDFPattern x : c.getPatterns()) { + children.add(x); + x.getChildren(children); + } + for (PDFShading x : c.getShadings()) { + children.add(x); + x.getChildren(children); + } + for (PDFGState x : c.getGStates()) { + children.add(x); + x.getChildren(children); + } + } + if (!isParent) { + for (PDFColorSpace x : colorSpaces.values()) { + children.add((PDFObject)x); + ((PDFObject)x).getChildren(children); + } + } + if (parent != null) { + parent.getChildren(children, true); + } + } } -- cgit v1.2.3