diff options
Diffstat (limited to 'src/java/org/apache/fop/render/afp')
6 files changed, 57 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPCustomizable.java b/src/java/org/apache/fop/render/afp/AFPCustomizable.java index ed1ea443b..5f3fe6823 100644 --- a/src/java/org/apache/fop/render/afp/AFPCustomizable.java +++ b/src/java/org/apache/fop/render/afp/AFPCustomizable.java @@ -51,6 +51,14 @@ public interface AFPCustomizable { void setNativeImagesSupported(boolean nativeImages); /** + * Controls whether CMYK images (IOCA FS45) are enabled. By default, support is disabled + * for wider compatibility. When disabled, any CMYK image is converted to the selected + * color format. + * @param value true to enabled CMYK images + */ + void setCMYKImagesSupported(boolean value); + + /** * Sets the shading mode for painting filled rectangles. * @param shadingMode the shading mode */ diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index 1f7a732d1..3fec25d8d 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -357,6 +357,11 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@inheritDoc} */ + public void setCMYKImagesSupported(boolean value) { + paintingState.setCMYKImagesSupported(value); + } + + /** {@inheritDoc} */ public void setShadingMode(AFPShadingMode shadingMode) { this.shadingMode = shadingMode; } diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java index 99ede8e79..fcfc9c64c 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java @@ -24,6 +24,7 @@ import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS; import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG; import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; +import org.apache.xmlgraphics.util.MimeConstants; import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.render.RenderingContext; @@ -35,6 +36,7 @@ public class AFPImageHandlerRawStream extends AbstractAFPImageHandlerRawStream { private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { ImageFlavor.RAW_JPEG, + ImageFlavor.RAW_TIFF, ImageFlavor.RAW_EPS, }; @@ -63,7 +65,12 @@ public class AFPImageHandlerRawStream extends AbstractAFPImageHandlerRawStream { if (targetContext instanceof AFPRenderingContext) { AFPRenderingContext afpContext = (AFPRenderingContext)targetContext; return (afpContext.getPaintingState().isNativeImagesSupported()) - && (image == null || image instanceof ImageRawJPEG || image instanceof ImageRawEPS); + && (image == null + || image instanceof ImageRawJPEG + || image instanceof ImageRawEPS + || ((image instanceof ImageRawStream) + && (MimeConstants.MIME_TIFF.equals( + ((ImageRawStream)image).getMimeType())))); } return false; } diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java index 8f7918583..b0988e754 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java @@ -89,7 +89,11 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima int resolution = paintingState.getResolution(); int maxPixelSize = paintingState.getBitsPerPixel(); if (paintingState.isColorImages()) { - maxPixelSize *= 3; //RGB only at the moment + if (paintingState.isCMYKImagesSupported()) { + maxPixelSize *= 4; //CMYK is maximum + } else { + maxPixelSize *= 3; //RGB is maximum + } } RenderedImage renderedImage = imageRendered.getRenderedImage(); @@ -97,6 +101,7 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima ImageSize intrinsicSize = imageInfo.getSize(); boolean useFS10 = (maxPixelSize == 1) || BitmapImageUtil.isMonochromeImage(renderedImage); + int functionSet = useFS10 ? 10 : 11; boolean usePageSegments = useFS10 && !imageObjectInfo.getResourceInfo().getLevel().isInline(); @@ -124,11 +129,6 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima resampledDim.width, resampledDim.height, resolution); } } - if (useFS10) { - imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10); - } else { - imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11); - } imageObjectInfo.setDataHeightRes((int)Math.round( effIntrinsicSize.getDpiHorizontal() * 10)); @@ -156,9 +156,9 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima byte[] imageData = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); boolean allowDirectEncoding = true; - if (allowDirectEncoding && pixelSize <= maxPixelSize) { + if (allowDirectEncoding && (pixelSize <= maxPixelSize)) { //Attempt to encode without resampling the image - ImageEncodingHelper helper = new ImageEncodingHelper(renderedImage); + ImageEncodingHelper helper = new ImageEncodingHelper(renderedImage, pixelSize == 32); ColorModel encodedColorModel = helper.getEncodedColorModel(); boolean directEncode = true; if (helper.getEncodedColorModel().getPixelSize() > maxPixelSize) { @@ -180,6 +180,9 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima log.trace("set subtractive mode"); imageObjectInfo.setSubtractive(true); } + if (pixelSize == 32) { + functionSet = 45; //IOCA FS45 required for CMYK + } helper.encode(baos); imageData = baos.toByteArray(); @@ -191,6 +194,7 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima //Convert image to 24bit RGB ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baos); imageData = baos.toByteArray(); + imageObjectInfo.setBitsPerPixel(24); boolean colorImages = paintingState.isColorImages(); imageObjectInfo.setColor(colorImages); @@ -212,6 +216,20 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima } } + switch (functionSet) { + case 10: + imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10); + break; + case 11: + imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11); + break; + case 45: + imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); + break; + default: + throw new IllegalStateException("Invalid IOCA function set: " + functionSet); + } + imageObjectInfo.setData(imageData); // set object area info diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index f019c6a47..250ff9624 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -90,8 +90,8 @@ import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPExtensionAttachment; import org.apache.fop.render.afp.extensions.AFPIncludeFormMap; import org.apache.fop.render.afp.extensions.AFPInvokeMediumMap; -import org.apache.fop.render.afp.extensions.AFPPageSetup; import org.apache.fop.render.afp.extensions.AFPPageOverlay; +import org.apache.fop.render.afp.extensions.AFPPageSetup; /** * This is an implementation of a FOP Renderer that renders areas to AFP. @@ -444,6 +444,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust ImageFlavor.XML_DOM, /*ImageFlavor.RAW_PNG, */ // PNG not natively supported in AFP ImageFlavor.RAW_JPEG, ImageFlavor.RAW_CCITTFAX, ImageFlavor.RAW_EPS, + ImageFlavor.RAW_TIFF, ImageFlavor.GRAPHICS2D, ImageFlavor.BUFFERED_IMAGE, ImageFlavor.RENDERED_IMAGE }; private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { @@ -831,6 +832,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust } /** {@inheritDoc} */ + public void setCMYKImagesSupported(boolean value) { + paintingState.setCMYKImagesSupported(value); + } + + /** {@inheritDoc} */ public void setShadingMode(AFPShadingMode shadingMode) { this.shadingMode = shadingMode; } diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 49e51b3d1..1e15d4c72 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -318,6 +318,9 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator String imagesMode = imagesCfg.getAttribute("mode", IMAGES_MODE_GRAYSCALE); if (IMAGES_MODE_COLOR.equals(imagesMode)) { customizable.setColorImages(true); + + boolean cmyk = imagesCfg.getAttributeAsBoolean("cmyk", false); + customizable.setCMYKImagesSupported(cmyk); } else { customizable.setColorImages(false); // default to 8 bits per pixel |