[cairo] Computing a group bounding box for an SVG image
vdanilchenko at cimpress.com
Tue Jun 2 13:17:11 PDT 2015
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)
Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo