1 18 package org.apache.batik.svggen; 19 20 import java.awt.Image ; 21 import java.awt.image.RenderedImage ; 22 import java.awt.image.renderable.RenderableImage ; 23 24 import org.w3c.dom.Element ; 25 26 35 public class DefaultImageHandler implements ImageHandler, ErrorConstants { 36 static final String XLINK_NAMESPACE_URI = 39 "http://www.w3.org/1999/xlink"; 40 41 44 public DefaultImageHandler() { 45 } 46 47 51 public void handleImage(Image image, Element imageElement, 52 SVGGeneratorContext generatorContext) { 53 imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, 57 "" + image.getWidth(null)); 58 imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE, 59 "" + image.getHeight(null)); 60 61 try { 65 handleHREF(image, imageElement, generatorContext); 66 } catch (SVGGraphics2DIOException e) { 67 try { 68 generatorContext.errorHandler.handleError(e); 69 } catch (SVGGraphics2DIOException io) { 70 throw new SVGGraphics2DRuntimeException(io); 73 } 74 } 75 } 76 77 81 public void handleImage(RenderedImage image, Element imageElement, 82 SVGGeneratorContext generatorContext) { 83 imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, 87 "" + image.getWidth()); 88 imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE, 89 "" + image.getHeight()); 90 91 try { 95 handleHREF(image, imageElement, generatorContext); 96 } catch (SVGGraphics2DIOException e) { 97 try { 98 generatorContext.errorHandler.handleError(e); 99 } catch (SVGGraphics2DIOException io) { 100 throw new SVGGraphics2DRuntimeException(io); 103 } 104 } 105 } 106 107 111 public void handleImage(RenderableImage image, Element imageElement, 112 SVGGeneratorContext generatorContext) { 113 imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, 117 "" + image.getWidth()); 118 imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE, 119 "" + image.getHeight()); 120 121 try { 125 handleHREF(image, imageElement, generatorContext); 126 } catch (SVGGraphics2DIOException e) { 127 try { 128 generatorContext.errorHandler.handleError(e); 129 } catch (SVGGraphics2DIOException io) { 130 throw new SVGGraphics2DRuntimeException(io); 133 } 134 } 135 } 136 137 141 protected void handleHREF(Image image, Element imageElement, 142 SVGGeneratorContext generatorContext) 143 throws SVGGraphics2DIOException { 144 imageElement.setAttributeNS(XLINK_NAMESPACE_URI, 146 ATTR_XLINK_HREF, image.toString()); 147 } 148 149 153 protected void handleHREF(RenderedImage image, Element imageElement, 154 SVGGeneratorContext generatorContext) 155 throws SVGGraphics2DIOException { 156 imageElement.setAttributeNS(XLINK_NAMESPACE_URI, 158 ATTR_XLINK_HREF, image.toString()); 159 } 160 161 165 protected void handleHREF(RenderableImage image, Element imageElement, 166 SVGGeneratorContext generatorContext) 167 throws SVGGraphics2DIOException { 168 imageElement.setAttributeNS(XLINK_NAMESPACE_URI, 170 ATTR_XLINK_HREF, image.toString()); 171 } 172 } 173 174 | Popular Tags |