aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/pdf/PDFResources.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/pdf/PDFResources.java')
-rw-r--r--src/java/org/apache/fop/pdf/PDFResources.java67
1 files changed, 59 insertions, 8 deletions
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<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
/** Map of color spaces (key: color space name) */
- protected Map<PDFName, PDFColorSpace> colorSpaces = new LinkedHashMap<PDFName, PDFColorSpace>();
+ protected Map<LazyName, PDFColorSpace> colorSpaces = new LinkedHashMap<LazyName, PDFColorSpace>();
/** Map of ICC color spaces (key: ICC profile description) */
protected Map<String, PDFICCBasedColorSpace> iccColorSpaces = new LinkedHashMap<String, PDFICCBasedColorSpace>();
@@ -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<LazyName, PDFColorSpace> 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<PDFObject> children) {
+ getChildren(children, false);
+ }
+
+ private void getChildren(Set<PDFObject> 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);
+ }
+ }
}