librsvg-rebind-0.1.0/Cargo.toml0000644000000026620000000000100117470ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "librsvg-rebind" version = "0.1.0" authors = ["Sophie Herold "] exclude = ["Gir.toml"] description = "Rust bindings for librsvg" homepage = "https://gitlab.gnome.org/GNOME/librsvg" documentation = "https://gnome.pages.gitlab.gnome.org/librsvg/doc/librsvg_rebind/" readme = "README.md" keywords = ["svg"] categories = ["api-bindings"] license = "MIT" repository = "https://gitlab.gnome.org/GNOME/librsvg" [package.metadata.docs.rs] all-features = true rustc-args = [ "--cfg", "docsrs", ] rustdoc-args = [ "--cfg", "docsrs", "--generate-link-to-definition", ] [dependencies.bitflags] version = "2.0" [dependencies.cairo-rs] version = "0.20" [dependencies.ffi] version = "0.1" package = "librsvg-rebind-sys" [dependencies.gio] version = "0.20" [dependencies.glib] version = "0.20" [dependencies.libc] version = "0.2" [dev-dependencies.cairo-rs] version = "0.20" features = ["png"] [features] v2_58 = ["ffi/v2_58"] librsvg-rebind-0.1.0/Cargo.toml.orig000064400000000000000000000016761046102023000154340ustar 00000000000000[package] name = "librsvg-rebind" authors = ["Sophie Herold "] readme = "README.md" homepage = "https://gitlab.gnome.org/GNOME/librsvg" description = "Rust bindings for librsvg" license = "MIT" repository = "https://gitlab.gnome.org/GNOME/librsvg" documentation = "https://gnome.pages.gitlab.gnome.org/librsvg/doc/librsvg_rebind/" categories = ["api-bindings"] version = "0.1.0" keywords = ["svg"] edition = "2021" exclude = ["Gir.toml"] [dependencies] libc.workspace = true bitflags.workspace = true cairo-rs.workspace = true [dev-dependencies] cairo-rs = { workspace = true, features = ['png'] } [dependencies.ffi] package = "librsvg-rebind-sys" version = "0.1" path = "./sys" [dependencies.glib] version = "0.20" [dependencies.gio] version = "0.20" [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] all-features = true [features] v2_58 = ["ffi/v2_58"] librsvg-rebind-0.1.0/LICENSE000064400000000000000000000017771046102023000135540ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. librsvg-rebind-0.1.0/README.md000064400000000000000000000005751046102023000140210ustar 00000000000000# 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](https://crates.io/crates/librsvg) 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.librsvg-rebind-0.1.0/src/auto/enums.rs000064400000000000000000000116351046102023000157750ustar 00000000000000// This file was generated by gir (https://github.com/gtk-rs/gir) // from ../builddir/rsvg // from gir-files // DO NOT EDIT use crate::ffi; use glib::{prelude::*, translate::*}; #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "RsvgError")] pub enum Error { #[doc(alias = "RSVG_ERROR_FAILED")] Failed, #[doc(hidden)] __Unknown(i32), } #[doc(hidden)] impl IntoGlib for Error { type GlibType = ffi::RsvgError; #[inline] fn into_glib(self) -> ffi::RsvgError { match self { Self::Failed => ffi::RSVG_ERROR_FAILED, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for Error { #[inline] unsafe fn from_glib(value: ffi::RsvgError) -> Self { skip_assert_initialized!(); match value { ffi::RSVG_ERROR_FAILED => Self::Failed, value => Self::__Unknown(value), } } } impl glib::error::ErrorDomain for Error { #[inline] fn domain() -> glib::Quark { skip_assert_initialized!(); unsafe { from_glib(ffi::rsvg_error_quark()) } } #[inline] fn code(self) -> i32 { self.into_glib() } #[inline] #[allow(clippy::match_single_binding)] fn from(code: i32) -> Option { skip_assert_initialized!(); match unsafe { from_glib(code) } { Self::__Unknown(_) => Some(Self::Failed), value => Some(value), } } } impl StaticType for Error { #[inline] #[doc(alias = "rsvg_error_get_type")] fn static_type() -> glib::Type { unsafe { from_glib(ffi::rsvg_error_get_type()) } } } impl glib::HasParamSpec for Error { type ParamSpec = glib::ParamSpecEnum; type SetValue = Self; type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder; fn param_spec_builder() -> Self::BuilderFn { Self::ParamSpec::builder_with_default } } impl glib::value::ValueType for Error { type Type = Self; } unsafe impl<'a> glib::value::FromValue<'a> for Error { type Checker = glib::value::GenericValueTypeChecker; #[inline] unsafe fn from_value(value: &'a glib::Value) -> Self { skip_assert_initialized!(); from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) } } impl ToValue for Error { #[inline] fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); } value } #[inline] fn value_type(&self) -> glib::Type { Self::static_type() } } impl From for glib::Value { #[inline] fn from(v: Error) -> Self { skip_assert_initialized!(); ToValue::to_value(&v) } } #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "RsvgUnit")] pub enum Unit { #[doc(alias = "RSVG_UNIT_PERCENT")] Percent, #[doc(alias = "RSVG_UNIT_PX")] Px, #[doc(alias = "RSVG_UNIT_EM")] Em, #[doc(alias = "RSVG_UNIT_EX")] Ex, #[doc(alias = "RSVG_UNIT_IN")] In, #[doc(alias = "RSVG_UNIT_CM")] Cm, #[doc(alias = "RSVG_UNIT_MM")] Mm, #[doc(alias = "RSVG_UNIT_PT")] Pt, #[doc(alias = "RSVG_UNIT_PC")] Pc, #[cfg(feature = "v2_58")] #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))] #[doc(alias = "RSVG_UNIT_CH")] Ch, #[doc(hidden)] __Unknown(i32), } #[doc(hidden)] impl IntoGlib for Unit { type GlibType = ffi::RsvgUnit; #[inline] fn into_glib(self) -> ffi::RsvgUnit { match self { Self::Percent => ffi::RSVG_UNIT_PERCENT, Self::Px => ffi::RSVG_UNIT_PX, Self::Em => ffi::RSVG_UNIT_EM, Self::Ex => ffi::RSVG_UNIT_EX, Self::In => ffi::RSVG_UNIT_IN, Self::Cm => ffi::RSVG_UNIT_CM, Self::Mm => ffi::RSVG_UNIT_MM, Self::Pt => ffi::RSVG_UNIT_PT, Self::Pc => ffi::RSVG_UNIT_PC, #[cfg(feature = "v2_58")] Self::Ch => ffi::RSVG_UNIT_CH, Self::__Unknown(value) => value, } } } #[doc(hidden)] impl FromGlib for Unit { #[inline] unsafe fn from_glib(value: ffi::RsvgUnit) -> Self { skip_assert_initialized!(); match value { ffi::RSVG_UNIT_PERCENT => Self::Percent, ffi::RSVG_UNIT_PX => Self::Px, ffi::RSVG_UNIT_EM => Self::Em, ffi::RSVG_UNIT_EX => Self::Ex, ffi::RSVG_UNIT_IN => Self::In, ffi::RSVG_UNIT_CM => Self::Cm, ffi::RSVG_UNIT_MM => Self::Mm, ffi::RSVG_UNIT_PT => Self::Pt, ffi::RSVG_UNIT_PC => Self::Pc, #[cfg(feature = "v2_58")] ffi::RSVG_UNIT_CH => Self::Ch, value => Self::__Unknown(value), } } } librsvg-rebind-0.1.0/src/auto/flags.rs000064400000000000000000000047741046102023000157500ustar 00000000000000// This file was generated by gir (https://github.com/gtk-rs/gir) // from ../builddir/rsvg // from gir-files // DO NOT EDIT use crate::ffi; use glib::{bitflags::bitflags, prelude::*, translate::*}; bitflags! { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[doc(alias = "RsvgHandleFlags")] pub struct HandleFlags: u32 { #[doc(alias = "RSVG_HANDLE_FLAGS_NONE")] const FLAGS_NONE = ffi::RSVG_HANDLE_FLAGS_NONE as _; #[doc(alias = "RSVG_HANDLE_FLAG_UNLIMITED")] const FLAG_UNLIMITED = ffi::RSVG_HANDLE_FLAG_UNLIMITED as _; #[doc(alias = "RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA")] const FLAG_KEEP_IMAGE_DATA = ffi::RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA as _; } } #[doc(hidden)] impl IntoGlib for HandleFlags { type GlibType = ffi::RsvgHandleFlags; #[inline] fn into_glib(self) -> ffi::RsvgHandleFlags { self.bits() } } #[doc(hidden)] impl FromGlib for HandleFlags { #[inline] unsafe fn from_glib(value: ffi::RsvgHandleFlags) -> Self { skip_assert_initialized!(); Self::from_bits_truncate(value) } } impl StaticType for HandleFlags { #[inline] #[doc(alias = "rsvg_handle_flags_get_type")] fn static_type() -> glib::Type { unsafe { from_glib(ffi::rsvg_handle_flags_get_type()) } } } impl glib::HasParamSpec for HandleFlags { type ParamSpec = glib::ParamSpecFlags; type SetValue = Self; type BuilderFn = fn(&str) -> glib::ParamSpecFlagsBuilder; fn param_spec_builder() -> Self::BuilderFn { Self::ParamSpec::builder } } impl glib::value::ValueType for HandleFlags { type Type = Self; } unsafe impl<'a> glib::value::FromValue<'a> for HandleFlags { type Checker = glib::value::GenericValueTypeChecker; #[inline] unsafe fn from_value(value: &'a glib::Value) -> Self { skip_assert_initialized!(); from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0)) } } impl ToValue for HandleFlags { #[inline] fn to_value(&self) -> glib::Value { let mut value = glib::Value::for_value_type::(); unsafe { glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, self.into_glib()); } value } #[inline] fn value_type(&self) -> glib::Type { Self::static_type() } } impl From for glib::Value { #[inline] fn from(v: HandleFlags) -> Self { skip_assert_initialized!(); ToValue::to_value(&v) } } librsvg-rebind-0.1.0/src/auto/handle.rs000064400000000000000000000413601046102023000160770ustar 00000000000000// This file was generated by gir (https://github.com/gtk-rs/gir) // from ../builddir/rsvg // from gir-files // DO NOT EDIT #![allow(deprecated)] use crate::{ffi, HandleFlags, Rectangle}; use glib::{ prelude::*, signal::{connect_raw, SignalHandlerId}, translate::*, }; use std::boxed::Box as Box_; glib::wrapper! { #[doc(alias = "RsvgHandle")] pub struct Handle(Object); match fn { type_ => || ffi::rsvg_handle_get_type(), } } impl Handle { pub const NONE: Option<&'static Handle> = None; #[doc(alias = "rsvg_handle_new")] pub fn new() -> Handle { assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::rsvg_handle_new()) } } #[doc(alias = "rsvg_handle_new_from_data")] #[doc(alias = "new_from_data")] pub fn from_data(data: &[u8]) -> Result, glib::Error> { assert_initialized_main_thread!(); let data_len = data.len() as _; unsafe { let mut error = std::ptr::null_mut(); let ret = ffi::rsvg_handle_new_from_data(data.to_glib_none().0, data_len, &mut error); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_new_from_file")] #[doc(alias = "new_from_file")] pub fn from_file(filename: &str) -> Result, glib::Error> { assert_initialized_main_thread!(); unsafe { let mut error = std::ptr::null_mut(); let ret = ffi::rsvg_handle_new_from_file(filename.to_glib_none().0, &mut error); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_new_from_gfile_sync")] #[doc(alias = "new_from_gfile_sync")] pub fn from_gfile_sync( file: &impl IsA, flags: HandleFlags, cancellable: Option<&impl IsA>, ) -> Result, glib::Error> { assert_initialized_main_thread!(); unsafe { let mut error = std::ptr::null_mut(); let ret = ffi::rsvg_handle_new_from_gfile_sync( file.as_ref().to_glib_none().0, flags.into_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error, ); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_new_from_stream_sync")] #[doc(alias = "new_from_stream_sync")] pub fn from_stream_sync( input_stream: &impl IsA, base_file: Option<&impl IsA>, flags: HandleFlags, cancellable: Option<&impl IsA>, ) -> Result, glib::Error> { assert_initialized_main_thread!(); unsafe { let mut error = std::ptr::null_mut(); let ret = ffi::rsvg_handle_new_from_stream_sync( input_stream.as_ref().to_glib_none().0, base_file.map(|p| p.as_ref()).to_glib_none().0, flags.into_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error, ); if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_new_with_flags")] #[doc(alias = "new_with_flags")] pub fn with_flags(flags: HandleFlags) -> Handle { assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::rsvg_handle_new_with_flags(flags.into_glib())) } } } impl Default for Handle { fn default() -> Self { Self::new() } } mod sealed { pub trait Sealed {} impl> Sealed for T {} } pub trait HandleExt: IsA + sealed::Sealed + 'static { #[doc(alias = "rsvg_handle_get_base_uri")] #[doc(alias = "get_base_uri")] #[doc(alias = "base-uri")] fn base_uri(&self) -> Option { unsafe { from_glib_none(ffi::rsvg_handle_get_base_uri( self.as_ref().to_glib_none().0, )) } } #[doc(alias = "rsvg_handle_get_geometry_for_element")] #[doc(alias = "get_geometry_for_element")] fn geometry_for_element( &self, id: Option<&str>, ) -> Result<(Rectangle, Rectangle), glib::Error> { unsafe { let mut out_ink_rect = Rectangle::uninitialized(); let mut out_logical_rect = Rectangle::uninitialized(); let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_get_geometry_for_element( self.as_ref().to_glib_none().0, id.to_glib_none().0, out_ink_rect.to_glib_none_mut().0, out_logical_rect.to_glib_none_mut().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok((out_ink_rect, out_logical_rect)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_get_geometry_for_layer")] #[doc(alias = "get_geometry_for_layer")] fn geometry_for_layer( &self, id: Option<&str>, viewport: &Rectangle, ) -> Result<(Rectangle, Rectangle), glib::Error> { unsafe { let mut out_ink_rect = Rectangle::uninitialized(); let mut out_logical_rect = Rectangle::uninitialized(); let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_get_geometry_for_layer( self.as_ref().to_glib_none().0, id.to_glib_none().0, viewport.to_glib_none().0, out_ink_rect.to_glib_none_mut().0, out_logical_rect.to_glib_none_mut().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok((out_ink_rect, out_logical_rect)) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_get_intrinsic_size_in_pixels")] #[doc(alias = "get_intrinsic_size_in_pixels")] fn intrinsic_size_in_pixels(&self) -> Option<(f64, f64)> { unsafe { let mut out_width = std::mem::MaybeUninit::uninit(); let mut out_height = std::mem::MaybeUninit::uninit(); let ret = from_glib(ffi::rsvg_handle_get_intrinsic_size_in_pixels( self.as_ref().to_glib_none().0, out_width.as_mut_ptr(), out_height.as_mut_ptr(), )); if ret { Some((out_width.assume_init(), out_height.assume_init())) } else { None } } } //#[cfg_attr(feature = "v2_58", deprecated = "Since 2.58")] //#[allow(deprecated)] //#[doc(alias = "rsvg_handle_get_pixbuf")] //#[doc(alias = "get_pixbuf")] //fn pixbuf(&self) -> /*Ignored*/Option { // unsafe { TODO: call ffi:rsvg_handle_get_pixbuf() } //} //#[cfg(feature = "v2_58")] //#[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))] //#[doc(alias = "rsvg_handle_get_pixbuf_and_error")] //#[doc(alias = "get_pixbuf_and_error")] //fn pixbuf_and_error(&self) -> Result, glib::Error> { // unsafe { TODO: call ffi:rsvg_handle_get_pixbuf_and_error() } //} //#[doc(alias = "rsvg_handle_get_pixbuf_sub")] //#[doc(alias = "get_pixbuf_sub")] //fn pixbuf_sub(&self, id: Option<&str>) -> /*Ignored*/Option { // unsafe { TODO: call ffi:rsvg_handle_get_pixbuf_sub() } //} #[doc(alias = "rsvg_handle_has_sub")] fn has_sub(&self, id: &str) -> bool { unsafe { from_glib(ffi::rsvg_handle_has_sub( self.as_ref().to_glib_none().0, id.to_glib_none().0, )) } } #[doc(alias = "rsvg_handle_internal_set_testing")] fn internal_set_testing(&self, testing: bool) { unsafe { ffi::rsvg_handle_internal_set_testing( self.as_ref().to_glib_none().0, testing.into_glib(), ); } } #[doc(alias = "rsvg_handle_read_stream_sync")] fn read_stream_sync( &self, stream: &impl IsA, cancellable: Option<&impl IsA>, ) -> Result<(), glib::Error> { unsafe { let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_read_stream_sync( self.as_ref().to_glib_none().0, stream.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_render_document")] fn render_document( &self, cr: &cairo::Context, viewport: &Rectangle, ) -> Result<(), glib::Error> { unsafe { let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_render_document( self.as_ref().to_glib_none().0, mut_override(cr.to_glib_none().0), viewport.to_glib_none().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_render_element")] fn render_element( &self, cr: &cairo::Context, id: Option<&str>, element_viewport: &Rectangle, ) -> Result<(), glib::Error> { unsafe { let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_render_element( self.as_ref().to_glib_none().0, mut_override(cr.to_glib_none().0), id.to_glib_none().0, element_viewport.to_glib_none().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_render_layer")] fn render_layer( &self, cr: &cairo::Context, id: Option<&str>, viewport: &Rectangle, ) -> Result<(), glib::Error> { unsafe { let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_render_layer( self.as_ref().to_glib_none().0, mut_override(cr.to_glib_none().0), id.to_glib_none().0, viewport.to_glib_none().0, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[doc(alias = "rsvg_handle_set_base_gfile")] fn set_base_gfile(&self, base_file: &impl IsA) { unsafe { ffi::rsvg_handle_set_base_gfile( self.as_ref().to_glib_none().0, base_file.as_ref().to_glib_none().0, ); } } #[doc(alias = "rsvg_handle_set_base_uri")] #[doc(alias = "base-uri")] fn set_base_uri(&self, base_uri: &str) { unsafe { ffi::rsvg_handle_set_base_uri( self.as_ref().to_glib_none().0, base_uri.to_glib_none().0, ); } } #[doc(alias = "rsvg_handle_set_cancellable_for_rendering")] fn set_cancellable_for_rendering(&self, cancellable: Option<&impl IsA>) { unsafe { ffi::rsvg_handle_set_cancellable_for_rendering( self.as_ref().to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, ); } } #[doc(alias = "rsvg_handle_set_dpi")] fn set_dpi(&self, dpi: f64) { unsafe { ffi::rsvg_handle_set_dpi(self.as_ref().to_glib_none().0, dpi); } } #[doc(alias = "rsvg_handle_set_dpi_x_y")] fn set_dpi_x_y(&self, dpi_x: f64, dpi_y: f64) { unsafe { ffi::rsvg_handle_set_dpi_x_y(self.as_ref().to_glib_none().0, dpi_x, dpi_y); } } #[doc(alias = "rsvg_handle_set_stylesheet")] fn set_stylesheet(&self, css: &[u8]) -> Result<(), glib::Error> { let css_len = css.len() as _; unsafe { let mut error = std::ptr::null_mut(); let is_ok = ffi::rsvg_handle_set_stylesheet( self.as_ref().to_glib_none().0, css.to_glib_none().0, css_len, &mut error, ); debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null()); if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } #[doc(alias = "dpi-x")] fn dpi_x(&self) -> f64 { ObjectExt::property(self.as_ref(), "dpi-x") } #[doc(alias = "dpi-x")] fn set_dpi_x(&self, dpi_x: f64) { ObjectExt::set_property(self.as_ref(), "dpi-x", dpi_x) } #[doc(alias = "dpi-y")] fn dpi_y(&self) -> f64 { ObjectExt::property(self.as_ref(), "dpi-y") } #[doc(alias = "dpi-y")] fn set_dpi_y(&self, dpi_y: f64) { ObjectExt::set_property(self.as_ref(), "dpi-y", dpi_y) } fn flags(&self) -> HandleFlags { ObjectExt::property(self.as_ref(), "flags") } #[doc(alias = "base-uri")] fn connect_base_uri_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_base_uri_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::RsvgHandle, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Handle::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::base-uri\0".as_ptr() as *const _, Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( notify_base_uri_trampoline:: as *const (), )), Box_::into_raw(f), ) } } #[doc(alias = "dpi-x")] fn connect_dpi_x_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_dpi_x_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::RsvgHandle, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Handle::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::dpi-x\0".as_ptr() as *const _, Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( notify_dpi_x_trampoline:: as *const (), )), Box_::into_raw(f), ) } } #[doc(alias = "dpi-y")] fn connect_dpi_y_notify(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_dpi_y_trampoline, F: Fn(&P) + 'static>( this: *mut ffi::RsvgHandle, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); f(Handle::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_ = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::dpi-y\0".as_ptr() as *const _, Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( notify_dpi_y_trampoline:: as *const (), )), Box_::into_raw(f), ) } } } impl> HandleExt for O {} librsvg-rebind-0.1.0/src/auto/mod.rs000064400000000000000000000005311046102023000154160ustar 00000000000000// This file was generated by gir (https://github.com/gtk-rs/gir) // from ../builddir/rsvg // from gir-files // DO NOT EDIT mod handle; pub use self::handle::Handle; mod enums; pub use self::enums::Error; pub use self::enums::Unit; mod flags; pub use self::flags::HandleFlags; pub(crate) mod traits { pub use super::handle::HandleExt; } librsvg-rebind-0.1.0/src/auto/versions.txt000064400000000000000000000002071046102023000167020ustar 00000000000000Generated by gir (https://github.com/gtk-rs/gir @ 727e064a9792) from ../builddir/rsvg (@ 3f6b01041a94) from gir-files (@ 4d1189172a70) librsvg-rebind-0.1.0/src/handle.rs000064400000000000000000000024751046102023000151330ustar 00000000000000use glib::{prelude::*, translate::*}; use crate::{Handle, Length, Rectangle}; pub trait HandleExtManual: IsA + 'static { #[doc(alias = "rsvg_handle_get_intrinsic_dimensions")] #[doc(alias = "get_intrinsic_dimensions")] fn intrinsic_dimensions(&self) -> (Length, Length, Option) { unsafe { let mut out_has_width = std::mem::MaybeUninit::uninit(); let mut out_width = Length::uninitialized(); let mut out_has_height = std::mem::MaybeUninit::uninit(); let mut out_height = Length::uninitialized(); let mut out_has_viewbox = std::mem::MaybeUninit::uninit(); let mut out_viewbox = Rectangle::uninitialized(); ffi::rsvg_handle_get_intrinsic_dimensions( self.as_ref().to_glib_none().0, out_has_width.as_mut_ptr(), out_width.to_glib_none_mut().0, out_has_height.as_mut_ptr(), out_height.to_glib_none_mut().0, out_has_viewbox.as_mut_ptr(), out_viewbox.to_glib_none_mut().0, ); ( out_width, out_height, (out_has_viewbox.assume_init() != 0).then_some(out_viewbox), ) } } } impl> HandleExtManual for O {} librsvg-rebind-0.1.0/src/length.rs000064400000000000000000000005551046102023000151560ustar 00000000000000use glib::translate::FromGlib; use crate::Unit; glib::wrapper! { #[doc(alias = "RsvgLength")] #[derive(Debug)] pub struct Length(BoxedInline); } impl Length { #[inline] pub fn length(&self) -> f64 { self.inner.length } pub fn unit(&self) -> Unit { unsafe { Unit::from_glib(self.inner.unit) } } } librsvg-rebind-0.1.0/src/lib.rs000064400000000000000000000033051046102023000144370ustar 00000000000000#![allow(clippy::needless_doctest_main)] #![cfg_attr(docsrs, feature(doc_cfg))] #![doc(html_logo_url = "https://gnome.pages.gitlab.gnome.org/librsvg/Rsvg-2.0/librsvg-r.svg")] //! # 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. //! //! [`rsvg`]: https://crates.io/crates/librsvg //! //! # 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(); //! ``` /// No-op. macro_rules! skip_assert_initialized { () => {}; } // Re-export the -sys bindings pub use ffi; pub use gio; pub use glib; /// No-op. macro_rules! assert_initialized_main_thread { () => {}; } mod auto; mod handle; mod length; mod rectangle; mod unit; pub use auto::*; pub use length::*; pub use rectangle::*; pub mod prelude; librsvg-rebind-0.1.0/src/prelude.rs000064400000000000000000000001111046102023000153210ustar 00000000000000pub use crate::auto::traits::*; pub use crate::handle::HandleExtManual; librsvg-rebind-0.1.0/src/rectangle.rs000064400000000000000000000014261046102023000156370ustar 00000000000000use ::glib::translate::*; glib::wrapper! { #[doc(alias = "GtkRectangle")] #[derive(Debug)] pub struct Rectangle(BoxedInline); } impl Rectangle { #[inline] pub fn new(x: f64, y: f64, width: f64, height: f64) -> Self { assert_initialized_main_thread!(); unsafe { Self::unsafe_from(ffi::RsvgRectangle { x, y, width, height, }) } } #[inline] pub fn x(&self) -> f64 { self.inner.x } #[inline] pub fn y(&self) -> f64 { self.inner.y } #[inline] pub fn width(&self) -> f64 { self.inner.width } #[inline] pub fn height(&self) -> f64 { self.inner.height } } librsvg-rebind-0.1.0/src/unit.rs000064400000000000000000000011101046102023000146400ustar 00000000000000use crate::Unit; impl std::fmt::Display for Unit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { Self::Percent => "%", Self::Px => "px", Self::Em => "em", Self::Ex => "ex", Self::In => "in", Self::Cm => "cm", Self::Mm => "mm", Self::Pt => "pt", Self::Pc => "pc", #[cfg(feature = "v2_60")] Self::Ch => "ch", Self::__Unknown(_) => "unknown", }; f.write_str(s) } }