Computing a group bounding box for an SVG image

Victor Danilchenko <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <94954D2ECA070E4B89A0FBC8693C3C6D7C916A39@WNDMAIL02.vistaprint.net>
Hi all,

I need to compute the size and coordinates for a bounding box for a <g> subtree in an SVG image (well, actually I just need the box center), identified by a specific attribute. It's easy to do in a web browser (a little DOM traversal, then a getBoundingClientRect() call), but I need to do it server-side. It looks to me like Cairo library might be able to do that, but it also looks fairly complicated, and I just need to perform that one specific task.

I am using the Ruby bindings for Cairo, together with SVG. Any suggestions on how to locate a given node by attribute (without the convenience of jQuery), and then to compute its bounding rectangle?

I am currently loading SVG into a Cairo surface as follows:

@rsvgHandle = RSVG::Handle.new_from_file(@baseFile)
dim = @rsvgHandle.dimensions
@width = dim.width
@height = dim.height

surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, @width, @height)
cr = Cairo::Context.new(surface)
cr.render_rsvg_handle(@rsvgHandle)

Thanks in advance!

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.