Thanks a lot, Thomas.

    I'll try that.
On 3/15/06, < > wrote:
Hi Alex,

"Alex Chew" <> wrote on 03/15/2006 12:43:21 AM:

> Sorry for i didnot make me understood.
> I want to modify an existing SVG file and add some ClipPaths to it for
> specified area.
> There is no clippath on original SVG, so , i want to generate a new one,
> apply it to some element such as <g>. The new SVG file should look like
> <g style="clip-path:url(#clipPath);"><!--others--></g>

  I would suggest simply constructing the SVG Elements you want using
org.w3c.dom.Document.createElementNS(<svg namespace>, <element name>);

Something like:
       static final String SVGNS = " ";
       static int clipCnt=0;

       String clipID = "clipPath_"+clipCnt++;
       Element clipPath = document.createElementNS(SVGNS, "clipPath");
       clipPath.setAttributeNS ("id", clipID);

       Element rect     = document.createElementNS(SVGNS, "rect");
       rect.setAttributeNS(null, "x", "0");
       rect.setAttributeNS(null, "y", "0");
       rect.setAttributeNS(null, "width", "60");
       rect.setAttributeNS(null, "height", "60");


       Element defs     = document.getElementById("defs");
       if (defs == null) {
          defs = document.createElementNS(SVGNS, defs);
       defs.append (clipPath);

       Element elemToClip = ....;
       elemToClip.setAttributeNS(null, "clip-path", "url("+clipiD+")");

>       //manipulate - add clipPath
>       SVGGraphics2D generator = new SVGGraphics2D(doc);
>       Shape circle = new Ellipse2D.Double (0,0,50,50);
>       generator.setPaint(;
>       generator.fill(circle);
>       generator.draw(circle);
>       generator.setPaint(Color.BLUE );
>       generator.drawString("Dance on SVG",60,60);
>       generator.setClip(0,0,60,60);
> Then, how can I use clipPath generated here?
> Or, there are some other ways for this?

       The SVGGenerator is not designed to modify existing documents.
You can use it (a little painfully) to generate fragments to add to
other documents but it's main purpose is to generate a complete
SVG file that captures all drawing to a Graphics2D.

To unsubscribe, e-mail:
For additional commands, e-mail: