xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maxber...@apache.org
Subject svn commit: r695776 - in /xmlgraphics/fop/trunk: lib/ src/java/org/apache/fop/image/loader/batik/ test/java/org/apache/fop/ test/java/org/apache/fop/image/loader/batik/
Date Tue, 16 Sep 2008 08:56:12 GMT
Author: maxberger
Date: Tue Sep 16 01:56:12 2008
New Revision: 695776

URL: http://svn.apache.org/viewvc?rev=695776&view=rev
Log:
Re-enabled image loader testcases
Made sure SVG converters use SVG flavor (updated in commons)
Added new ImageLoaderTest which tests JPGs embedded in SVG

Modified:
    xmlgraphics/fop/trunk/lib/xmlgraphics-commons-1.4svn.jar
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java

Modified: xmlgraphics/fop/trunk/lib/xmlgraphics-commons-1.4svn.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/lib/xmlgraphics-commons-1.4svn.jar?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
Binary files - no diff available.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageConverterSVG2G2D.java
Tue Sep 16 01:56:12 2008
@@ -32,19 +32,18 @@
 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.
  * <p>
@@ -132,7 +131,7 @@
 
     /** {@inheritDoc} */
     public ImageFlavor getSourceFlavor() {
-        return ImageFlavor.XML_DOM;
+        return XMLNamespaceEnabledImageFlavor.SVG_DOM;
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderFactorySVG.java
Tue Sep 16 01:56:12 2008
@@ -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 @@
 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};

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java Tue
Sep 16 01:56:12 2008
@@ -23,12 +23,12 @@
 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 @@
      * @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;

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java Tue Sep 16 01:56:12
2008
@@ -23,6 +23,8 @@
 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 @@
         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;
     }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java?rev=695776&r1=695775&r2=695776&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java
(original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/image/loader/batik/ImageLoaderTestCase.java
Tue Sep 16 01:56:12 2008
@@ -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 @@
         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 @@
         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 @@
         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);
+    }
+
+
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message