diff options
author | Federico Mena Quintero <federico.mena@gmail.com> | 2020-09-18 01:08:43 +0000 |
---|---|---|
committer | Federico Mena Quintero <federico.mena@gmail.com> | 2020-09-18 01:08:43 +0000 |
commit | 47a89e0e11c615b01236084fdb61d4d8b65ccd59 (patch) | |
tree | 38331b5a84b5a47582b2ec84c10a903d1f94941b | |
parent | 5fd2ca31c41384c41ae3eddc11c96e70fb59709e (diff) | |
parent | 41c23b4347362282afa301fcc296a6022ec6ab27 (diff) | |
download | librsvg-47a89e0e11c615b01236084fdb61d4d8b65ccd59.tar.gz |
Merge branch 'port-c-convenience-functions-to-rust' into 'master'
Port the remaining C convenience functions to Rust
Closes #626
See merge request GNOME/librsvg!378
-rw-r--r-- | librsvg/c_api.rs | 73 | ||||
-rw-r--r-- | librsvg/rsvg-handle.c | 21 |
2 files changed, 85 insertions, 9 deletions
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs index 50d2a039..5985f3c6 100644 --- a/librsvg/c_api.rs +++ b/librsvg/c_api.rs @@ -1164,6 +1164,19 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_base_url( } #[no_mangle] +pub unsafe extern "C" fn rsvg_rust_handle_set_dpi(handle: *const RsvgHandle, dpi: f64) { + rsvg_return_if_fail! { + rsvg_handle_set_dpi; + + is_rsvg_handle(handle), + } + + let rhandle = get_rust_handle(handle); + rhandle.set_dpi_x(dpi); + rhandle.set_dpi_y(dpi); +} + +#[no_mangle] pub unsafe extern "C" fn rsvg_rust_handle_set_dpi_x_y( handle: *const RsvgHandle, dpi_x: f64, @@ -1312,6 +1325,31 @@ pub unsafe extern "C" fn rsvg_rust_handle_has_sub( } #[no_mangle] +pub unsafe extern "C" fn rsvg_rust_handle_render_cairo( + handle: *const RsvgHandle, + cr: *mut cairo_sys::cairo_t, +) -> glib_sys::gboolean { + rsvg_return_val_if_fail! { + rsvg_handle_render_cairo => false.to_glib(); + + is_rsvg_handle(handle), + !cr.is_null(), + } + + let rhandle = get_rust_handle(handle); + let cr = from_glib_none(cr); + + match rhandle.render_cairo_sub(&cr, None) { + Ok(()) => true.to_glib(), + + Err(e) => { + rsvg_log!("could not render: {}", e); + false.to_glib() + } + } +} + +#[no_mangle] pub unsafe extern "C" fn rsvg_rust_handle_render_cairo_sub( handle: *const RsvgHandle, cr: *mut cairo_sys::cairo_t, @@ -1339,6 +1377,27 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_cairo_sub( } #[no_mangle] +pub unsafe extern "C" fn rsvg_rust_handle_get_pixbuf( + handle: *const RsvgHandle, +) -> *mut gdk_pixbuf_sys::GdkPixbuf { + rsvg_return_val_if_fail! { + rsvg_handle_get_pixbuf => ptr::null_mut(); + + is_rsvg_handle(handle), + } + + let rhandle = get_rust_handle(handle); + + match rhandle.get_pixbuf_sub(None) { + Ok(pixbuf) => pixbuf.to_glib_full(), + Err(e) => { + rsvg_log!("could not render: {}", e); + ptr::null_mut() + } + } +} + +#[no_mangle] pub unsafe extern "C" fn rsvg_rust_handle_get_pixbuf_sub( handle: *const RsvgHandle, id: *const libc::c_char, @@ -1436,6 +1495,15 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_position_sub( } #[no_mangle] +pub unsafe extern "C" fn rsvg_rust_handle_new() -> *const RsvgHandle { + let obj: *mut gobject_sys::GObject = glib::Object::new(CHandle::get_type(), &[]) + .unwrap() + .to_glib_full(); + + obj as *mut _ +} + +#[no_mangle] pub unsafe extern "C" fn rsvg_rust_handle_new_with_flags(flags: u32) -> *const RsvgHandle { let obj: *mut gobject_sys::GObject = glib::Object::new(CHandle::get_type(), &[("flags", &flags)]) @@ -1613,6 +1681,11 @@ unsafe fn set_out_param<T: Copy>( } #[no_mangle] +pub unsafe extern "C" fn rsvg_rust_handle_free(handle: *mut RsvgHandle) { + gobject_sys::g_object_unref(handle as *mut _); +} + +#[no_mangle] pub unsafe extern "C" fn rsvg_rust_handle_set_stylesheet( handle: *const RsvgHandle, css: *const u8, diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c index 8902460d..bc06d4a2 100644 --- a/librsvg/rsvg-handle.c +++ b/librsvg/rsvg-handle.c @@ -323,6 +323,7 @@ #include "rsvg.h" /* Implemented in rsvg_internals/src/handle.rs */ +extern void rsvg_rust_handle_set_dpi (RsvgHandle *raw_handle, double dpi); extern void rsvg_rust_handle_set_dpi_x_y (RsvgHandle *raw_handle, double dpi_x, double dpi_y); extern void rsvg_rust_handle_set_base_url (RsvgHandle *raw_handle, const char *uri); extern void rsvg_rust_handle_set_base_gfile (RsvgHandle *raw_handle, GFile *file); @@ -335,9 +336,11 @@ extern gboolean rsvg_rust_handle_read_stream_sync (RsvgHandle *handle, extern gboolean rsvg_rust_handle_write (RsvgHandle *handle, const guchar *buf, gsize count, GError **error); extern gboolean rsvg_rust_handle_close (RsvgHandle *handle, GError **error); extern gboolean rsvg_rust_handle_has_sub (RsvgHandle *handle, const char *id); +extern gboolean rsvg_rust_handle_render_cairo (RsvgHandle *handle, cairo_t *cr); extern gboolean rsvg_rust_handle_render_cairo_sub (RsvgHandle *handle, cairo_t *cr, const char *id); +extern GdkPixbuf *rsvg_rust_handle_get_pixbuf (RsvgHandle *handle); extern GdkPixbuf *rsvg_rust_handle_get_pixbuf_sub (RsvgHandle *handle, const char *id); extern void rsvg_rust_handle_get_dimensions (RsvgHandle *handle, RsvgDimensionData *dimension_data); @@ -351,6 +354,7 @@ extern void rsvg_rust_handle_set_size_callback (RsvgHandle *raw_handle, RsvgSizeFunc size_func, gpointer user_data, GDestroyNotify destroy_notify); +extern RsvgHandle *rsvg_rust_handle_new (void); extern RsvgHandle *rsvg_rust_handle_new_with_flags (RsvgHandleFlags flags); extern RsvgHandle *rsvg_rust_handle_new_from_file (const char *filename, GError **error); @@ -366,6 +370,7 @@ extern RsvgHandle *rsvg_rust_handle_new_from_stream_sync (GInputStream *input_st extern RsvgHandle *rsvg_rust_handle_new_from_data (const guint8 *data, gsize data_len, GError **error); +extern void rsvg_rust_handle_free (RsvgHandle *handle); extern gboolean rsvg_rust_handle_set_stylesheet (RsvgHandle *handle, const char *css, gsize css_len, @@ -406,12 +411,10 @@ extern gboolean rsvg_rust_handle_render_element (RsvgHandle *handle, -/* Implemented in rsvg_internals/src/c_api.rs */ +/* Implemented in librsvg/c_api.rs */ extern GType rsvg_rust_error_get_type (void); -extern GType rsvg_rust_handle_flags_get_type (void); - -/* Implemented in rsvg_internals/src/c_api.rs */ extern GType rsvg_rust_handle_get_type (void); +extern GType rsvg_rust_handle_flags_get_type (void); GType rsvg_handle_get_type (void) @@ -429,7 +432,7 @@ rsvg_handle_get_type (void) void rsvg_handle_free (RsvgHandle *handle) { - g_object_unref (handle); + rsvg_rust_handle_free (handle); } /** @@ -461,7 +464,7 @@ rsvg_handle_free (RsvgHandle *handle) RsvgHandle * rsvg_handle_new (void) { - return RSVG_HANDLE (g_object_new (RSVG_TYPE_HANDLE, NULL)); + return rsvg_rust_handle_new(); } /** @@ -875,7 +878,7 @@ rsvg_handle_render_cairo_sub (RsvgHandle *handle, cairo_t *cr, const char *id) gboolean rsvg_handle_render_cairo (RsvgHandle *handle, cairo_t *cr) { - return rsvg_handle_render_cairo_sub (handle, cr, NULL); + return rsvg_rust_handle_render_cairo (handle, cr); } /** @@ -1034,7 +1037,7 @@ rsvg_handle_get_pixbuf_sub (RsvgHandle *handle, const char *id) GdkPixbuf * rsvg_handle_get_pixbuf (RsvgHandle *handle) { - return rsvg_handle_get_pixbuf_sub (handle, NULL); + return rsvg_rust_handle_get_pixbuf (handle); } /** @@ -1054,7 +1057,7 @@ rsvg_handle_get_pixbuf (RsvgHandle *handle) void rsvg_handle_set_dpi (RsvgHandle *handle, double dpi) { - rsvg_handle_set_dpi_x_y (handle, dpi, dpi); + rsvg_rust_handle_set_dpi (handle, dpi); } /** |