I want to set the
attributes 'width' and 'height' an the root-element of the DOM-tree that is
built by SVGGraphics2D before outputting it to a file. But this doeasn't work!
Can anybody help me please? This is my code:
DOMImplementation impl =
SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document document = impl.createDocument(svgNS, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
org.w3c.dom.Element svgRoot = svgGenerator.getRoot();
if(comp instanceof QbChart){
((QbChart)comp).draw(svgGenerator, comp, d.width, d.height);
} else {
if(comp instanceof ZOwnerDrawnChart) {
ZOwnerDrawnChart oChart = (ZOwnerDrawnChart)comp;
oChart.setStringCalculationGraphics(svgGenerator);
oChart.setSize(d.width, d.height);
oChart.containerResized();
}
boolean opaque = comp.isOpaque();
comp.setOpaque(true);
svgGenerator.setClip(new java.awt.Rectangle(0, 0, d.width, d.height));
comp.paint(svgGenerator);
comp.setOpaque(opaque);
}
try {
// set the width and height attribute on the root svg element
svgRoot.setAttributeNS(null, "width", "15cm");
svgRoot.setAttributeNS(null, "height", "10cm");
//
boolean useCSS = true;
Writer out = new OutputStreamWriter(oStream, "UTF-8");
svgGenerator.stream(out, useCSS);
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document document = impl.createDocument(svgNS, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
org.w3c.dom.Element svgRoot = svgGenerator.getRoot();
if(comp instanceof QbChart){
((QbChart)comp).draw(svgGenerator, comp, d.width, d.height);
} else {
if(comp instanceof ZOwnerDrawnChart) {
ZOwnerDrawnChart oChart = (ZOwnerDrawnChart)comp;
oChart.setStringCalculationGraphics(svgGenerator);
oChart.setSize(d.width, d.height);
oChart.containerResized();
}
boolean opaque = comp.isOpaque();
comp.setOpaque(true);
svgGenerator.setClip(new java.awt.Rectangle(0, 0, d.width, d.height));
comp.paint(svgGenerator);
comp.setOpaque(opaque);
}
try {
// set the width and height attribute on the root svg element
svgRoot.setAttributeNS(null, "width", "15cm");
svgRoot.setAttributeNS(null, "height", "10cm");
//
boolean useCSS = true;
Writer out = new OutputStreamWriter(oStream, "UTF-8");
svgGenerator.stream(out, useCSS);
} catch .....
