I had the same problem.

I also noticed something that I think explains why your originial code
solution does not work.  I don't think that
>     Element svgRoot = doc.getDocumentElement();
is what you want to modify.  If you instead use
g.getRoot(), then this returns the svg node element that you want,
doc.getDocumentElement() does not seem to return the svg node.

I also noticed the "hanging" problem that you mentioned.  My solution was to
get the root element using getRoot() and then writing it out using Xerces,
rather than using the .stream() operation.


-Tom

----- Original Message -----
From: "Dinkar Ganti" <[EMAIL PROTECTED]>
To: "Batik Users" <[EMAIL PROTECTED]>
Sent: Thursday, August 16, 2001 9:18 AM
Subject: RE: trouble setting attributes with SVGGraphics2D


> Hi,
>
> I had a similar problem. The fix is a very simple line:
>
>     SVGGraphics2D g = new SVGGraphics2D(doc);
>     g.setSVGCanvasSize(new Dimension(width,height));
>
> Hope this helps.
>
> Thanks
>
> Dinkar
> -----Original Message-----
> From: armhold [mailto:armhold]On Behalf Of George Armhold
> Sent: Thursday, August 16, 2001 11:11 AM
> To: [EMAIL PROTECTED]
> Subject: trouble setting attributes with SVGGraphics2D
>
>
> Hello,
>
> I'm having trouble setting width and height attributes while using
> SVGGraphics2D.  It seems that the default width and height get set to
> "2147483647" when using SVGGraphics2D.  When I try to set these
> attributes by manipulating the DOM I get strange results.  In the
> following code, I attempt to set the attributes by hand.  However when
> run (with Batik 1.0, JDK 1.3.0, RedHat Linux 7.1) my changes never
> appear in the resulting XML output.
>
>
>
> import java.io.*;
> import java.awt.*;
> import org.apache.batik.svggen.SVGGraphics2D;
> import org.apache.batik.dom.svg.SVGDOMImplementation;
> import org.w3c.dom.DOMImplementation;
> import org.w3c.dom.*;
>
> public class SVGTest {
>
>   public static void main(String[] args) {
>     DOMImplementation impl =
> SVGDOMImplementation.getDOMImplementation();
>     String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>     Document doc = impl.createDocument(svgNS, "svg", null);
>
>     // get the root element (the svg element)
>     Element svgRoot = doc.getDocumentElement();
>
>     // set the width and height attribute on the root svg element
>     svgRoot.setAttributeNS(svgNS, "width", "1024");
>     svgRoot.setAttributeNS(svgNS, "height", "768");
>
>
>     // Create an instance of the SVG Generator
>     SVGGraphics2D g = new SVGGraphics2D(doc);
>
>     // set background to white
>     g.setColor(Color.white);
>     g.fill(new Rectangle(0, 0, 1024, 768));
>     g.setColor(Color.red);
>     g.fill(new Rectangle(100, 100, 100, 100));
>
>     try {
>       FileWriter writer = new FileWriter(new File("svgtest.xml"));
>       g.stream(writer, false);
>       writer.flush();
>       writer.close();
>     } catch (IOException e) {
>       System.err.println(e.getMessage());
>       System.exit(1);
>     }
>
>     System.exit(0);
>   }
>
> }
>
>
> Also, I notice that I need to explicitly call System.exit(), else my
> main never exits... are there lingering threads in the batik code?
>
> Thanks for your help.
>
> PS: I'd like to say thanks to all the Batik developers; this is a
> great package!  I've been meaning to send a "thank you" email to you
> guys ever since the JavaOne talk back in June.  Great job!
>
>
>
> --
> George Armhold
> Rutgers University
> Bioinformatics Initiative
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to