Commit 6c766fdf authored by Fabien Triolet's avatar Fabien Triolet
Browse files

transcoder parameter is used for coosing the type of Transcoder to use.

Available values for this parameter are TIFF, JPEG or PNG.
parent e2a19066
/*
* $Id: SVGSerializer.java,v 1.1 2003-04-09 13:51:41 triolet Exp $
* $Id: SVGSerializer.java,v 1.2 2003-04-10 14:52:46 triolet Exp $
*
* Transmorpher
*
......@@ -41,6 +41,8 @@ import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.transcoder.image.*;
import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
......@@ -54,48 +56,47 @@ import javax.xml.transform.dom.DOMResult;
*/
public final class SVGSerializer extends TSerializer {
/**
* The handler that receives SAX events
*/
protected SVGHandler handler = null;
protected SAXTransformerFactory tfactory = null;
public SVGSerializer(String[] pIn, Parameters pParam, StringParameters pStaticAttributes) throws TMRuntimeException {
super(pIn, pParam, pStaticAttributes);
handler = new SVGHandler(this);
}
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
}
public SVGSerializer(String[] pIn, Parameters pParam, StringParameters pStaticAttributes) throws TMRuntimeException {
super(pIn, pParam, pStaticAttributes);
handler = new SVGHandler(this);
}
public void setOutputStream() throws TMRuntimeException, TMException, SAXException {
super.setOutputStream();
}
public void notify(Document doc) throws SAXException{
try {
JPEGTranscoder t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(.8));
/* t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH,
new Float(10)); */
trans.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "print");
public void notify(Document doc) throws SAXException{
try {
String transcoderFormat=(String)getParameters().getParameter("transcoder");
if (transcoderFormat==null)
transcoderFormat="JPEG";
String transcoderName = "org.apache.batik.transcoder.image."+transcoderFormat+"Transcoder";
Class transcoderClass = Class.forName(transcoderName);
java.lang.reflect.Constructor[] transcoderConstructors = transcoderClass.getConstructors();
Transcoder t = (Transcoder)transcoderConstructors[0].newInstance(null);
t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "print");
TranscoderInput input = new TranscoderInput(doc);
TranscoderOutput output = new TranscoderOutput(getOutputStream());
t.transcode(input,output);
}
catch (Exception ex) {
throw new SAXException("Exception writing image ", ex);
}
}
protected SAXTransformerFactory getTransformerFactory() {
if (tfactory == null) {
tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
TranscoderInput input = new TranscoderInput(doc);
TranscoderOutput output = new TranscoderOutput(getOutputStream());
t.transcode(input,output);
}
return tfactory;
catch (Exception ex) {
throw new SAXException("Exception writing image ", ex);
}
}
public ContentHandler getContentHandler() {
return (ContentHandler)handler;
}
public ContentHandler getContentHandler() {
return (ContentHandler)handler;
}
}
class SVGHandler extends SAXSVGDocumentFactory{
......@@ -130,9 +131,6 @@ class SVGHandler extends SAXSVGDocumentFactory{
try {
super.endDocument();
// FIXME: Hack.
((org.apache.batik.dom.svg.SVGOMDocument)this.document).setURLObject(new java.net.URL("http://xml.apache.org"));
owner.notify(this.document);
} catch (Exception ex){
ex.printStackTrace();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment