1 unstable release

0.1.0 Aug 2, 2024

#324 in Graphics APIs

Download history 124/week @ 2024-10-26 365/week @ 2024-11-02 293/week @ 2024-11-09 162/week @ 2024-11-16 217/week @ 2024-11-23 110/week @ 2024-11-30 121/week @ 2024-12-07 366/week @ 2024-12-14 228/week @ 2024-12-21 420/week @ 2024-12-28 430/week @ 2025-01-04 600/week @ 2025-01-11 288/week @ 2025-01-18 544/week @ 2025-01-25 471/week @ 2025-02-01 404/week @ 2025-02-08

1,858 downloads per month

MIT license

49KB
1K SLoC

librsvg-rebind

The librsvg-rebind crates allow to use librsvg's C-API from rust. Since librsvg is written in Rust, a native Rust API does exist. However, statically linking the library into a binary might not be desired in all cases. In these cases, librsvg can be linked dynamically and can reduce the Rust binary size by about 5 MB.


lib.rs:

Rust librsvg bindings

This package contains safe Rust bindings for the librsvg C library.

Since librsvg is written in Rust, the native rsvg crate is available to use the same features. One of the main purposes of librsvg-rebind is to reduce the binary sice.

To use this package, the librsvg-2 library has to be available on the system. If you use the native rsvg crate, this is not required.

Example

use librsvg_rebind::prelude::*;

let handle = librsvg_rebind::Handle::from_file("../../rsvg/example.svg")
    .unwrap()
    .unwrap();

let (width, height) = handle.intrinsic_size_in_pixels().unwrap();

let surface =
    cairo::ImageSurface::create(cairo::Format::ARgb32, width as i32, height as i32).unwrap();
let context = cairo::Context::new(&surface).unwrap();

let viewport = librsvg_rebind::Rectangle::new(0., 0., height, width);

handle.render_document(&context, &viewport).unwrap();

let mut output_file = std::fs::File::create("/dev/null").unwrap();
surface.write_to_png(&mut output_file).unwrap();

Dependencies

~7–15MB
~227K SLoC