You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Rob Davis-5 <te...@robertjdavis.co.uk> on 2008/04/03 12:36:05 UTC

Solution: How to filter/clip SVG elements in a certain region in drawing and get resultant SVG-XML (Can you do better?)

I searched the forum about this subject but the results are always to do with
displaying a region of a drawing or using Swing - which I do not want.

My requirement is to take an SVG drawing and generate just the SVG of the
elements that exist within a certain region (as defined by a Shape, or a
Shape derived from a SVG element within the document).

I have a solution to this problem that works very well. But I wondered if I
was re-inventing the wheel. Perhaps batik has a too built in.  (the batik
documentation is great to get started but is incomplete - supplemented by
this forum which I guess is being pragmatic!) 

In summary, my solution uses a recursive algorithm on the DOM Tree Walker
and implementation of NodeFilter to inspect each element to see if it is
inside the region and indicate that it should be excluded it if is not. To
do this it uses the standard batik GVT - the CSS and DOM is booted. A list
is built of the elements outside the region.

The list returned is then iterated through and elements deleted using
standard DOM methods.

Thoughts?

-- 
View this message in context: http://www.nabble.com/Solution%3A-How-to-filter-clip-SVG-elements-in-a-certain-region-in-drawing-and-get-resultant-SVG-XML-%28Can-you-do-better-%29-tp16467384p16467384.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Solution: How to filter/clip SVG elements in a certain region in drawing and get resultant SVG-XML (Can you do better?)

Posted by Jonathan Chetwynd <j....@btinternet.com>.
Rob,

a number of versions have been produced, not necessarily for batik.

could be useful for copy and paste

cheers

~:"

On 3 Apr 2008, at 11:36, Rob Davis-5 wrote:

>
> I searched the forum about this subject but the results are always  
> to do with
> displaying a region of a drawing or using Swing - which I do not want.
>
> My requirement is to take an SVG drawing and generate just the SVG  
> of the
> elements that exist within a certain region (as defined by a Shape,  
> or a
> Shape derived from a SVG element within the document).
>
> I have a solution to this problem that works very well. But I  
> wondered if I
> was re-inventing the wheel. Perhaps batik has a too built in.  (the  
> batik
> documentation is great to get started but is incomplete -  
> supplemented by
> this forum which I guess is being pragmatic!)
>
> In summary, my solution uses a recursive algorithm on the DOM Tree  
> Walker
> and implementation of NodeFilter to inspect each element to see if  
> it is
> inside the region and indicate that it should be excluded it if is  
> not. To
> do this it uses the standard batik GVT - the CSS and DOM is booted.  
> A list
> is built of the elements outside the region.
>
> The list returned is then iterated through and elements deleted using
> standard DOM methods.
>
> Thoughts?
>
> -- 
> View this message in context: http://www.nabble.com/Solution%3A-How-to-filter-clip-SVG-elements-in-a-certain-region-in-drawing-and-get-resultant-SVG-XML-%28Can-you-do-better-%29-tp16467384p16467384.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>


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


Re: Solution: How to filter/clip SVG elements in a certain region in drawing and get resultant SVG-XML (Can you do better?)

Posted by Rob Davis-5 <te...@robertjdavis.co.uk>.
Thomas,
thanks. However my solution works with detecting inside/outside an irregular
shape, i.e. not just rectangles.

I can see how to make my solution more efficient, as I probably don't need
to use the DOM Tree Walker - I can traverse the batik GVT tree instead. (It
was a good exercise to learn about the DOM Tree Walker any way - the Oreilly
Java and XML book is quite good for this and this article:
http://www.onjava.com/pub/a/onjava/2001/02/08/dom.html?page=1 is a good
example.)

I would like to remove the elements outside of the shape as I traverse the
GVT tree. This would be the most efficient solution. But I think I'll run
into problems with Concurrent Modification Exception. The solution might be
to do this inside RunnableQueue - but you said in another thread that this
is only for Swing. Comments?

I'll probably settle for the GVT traversal to return me a NodeList to then
remove elements from  - I know I can do this without problems.
-- 
View this message in context: http://www.nabble.com/Solution%3A-How-to-filter-clip-SVG-elements-in-a-certain-region-in-drawing-and-get-resultant-SVG-XML-%28Can-you-do-better-%29-tp16467384p16536330.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Solution: How to filter/clip SVG elements in a certain region in drawing and get resultant SVG-XML (Can you do better?)

Posted by th...@kodak.com.
Hi Rob,

Rob Davis-5 <te...@robertjdavis.co.uk> wrote on 04/03/2008 06:36:05 AM:

> My requirement is to take an SVG drawing and generate just the SVG of 
the
> elements that exist within a certain region (as defined by a Shape, or a
> Shape derived from a SVG element within the document).

   If you are happy to deal with bounding boxes the SVG standard
provides: SVGSVGElement.getIntersectionList(SVGRect rect, SVGElement 
refElem);

  This will return a NodeList that has all of the elements that
intersect the SVGRect and are before refElem (if not null) in 
drawing (~document) order.