xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Newbie question
Date Sun, 11 Jun 2006 19:39:52 GMT
Hi Baris

Baris YILMAZ <baris_999@yahoo.com> wrote on 06/11/2006 02:49:34 PM:

> I am a newbie in Batik and try to generate a simple svg file as below. 
But 
> somehow, my rectange is not appended to my svg file. Can anyone tell me 
why?

    Because the SVGGraphics2D.stream method writes what you have drawn to
the SVGGraphics2D.  Not the Document you give it as a factory.

> Moreover, I am trying to find a tutorial on Batik. Except whose in the 
> homepage I can't find anything. The ones in the homepage, are very 
> bad written and simple...

   Uhh, thanks...

> I'll appreciate your help..

   Perhaps I could help if you could describe what you want to do, I
could help.

   If you just want to serialize a DOM there is no reason to bring
in the SVGGraphics2D (in fact there is no reason to use Batik).
Batik happens to provide a simple XML serializer:

   org.apache.batik.dom.util.DOMUtilities.writeDocument(Document, Writer);

> public class SVGNeu {
> 
>     public static void main(String[] args) throws IOException {
>         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(null, "width", "400");
>         svgRoot.setAttributeNS(null, "height", "450");
> 
> //         create the rectangle
>         Element rectangle = doc.createElementNS(svgNS, "rect");
>         rectangle.setAttributeNS(null, "x", "10");
>         rectangle.setAttributeNS(null, "y", "20");
>         rectangle.setAttributeNS(null, "width", "100");
>         rectangle.setAttributeNS(null, "height", "50");
>         rectangle.setAttributeNS(null, "style", "fill:red");
> 
> //         attach the rectangle to the svg root element
>         svgRoot.appendChild(rectangle);
> 
>         SVGGeneratorContext ctx = 
SVGGeneratorContext.createDefault(doc);
>         ctx.setComment("Generated by FooApplication with Batik SVG 
Generator");
>         SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
> 
>         // Finally, stream out SVG to the standard output using UTF-8
>         // character to byte encoding
>         boolean useCSS = true; // we want to use CSS style attribute
>         Writer out = new OutputStreamWriter(System.out, "UTF-8");
>         g2d.stream(out, useCSS);
>     }
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message