xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Chew" <chew.a...@gmail.com>
Subject Re: how can i generate clipPath?
Date Fri, 17 Mar 2006 10:25:18 GMT
Thanks a lot, Thomas.

    I'll try that.

On 3/15/06, thomas.deweese@kodak.com <thomas.deweese@kodak.com> wrote:
>
> 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