xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oliver clement <Oliver.Clem...@igh.cnrs.fr>
Subject [Design pbm]How can I Customize SVGShape
Date Mon, 19 Jul 2004 17:30:03 GMT
Thanks for your answer,

However my explanations must have been a little messy because my purpose 
is neither to extend batik with new elements
nor to define custom Paint. Therefore the ExtensionHandler subclassing 
seems inadequate.

I will try to be more explicit, below is the code for a Rectangle class.

public class Rectangle extends DrawableComponent {


    private int x;

    private int y;

    private int width;

    private int height;    

    private Color color;//if null defaults to black


    public Rectangle (int x, int y, int width, int height, Color color, Taggable taggable){


        this.x = x;

        this.y = y;

        this.width = width;

        this.height = height;

        this.color = color;



     * @see org.imgt.representation.tests.Drawable#paint()


    public void paint(Graphics g) {

        Graphics2D g2 = (Graphics2D)g;


        g2.fill(new java.awt.Rectangle(x, y, width, height));        



Let's say I want to draw  rectangles from an elsewhere  paint:

class ElseWhere{

public void paint(Graphics g){

while (..){


Rectangle rect = new Rectangle(






                    t1 //implements taggable





public static void main(String[] args){

	/ Get a DOMImplementation
        DOMImplementation domImpl =

        // Create an instance of org.w3c.dom.Document
        Document document = domImpl.createDocument(null, "svg", null);

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        // Ask the test to render into the SVG Graphics2D implementation
        Elsewhere test = new Elsewhere();



I'd like the program, when i call the paint method with an SVGGraphics2D 
to recurse through the paints like it normally goes on (?)
to check if the component has a taggable object associated, and if true 
to append its content to the SVG DOM.
This XML content is not to be rendered at all, it is only there for 
contextual and perhaps interaction purposes.

Thanks again if anyone has an idea


Hi Oliver,

    You want to implement an extension handler:


    You might also want to look at the code in batik.extension.svg
In particular the classes:

BatikStarElement, BatikStarElementBridge, BatikDomExtension &

oliver clement wrote:

 > Hello,
 > I'm starting to play with the Graphics2D capabilities of batik.
 > The API i'm working on enables objects to be serialized into XML via a
 > toXML() method defined in an interface called Taggable
 > and I'd like to be able to customize the way batik converts 2D objects
 > to SVG in a way such as it could include my XML content into the SVG
 > groups.
 > Lets say I use a CustomRectangle defining the paint(Graphics g) method,
 > associated with an a A object implementing Taggable.
 > The thing i'd like to obtain would be :
 > <g fill="lime" stroke="lime">  
 > <rect x="284341" width="471" y="245" height="10" stroke="none" />   
 >  <a name="ect" attr1="value1" xmlns="myNameSpace">
 >   <.../>   
 >  </a>
 > </g>
 > What should I do, subclass or redefine the SVGShapes, play with the
 > domGroupManager or create an extensioHandler ?
 > Any help would be greatly appreciated
 > Thanks
 > Oliver

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

View raw message