From: Maximilian Berger Date: Tue, 16 Sep 2008 08:56:12 +0000 (+0000) Subject: Re-enabled image loader testcases X-Git-Tag: fop-1_0~415 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=937b5b3d50ada4cb2f9607810914adb7888fe9ab;p=xmlgraphics-fop.git Re-enabled image loader testcases Made sure SVG converters use SVG flavor (updated in commons) Added new ImageLoaderTest which tests JPGs embedded in SVG git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@695776 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/xmlgraphics-commons-1.4svn.jar b/lib/xmlgraphics-commons-1.4svn.jar index 6d8181de8..7328fa62b 100644 Binary files a/lib/xmlgraphics-commons-1.4svn.jar and b/lib/xmlgraphics-commons-1.4svn.jar differ diff --git a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java index 6c43e4878..9ea333af0 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java @@ -32,19 +32,18 @@ import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.gvt.GraphicsNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import org.apache.fop.svg.SimpleSVGUserAgent; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageProcessingHints; +import org.apache.xmlgraphics.image.loader.XMLNamespaceEnabledImageFlavor; import org.apache.xmlgraphics.image.loader.impl.AbstractImageConverter; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; import org.apache.xmlgraphics.util.UnitConv; -import org.apache.fop.svg.SimpleSVGUserAgent; - /** * This ImageConverter converts SVG images to Java2D. *

@@ -132,7 +131,7 @@ public class ImageConverterSVG2G2D extends AbstractImageConverter { /** {@inheritDoc} */ public ImageFlavor getSourceFlavor() { - return ImageFlavor.XML_DOM; + return XMLNamespaceEnabledImageFlavor.SVG_DOM; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java b/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java index 9203bf7e8..b37ba925b 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java @@ -20,6 +20,7 @@ package org.apache.fop.image.loader.batik; import org.apache.xmlgraphics.image.loader.ImageFlavor; +import org.apache.xmlgraphics.image.loader.XMLNamespaceEnabledImageFlavor; import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoaderFactory; import org.apache.xmlgraphics.image.loader.spi.ImageLoader; import org.apache.xmlgraphics.util.MimeConstants; @@ -30,7 +31,7 @@ import org.apache.xmlgraphics.util.MimeConstants; public class ImageLoaderFactorySVG extends AbstractImageLoaderFactory { private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { - ImageFlavor.XML_DOM}; + XMLNamespaceEnabledImageFlavor.SVG_DOM}; private static final String[] MIMES = new String[] { MimeConstants.MIME_SVG}; diff --git a/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java b/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java index 483d6c502..c5c113b04 100644 --- a/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java +++ b/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java @@ -23,12 +23,12 @@ import java.io.IOException; import java.util.Map; import org.apache.batik.dom.svg.SVGDOMImplementation; - import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.ImageSessionContext; +import org.apache.xmlgraphics.image.loader.XMLNamespaceEnabledImageFlavor; import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoader; import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.util.MimeConstants; @@ -45,7 +45,7 @@ public class ImageLoaderSVG extends AbstractImageLoader { * @param targetFlavor the target flavor */ public ImageLoaderSVG(ImageFlavor targetFlavor) { - if (!(ImageFlavor.XML_DOM.equals(targetFlavor))) { + if (!(XMLNamespaceEnabledImageFlavor.SVG_DOM.equals(targetFlavor))) { throw new IllegalArgumentException("Unsupported target ImageFlavor: " + targetFlavor); } this.targetFlavor = targetFlavor; diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index c20683912..290b29050 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -23,6 +23,8 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.apache.fop.fonts.TrueTypeAnsiTestCase; +import org.apache.fop.image.loader.batik.ImageLoaderTestCase; +import org.apache.fop.image.loader.batik.ImagePreloaderTestCase; import org.apache.fop.render.pdf.PDFAConformanceTestCase; import org.apache.fop.render.pdf.PDFCMapTestCase; import org.apache.fop.render.pdf.PDFEncodingTestCase; @@ -50,6 +52,8 @@ public class StandardTestSuite { suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class)); suite.addTest(new TestSuite(TrueTypeAnsiTestCase.class)); suite.addTest(RichTextFormatTestSuite.suite()); + suite.addTest(new TestSuite(ImageLoaderTestCase.class)); + suite.addTest(new TestSuite(ImagePreloaderTestCase.class)); //$JUnit-END$ return suite; } diff --git a/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java b/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java index 457aa91d4..97bfb4d5c 100644 --- a/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java +++ b/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java @@ -19,21 +19,23 @@ package org.apache.fop.image.loader.batik; +import java.awt.image.Raster; +import java.awt.image.RenderedImage; import java.io.File; import junit.framework.TestCase; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.ImageManager; +import org.apache.xmlgraphics.image.loader.XMLNamespaceEnabledImageFlavor; import org.apache.xmlgraphics.image.loader.impl.ImageRendered; import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.image.writer.ImageWriterUtil; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.FopFactory; - /** * Tests for bundled ImageLoader implementations. */ @@ -59,10 +61,10 @@ public class ImageLoaderTestCase extends TestCase { ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext()); assertNotNull("ImageInfo must not be null", info); - Image img = manager.getImage(info, ImageFlavor.XML_DOM, + Image img = manager.getImage(info, XMLNamespaceEnabledImageFlavor.SVG_DOM, userAgent.getImageSessionContext()); assertNotNull("Image must not be null", img); - assertEquals(ImageFlavor.XML_DOM, img.getFlavor()); + assertEquals(XMLNamespaceEnabledImageFlavor.SVG_DOM, img.getFlavor()); ImageXMLDOM imgDom = (ImageXMLDOM)img; assertNotNull(imgDom.getDocument()); assertEquals("http://www.w3.org/2000/svg", imgDom.getRootNamespace()); @@ -101,10 +103,10 @@ public class ImageLoaderTestCase extends TestCase { ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext()); assertNotNull("ImageInfo must not be null", info); - Image img = manager.getImage(info, ImageFlavor.XML_DOM, + Image img = manager.getImage(info, XMLNamespaceEnabledImageFlavor.SVG_DOM, userAgent.getImageSessionContext()); assertNotNull("Image must not be null", img); - assertEquals(ImageFlavor.XML_DOM, img.getFlavor()); + assertEquals(XMLNamespaceEnabledImageFlavor.SVG_DOM, img.getFlavor()); ImageXMLDOM imgDom = (ImageXMLDOM)img; assertNotNull(imgDom.getDocument()); assertEquals("http://www.w3.org/2000/svg", imgDom.getRootNamespace()); @@ -160,4 +162,58 @@ public class ImageLoaderTestCase extends TestCase { assertEquals(612000, info.getSize().getHeightMpt()); } + public void testSVGWithReferences() throws Exception { + String uri = "test/resources/fop/svg/images.svg"; + FopFactory ff = FopFactory.newInstance(); + FOUserAgent userAgent = ff.newFOUserAgent(); + + ImageManager manager = ff.getImageManager(); + ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext()); + assertNotNull("ImageInfo must not be null", info); + + Image img = manager.getImage(info, XMLNamespaceEnabledImageFlavor.SVG_DOM, + userAgent.getImageSessionContext()); + assertNotNull("Image must not be null", img); + assertEquals(XMLNamespaceEnabledImageFlavor.SVG_DOM, img.getFlavor()); + ImageXMLDOM imgDom = (ImageXMLDOM)img; + assertNotNull(imgDom.getDocument()); + assertEquals("http://www.w3.org/2000/svg", imgDom.getRootNamespace()); + info = imgDom.getInfo(); //Switch to the ImageInfo returned by the image + assertEquals(400000, info.getSize().getWidthMpt()); + assertEquals(400000, info.getSize().getHeightMpt()); + assertEquals(400, info.getSize().getWidthPx()); + assertEquals(400, info.getSize().getHeightPx()); + + img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE, + userAgent.getImageSessionContext()); + assertNotNull("Image must not be null", img); + assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor()); + ImageRendered imgRed = (ImageRendered)img; + RenderedImage renImg = imgRed.getRenderedImage(); + assertNotNull(renImg); + if (DEBUG_TARGET_DIR != null) { + ImageWriterUtil.saveAsPNG(renImg, + (int)userAgent.getTargetResolution(), + new File(DEBUG_TARGET_DIR, "images.svg.png")); + } + assertEquals(400, renImg.getWidth()); + assertEquals(400, renImg.getHeight()); + info = imgRed.getInfo(); //Switch to the ImageInfo returned by the image + assertEquals(400000, info.getSize().getWidthMpt()); + assertEquals(400000, info.getSize().getHeightMpt()); + Raster raster = renImg.getData(); + // This pixel is white + int[] pixel1 = raster.getPixel(1, 1, (int[] )null); + // This pixel is from the embedded JPG and is not white + int[] pixel80 = raster.getPixel(80, 80, (int[]) null); + assertEquals(pixel1.length, pixel80.length); + boolean same = true; + for (int i = 0; i < pixel1.length; i++) { + same &= (pixel1[i] == pixel80[i]); + } + assertFalse("Embedding JPG into SVG failed", same); + } + + + }