aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/pdf
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-02-01 16:02:33 +0000
committerJeremias Maerki <jeremias@apache.org>2008-02-01 16:02:33 +0000
commit631864454a9b6300bb67a76d9d8eee030951ee69 (patch)
treed70c138eecbc1653dd4202b2d23e8d19b4db0329 /src/java/org/apache/fop/render/pdf
parentc4f0551dbf87d84fe955565231f6195d418b46a4 (diff)
downloadxmlgraphics-fop-631864454a9b6300bb67a76d9d8eee030951ee69.tar.gz
xmlgraphics-fop-631864454a9b6300bb67a76d9d8eee030951ee69.zip
Move sRGB installation into the PDF library. That way it can be used in PDFDocumentGraphics2D, too (via AbstractImageAdapter).
Ensures correct handling of sRGB images in PDFTranscoder. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@617531 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/pdf')
-rw-r--r--src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java63
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java19
2 files changed, 36 insertions, 46 deletions
diff --git a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
index d9fd614cc..b676ad6d5 100644
--- a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
@@ -84,32 +84,7 @@ public abstract class AbstractImageAdapter implements PDFImage {
ICC_Profile prof = image.getICCProfile();
PDFDeviceColorSpace pdfCS = toPDFColorSpace(getImageColorSpace());
if (prof != null) {
- boolean defaultsRGB = ColorProfileUtil.isDefaultsRGB(prof);
- String desc = ColorProfileUtil.getICCProfileDescription(prof);
- if (log.isDebugEnabled()) {
- log.debug("Image returns ICC profile: " + desc + ", default sRGB=" + defaultsRGB);
- }
- PDFICCBasedColorSpace cs = doc.getResources().getICCColorSpaceByProfileName(desc);
- if (!defaultsRGB) {
- if (cs == null) {
- pdfICCStream = doc.getFactory().makePDFICCStream();
- pdfICCStream.setColorSpace(prof, pdfCS);
- cs = doc.getFactory().makeICCBasedColorSpace(null, null, pdfICCStream);
- } else {
- pdfICCStream = cs.getICCStream();
- }
- } else {
- if (cs == null && desc.startsWith("sRGB")) {
- //It's the default sRGB profile which we mapped to DefaultRGB in PDFRenderer
- cs = doc.getResources().getColorSpace("DefaultRGB");
- }
- if (cs != null) {
- pdfICCStream = cs.getICCStream();
- } else {
- //DefaultRGB hasn't been mapped to sRGB
- //(that's the case with a plain PDFGraphics2D)
- }
- }
+ pdfICCStream = setupColorProfile(doc, prof, pdfCS);
}
if (doc.getProfile().getPDFAMode().isPDFA1LevelB()) {
if (pdfCS != null
@@ -119,10 +94,42 @@ public abstract class AbstractImageAdapter implements PDFImage {
//See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
//FOP is currently restricted to DeviceRGB if PDF/A-1 is active.
throw new PDFConformanceException(
- "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK: "
- + image.getInfo());
+ "PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK: "
+ + image.getInfo());
+ }
+ }
+ }
+
+ private static PDFICCStream setupColorProfile(PDFDocument doc,
+ ICC_Profile prof, PDFDeviceColorSpace pdfCS) {
+ boolean defaultsRGB = ColorProfileUtil.isDefaultsRGB(prof);
+ String desc = ColorProfileUtil.getICCProfileDescription(prof);
+ if (log.isDebugEnabled()) {
+ log.debug("Image returns ICC profile: " + desc + ", default sRGB=" + defaultsRGB);
+ }
+ PDFICCBasedColorSpace cs = doc.getResources().getICCColorSpaceByProfileName(desc);
+ PDFICCStream pdfICCStream;
+ if (!defaultsRGB) {
+ if (cs == null) {
+ pdfICCStream = doc.getFactory().makePDFICCStream();
+ pdfICCStream.setColorSpace(prof, pdfCS);
+ cs = doc.getFactory().makeICCBasedColorSpace(null, null, pdfICCStream);
+ } else {
+ pdfICCStream = cs.getICCStream();
}
+ } else {
+ if (cs == null && desc.startsWith("sRGB")) {
+ //It's the default sRGB profile which we mapped to DefaultRGB in PDFRenderer
+ cs = doc.getResources().getColorSpace("DefaultRGB");
+ if (cs == null) {
+ //sRGB hasn't been set up for the PDF document
+ //so install but don't set to DefaultRGB
+ cs = PDFICCBasedColorSpace.setupsRGBColorSpace(doc);
+ }
+ }
+ pdfICCStream = cs.getICCStream();
}
+ return pdfICCStream;
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index 4d641517a..86c01f673 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -23,7 +23,6 @@ package org.apache.fop.render.pdf;
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
-import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
@@ -391,24 +390,8 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
if (this.sRGBColorSpace != null) {
return;
}
- ICC_Profile profile;
- PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
- InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
- if (in != null) {
- try {
- profile = ICC_Profile.getInstance(in);
- } finally {
- IOUtils.closeQuietly(in);
- }
- } else {
- //Fallback: Use the sRGB profile from the JRE (about 140KB)
- profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
- }
- sRGBProfile.setColorSpace(profile, null);
-
//Map sRGB as default RGB profile for DeviceRGB
- this.sRGBColorSpace = pdfDoc.getFactory().makeICCBasedColorSpace(
- null, "DefaultRGB", sRGBProfile);
+ this.sRGBColorSpace = PDFICCBasedColorSpace.setupsRGBAsDefaultRGBColorSpace(pdfDoc);
}
private void addDefaultOutputProfile() throws IOException {