diff options
Diffstat (limited to 'src/java/org')
24 files changed, 228 insertions, 217 deletions
diff --git a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java index aba181358..80cb40713 100644 --- a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java @@ -77,7 +77,7 @@ public class AFPDataObjectFactory { ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, objectType, dataInContainer, containerHasOEG, dataInOCD); - objectContainer.setInputStream(dataObjectInfo.getInputStream()); + objectContainer.setData(dataObjectInfo.getData()); return objectContainer; } @@ -117,6 +117,7 @@ public class AFPDataObjectFactory { } else { imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel()); } + imageObj.setData(imageObjectInfo.getData()); return imageObj; diff --git a/src/java/org/apache/fop/afp/AFPDataObjectInfo.java b/src/java/org/apache/fop/afp/AFPDataObjectInfo.java index c618a53fc..f6ff0046a 100644 --- a/src/java/org/apache/fop/afp/AFPDataObjectInfo.java +++ b/src/java/org/apache/fop/afp/AFPDataObjectInfo.java @@ -19,8 +19,6 @@ package org.apache.fop.afp; -import java.io.InputStream; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.afp.modca.Registry; @@ -43,12 +41,18 @@ public class AFPDataObjectInfo { /** the data object height */ private int dataHeight; - /** the object data in an inputstream */ - private InputStream inputStream; - /** the object registry mimetype */ private String mimeType; + /** the object data in a byte array */ + private byte[] data; + + /** the object data height resolution */ + private int dataHeightRes; + + /** the object data width resolution */ + private int dataWidthRes; + /** * Default constructor */ @@ -121,16 +125,6 @@ public class AFPDataObjectInfo { return this.objectAreaInfo; } - /** {@inheritDoc} */ - public String toString() { - return "AFPDataObjectInfo{" - + "mimeType=" + mimeType - + ", dataWidth=" + dataWidth - + ", dataHeight=" + dataHeight - + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") - + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); - } - /** * Returns the uri of this data object * @@ -186,21 +180,68 @@ public class AFPDataObjectInfo { } /** - * Sets the object data inputstream + * Returns the data height resolution + * + * @return the data height resolution + */ + public int getDataHeightRes() { + return this.dataHeightRes; + } + + /** + * Sets the data width resolution + * + * @param dataWidthRes the data width resolution + */ + public void setDataHeightRes(int dataHeightRes) { + this.dataHeightRes = dataHeightRes; + } + + /** + * Returns the data width resolution + * + * @return the data width resolution + */ + public int getDataWidthRes() { + return this.dataWidthRes; + } + + /** + * Sets the data width resolution + * + * @param dataWidthRes the data width resolution + */ + public void setDataWidthRes(int dataWidthRes) { + this.dataWidthRes = dataWidthRes; + } + + /** + * Sets the object data * - * @param inputStream the object data inputstream + * @param data the object data */ - public void setInputStream(InputStream inputStream) { - this.inputStream = inputStream; + public void setData(byte[] data) { + this.data = data; } /** - * Returns the object data inputstream + * Returns the object data * - * @return the object data inputstream + * @return the object data */ - public InputStream getInputStream() { - return this.inputStream; + public byte[] getData() { + return this.data; } + /** {@inheritDoc} */ + public String toString() { + return "AFPDataObjectInfo{" + + "mimeType=" + mimeType + + ", dataWidth=" + dataWidth + + ", dataHeight=" + dataHeight + + ", dataWidthRes=" + dataWidthRes + + ", dataHeightRes=" + dataHeightRes + + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") + + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); + } } diff --git a/src/java/org/apache/fop/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java index 561ad438b..f3677534f 100644 --- a/src/java/org/apache/fop/afp/AFPImageObjectInfo.java +++ b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java @@ -24,6 +24,7 @@ package org.apache.fop.afp; * A list of parameters associated with an image */ public class AFPImageObjectInfo extends AFPDataObjectInfo { + /** number of bits per pixel used */ private int bitsPerPixel; @@ -33,9 +34,6 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo { /** compression type if any */ private int compression = -1; - /** the object data in a byte array */ - private byte[] data; - /** * Default constructor */ @@ -106,24 +104,6 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo { this.compression = compression; } - /** - * Sets the object data - * - * @param data the object data - */ - public void setData(byte[] data) { - this.data = data; - } - - /** - * Returns the object data - * - * @return the object data - */ - public byte[] getData() { - return this.data; - } - /** {@inheritDoc} */ public String toString() { return "AFPImageObjectInfo{" + super.toString() @@ -132,5 +112,4 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo { + ", bitsPerPixel=" + bitsPerPixel + "}"; } - }
\ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageContent.java b/src/java/org/apache/fop/afp/ioca/ImageContent.java index 028d08475..40e51578b 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageContent.java +++ b/src/java/org/apache/fop/afp/ioca/ImageContent.java @@ -123,7 +123,7 @@ public class ImageContent extends AbstractStructuredObject { } /** - * Set the data image store information. + * Set the image data (can be byte array or inputstream) * * @param imageData the image data */ @@ -148,15 +148,16 @@ public class ImageContent extends AbstractStructuredObject { os.write(getExternalAlgorithmParameter()); - // Image Data - if (data != null) { - final byte[] dataHeader = new byte[] { + final byte[] dataHeader = new byte[] { (byte)0xFE, // ID (byte)0x92, // ID 0x00, // length 0x00 // length }; - final int lengthOffset = 2; + final int lengthOffset = 2; + + // Image Data + if (data != null) { writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); } } diff --git a/src/java/org/apache/fop/afp/ioca/ImageSegment.java b/src/java/org/apache/fop/afp/ioca/ImageSegment.java index eab8b931a..9fb544719 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageSegment.java +++ b/src/java/org/apache/fop/afp/ioca/ImageSegment.java @@ -118,8 +118,8 @@ public class ImageSegment extends AbstractNamedAFPObject { * * @param data the image data */ - public void setData(byte[] data) { - getImageContent().setImageData(data); + public void setData(byte[] imageData) { + getImageContent().setImageData(imageData); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java index ec1b45be6..4a13b4a55 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java @@ -112,6 +112,7 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject implemen /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { + writeTriplets(os); if (objectEnvironmentGroup != null) { objectEnvironmentGroup.writeToStream(os); } diff --git a/src/java/org/apache/fop/afp/modca/ImageObject.java b/src/java/org/apache/fop/afp/modca/ImageObject.java index 8ab56691f..24ac0cb22 100644 --- a/src/java/org/apache/fop/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/afp/modca/ImageObject.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPImageObjectInfo; -import org.apache.fop.afp.AFPObjectAreaInfo; import org.apache.fop.afp.Factory; import org.apache.fop.afp.ioca.ImageSegment; @@ -65,15 +64,17 @@ public class ImageObject extends AbstractDataObject { int dataWidth = imageObjectInfo.getDataWidth(); int dataHeight = imageObjectInfo.getDataHeight(); - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); +// AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); +// int widthRes = objectAreaInfo.getWidthRes(); +// int heightRes = objectAreaInfo.getHeightRes(); + int dataWidthRes = imageObjectInfo.getDataWidthRes(); + int dataHeightRes = imageObjectInfo.getDataWidthRes(); ImageDataDescriptor imageDataDescriptor - = factory.createImageDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); + = factory.createImageDataDescriptor(dataWidth, dataHeight, dataWidthRes, dataHeightRes); getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor); - getImageSegment().setImageSize(dataWidth, dataHeight, widthRes, heightRes); + getImageSegment().setImageSize(dataWidth, dataHeight, dataWidthRes, dataHeightRes); } /** @@ -117,8 +118,8 @@ public class ImageObject extends AbstractDataObject { * * @param data the image data */ - public void setData(byte[] data) { - getImageSegment().setData(data); + public void setData(byte[] imageData) { + getImageSegment().setData(imageData); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/afp/modca/ObjectContainer.java index 791f4da1b..39b935d01 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/afp/modca/ObjectContainer.java @@ -20,10 +20,8 @@ package org.apache.fop.afp.modca; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPObjectAreaInfo; import org.apache.fop.afp.AFPResourceInfo; @@ -40,7 +38,7 @@ public class ObjectContainer extends AbstractDataObject { /** the object container data maximum length */ private static final int MAX_DATA_LEN = 32759; - private InputStream inputStream; + private byte[] data; /** * Main constructor @@ -75,8 +73,9 @@ public class ObjectContainer extends AbstractDataObject { copySF(dataHeader, SF_CLASS, Type.DATA, Category.OBJECT_CONTAINER); final int lengthOffset = 1; - copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os); - IOUtils.closeQuietly(inputStream); + if (data != null) { + writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); + } } /** {@inheritDoc} */ @@ -118,7 +117,7 @@ public class ObjectContainer extends AbstractDataObject { * * @param inputStream the inputstream for the object container data */ - public void setInputStream(InputStream inputStream) { - this.inputStream = inputStream; + public void setData(byte[] data) { + this.data = data; } } diff --git a/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java b/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java index e305e0a55..e8001f2fa 100644 --- a/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java +++ b/src/java/org/apache/fop/render/AbstractImageHandlerRegistry.java @@ -100,10 +100,7 @@ public abstract class AbstractImageHandlerRegistry { * @param handler the ImageHandler instance */ public synchronized void addHandler(ImageHandler handler) { - Class[] imageClasses = handler.getSupportedImageClasses(); - for (int i = 0; i < imageClasses.length; i++) { - this.handlers.put(imageClasses[i], handler); - } + this.handlers.put(handler.getSupportedImageClass(), handler); //Sorted insert ListIterator iter = this.handlerList.listIterator(); diff --git a/src/java/org/apache/fop/render/ImageHandler.java b/src/java/org/apache/fop/render/ImageHandler.java index 05d1e2e79..6a44c01a9 100644 --- a/src/java/org/apache/fop/render/ImageHandler.java +++ b/src/java/org/apache/fop/render/ImageHandler.java @@ -19,15 +19,14 @@ package org.apache.fop.render; -import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageFlavor; public interface ImageHandler { /** * Returns the priority for this image handler. A lower value means higher priority. This - * information is used to build the ordered/prioritized list of supported ImageFlavors for - * the PDF renderer. The built-in handlers use priorities between 100 and 999. + * information is used to build the ordered/prioritized list of supported ImageFlavors. + * The built-in handlers use priorities between 100 and 999. * @return a positive integer (>0) indicating the priority */ int getPriority(); @@ -39,8 +38,8 @@ public interface ImageHandler { ImageFlavor[] getSupportedImageFlavors(); /** - * Returns the {@link Image} subclasses supported by this instance. - * @return the Image types + * Returns the {@link Class} subclass supported by this instance. + * @return the image Class type */ - Class[] getSupportedImageClasses(); + Class getSupportedImageClass(); } diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandler.java b/src/java/org/apache/fop/render/afp/AFPImageHandler.java index 8e925d460..3ec3ea0b1 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandler.java @@ -31,6 +31,9 @@ import org.apache.fop.afp.AFPResourceInfo; import org.apache.fop.afp.AFPUnitConverter; import org.apache.fop.render.ImageHandler; +/** + * A base abstract AFP image handler + */ public abstract class AFPImageHandler implements ImageHandler { private static final int X = 0; private static final int Y = 1; diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java index fa3f00cdb..0780e8a59 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java @@ -41,10 +41,6 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler { ImageFlavor.GRAPHICS2D }; - private static final Class[] CLASSES = new Class[] { - ImageGraphics2D.class - }; - /** {@inheritDoc} */ public AFPDataObjectInfo generateDataObjectInfo( AFPRendererImageInfo rendererImageInfo) throws IOException { @@ -98,8 +94,8 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageGraphics2D.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java index aa91bb660..3ac1d5696 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawCCITTFax.java @@ -23,24 +23,18 @@ import java.io.IOException; import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPImageObjectInfo; -import org.apache.fop.afp.AFPObjectAreaInfo; import org.apache.xmlgraphics.image.loader.ImageFlavor; -import org.apache.xmlgraphics.image.loader.ImageSize; import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; /** - * PDFImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4). + * AFPImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4). */ -public class AFPImageHandlerRawCCITTFax extends AFPImageHandler { +public class AFPImageHandlerRawCCITTFax extends AbstractAFPImageHandlerRawStream { private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { ImageFlavor.RAW_CCITTFAX, }; - private static final Class[] CLASSES = new Class[] { - ImageRawCCITTFax.class, - }; - /** {@inheritDoc} */ public AFPDataObjectInfo generateDataObjectInfo( AFPRendererImageInfo rendererImageInfo) throws IOException { @@ -48,18 +42,10 @@ public class AFPImageHandlerRawCCITTFax extends AFPImageHandler { = (AFPImageObjectInfo)super.generateDataObjectInfo(rendererImageInfo); ImageRawCCITTFax ccitt = (ImageRawCCITTFax) rendererImageInfo.getImage(); - imageObjectInfo.setCompression(ccitt.getCompression()); - - AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo(); - ImageSize imageSize = ccitt.getSize(); - int widthRes = (int) (imageSize.getDpiHorizontal() * 10); - objectAreaInfo.setWidthRes(widthRes); - - int heightRes = (int) (imageSize.getDpiVertical() * 10); - objectAreaInfo.setHeightRes(heightRes); - - imageObjectInfo.setInputStream(ccitt.createInputStream()); + int compression = ccitt.getCompression(); + imageObjectInfo.setCompression(compression); + imageObjectInfo.setBitsPerPixel(1); return imageObjectInfo; } @@ -74,8 +60,8 @@ public class AFPImageHandlerRawCCITTFax extends AFPImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRawCCITTFax.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java index 47344b200..ded9ec9d5 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java @@ -19,76 +19,28 @@ package org.apache.fop.render.afp; -import java.io.IOException; -import java.io.InputStream; - import org.apache.fop.afp.AFPDataObjectInfo; -import org.apache.fop.afp.AFPObjectAreaInfo; -import org.apache.fop.afp.AFPPaintingState; import org.apache.xmlgraphics.image.loader.ImageFlavor; -import org.apache.xmlgraphics.image.loader.ImageInfo; -import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; -import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS; -import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG; import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; /** * AFPImageHandler implementation which handles raw stream images. */ -public class AFPImageHandlerRawStream extends AFPImageHandler { +public class AFPImageHandlerRawStream extends AbstractAFPImageHandlerRawStream { private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { ImageFlavor.RAW_JPEG, - ImageFlavor.RAW_CCITTFAX, ImageFlavor.RAW_EPS, }; - private static final Class[] CLASSES = new Class[] { - ImageRawJPEG.class, - ImageRawCCITTFax.class, - ImageRawEPS.class - }; - - /** {@inheritDoc} */ - public AFPDataObjectInfo generateDataObjectInfo( - AFPRendererImageInfo rendererImageInfo) throws IOException { - AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo); - ImageInfo imageInfo = rendererImageInfo.getImageInfo(); - String mimeType = imageInfo.getMimeType(); - if (mimeType != null) { - dataObjectInfo.setMimeType(mimeType); - } - ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage(); - - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - - AFPRendererContext rendererContext - = (AFPRendererContext)rendererImageInfo.getRendererContext(); - AFPInfo afpInfo = rendererContext.getInfo(); - AFPPaintingState paintingState = afpInfo.getPaintingState(); - int resolution = paintingState.getResolution(); - objectAreaInfo.setWidthRes(resolution); - objectAreaInfo.setHeightRes(resolution); - - InputStream inputStream = rawStream.createInputStream(); - dataObjectInfo.setInputStream(inputStream); - - int dataHeight = rawStream.getSize().getHeightPx(); - dataObjectInfo.setDataHeight(dataHeight); - - int dataWidth = rawStream.getSize().getWidthPx(); - dataObjectInfo.setDataWidth(dataWidth); - return dataObjectInfo; - } - /** {@inheritDoc} */ public int getPriority() { - return 100; + return 200; } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRawStream.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java index ef6a6bb65..28c942a08 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java @@ -28,7 +28,6 @@ import org.apache.fop.afp.AFPImageObjectInfo; import org.apache.fop.afp.AFPObjectAreaInfo; import org.apache.fop.afp.AFPPaintingState; import org.apache.xmlgraphics.image.loader.ImageFlavor; -import org.apache.xmlgraphics.image.loader.impl.ImageBuffered; import org.apache.xmlgraphics.image.loader.impl.ImageRendered; import org.apache.xmlgraphics.ps.ImageEncodingHelper; import org.apache.xmlgraphics.util.MimeConstants; @@ -43,27 +42,21 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler { ImageFlavor.RENDERED_IMAGE }; - private static final Class[] CLASSES = new Class[] { - ImageBuffered.class, - ImageRendered.class - }; - /** {@inheritDoc} */ public AFPDataObjectInfo generateDataObjectInfo( AFPRendererImageInfo rendererImageInfo) throws IOException { AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)super.generateDataObjectInfo(rendererImageInfo); - imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); - - AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo(); AFPRendererContext rendererContext = (AFPRendererContext)rendererImageInfo.getRendererContext(); AFPInfo afpInfo = rendererContext.getInfo(); AFPPaintingState paintingState = afpInfo.getPaintingState(); int resolution = paintingState.getResolution(); - objectAreaInfo.setWidthRes(resolution); - objectAreaInfo.setHeightRes(resolution); + + imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); + imageObjectInfo.setDataHeightRes(resolution); + imageObjectInfo.setDataWidthRes(resolution); ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img; RenderedImage renderedImage = imageRendered.getRenderedImage(); @@ -92,6 +85,11 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler { } imageObjectInfo.setData(imageData); + // set object area info + AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo(); + objectAreaInfo.setWidthRes(resolution); + objectAreaInfo.setHeightRes(resolution); + return imageObjectInfo; } @@ -106,8 +104,8 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRendered.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerXML.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerXML.java index b7345811a..7ea1a7a10 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerXML.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerXML.java @@ -39,10 +39,6 @@ public class AFPImageHandlerXML extends AFPImageHandler { ImageFlavor.XML_DOM, }; - private static final Class[] CLASSES = new Class[] { - ImageXMLDOM.class, - }; - /** {@inheritDoc} */ public AFPDataObjectInfo generateDataObjectInfo(AFPRendererImageInfo rendererImageInfo) throws IOException { @@ -64,8 +60,8 @@ public class AFPImageHandlerXML extends AFPImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageXMLDOM.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 903099610..b73b036c3 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -71,7 +71,6 @@ import org.apache.fop.render.Graphics2DAdapter; import org.apache.fop.render.RendererContext; import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPPageSetup; -import org.apache.fop.util.AbstractPaintingState; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; @@ -743,15 +742,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } /** - * Returns the current AFP state - * - * @return the current AFP state - */ - public AbstractPaintingState getState() { - return this.paintingState; - } - - /** * Sets the default resource group file path * @param filePath the default resource group file path */ diff --git a/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java index 0aa3eb6ab..2687d9071 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java @@ -146,4 +146,17 @@ public class AFPRendererImageInfo { return this.pos; } + /** {@inheritDoc} */ + public String toString() { + return "AFPRendererImageInfo{\n" + + "\turi=" + uri + ",\n" + + "\tinfo=" + info + ",\n" + + "\tpos=" + pos + ",\n" + + "\torigin=" + origin + ",\n" + + "\timg=" + img + ",\n" + + "\tforeignAttributes=" + foreignAttributes + ",\n" + + "\trendererContext=" + rendererContext + "\n" + + "}"; + + } } diff --git a/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java b/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java new file mode 100644 index 000000000..ae8ac9950 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPPaintingState; +import org.apache.xmlgraphics.image.loader.ImageInfo; +import org.apache.xmlgraphics.image.loader.ImageSize; +import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; + +/** + * A base abstract AFP raw stream image handler + */ +public abstract class AbstractAFPImageHandlerRawStream extends AFPImageHandler { + + /** {@inheritDoc} */ + public AFPDataObjectInfo generateDataObjectInfo( + AFPRendererImageInfo rendererImageInfo) throws IOException { + AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo); + + ImageInfo imageInfo = rendererImageInfo.getImageInfo(); + String mimeType = imageInfo.getMimeType(); + if (mimeType != null) { + dataObjectInfo.setMimeType(mimeType); + } + ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage(); + InputStream inputStream = rawStream.createInputStream(); + try { + dataObjectInfo.setData(IOUtils.toByteArray(inputStream)); + } finally { + IOUtils.closeQuietly(inputStream); + } + + int dataHeight = rawStream.getSize().getHeightPx(); + dataObjectInfo.setDataHeight(dataHeight); + + int dataWidth = rawStream.getSize().getWidthPx(); + dataObjectInfo.setDataWidth(dataWidth); + + ImageSize imageSize = rawStream.getSize(); + dataObjectInfo.setDataHeightRes((int) (imageSize.getDpiHorizontal() * 10)); + dataObjectInfo.setDataWidthRes((int) (imageSize.getDpiVertical() * 10)); + + // set object area info + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + AFPRendererContext rendererContext + = (AFPRendererContext)rendererImageInfo.getRendererContext(); + AFPInfo afpInfo = rendererContext.getInfo(); + AFPPaintingState paintingState = afpInfo.getPaintingState(); + int resolution = paintingState.getResolution(); + objectAreaInfo.setWidthRes(resolution); + objectAreaInfo.setHeightRes(resolution); + + return dataObjectInfo; + } + +} diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java index 9f44e58b5..3e4a9b354 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java @@ -38,10 +38,6 @@ public class PDFImageHandlerGraphics2D implements PDFImageHandler { ImageFlavor.GRAPHICS2D, }; - private static final Class[] CLASSES = new Class[] { - ImageGraphics2D.class, - }; - /** {@inheritDoc} */ public PDFXObject generateImage(RendererContext context, Image image, Point origin, Rectangle pos) @@ -59,8 +55,8 @@ public class PDFImageHandlerGraphics2D implements PDFImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageGraphics2D.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java index 158e93c86..1ba498ff0 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawCCITTFax.java @@ -41,10 +41,6 @@ public class PDFImageHandlerRawCCITTFax implements PDFImageHandler { ImageFlavor.RAW_CCITTFAX, }; - private static final Class[] CLASSES = new Class[] { - ImageRawCCITTFax.class, - }; - /** {@inheritDoc} */ public PDFXObject generateImage(RendererContext context, Image image, Point origin, Rectangle pos) @@ -74,8 +70,8 @@ public class PDFImageHandlerRawCCITTFax implements PDFImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRawCCITTFax.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java index 1432547da..41a2d7565 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRawJPEG.java @@ -41,10 +41,6 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler { ImageFlavor.RAW_JPEG, }; - private static final Class[] CLASSES = new Class[] { - ImageRawJPEG.class, - }; - /** {@inheritDoc} */ public PDFXObject generateImage(RendererContext context, Image image, Point origin, Rectangle pos) @@ -74,8 +70,8 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRawJPEG.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java index edbe9005d..268ff8862 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerRenderedImage.java @@ -42,11 +42,6 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler { ImageFlavor.RENDERED_IMAGE }; - private static final Class[] CLASSES = new Class[] { - ImageRendered.class, - }; - - /** {@inheritDoc} */ public PDFXObject generateImage(RendererContext context, Image image, Point origin, Rectangle pos) @@ -76,8 +71,8 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageRendered.class; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerXML.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerXML.java index 069fef172..26ba83371 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerXML.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerXML.java @@ -40,10 +40,6 @@ public class PDFImageHandlerXML implements PDFImageHandler { ImageFlavor.XML_DOM, }; - private static final Class[] CLASSES = new Class[] { - ImageXMLDOM.class, - }; - /** {@inheritDoc} */ public PDFXObject generateImage(RendererContext context, Image image, Point origin, Rectangle pos) @@ -64,8 +60,8 @@ public class PDFImageHandlerXML implements PDFImageHandler { } /** {@inheritDoc} */ - public Class[] getSupportedImageClasses() { - return CLASSES; + public Class getSupportedImageClass() { + return ImageXMLDOM.class; } /** {@inheritDoc} */ |