From 37ff704262a892e22100b9e56c40228c5bcf562d Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Thu, 12 Apr 2012 14:17:05 +0000 Subject: [PATCH] Bugzilla#49893: A global setting to wrap F11 images in page segments. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1325277 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/trunk/output.xml | 11 +++++ .../org/apache/fop/afp/AFPPaintingState.java | 42 +++++++++++++++++ .../org/apache/fop/afp/modca/ImageObject.java | 7 +-- .../fop/render/afp/AFPCustomizable.java | 24 ++++++++++ .../fop/render/afp/AFPDocumentHandler.java | 20 ++++++++ .../afp/AFPImageHandlerRenderedImage.java | 47 ++++++++++++------- .../render/afp/AFPRendererConfigurator.java | 8 ++++ status.xml | 3 ++ 8 files changed, 142 insertions(+), 20 deletions(-) diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 9b6a3edc9..8597ab787 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -796,6 +796,17 @@ Note that the value of the encoding attribute in the example is the double-byte

]]> +

+ When the boolean attribute pseg (default false) is set to true, non-inline FS11 and FS45 IOCA images are wrapped in page segment. + This option is provided to support printers/print servers that require this MO:DCA structure. +

+ ]]> +

+ Setting the boolean attribute fs45 to true (default false) will force all images to FS45. +

+ ]]>

By default, JPEG images are rasterized to a bitmap and the bitmap is included in the AFP doc. However it is possible to encode in a lossless way to maintain maximum quality. But due diff --git a/src/java/org/apache/fop/afp/AFPPaintingState.java b/src/java/org/apache/fop/afp/AFPPaintingState.java index 1c87b27d2..7e6b940a5 100644 --- a/src/java/org/apache/fop/afp/AFPPaintingState.java +++ b/src/java/org/apache/fop/afp/AFPPaintingState.java @@ -84,6 +84,13 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState /** determines whether to stroke text in GOCA mode or to use text operators where possible */ private boolean strokeGocaText = false; + + /** use page segment with F11 and F45 images*/ + private boolean pSeg; + + /** use FS45 images*/ + private boolean fs45; + /** the current page */ private transient AFPPagePaintingState pagePaintingState = new AFPPagePaintingState(); @@ -356,6 +363,41 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState return this.strokeGocaText; } + /** + * Whether FS11 and SF45 non-inline images should be wrapped in a page segment + * @return true iff images should be wrapped + */ + public boolean getWrapPSeg() { + return pSeg; + } + + /** + * Sets whether FS11 and FS45 non-inline images should be wrapped in a page segment + * @param pSeg true iff images should be wrapped + */ + public void setWrapPSeg(boolean pSeg) { + this.pSeg = pSeg; + } + + + /** + * gets whether images should be FS45 + * @return true iff images should be FS45 + */ + public boolean getFS45() { + return fs45; + } + + /** + * sets whether images should be FS45 + * @param fs45 true iff images should be FS45 + */ + public void setFS45(boolean fs45) { + this.fs45 = fs45; + } + + + /** {@inheritDoc} */ @Override protected AbstractData instantiateData() { diff --git a/src/java/org/apache/fop/afp/modca/ImageObject.java b/src/java/org/apache/fop/afp/modca/ImageObject.java index c6cfa3808..adb56e626 100644 --- a/src/java/org/apache/fop/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/afp/modca/ImageObject.java @@ -75,10 +75,11 @@ public class ImageObject extends AbstractDataObject { int dataHeightRes = imageObjectInfo.getDataWidthRes(); ImageDataDescriptor imageDataDescriptor = factory.createImageDataDescriptor(dataWidth, dataHeight, dataWidthRes, dataHeightRes); - if (imageObjectInfo.getBitsPerPixel() == 1) { - imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS10); - } else if (MimeConstants.MIME_AFP_IOCA_FS45.equals(imageObjectInfo.getMimeType())) { + + if (MimeConstants.MIME_AFP_IOCA_FS45.equals(imageObjectInfo.getMimeType())) { imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS45); + } else if (imageObjectInfo.getBitsPerPixel() == 1) { + imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS10); } getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor); getObjectEnvironmentGroup().setMapImageObject( diff --git a/src/java/org/apache/fop/render/afp/AFPCustomizable.java b/src/java/org/apache/fop/render/afp/AFPCustomizable.java index 684ac057c..6eca86458 100644 --- a/src/java/org/apache/fop/render/afp/AFPCustomizable.java +++ b/src/java/org/apache/fop/render/afp/AFPCustomizable.java @@ -89,6 +89,30 @@ public interface AFPCustomizable { */ void setResolution(int resolution); + /** + * Sets whether FS11 and FS45 non-inline images should be wrapped in a page segment + * @param pSeg true iff images should be wrapped + */ + void setWrapPSeg(boolean pSeg); + + /** + * set true if images should be FS45 + * @param fs45 true iff images should be FS45 + */ + void setFS45(boolean fs45); + + /** + * gets whether FS11 and FS45 non-inline images should be wrapped in a page segment + * @return true iff images should be wrapped + */ + boolean getWrapPSeg(); + + /** + * gets whether images should be FS45 + * @return true iff images should be FS45 + */ + boolean getFS45(); + /** * Returns the output/device resolution. * diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index cddcc7b84..0c778303c 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -467,6 +467,26 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler return this.paintingState.isStrokeGOCAText(); } + /** {@inheritDoc} */ + public void setWrapPSeg(boolean pSeg) { + paintingState.setWrapPSeg(pSeg); + } + + /** {@inheritDoc} */ + public void setFS45(boolean fs45) { + paintingState.setFS45(fs45); + } + + /** {@inheritDoc} */ + public boolean getWrapPSeg() { + return paintingState.getWrapPSeg(); + } + + /** {@inheritDoc} */ + public boolean getFS45() { + return paintingState.getFS45(); + } + /** {@inheritDoc} */ public void setDefaultResourceGroupFilePath(String filePath) { resourceManager.setDefaultResourceGroupFilePath(filePath); diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java index 0b4b6ea98..e5f41d232 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java @@ -149,6 +149,25 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima private static final class RenderedImageEncoder { + private enum FunctionSet { + + FS10(MimeConstants.MIME_AFP_IOCA_FS10), + FS11(MimeConstants.MIME_AFP_IOCA_FS11), + FS45(MimeConstants.MIME_AFP_IOCA_FS45); + + private String mimeType; + + FunctionSet(String mimeType) { + this.mimeType = mimeType; + } + + private String getMimeType() { + return mimeType; + } + }; + + + private ImageRendered imageRendered; private Dimension targetSize; @@ -223,7 +242,7 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima throws IOException { RenderedImage renderedImage = imageRendered.getRenderedImage(); - int functionSet = useFS10 ? 10 : 11; + FunctionSet functionSet = useFS10 ? FunctionSet.FS10 : FunctionSet.FS11; if (usePageSegments) { assert resampledDim != null; @@ -285,7 +304,7 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima log.debug("Encoding image directly..."); imageObjectInfo.setBitsPerPixel(encodedColorModel.getPixelSize()); if (pixelSize == 32) { - functionSet = 45; //IOCA FS45 required for CMYK + functionSet = FunctionSet.FS45; //IOCA FS45 required for CMYK } //Lossy or loss-less? @@ -315,23 +334,17 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima log.debug("Encoding image via RGB..."); imageData = encodeViaRGB(renderedImage, imageObjectInfo, paintingState, baos); } - - 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); + // Should image be FS45? + if (paintingState.getFS45()) { + functionSet = FunctionSet.FS45; } - + //Wrapping 300+ resolution FS11 IOCA in a page segment is apparently necessary(?) + imageObjectInfo.setCreatePageSegment( + (functionSet.equals(FunctionSet.FS11) || functionSet.equals(FunctionSet.FS45)) + && paintingState.getWrapPSeg() + ); + imageObjectInfo.setMimeType(functionSet.getMimeType()); imageObjectInfo.setData(imageData); - return imageObjectInfo; } diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 23449ce4e..bf7fbde4a 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -415,6 +415,14 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator customizable.canEmbedJpeg(allowEmbedding); customizable.setBitmapEncodingQuality(ieq); + //FS11 and FS45 page segment wrapping + boolean pSeg = imagesCfg.getAttributeAsBoolean("pseg", false); + customizable.setWrapPSeg(pSeg); + + //FS45 image forcing + boolean fs45 = imagesCfg.getAttributeAsBoolean("fs45", false); + customizable.setFS45(fs45); + // shading (filled rectangles) Configuration shadingCfg = cfg.getChild("shading"); AFPShadingMode shadingMode = AFPShadingMode.valueOf( diff --git a/status.xml b/status.xml index 9cb50efbd..105b80fbd 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + A global setting to wrap F11 images in page segments. + Support list-block in marker, thus preventing NPE. -- 2.39.5