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));
      
    • Constructor Detail

      • ToSVGAbstractTranscoder

        public ToSVGAbstractTranscoder()
    • Method Detail

      • createDocument

        protected org.w3c.dom.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
      • writeSVGToOutput

        protected void writeSVGToOutput​(SVGGraphics2D svgGenerator,
                                        org.w3c.dom.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