aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2014-08-19 15:24:45 +0000
committerSimon Steiner <ssteiner@apache.org>2014-08-19 15:24:45 +0000
commit24675249db03c7a4ed6b8770fdffa5f64de496cf (patch)
tree9103c8afc37ba3fdb2854d2ecf5a8883e10c8882 /src/java/org/apache
parent484c5fdefb02cd6ac4d36429343888d46ca04772 (diff)
downloadxmlgraphics-fop-24675249db03c7a4ed6b8770fdffa5f64de496cf.tar.gz
xmlgraphics-fop-24675249db03c7a4ed6b8770fdffa5f64de496cf.zip
FOP-2406: Error when image next to pdf
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1618887 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/pdf/PDFDocument.java24
-rw-r--r--src/java/org/apache/fop/pdf/PDFFactory.java12
-rw-r--r--src/java/org/apache/fop/pdf/PDFResourceContext.java36
-rw-r--r--src/java/org/apache/fop/pdf/PDFResources.java111
-rw-r--r--src/java/org/apache/fop/svg/PDFGraphics2D.java6
5 files changed, 112 insertions, 77 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFDocument.java b/src/java/org/apache/fop/pdf/PDFDocument.java
index 468d2f1c1..ccdd69a7a 100644
--- a/src/java/org/apache/fop/pdf/PDFDocument.java
+++ b/src/java/org/apache/fop/pdf/PDFDocument.java
@@ -402,6 +402,19 @@ public class PDFDocument {
}
/**
+ * Registers a {@link PDFObject} in this PDF document at end.
+ * The object is assigned a new object number.
+ *
+ * @param obj {@link PDFObject} to add
+ * @return the added {@link PDFObject} added (with its object number set)
+ */
+ <T extends PDFObject> T registerTrailerObject(T obj) {
+ assignObjectNumber(obj);
+ addTrailerObject(obj);
+ return obj;
+ }
+
+ /**
* Assigns the {@link PDFObject} an object number,
* and sets the parent of the {@link PDFObject} to this document.
*
@@ -827,7 +840,7 @@ public class PDFDocument {
PDFImageXObject xObject = (PDFImageXObject)this.xObjectsMap.get(key);
if (xObject != null) {
if (res != null) {
- res.getPDFResources().addXObject(xObject);
+ res.addXObject(xObject);
}
return xObject;
}
@@ -839,7 +852,7 @@ public class PDFDocument {
registerObject(xObject);
this.resources.addXObject(xObject);
if (res != null) {
- res.getPDFResources().addXObject(xObject);
+ res.addXObject(xObject);
}
this.xObjectsMap.put(key, xObject);
return xObject;
@@ -867,7 +880,7 @@ public class PDFDocument {
PDFFormXObject xObject = (PDFFormXObject)xObjectsMap.get(key);
if (xObject != null) {
if (res != null) {
- res.getPDFResources().addXObject(xObject);
+ res.addXObject(xObject);
}
return xObject;
}
@@ -879,7 +892,7 @@ public class PDFDocument {
registerObject(xObject);
this.resources.addXObject(xObject);
if (res != null) {
- res.getPDFResources().addXObject(xObject);
+ res.addXObject(xObject);
}
this.xObjectsMap.put(key, xObject);
return xObject;
@@ -1092,6 +1105,9 @@ public class PDFDocument {
public void setMergeFontsEnabled(boolean mergeFontsEnabled) {
this.mergeFontsEnabled = mergeFontsEnabled;
+ if (mergeFontsEnabled) {
+ getResources().createFontsAsObj();
+ }
}
private interface TrailerOutputHelper {
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java
index cad0a405d..5ab483f60 100644
--- a/src/java/org/apache/fop/pdf/PDFFactory.java
+++ b/src/java/org/apache/fop/pdf/PDFFactory.java
@@ -303,9 +303,7 @@ public class PDFFactory {
// add this shading to resources
if (res != null) {
- res.getPDFResources().addShading(shading);
- } else {
- getDocument().getResources().addShading(shading);
+ res.addShading(shading);
}
return shading;
}
@@ -348,9 +346,7 @@ public class PDFFactory {
}
if (res != null) {
- res.getPDFResources().addPattern(pattern);
- } else {
- getDocument().getResources().addPattern(pattern);
+ res.addPattern(pattern);
}
return (pattern);
@@ -365,9 +361,7 @@ public class PDFFactory {
}
if (res != null) {
- res.getPDFResources().addPattern(pattern);
- } else {
- getDocument().getResources().addPattern(pattern);
+ res.addPattern(pattern);
}
return pattern;
}
diff --git a/src/java/org/apache/fop/pdf/PDFResourceContext.java b/src/java/org/apache/fop/pdf/PDFResourceContext.java
index 16c1976db..1419b2b76 100644
--- a/src/java/org/apache/fop/pdf/PDFResourceContext.java
+++ b/src/java/org/apache/fop/pdf/PDFResourceContext.java
@@ -19,6 +19,9 @@
package org.apache.fop.pdf;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
/**
* The PDF resource context.
*
@@ -34,6 +37,10 @@ package org.apache.fop.pdf;
* only the object ID of the parent, rather than the parent itself.
*/
public class PDFResourceContext extends PDFDictionary {
+ private Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
+ private Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
+ private Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
+ private Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
/**
* Creates a new ResourceContext.
@@ -45,6 +52,16 @@ public class PDFResourceContext extends PDFDictionary {
/* set fields using parameters */
put("Resources", resources);
+
+ resources.addContext(this);
+ }
+
+ public void addXObject(PDFXObject xObject) {
+ xObjects.add(xObject);
+ }
+
+ public Set<PDFXObject> getXObjects() {
+ return xObjects;
}
/**
@@ -85,7 +102,11 @@ public class PDFResourceContext extends PDFDictionary {
* @param gstate the GState to add
*/
public void addGState(PDFGState gstate) {
- getPDFResources().addGState(gstate);
+ gstates.add(gstate);
+ }
+
+ public Set<PDFGState> getGStates() {
+ return gstates;
}
/**
@@ -94,7 +115,18 @@ public class PDFResourceContext extends PDFDictionary {
* @param shading the shading to add
*/
public void addShading(PDFShading shading) {
- getPDFResources().addShading(shading);
+ shadings.add(shading);
+ }
+
+ public Set<PDFShading> getShadings() {
+ return shadings;
}
+ public Set<PDFPattern> getPatterns() {
+ return patterns;
+ }
+
+ public void addPattern(PDFPattern pattern) {
+ patterns.add(pattern);
+ }
}
diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java
index 86e771c46..4d31e2e6a 100644
--- a/src/java/org/apache/fop/pdf/PDFResources.java
+++ b/src/java/org/apache/fop/pdf/PDFResources.java
@@ -51,32 +51,20 @@ public class PDFResources extends PDFDictionary {
* Set of XObjects
*/
protected Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
-
- /**
- * Set of patterns
- */
- protected Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
-
- /**
- * Set of shadings
- */
- protected Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
-
- /**
- * Set of ExtGStates
- */
- protected Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
-
/** Map of color spaces (key: color space name) */
protected Map<PDFName, PDFColorSpace> colorSpaces = new LinkedHashMap<PDFName, PDFColorSpace>();
/** Map of ICC color spaces (key: ICC profile description) */
protected Map<String, PDFICCBasedColorSpace> iccColorSpaces = new LinkedHashMap<String, PDFICCBasedColorSpace>();
+ private PDFResources parent;
+ private PDFDictionary fontsObj;
+ private Map<String, PDFDictionary> fontsObjDict = new LinkedHashMap<String, PDFDictionary>();
+
/** Named properties */
protected Map<String, PDFReference> properties = new LinkedHashMap<String, PDFReference>();
- private PDFResources parent;
+ protected Set<PDFResourceContext> contexts = new LinkedHashSet<PDFResourceContext>();
/**
* create a /Resources object.
@@ -89,6 +77,10 @@ public class PDFResources extends PDFDictionary {
setObjectNumber(objnum);
}
+ public void addContext(PDFResourceContext c) {
+ contexts.add(c);
+ }
+
public void setParentResources(PDFResources p) {
parent = p;
}
@@ -103,15 +95,22 @@ public class PDFResources extends PDFDictionary {
* @param font the PDFFont to add
*/
public void addFont(PDFFont font) {
- fonts.put(font.getName(), font);
+ addFont(font.getName(), font);
}
public void addFont(String name, PDFDictionary font) {
- fonts.put(name, font);
+ if (fontsObj != null) {
+ fontsObj.put(name, font);
+ fontsObjDict.put(name, font);
+ } else {
+ fonts.put(name, font);
+ }
}
- public Map<String, PDFDictionary> getFonts() {
- return fonts;
+ public void createFontsAsObj() {
+ fontsObj = new PDFDictionary();
+ getDocument().registerTrailerObject(fontsObj);
+ put("Font", fontsObj);
}
/**
@@ -122,9 +121,8 @@ public class PDFResources extends PDFDictionary {
*/
public void addFonts(PDFDocument doc, FontInfo fontInfo) {
Map<String, Typeface> usedFonts = fontInfo.getUsedFonts();
- for (Map.Entry<String, Typeface> e : usedFonts.entrySet()) {
- String f = e.getKey();
- Typeface font = e.getValue();
+ for (String f : usedFonts.keySet()) {
+ Typeface font = usedFonts.get(f);
//Check if the font actually had any mapping operations. If not, it is an indication
//that it has never actually been used and therefore doesn't have to be embedded.
@@ -141,34 +139,7 @@ public class PDFResources extends PDFDictionary {
f, font.getEmbedFontName(), encoding, font, desc));
}
}
- }
-
- /**
- * Add a PDFGState to the resources.
- *
- * @param gs the PDFGState to add
- */
- public void addGState(PDFGState gs) {
- this.gstates.add(gs);
- }
-
- /**
- * Add a Shading to the resources.
- *
- * @param theShading the shading to add
- */
- public void addShading(PDFShading theShading) {
- this.shadings.add(theShading);
- }
-
- /**
- * Add the pattern to the resources.
- *
- * @param thePattern the pattern to add
- */
- public void addPattern(PDFPattern thePattern) {
- this.patterns.add(thePattern);
- }
+ }
/**
* Add an XObject to the resources.
@@ -239,21 +210,40 @@ public class PDFResources extends PDFDictionary {
}
private void populateDictionary() {
- if (!this.fonts.isEmpty() || (parent != null && !parent.getFonts().isEmpty())) {
+ if (parent != null && parent.fontsObj != null) {
+ put("Font", parent.fontsObj);
+ }
+ if (!this.fonts.isEmpty() || (parent != null && !parent.fonts.isEmpty())) {
PDFDictionary dict = new PDFDictionary(this);
/* construct PDF dictionary of font object references */
for (Map.Entry<String, PDFDictionary> entry : fonts.entrySet()) {
dict.put(entry.getKey(), entry.getValue());
}
if (parent != null) {
- for (Map.Entry<String, PDFDictionary> entry : parent.getFonts().entrySet()) {
+ for (Map.Entry<String, PDFDictionary> entry : parent.fonts.entrySet()) {
+ dict.put(entry.getKey(), entry.getValue());
+ }
+ for (Map.Entry<String, PDFDictionary> entry : parent.fontsObjDict.entrySet()) {
dict.put(entry.getKey(), entry.getValue());
}
}
put("Font", dict);
}
- if (!this.shadings.isEmpty()) {
+ Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
+ Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
+ Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
+ for (PDFResourceContext c : contexts) {
+ xObjects.addAll(c.getXObjects());
+ patterns.addAll(c.getPatterns());
+ shadings.addAll(c.getShadings());
+ gstates.addAll(c.getGStates());
+ }
+ if (parent != null) {
+ xObjects.addAll(parent.xObjects);
+ }
+
+ if (!shadings.isEmpty()) {
PDFDictionary dict = new PDFDictionary(this);
for (PDFShading shading : shadings) {
dict.put(shading.getName(), shading);
@@ -261,7 +251,7 @@ public class PDFResources extends PDFDictionary {
put("Shading", dict);
}
- if (!this.patterns.isEmpty()) {
+ if (!patterns.isEmpty()) {
PDFDictionary dict = new PDFDictionary(this);
for (PDFPattern pattern : patterns) {
dict.put(pattern.getName(), pattern);
@@ -276,15 +266,18 @@ public class PDFResources extends PDFDictionary {
procset.add(new PDFName("Text"));
put("ProcSet", procset);
- if (this.xObjects != null && !this.xObjects.isEmpty()) {
- PDFDictionary dict = new PDFDictionary(this);
+ if (!xObjects.isEmpty()) {
+ PDFDictionary dict = (PDFDictionary) get("XObject");
+ if (dict == null) {
+ dict = new PDFDictionary(this);
+ }
for (PDFXObject xObject : xObjects) {
dict.put(xObject.getName().toString(), xObject);
}
put("XObject", dict);
}
- if (!this.gstates.isEmpty()) {
+ if (!gstates.isEmpty()) {
PDFDictionary dict = new PDFDictionary(this);
for (PDFGState gstate : gstates) {
dict.put(gstate.getName(), gstate);
diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java
index c9ec79d0d..dc897f40e 100644
--- a/src/java/org/apache/fop/svg/PDFGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java
@@ -564,7 +564,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
xObject = addRenderedImage(key, buf);
} else {
- resourceContext.getPDFResources().addXObject(xObject);
+ resourceContext.addXObject(xObject);
}
AffineTransform at = new AffineTransform();
@@ -1025,7 +1025,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
PDFXObject imageInfo = pdfDoc.getXObject(
"TempImage:" + pctx.toString());
if (imageInfo != null) {
- resourceContext.getPDFResources().addXObject(imageInfo);
+ resourceContext.addXObject(imageInfo);
} else {
Raster r = pctx.getRaster(devX, devY, devW, devH);
WritableRaster wr = (WritableRaster)r;
@@ -1176,7 +1176,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
if (xObject == null) {
xObject = addRenderedImage(key, img);
} else {
- resourceContext.getPDFResources().addXObject(xObject);
+ resourceContext.addXObject(xObject);
}
useXObject(xObject, xform, img.getWidth(), img.getHeight());