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 23:45:19 GMT
Hi Baris,

Baris YILMAZ <baris_999@yahoo.com> wrote on 06/11/2006 06:44:40 PM:

> I am trying to implement a java application, which produces a graphic, 
which 
> represents the different soil layers along a section of topography. For 
this, 
> I will have to draw paths, which will be filled with pattern elements.
> 
> Later I want to show this graphic in Java panel, and give the user the 
> opportunity to do some modifications.
> 
> I'll appreciate if you give me some oppinion on the following points;
> 
> 1- How should I create and fill this SVG document?

   There are many options, the SVGGraphics2D is really designed to take
existing code to draw in Java and turn it into SVG.  It is very good at
this but it isn't very good as a high level interface for creating an
SVG document (it's ok but not great).  In particular it's difficult to
tweak it's output.

   So from Batik you have two main options:
        1) Use the SVGGraphics2D (perhaps customized, extended).
        2) Use the DOM directly (perhaps leveraging some of the lower 
level
           pieces of the SVGGraphics2D to generate pieces of the 
Document).

   The decision really is how much you want to tweak things...

> 2- I already did this by using SVGGraphics2D, draw(generalpath) methods. 
But I
> don't know, how it is possible to fill this path with a predefined 
pattern like below; 

   You can get close to this by filling your shape with a TexturePaint. 
But this
will use a BufferedImage.  I think the only way to get a 'vector' version 
would be
to install a custom paint converter, 
setExtensionHandler(ExtensionHandler).

>     <pattern id="pattern1" x="0" y="0" width="15" height="15" 
>       patternUnits="userSpaceOnUse"> 
>    <circle cx="6" cy="6" r="5" 
>           style="fill: red;
>  stroke:black;" />
>  </pattern> 

> I have many other questions in my mind. But for the first time, this is 
enough. 
> Thank you for your help.

---

> Baris YILMAZ 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

> 
>  __________________________________________________
> 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