tkormann 01/10/30 06:19:07 Added: test-sources/org/apache/batik/transcoder/image AOITest.java AbstractImageTranscoderTest.java AlternateStylesheetTest.java BackgroundColorTest.java DOMTest.java DimensionTest.java InputStreamTest.java LanguageTest.java MediaTest.java Messages.java ParametrizedDOMTest.java PixelToMMTest.java ReaderTest.java URITest.java Log: new tests for ImageTranscoder Revision Changes Path 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/AOITest.java Index: AOITest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_AOI transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: AOITest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class AOITest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The area of interest. */ protected Rectangle2D aoi; /** The width of the image. */ protected Float imgWidth; /** The height of the image. */ protected Float imgHeight; /** * Constructs a new <tt>AOITest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param x the x coordinate of the area of interest * @param y the y coordinate of the area of interest * @param width the width of the area of interest * @param height the height of the area of interest */ public AOITest(String inputURI, String refImageURI, Float x, Float y, Float width, Float height) { this(inputURI, refImageURI, x, y, width, height, new Float(-1), new Float(-1)); } /** * Constructs a new <tt>AOITest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param x the x coordinate of the area of interest * @param y the y coordinate of the area of interest * @param width the width of the area of interest * @param height the height of the area of interest * @param imgWidth the width of the image to generate * @param imgHeight the height of the image to generate */ public AOITest(String inputURI, String refImageURI, Float x, Float y, Float width, Float height, Float imgWidth, Float imgHeight) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.aoi = new Rectangle2D.Float(x.floatValue(), y.floatValue(), width.floatValue(), height.floatValue()); this.imgWidth = imgWidth; this.imgHeight = imgHeight; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(11); hints.put(ImageTranscoder.KEY_AOI, aoi); if (imgWidth.floatValue() > 0) { hints.put(ImageTranscoder.KEY_WIDTH, imgWidth); } if (imgHeight.floatValue() > 0) { hints.put(ImageTranscoder.KEY_HEIGHT, imgHeight); } return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/AbstractImageTranscoderTest.java Index: AbstractImageTranscoderTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import org.apache.batik.ext.awt.image.spi.ImageTagRegistry; import org.apache.batik.ext.awt.image.renderable.Filter; import org.apache.batik.util.ParsedURL; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.test.AbstractTest; import org.apache.batik.test.DefaultTestReport; import org.apache.batik.test.TestReport; /** * The base class for the ImageTranscoder tests. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: AbstractImageTranscoderTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public abstract class AbstractImageTranscoderTest extends AbstractTest { /** * Error when the reference image and the generated image is different. */ public static final String ERROR_IMAGE_DIFFER = "AbstractImageTranscoderTest.error.image.differ"; /** * Error when an exception occured while transcoding. */ public static final String ERROR_TRANSCODING = "AbstractImageTranscoderTest.error.transcoder.exception"; /** * Constructs a new <tt>AbstractImageTranscoderTest</tt>. */ public AbstractImageTranscoderTest() { } /** * Runs this test. This method will only throw exceptions if some aspect of * the test's internal operation fails. */ public TestReport runImpl() throws Exception { DefaultTestReport report = new DefaultTestReport(this); try { DiffImageTranscoder transcoder = new DiffImageTranscoder(getReferenceImage()); Map hints = createTranscodingHints(); if (hints != null) { transcoder.setTranscodingHints(hints); } TranscoderInput input = createTranscoderInput(); transcoder.transcode(input, null); if (!transcoder.isIdentical()) { report.setErrorCode(ERROR_IMAGE_DIFFER); report.addDescriptionEntry(ERROR_IMAGE_DIFFER, ""); report.setPassed(false); } } catch (TranscoderException ex) { report.setErrorCode(ERROR_TRANSCODING); report.addDescriptionEntry(ERROR_TRANSCODING, toString(ex)); ex.printStackTrace(); report.setPassed(false); } return report; } /** * Creates the <tt>TranscoderInput</tt>. */ protected abstract TranscoderInput createTranscoderInput(); /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { return null; } /** * Returns the reference image for this test. */ protected abstract BufferedImage getReferenceImage(); ////////////////////////////////////////////////////////////////////////// // Convenient methods ////////////////////////////////////////////////////////////////////////// /** * Gives the specified exception as a string. */ public static String toString(Exception ex) { StringWriter trace = new StringWriter(); ex.printStackTrace(new PrintWriter(trace)); return trace.toString(); } /** * Resolves the input string as follows. * + First, the string is interpreted as a file description. * If the file exists, then the file name is turned into * a URL. * + Otherwise, the string is supposed to be a URL. If it * is an invalid URL, an IllegalArgumentException is thrown. */ public static URL resolveURL(String url){ // Is url a file? File f = (new File(url)).getAbsoluteFile(); if (f.exists()) { try { return f.toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException(url); } } // url is not a file. It must be a regular URL... try { return new URL(url); } catch(MalformedURLException e) { throw new IllegalArgumentException(url); } } /** * Loads an image from a URL */ public static BufferedImage createBufferedImage(URL url) { ImageTagRegistry reg = ImageTagRegistry.getRegistry(); Filter filt = reg.readURL(new ParsedURL(url)); if (filt == null) { return null; } RenderedImage red = filt.createDefaultRendering(); if (red == null) { return null; } BufferedImage img = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB); red.copyData(img.getRaster()); return img; } /** * A custom ImageTranscoder for testing. */ protected static class DiffImageTranscoder extends ImageTranscoder { /** The result of the image comparaison. */ protected boolean state; /** The reference image. */ protected BufferedImage refImg; /** * Constructs a new <tt>DiffImageTranscoder</tt>. * * @param refImg the reference image * @param report the test report into which errors have been sent */ public DiffImageTranscoder(BufferedImage refImg) { this.refImg = refImg; } /** * Creates a new image with the specified dimension. * @param w the image width in pixels * @param h the image height in pixels */ public BufferedImage createImage(int w, int h) { return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); } /** * Compares the specified image with the reference image and set the * state flag. * * @param img the image to write * @param output the output (ignored) * @param TranscoderException if an error occured while storing the * image */ public void writeImage(BufferedImage img, TranscoderOutput output) throws TranscoderException { compareImage(img); } /** * Compares both source and result images and set the state flag. */ protected void compareImage(BufferedImage img) { // compare the resulting image with the reference image // state = true if refImg is the same than img if ((img.getType() != BufferedImage.TYPE_INT_ARGB) || (refImg.getType() != BufferedImage.TYPE_INT_ARGB)) { throw new IllegalArgumentException("Different Image type"); } int minX = refImg.getMinX(); int minY = refImg.getMinY(); int w = refImg.getWidth(); int h = refImg.getHeight(); if ((img.getMinX() != minX) || (img.getMinY() != minY) || (img.getWidth() != w) || (img.getHeight() != h)) { showDiff(img); state = false; return; } for (int y = minY; y < minY+h; ++y) { for (int x = minX; x < minX+w; ++x) { if (img.getRGB(x, y) != refImg.getRGB(x, y)) { showDiff(img); state = false; return; } } } state = true; } private void showDiff(BufferedImage img) { javax.swing.JFrame frame = new javax.swing.JFrame(); frame.getContentPane().add (new javax.swing.JLabel(new javax.swing.ImageIcon(img)), java.awt.BorderLayout.EAST); frame.getContentPane().add (new javax.swing.JLabel(new javax.swing.ImageIcon(refImg)), java.awt.BorderLayout.WEST); frame.pack(); frame.show(); } /** * Returns true if the reference image is the same than the generated * image, false otherwise. */ public boolean isIdentical() { return state; } } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/AlternateStylesheetTest.java Index: AlternateStylesheetTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_ALTERNATE_STYLESHEET transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: AlternateStylesheetTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class AlternateStylesheetTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The alternate stylesheet to use. */ protected String alternateStylesheet; /** * Constructs a new <tt>AlternateStylesheetTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param alternateStylesheet the alternate stylesheet CSS media */ public AlternateStylesheetTest(String inputURI, String refImageURI, String alternateStylesheet) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.alternateStylesheet = alternateStylesheet; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(3); hints.put(ImageTranscoder.KEY_ALTERNATE_STYLESHEET, alternateStylesheet); return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/BackgroundColorTest.java Index: BackgroundColorTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.DOMImplementation; /** * Test the ImageTranscoder with the KEY_BACKGROUND_COLOR transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: BackgroundColorTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class BackgroundColorTest extends AbstractImageTranscoderTest { /** * Constructs a new <tt>BackgroundColorTest</tt>. */ public BackgroundColorTest() { } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.setAttributeNS(null, "width", "400"); root.setAttributeNS(null, "height", "400"); Element r = doc.createElementNS(svgNS, "rect"); r.setAttributeNS(null, "x", "100"); r.setAttributeNS(null, "y", "50"); r.setAttributeNS(null, "width", "100"); r.setAttributeNS(null, "height", "50"); r.setAttributeNS(null, "style", "fill:red"); root.appendChild(r); return new TranscoderInput(doc); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(7); hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.blue); return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { BufferedImage img = new BufferedImage (400, 400, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setColor(Color.blue); g2d.fillRect(0, 0, 400, 400); g2d.setColor(Color.red); g2d.fillRect(100, 50, 100, 50); return img; } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/DOMTest.java Index: DOMTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.transcoder.TranscodingHints; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.DOMImplementation; /** * Test the ImageTranscoder input with a DOM tree. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: DOMTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class DOMTest extends AbstractImageTranscoderTest { /** * Constructs a new <tt>DOMTest</tt>. */ public DOMTest() { } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.setAttributeNS(null, "width", "400"); root.setAttributeNS(null, "height", "400"); Element r = doc.createElementNS(svgNS, "rect"); r.setAttributeNS(null, "x", "0"); r.setAttributeNS(null, "y", "0"); r.setAttributeNS(null, "width", "400"); r.setAttributeNS(null, "height", "400"); r.setAttributeNS(null, "style", "fill:black"); root.appendChild(r); r = doc.createElementNS(svgNS, "rect"); r.setAttributeNS(null, "x", "100"); r.setAttributeNS(null, "y", "50"); r.setAttributeNS(null, "width", "100"); r.setAttributeNS(null, "height", "50"); r.setAttributeNS(null, "style", "stroke:red; fill:none"); root.appendChild(r); return new TranscoderInput(doc); } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { BufferedImage img = new BufferedImage (400, 400, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setColor(Color.black); g2d.fillRect(0, 0, 400, 400); g2d.setColor(Color.red); g2d.drawRect(100, 50, 100, 50); return img; } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/DimensionTest.java Index: DimensionTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.util.Map; import java.util.HashMap ; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_WIDTH and/or the KEY_HEIGHT transcoding * hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: DimensionTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class DimensionTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The width of the image. */ protected Float width; /** The height of the image. */ protected Float height; /** * Constructs a new <tt>DimensionTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param width the image width * @param height the image height */ public DimensionTest(String inputURI, String refImageURI, Float width, Float height) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.width = width; this.height = height; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(7); if (width.floatValue() > 0) { hints.put(ImageTranscoder.KEY_WIDTH, width); } if (height.floatValue() > 0) { hints.put(ImageTranscoder.KEY_HEIGHT, height); } return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/InputStreamTest.java Index: InputStreamTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.io.InputStream; import java.io.IOException; import java.net.URL; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder input with a InputStream. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: InputStreamTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class InputStreamTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** * Constructs a new <tt>InputStreamTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image */ public InputStreamTest(String inputURI, String refImageURI) { this.inputURI = inputURI; this.refImageURI = refImageURI; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { try { URL url = resolveURL(inputURI); InputStream istream = url.openStream(); TranscoderInput input = new TranscoderInput(istream); input.setURI(url.toString()); // Needed for external resources return input; } catch (IOException ex) { throw new IllegalArgumentException(inputURI); } } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/LanguageTest.java Index: LanguageTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_LANGUAGE transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: LanguageTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class LanguageTest extends AbstractImageTranscoderTest { /** * Constructs a new <tt>LanguageTest</tt>. */ /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The preferred language. */ protected String language; /** * Constructs a new <tt>LanguageTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param language the preferred language */ public LanguageTest(String inputURI, String refImageURI, String language) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.language = language; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(7); hints.put(ImageTranscoder.KEY_LANGUAGE, language); return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/MediaTest.java Index: MediaTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_MEDIA transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: MediaTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class MediaTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The CSS media to use. */ protected String media; /** * Constructs a new <tt>MediaTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param media the CSS media */ public MediaTest(String inputURI, String refImageURI, String media) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.media = media; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(3); hints.put(ImageTranscoder.KEY_MEDIA, media); return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/Messages.java Index: Messages.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.util.Locale; import java.util.MissingResourceException; import org.apache.batik.i18n.Localizable; import org.apache.batik.i18n.LocalizableSupport; /** * This class manages the message for the test.svg module. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: Messages.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class Messages { /** * This class does not need to be instantiated. */ protected Messages() { } /** * The error messages bundle class name. */ protected final static String RESOURCES = "org.apache.batik.transcoder.image.resources.TestMessages"; /** * The localizable support for the error messages. */ protected static LocalizableSupport localizableSupport = new LocalizableSupport(RESOURCES); /** * Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}. */ public static void setLocale(Locale l) { localizableSupport.setLocale(l); } /** * Implements {@link org.apache.batik.i18n.Localizable#getLocale()}. */ public static Locale getLocale() { return localizableSupport.getLocale(); } /** * Implements {@link * org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}. */ public static String formatMessage(String key, Object[] args) throws MissingResourceException { return localizableSupport.formatMessage(key, args); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/ParametrizedDOMTest.java Index: ParametrizedDOMTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; import org.w3c.dom.Document; /** * Test the ImageTranscoder input with a DOM tree. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: ParametrizedDOMTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class ParametrizedDOMTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** * Constructs a new <tt>ParametrizedDOMTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image */ public ParametrizedDOMTest(String inputURI, String refImageURI) { this.inputURI = inputURI; this.refImageURI = refImageURI; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { try { String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); Document doc = f.createDocument(resolveURL(inputURI).toString()); return new TranscoderInput(doc); } catch (IOException ex) { throw new IllegalArgumentException(inputURI); } } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/PixelToMMTest.java Index: PixelToMMTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_PIXEL_TO_MM transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: PixelToMMTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class PixelToMMTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The pixel to mm factor. */ protected Float px2mm; /** * Constructs a new <tt>PixelToMMTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param px2mm the pixel to mm conversion factor */ public PixelToMMTest(String inputURI, String refImageURI, Float px2mm) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.px2mm = px2mm; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(3); hints.put(ImageTranscoder.KEY_PIXEL_TO_MM, px2mm); return hints; } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/ReaderTest.java Index: ReaderTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder input with a Reader. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: ReaderTest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class ReaderTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** * Constructs a new <tt>ReaderTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image */ public ReaderTest(String inputURI, String refImageURI) { this.inputURI = inputURI; this.refImageURI = refImageURI; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { try { URL url = resolveURL(inputURI); Reader reader = new InputStreamReader(url.openStream()); TranscoderInput input = new TranscoderInput(reader); input.setURI(url.toString()); // Needed for external resources return input; } catch (IOException ex) { throw new IllegalArgumentException(inputURI); } } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/URITest.java Index: URITest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder input with a URI. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: URITest.java,v 1.1 2001/10/30 14:19:07 tkormann Exp $ */ public class URITest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** * Constructs a new <tt>URITest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image */ public URITest(String inputURI, String refImageURI) { this.inputURI = inputURI; this.refImageURI = refImageURI; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Returns the reference image for this test. */ protected BufferedImage getReferenceImage() { return createBufferedImage(resolveURL(refImageURI)); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]