xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: how can i generate clipPath?
Date Wed, 15 Mar 2006 11:38:53 GMT
Hi Alex,

"Alex Chew" <chew.alex@gmail.com> 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 
display
> specified area.
> There is no clippath on original SVG, so , i want to generate a new one, 
and 
> apply it to some element such as <g>. The new SVG file should look like 
this 
> <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 = "http://www.w3.org/2000/svg";
        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");
 
        clipPath.appendChild(rect);

        Element defs     = document.getElementById("defs");
        if (defs == null) {
           defs = document.createElementNS(SVGNS, defs);
           document.getRootElement().appendChild(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(Color.red);
>       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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message