Class ToSVGAbstractTranscoder

All Implemented Interfaces:
XMLConstants, Transcoder, CSSConstants, SVGConstants
Direct Known Subclasses:
WMFTranscoder

public abstract class ToSVGAbstractTranscoder extends AbstractTranscoder implements SVGConstants
This class allows to simplify the creation of a transcoder which transcodes to SVG content. To use this class, you just have to implement the transcode method of the AbstractTranscoder class : first get the associated Document from the TranscoderOutput : createDocument(TranscoderOutput), then create a new SVGGraphics2D with this Document
    Document doc = this.createDocument(output);
    svgGenerator = new SVGGraphics2D(doc);
  
Perform the effective transcoding, using the SVGGraphics2D previously created then call the writeSVGToOutput(SVGGraphics2D, Element, TranscoderOutput) to create the effective output file (if the output is set to be a File or URI)
    Element svgRoot = svgGenerator.getRoot();
    writeSVGToOutput(svgGenerator, svgRoot, output);
  

Several transcoding hints are defined for this abstract transcoder, but no default implementation is provided. Subclasses must implement which keys are relevant to them :

  • KEY_INPUT_WIDTH, KEY_INPUT_HEIGHT, KEY_XOFFSET, KEY_YOFFSET : this Integer keys allows to set the portion of the image to transcode, defined by the width, height, and offset of this portion in Metafile units.
  • KEY_ESCAPED : this Boolean ley allow to escape XML characters in the output
     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_INPUT_WIDTH, Integer.valueOf(input_width));
  
KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output:
     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_WIDTH, Float.valueOf(width));
  
Version:
$Id: ToSVGAbstractTranscoder.java 1831630 2018-05-15 12:56:55Z ssteiner $
  • Field Details

  • Constructor Details

    • ToSVGAbstractTranscoder

      public ToSVGAbstractTranscoder()
  • Method Details

    • createDocument

      protected Document createDocument(TranscoderOutput output)
      Create an empty Document from a TranscoderOutput.
      • If the TranscoderOutput already contains an empty Document : returns this Document
      • else create a new empty DOM Document
    • getGraphics2D

      public SVGGraphics2D getGraphics2D()
      Get the SVGGraphics2D associated with this transcoder.
    • writeSVGToOutput

      protected void writeSVGToOutput(SVGGraphics2D svgGenerator, Element svgRoot, TranscoderOutput output) throws TranscoderException
      Writes the SVG content held by the svgGenerator to the TranscoderOutput. This method does nothing if the output already contains a Document.
      Throws:
      TranscoderException