How do I get SVGGraphics2D to prepend "svg:" to all of the SVG elements it creates?
Creating the factory document with the namespace doesn't do it and I can't seem to find any clues in the documentation or on the web.
Thanks Murray
P.S. Here is my code: (I'm using swing tables as a cheat in producing tables in SVG)
/// SVG Support import org.apache.batik.dom.GenericDOMImplementation; import org.apache.batik.svggen.SVGGraphics2D; import org.apache.batik.svggen.SVGGeneratorContext; import org.apache.batik.svggen.SVGGraphics2DIOException; import org.apache.batik.svggen.SwingSVGPrettyPrint; import org.w3c.dom.DOMImplementation; import java.awt.geom.Rectangle2D;
import javax.swing.JTable; import javax.swing.table.*; import java.awt.RenderingHints;
/**
*
* @author murray
*/
public class SvgTable
{ /** Creates a new instance of SvgTable */
public SvgTable()
{
} /**
* @param args the command line arguments
*/
public static void main(String[] args)
{
AbstractTableModel tableModel = new AbstractTableModel()
{
String[] columnNames =
{
"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"
}; Object[][] rowData = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
public String getColumnName(int col) { return columnNames[col].toString(); } public int getRowCount() { return rowData.length; } public int getColumnCount() { return columnNames.length; } public Object getValueAt(int row, int col) { return rowData[row][col]; } public boolean isCellEditable(int row, int col) { return false; } public void setValueAt(Object value, int row, int col) { rowData[row][col] = value; //fireTableCellUpdated(row, col); } };
JTable table = new JTable(tableModel);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
JTableHeader tableHeader = table.getTableHeader();
tableHeader.setSize(400, 20);
table.setSize(400, 280);
table.doLayout(); try
{
writeTableAsSvg(tableHeader,
table,
400, 300,
"C:/temp/MyTable.svg");
}
catch (SVGGraphics2DIOException e1)
{
System.out.println(e1);
}
catch (java.io.IOException e2)
{
System.out.println(e2);
}}
protected static void writeTableAsSvg(JTableHeader header,
JTable table,
int width,
int height,
String strFile)
throws SVGGraphics2DIOException
{
// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
org.w3c.dom.Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg:svg", null);
/// Create an SVG Context to customise
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);java.awt.Dimension size = new java.awt.Dimension(width, height);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
svgGenerator.setSVGCanvasSize(size); svgGenerator.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
svgGenerator.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); SwingSVGPrettyPrint.print(header, svgGenerator);
svgGenerator.translate(0, 20);
SwingSVGPrettyPrint.print(table, svgGenerator);svgGenerator.stream(strFile, false);
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
