1

Is there a way to load an SVG from file and then render it to a Cairo canvas? Ideally something like:

image = read_from_svg("my.svg")
set_source_surface(cr, image, 0, 0)
paint(cr)
Mageek
  • 4,691
  • 3
  • 26
  • 42
  • 2
    Possible duplicate of [load svg with Cairo](http://stackoverflow.com/questions/21152068/load-svg-with-cairo) – oldtechaa Jun 27 '16 at 19:04
  • See also https://stackoverflow.com/questions/13709243/create-cairo-path-from-svg-file?rq=1 – oldtechaa Jun 27 '16 at 19:05
  • Thank you for the comments. It sounds like there is no built-in way to do it in Julia atm. It may be possible to call librsvg through a C++ binding. The CairoSVG thing doesn't look like it would give me an internal object that I can call set_source_surface() on, and I don't want to convert to PNG externally and then load that in. – Mageek Jun 28 '16 at 22:34

1 Answers1

2

There is the Rsvg.jl package that wraps the rsvg library. The package can be installed with Pkg.add("Rsvg"). You might have to troubleshoot the installation of the native Cairo and Rsvg libraries -- the package will attempt to do this automatically, but it is a difficult problem based on the multitude of different configurations.

Using that package, it seems be possible to do what you want. From the package's README:

using Rsvg
using Cairo

filename_in = "a4.svg"

r = Rsvg.handle_new_from_file(filename_in);
d = Rsvg.handle_get_dimensions(r);
cs = Cairo.CairoImageSurface(d.width,d.height,Cairo.FORMAT_ARGB32);
c = Cairo.CairoContext(cs);
Rsvg.handle_render_cairo(c,r);
aviks
  • 2,087
  • 18
  • 18