diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-10-01 12:56:26 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-10-01 12:56:26 +0000 |
commit | 5ad3308501dc6144aa4883ae4553d1d9739d05ef (patch) | |
tree | 99ef3cef3b51515788518b26958c8fa8d36a90a9 /src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java | |
parent | 404eacbf2cdc7202bc3161829182e33776320829 (diff) | |
download | xmlgraphics-fop-5ad3308501dc6144aa4883ae4553d1d9739d05ef.tar.gz xmlgraphics-fop-5ad3308501dc6144aa4883ae4553d1d9739d05ef.zip |
Added a DocumentHandler implementation for PNG output including multi-file output support.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@820637 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java')
-rw-r--r-- | src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java | 229 |
1 files changed, 4 insertions, 225 deletions
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java index 81f8bdee7..46603a3e6 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java @@ -19,60 +19,13 @@ package org.apache.fop.render.bitmap; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.image.writer.ImageWriter; -import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; -import org.apache.xmlgraphics.image.writer.MultiImageWriter; - -import org.apache.fop.apps.FopFactoryConfigurator; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler; -import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator; -import org.apache.fop.render.intermediate.IFException; -import org.apache.fop.render.intermediate.IFPainter; -import org.apache.fop.render.java2d.Java2DPainter; -import org.apache.fop.render.java2d.Java2DUtil; /** - * {@code IFDocumentHandler} implementation that produces PCL 5. + * {@code IFDocumentHandler} implementation that produces TIFF files. */ -public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler - implements TIFFConstants { - - /** logging instance */ - private static Log log = LogFactory.getLog(TIFFDocumentHandler.class); - - private ImageWriter imageWriter; - private MultiImageWriter multiImageWriter; - - private int pageCount; - private Dimension currentPageDimensions; - private BufferedImage currentImage; - - private BitmapRenderingSettings bitmapSettings = new BitmapRenderingSettings(); - - private double scaleFactor = 1.0; - - /** - * Default constructor. - */ - public TIFFDocumentHandler() { - } - - /** {@inheritDoc} */ - public boolean supportsPagesOutOfOrder() { - return false; - } +public class TIFFDocumentHandler extends AbstractBitmapDocumentHandler { /** {@inheritDoc} */ public String getMimeType() { @@ -80,12 +33,8 @@ public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@inheritDoc} */ - public void setContext(IFContext context) { - super.setContext(context); - - //Set target resolution - int dpi = Math.round(context.getUserAgent().getTargetResolution()); - getSettings().getWriterParams().setResolution(dpi); + public String getDefaultExtension() { + return "tif"; } /** {@inheritDoc} */ @@ -93,174 +42,4 @@ public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler return new TIFFRendererConfigurator(getUserAgent()); } - /** - * Returns the settings for bitmap rendering. - * @return the settings object - */ - public BitmapRenderingSettings getSettings() { - return this.bitmapSettings; - } - - /** {@inheritDoc} */ - public void setDefaultFontInfo(FontInfo fontInfo) { - FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent()); - setFontInfo(fi); - } - - //---------------------------------------------------------------------------------------------- - - /** {@inheritDoc} */ - public void startDocument() throws IFException { - super.startDocument(); - try { - // Creates writer - this.imageWriter = ImageWriterRegistry.getInstance().getWriterFor(getMimeType()); - if (this.imageWriter == null) { - BitmapRendererEventProducer eventProducer - = BitmapRendererEventProducer.Provider.get( - getUserAgent().getEventBroadcaster()); - eventProducer.noImageWriterFound(this, getMimeType()); - } - if (this.imageWriter.supportsMultiImageWriter()) { - this.multiImageWriter = this.imageWriter.createMultiImageWriter(outputStream); - } - this.pageCount = 0; - } catch (IOException e) { - throw new IFException("I/O error in startDocument()", e); - } - } - - /** {@inheritDoc} */ - public void endDocumentHeader() throws IFException { - } - - /** {@inheritDoc} */ - public void endDocument() throws IFException { - try { - if (this.multiImageWriter != null) { - this.multiImageWriter.close(); - } - this.multiImageWriter = null; - this.imageWriter = null; - } catch (IOException ioe) { - throw new IFException("I/O error in endDocument()", ioe); - } - super.endDocument(); - } - - /** {@inheritDoc} */ - public void startPageSequence(String id) throws IFException { - //nop - } - - /** {@inheritDoc} */ - public void endPageSequence() throws IFException { - //nop - } - - /** {@inheritDoc} */ - public void startPage(int index, String name, String pageMasterName, Dimension size) - throws IFException { - this.pageCount++; - this.currentPageDimensions = new Dimension(size); - } - - /** {@inheritDoc} */ - public IFPainter startPageContent() throws IFException { - double scale = scaleFactor - * (25.4f / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) - / getUserAgent().getTargetPixelUnitToMillimeter(); - int bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); - int bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); - this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); - Graphics2D graphics2D = this.currentImage.createGraphics(); - // draw page background - if (!getSettings().hasTransparentPageBackground()) { - graphics2D.setBackground(getSettings().getPageBackgroundColor()); - graphics2D.setPaint(getSettings().getPageBackgroundColor()); - graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight); - } - - graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, - RenderingHints.VALUE_FRACTIONALMETRICS_ON); - if (getSettings().isAntiAliasingEnabled() - && this.currentImage.getColorModel().getPixelSize() > 1) { - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - } else { - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_OFF); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - } - if (getSettings().isQualityRenderingEnabled()) { - graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, - RenderingHints.VALUE_RENDER_QUALITY); - } else { - graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, - RenderingHints.VALUE_RENDER_SPEED); - } - graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, - RenderingHints.VALUE_STROKE_PURE); - graphics2D.scale(scale / 1000f, scale / 1000f); - - return new Java2DPainter(graphics2D, getContext(), getFontInfo()); - } - - /** - * Creates a new BufferedImage. - * @param bitmapWidth the desired width in pixels - * @param bitmapHeight the desired height in pixels - * @return the new BufferedImage instance - */ - protected BufferedImage createBufferedImage(int bitmapWidth, int bitmapHeight) { - return new BufferedImage(bitmapWidth, bitmapHeight, getSettings().getBufferedImageType()); - } - - /** {@inheritDoc} */ - public void endPageContent() throws IFException { - try { - if (this.multiImageWriter == null) { - switch (this.pageCount) { - case 1: - this.imageWriter.writeImage( - this.currentImage, this.outputStream, - getSettings().getWriterParams()); - break; - case 2: - BitmapRendererEventProducer eventProducer - = BitmapRendererEventProducer.Provider.get( - getUserAgent().getEventBroadcaster()); - eventProducer.stoppingAfterFirstPageNoFilename(this); - break; - default: - //ignore - } - } else { - this.multiImageWriter.writeImage(this.currentImage, - getSettings().getWriterParams()); - } - this.currentImage = null; - } catch (IOException ioe) { - throw new IFException("I/O error while encoding BufferedImage", ioe); - } - } - - /** {@inheritDoc} */ - public void endPage() throws IFException { - this.currentPageDimensions = null; - } - - /** {@inheritDoc} */ - public void handleExtensionObject(Object extension) throws IFException { - if (false) { - //TODO Handle extensions - } else { - log.debug("Don't know how to handle extension object. Ignoring: " - + extension + " (" + extension.getClass().getName() + ")"); - } - } - } |