I've looked at the code fairly closely and I can't see why this would happen. The only real difference I see is that I think width/height get set twice.
That must have something to do with it...
I suppose this is likely not a Batik bug... I'm using xalan 2.6.0 and xerces 2.6.2.
Does this mean that you are using the Xerces DOM Implementation as well? I suppose it's possible that there is a bug where setting an attribute twice with a null namespace does this in their DOM implementation.
I'm not sure what DOM implementation I'm using, I'm just using the javax.xml APIs on JDK 1.4.2 (see attachment).
I tried to create a simple test case that reproduces this bug but of course when I did that it didn't happen. Will keep trying.
Of course ;) Please let us know if you succeed (a Bug report in any case might be useful, but especially if there is a reproducible test case).
I am determined to track this down today :-) In any case, attached is my test program, which doesn't yet demonstrate the bug, but does show basically how I'm doing things.
Thanks, -Archie
__________________________________________________________________________ Archie Cobbs * CTO, Awarix * http://www.awarix.com
import java.awt.Color; import java.awt.Image; import java.awt.Toolkit; import java.awt.geom.AffineTransform; import java.io.ByteArrayOutputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.util.XMLConstants;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class ImportBug implements XMLConstants, SVGConstants {
public static final String SVG_PUBLIC_ID
= "-//W3C//DTD SVG 1.1//EN";
public static final String SVG_DTD
= "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";
public static final String SVG_MEDIA_TYPE = "image/svg+xml";
protected static DOMImplementation getDOMImplementation() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setIgnoringComments(false);
try {
return dbf.newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException e) {
throw new Exception("Can't create XML document builder", e);
}
}
protected static Document createDocument() throws Exception {
DOMImplementation di = getDOMImplementation();
Document doc = di.createDocument(SVG_NAMESPACE_URI, "svg",
di.createDocumentType("svg", SVG_PUBLIC_ID, SVG_DTD));
doc.getDocumentElement().setAttributeNS(XMLNS_NAMESPACE_URI,
XMLNS_PREFIX, SVG_NAMESPACE_URI);
doc.getDocumentElement().setAttributeNS(XMLNS_NAMESPACE_URI,
XMLNS_PREFIX + ":" + XLINK_PREFIX, XLINK_NAMESPACE_URI);
return doc;
}
protected static Transformer getTransformer() throws Exception {
Transformer transformer;
try {
transformer = TransformerFactory.newInstance().newTransformer();
} catch (TransformerConfigurationException e) {
throw new Exception("can't create XML transformer", e);
}
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, SVG_MEDIA_TYPE);
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
return transformer;
}
public static void main(String[] args) throws Exception {
// Create document
Document doc = createDocument();
// Build document
createDoc(doc);
// Output document
getTransformer().transform(new DOMSource(doc),
new StreamResult(new BufferedOutputStream(System.out)));
}
private static void createDoc(Document doc) throws Exception {
// Get root <svg> element
Element root = doc.getDocumentElement();
root = addElement(root, "g");
// Add a <svg> child
Element svg = addElement(root, "svg");
svg.setAttribute("viewBox", "0 0 200 200");
svg.setAttribute("overflow", "visible");
// Create a Graphics2D -> SVG transcoder
SVGGraphics2D g2d = new SVGGraphics2D(svg.getOwnerDocument());
// Render image, converting it to SVG
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, 100, 100);
g2d.drawImage(getImage(), 20, 20, 60, 60, null);
// Get resulting SVG
svg = g2d.getRoot(svg);
// Set up viewbox
svg.setAttribute("width", "200");
svg.setAttribute("height", "200");
// Discard converter
// g2d.dispose();
}
private static Element addElement(Element parent, String name) {
Element elem = parent.getOwnerDocument().createElementNS(
SVG_NAMESPACE_URI, name);
parent.appendChild(elem);
return elem;
}
private static Image getImage() throws Exception {
return new javax.swing.ImageIcon("jc.png").getImage();
}
}
<<inline: jc.png>>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
