Esempio n. 1
0
  /**
   * Transcodes the specified Document as an image in the specified output.
   *
   * @param document the document to transcode
   * @param uri the uri of the document or null if any
   * @param output the ouput where to transcode
   * @exception org.apache.batik.transcoder.TranscoderException if an error occurred while
   *     transcoding
   */
  protected void transcode(Document document, String uri, TranscoderOutput output)
      throws TranscoderException {

    if (!(document instanceof SVGOMDocument)) {
      throw new TranscoderException(Messages.formatMessage("notsvg", null));
    }

    BridgeContext ctx = new BridgeContext(userAgent);
    SVGOMDocument svgDoc = (SVGOMDocument) document;

    // build the GVT tree
    GraphicsNode gvtRoot = buildGVT(ctx, svgDoc);

    // get the 'width' and 'height' attributes of the SVG document
    width = (int) (ctx.getDocumentSize().getWidth() + 0.5);
    height = (int) (ctx.getDocumentSize().getHeight() + 0.5);

    SpriteGraphics2D swf2d = new SpriteGraphics2D(width, height);
    gvtRoot.paint(swf2d);
    tags = swf2d.getTags();

    // Override width and height based on the SWF-specific bounds of the sprite contents
    // However we have to correct co-ordinates back to pixels... TODO: Remove all TWIPS references!
    Rect bounds = swf2d.getBounds();
    width = (int) Math.rint((bounds.xMax - bounds.xMin) / 20.0);
    height = (int) Math.rint((bounds.yMax - bounds.yMin) / 20.0);
  }