You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by DeWeese Thomas <th...@gmail.com> on 2012/10/06 16:11:52 UTC

Re: SVG which renders in 1.7 fails in 1.8pre

Hi Joel,
	I suspect that you are missing some of the SPI files in the jar file you are building from 1.8pre.
Do you have the files from resources/META-INF/services/* in your jar files?
These may not have been needed in 1.7 (since defaults were included).

	Thomas

On Oct 4, 2012, at 6:34 PM, Joel Uckelman <uc...@nomic.net> wrote:

> I'm investigating switching from Batik 1.7 to a nightly 1.8 build
> because 1.7 fails catastrophically when used with Java 7 to load SVG
> containing <image> elements which reference JPEGs. (This is apparently
> due to Batik 1.7 using com.sun.image.codec.jpeg.TruncatedFileException,
> which no longer exists in Java 7, so one ends up with a
> NoClassDefFoundError.) This is a growing problem for us because our
> users are starting to use Java 7 now.
> 
> I have some SVG files which reside in a JAR and are rendered to
> BufferedImages using a custom subclass of SVGAbstractTranscoder which
> I wrote (it's nearly the same as ImageTranscoder, except it doesn't
> write the image to a file). When I use the Batik 1.7 JARs, all SVG---
> both SVG containing <image> elements and SVG without <image> elements---
> renders correctly. When I use the Batik JARs built with the the 12-09-25
> 1.8pre source, SVG without <image> elements renders correctly, but
> rendering the SVG with <image> elements fails with an exception. (I've
> trimmed the bottom of the stack trace, as that's my code which is
> calling custom transcoder, so not relevant, as well as a ton of base64
> in the URI.)
> 
> org.apache.batik.bridge.BridgeException: jar:file:/home/uckelman/projects/VASSAL/mods/Here_I_Stand_2.3.vmod!/images/Ottoman_hand.svg:0
> The URI "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAAA0CAYA
> ...
> m/8Dgk9CDmp9DwIAAAAASUVORK5CYII= "
> on element <image> can't be opened because:
> URL data in unsupported format or corrupt
>  at org.apache.batik.bridge.UserAgentAdapter.getBrokenLinkDocument(Unknown Source)
>  at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(Unknown Source)
>  at org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(Unknown Source)
>  at org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(Unknown Source)
>  at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(Unknown Source)
>  at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
>  at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
>  at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
>  at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
>  at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
>  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
>  at VASSAL.tools.image.svg.SVGRenderer$Rasterizer.transcode(SVGRenderer.java:224)
>  at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
>  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
>  at VASSAL.tools.image.svg.SVGRenderer.render(SVGRenderer.java:133)
> 
> 
> I extracted the same SVG file above from the JAR and tried opening it
> using Squiggle from 1.8pre, and found that Squiggle was able to render
> it. I also tried the URI
> 
>  jar:file:/home/uckelman/projects/VASSAL/mods/Here_I_Stand_2.3.vmod!/images/Ottoman_hand.svg
> 
> with "Open Location", and Squiggle was able to render that, too. This
> makes it clear that the SVG file is fine and that 1.8pre can render it.
> 
> Can anyone tell me what changed between 1.7 and 1.8pre that could be
> causing the failure I'm seeing?
> 
> The code for my renderer is here:
> 
> http://vassalengine.svn.sourceforge.net/viewvc/vassalengine/VASSAL-src/trunk/src/VASSAL/tools/image/svg/SVGRenderer.java?view=markup&pathrev=8398
> 
> -- 
> J.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: SVG which renders in 1.7 fails in 1.8pre

Posted by Joel Uckelman <uc...@nomic.net>.
Thus spake DeWeese Thomas:
> Hi Joel,
> 	I suspect that you are missing some of the SPI files in the jar =
> file you are building from 1.8pre.
> Do you have the files from resources/META-INF/services/* in your jar =
> files?
> These may not have been needed in 1.7 (since defaults were included).
> 
> 	Thomas

In batik-codec.jar:

  META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter
  META-INF/services/org.apache.batik.ext.awt.image.spi.RegistryEntry

In batik-extension.jar:

  META-INF/services/org.apache.batik.bridge.BridgeExtension
  META-INF/services/org.apache.batik.dom.DomExtension

In batik-script.jar:

  META-INF/services/org.apache.batik.script.InterpreterFactory

So it looks like I have the resources files in JARs on my classpath
(except the resource file for Squiggle, which I assume is not necessary
for anything but Squiggle.)

I also have a short test case now which exhibits the problem for me:


import java.awt.image.BufferedImage;
import java.io.File;

import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.ImageTranscoder;

public class Test {
  private static class Rasterizer extends ImageTranscoder {
    public BufferedImage createImage(int w, int h) {
      return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    }

    public void writeImage(BufferedImage img, TranscoderOutput output) {
    }
  }

  public static void main(String[] args) throws Exception {
    final String uri = new File(args[0]).toURI().toString();
    final Rasterizer r = new Rasterizer();
    r.transcode(new TranscoderInput(uri), new TranscoderOutput());
  }
}

Here's the command line:

java -cp lib/batik-anim.jar:lib/batik-awt-util.jar:lib/batik-bridge.jar:lib/batik-codec.jar:lib/batik-css.jar:lib/batik-dom.jar:lib/batik-ext.jar:lib/batik-extension.jar:lib/batik-gui-util.jar:lib/batik-gvt.jar:lib/batik-parser.jar:lib/batik-rasterizer-ext.jar:lib/batik-script.jar:lib/batik-svg-dom.jar:lib/batik-svggen.jar:lib/batik-swing.jar:lib/batik-transcoder.jar:lib/batik-util.jar:lib/batik-xml.jar:lib/xerces_2_5_0.jar:lib/xml-apis.jar:lib/xml-apis-ext.jar:. Test tmp/images/Ottoman_hand.svg

Here's the exception:

org.apache.batik.bridge.BridgeException: file:/home/uckelman/projects/VASSAL/VASSAL-src/tmp/images/Ottoman_hand.svg:0
The URI "data:image/png;base64,iVBORw0KG
...
5Cc6 P3b8DhjQm/8Dgk9CDmp9DwIAAAAASUVORK5CYII= "
on element <image> can't be opened because:
URL data in unsupported format or corrupt
  at org.apache.batik.bridge.UserAgentAdapter.getBrokenLinkDocument(Unknown Source)
  at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(Unknown Source)
  at org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(Unknown Source)
  at org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(Unknown Source)
  at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(Unknown Source)
  at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
  at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
  at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
  at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
  at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
  at Test.main(Test.java:23)
Exception in thread "main" org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
file:/home/uckelman/projects/VASSAL/VASSAL-src/tmp/images/Ottoman_hand.svg:0
The URI "data:image/png;base64,iVBORw0KGgoAAAANSUhE
...
5Cc6 P3b8DhjQm/8Dgk9CDmp9DwIAAAAASUVORK5CYII= "
on element <image> can't be opened because:
URL data in unsupported format or corrupt
  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
  at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
  at Test.main(Test.java:23)

Here's the test SVG: