Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-2489

An SVG file using markers is not rendered by FOP 2.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.2
    • None
    • None
    • Linux; Java 1.6 64-bit (not relevant).

    Description

      An SVG file using markers is not rendered by FOP 2.0

      How to reproduce the problem (see attached files)

      fop -fo __doc.fo -pdf __doc.pdf

      Running this command reports:

      SEVERE: SVG graphic could not be built. Reason: org.apache.batik.bridge.BridgeException: resources/resources/header_layout.svg (No such file or directory)
      org.apache.batik.bridge.BridgeException: resources/resources/header_layout.svg (No such file or directory)
              at org.apache.batik.bridge.BridgeContext.getReferencedNode(Unknown Source)
              at org.apache.batik.bridge.BridgeContext.getReferencedElement(Unknown Source)
              at org.apache.batik.bridge.PaintServer.convertMarker(Unknown Source)
              at org.apache.batik.bridge.PaintServer.convertMarkers(Unknown Source)
              at org.apache.batik.bridge.SVGDecoratedShapeElementBridge.createMarkerPainter(Unknown Source)
              at org.apache.batik.bridge.SVGDecoratedShapeElementBridge.createShapePainter(Unknown Source)
              at org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(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.buildGraphicsNode(Unknown Source)
              at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
              at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
              at org.apache.fop.render.pdf.PDFImageHandlerSVG.handleImage(PDFImageHandlerSVG.java:103)
              at org.apache.fop.render.intermediate.AbstractIFPainter.drawImage(AbstractIFPainter.java:249)
              at org.apache.fop.render.intermediate.AbstractIFPainter.drawImage(AbstractIFPainter.java:205)
              at org.apache.fop.render.intermediate.AbstractIFPainter.drawImageUsingImageHandler(AbstractIFPainter.java:170)
              at org.apache.fop.render.intermediate.AbstractIFPainter.drawImageUsingURI(AbstractIFPainter.java:292)
              at org.apache.fop.render.pdf.PDFPainter.drawImage(PDFPainter.java:173)
              at org.apache.fop.render.intermediate.IFRenderer.drawImage(IFRenderer.java:1295)
              at org.apache.fop.render.intermediate.IFRenderer.renderImage(IFRenderer.java:1282)
              at org.apache.fop.render.AbstractRenderer.renderInlineViewport(AbstractRenderer.java:858)
      

      The expected result is EXPECTED__doc.pdf

      My workaround:

      To resolve URLs such as "marker-start:url(#TriangleInM)", Batik 1.8 needs
      to know the URL of the SVG document it processes.

      Therefore in org/apache/fop/apps/FOUserAgent.java, I've replaced:

          public StreamSource resolveURI(String uri) {
              // TODO: What do we want to do when resources aren't found??? We also need to remove this
              // method entirely
              try {
                  // Have to do this so we can resolve data URIs
                  StreamSource src = new StreamSource(resourceResolver.getResource(uri));
                  src.setSystemId(uri);
                  return src;
              } catch (URISyntaxException use) {
                  return null;
              } catch (IOException ioe) {
                  return null;
              }
          }
      

      by:

          public StreamSource resolveURI(String uri) {
              // TODO: What do we want to do when resources aren't found??? We also need to remove this
              // method entirely
              try {
                  // Have to do this so we can resolve data URIs
                  StreamSource src = new StreamSource(resourceResolver.getResource(uri));
      
                  // A systemId is always expected to be absolute.
                  // Anyway, without this, SVG files using markers 
                  // (e.g. marker-start:url(#TriangleInM)) cannot be rendered.
      
                  if (!uri.startsWith("data:")) {
                      uri = resourceResolver.getBaseURI().resolve(uri).toASCIIString();
                  }
      
                  src.setSystemId(uri);
                  return src;
              } catch (URISyntaxException use) {
                  return null;
              } catch (IOException ioe) {
                  return null;
              }
          }
      

      Attachments

        1. __doc.fo
          29 kB
          Hussein Shafie
        2. header_layout.svg
          12 kB
          Hussein Shafie
        3. __doc.pdf
          6 kB
          Hussein Shafie
        4. EXPECTED__doc.pdf
          10 kB
          Hussein Shafie

        Issue Links

          Activity

            People

              Unassigned Unassigned
              h_shafie Hussein Shafie
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: