diff options
author | Keiron Liddle <keiron@apache.org> | 2001-09-24 07:31:52 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-09-24 07:31:52 +0000 |
commit | c035335895585f1aceb6ce01d05659d954c658b9 (patch) | |
tree | 337b1d7c10fdd3dd6ec7a9ef10c88e5645d5ae80 /src/org/apache/fop/image | |
parent | cbf1038a5ff8000c0a00ca33bed49c4b7d8c77e5 (diff) | |
download | xmlgraphics-fop-c035335895585f1aceb6ce01d05659d954c658b9.tar.gz xmlgraphics-fop-c035335895585f1aceb6ce01d05659d954c658b9.zip |
updated use of batik to changed api
from cvs batik 23/9/2001
improved the user agent
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194478 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/image')
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 159 |
1 files changed, 149 insertions, 10 deletions
diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index d2f60a1af..1b3801470 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -23,12 +23,36 @@ import org.xml.sax.XMLReader; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.dom.svg.*; +import org.w3c.dom.*; +import org.w3c.dom.svg.*; +import org.w3c.dom.svg.SVGLength; +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; + +import org.w3c.dom.DOMImplementation; +import org.apache.batik.dom.svg.SVGDOMImplementation; + +import java.io.File; +import java.net.URL; +import java.util.List; +import java.util.ArrayList; +import java.awt.geom.AffineTransform; +import java.awt.Point; +import java.awt.geom.Dimension2D; +import java.awt.Dimension; + /** * ImageReader object for SVG document image type. */ public class SVGReader extends AbstractImageReader { - public boolean verifySignature(String uri, BufferedInputStream fis) - throws IOException { + public boolean verifySignature(String uri, + BufferedInputStream fis) throws IOException { this.imageStream = fis; return loadImage(uri); } @@ -45,24 +69,139 @@ public class SVGReader extends AbstractImageReader { // parse document and get the size attributes of the svg element try { SAXSVGDocumentFactory factory = - new SAXSVGDocumentFactory(SVGImage.getParserName()); + new SAXSVGDocumentFactory(SVGImage.getParserName()); SVGDocument doc = factory.createDocument(uri, imageStream); - // should check the stream contains text data - SVGSVGElement svg = doc.getRootElement(); - this.width = (int)svg.getWidth().getBaseVal().getValue(); - this.height = (int)svg.getHeight().getBaseVal().getValue(); + + // this is ugly preprocessing to get the width and height + UserAgent userAgent = new MUserAgent(new AffineTransform()); + GVTBuilder builder = new GVTBuilder(); + BridgeContext ctx = new BridgeContext(userAgent); + GraphicsNode root; + root = builder.build(ctx, doc); + // get the 'width' and 'height' attributes of the SVG document + width = (int) ctx.getDocumentSize().getWidth(); + height = (int) ctx.getDocumentSize().getHeight(); + ctx = null; + builder = null; + /////// + return true; } catch (NoClassDefFoundError ncdfe) { MessageHandler.errorln("Batik not in class path"); return false; - } catch (Exception e) { - MessageHandler.errorln("Could not load external SVG: " - + e.getMessage()); + } + catch (Exception e) { + MessageHandler.errorln("Could not load external SVG: " + + e.getMessage()); // assuming any exception means this document is not svg // or could not be loaded for some reason return false; } } + protected class MUserAgent implements UserAgent { + AffineTransform currentTransform = null; + + /** + * Creates a new SVGUserAgent. + */ + protected MUserAgent(AffineTransform at) { + currentTransform = at; + } + + /** + * Displays an error message. + */ + public void displayError(String message) { + System.err.println(message); + } + + /** + * Displays an error resulting from the specified Exception. + */ + public void displayError(Exception ex) { + ex.printStackTrace(System.err); + } + + /** + * Displays a message in the User Agent interface. + * The given message is typically displayed in a status bar. + */ + public void displayMessage(String message) { + System.out.println(message); + } + + /** + * Returns a customized the pixel to mm factor. + */ + public float getPixelToMM() { + // this is set to 72dpi as the values in fo are 72dpi + return 0.35277777777777777778f; // 72 dpi + // return 0.26458333333333333333333333333333f; // 96dpi + } + + /** + * Returns the language settings. + */ + public String getLanguages() { + return "en"; // userLanguages; + } + + /** + * Returns the user stylesheet uri. + * @return null if no user style sheet was specified. + */ + public String getUserStyleSheetURI() { + return null; // userStyleSheetURI; + } + + /** + * Returns the class name of the XML parser. + */ + public String getXMLParserClassName() { + return org.apache.fop.apps.Driver.getParserClassName(); + } + + /** + * Opens a link in a new component. + * @param doc The current document. + * @param uri The document URI. + */ + public void openLink(SVGAElement elt) { + } + + public Point getClientAreaLocationOnScreen() { + return new Point(0, 0); + } + + public void setSVGCursor(java.awt.Cursor cursor) {} + + + public AffineTransform getTransform() { + return currentTransform; + } + + public Dimension2D getViewportSize() { + return new Dimension(100, 100); + } + + public EventDispatcher getEventDispatcher() { + return null; + } + + public boolean supportExtension(String str) { + return false; + } + + public boolean hasFeature(String str) { + return false; + } + + public void registerExtension(BridgeExtension be) {} + + public void handleElement(Element elt, Object data) {} + + } + } |