[librsvg: 3/4] Move the size_callback machinery to c_api



commit c0aa75f1227f19bdf0d9893d72f37a8525cf6783
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Apr 30 20:33:45 2020 -0500

    Move the size_callback machinery to c_api
    
    It is not used in rsvg_internals anymore

 librsvg/c_api.rs             | 84 ++++++++++++++++++++++++++++++++++++++++++--
 rsvg_internals/src/handle.rs | 82 ------------------------------------------
 rsvg_internals/src/lib.rs    |  2 +-
 3 files changed, 82 insertions(+), 86 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 3291c1fc..e72cca48 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -1,4 +1,4 @@
-use std::cell::{Ref, RefCell, RefMut};
+use std::cell::{Cell, Ref, RefCell, RefMut};
 use std::ffi::{CStr, CString};
 use std::ops;
 use std::path::PathBuf;
@@ -34,8 +34,7 @@ use gobject_sys::{GEnumValue, GFlagsValue};
 
 use rsvg_internals::{
     rsvg_log, DefsLookupErrorKind, Dpi, Handle, IntrinsicDimensions, LoadOptions, LoadingError,
-    RenderingError, RsvgLength, RsvgSizeFunc, SharedImageSurface, SizeCallback, SurfaceType,
-    ViewBox,
+    RenderingError, RsvgLength, SharedImageSurface, SurfaceType, ViewBox,
 };
 
 use crate::messages::{rsvg_g_critical, rsvg_g_warning};
@@ -498,6 +497,85 @@ impl RsvgDimensionData {
     }
 }
 
+// Keep in sync with rsvg.h:RsvgSizeFunc
+pub type RsvgSizeFunc = Option<
+    unsafe extern "C" fn(
+        inout_width: *mut libc::c_int,
+        inout_height: *mut libc::c_int,
+        user_data: glib_sys::gpointer,
+    ),
+>;
+
+pub struct SizeCallback {
+    pub size_func: RsvgSizeFunc,
+    pub user_data: glib_sys::gpointer,
+    pub destroy_notify: glib_sys::GDestroyNotify,
+    pub in_loop: Cell<bool>,
+}
+
+impl SizeCallback {
+    pub fn new(
+        size_func: RsvgSizeFunc,
+        user_data: glib_sys::gpointer,
+        destroy_notify: glib_sys::GDestroyNotify,
+    ) -> Self {
+        SizeCallback {
+            size_func,
+            user_data,
+            destroy_notify,
+            in_loop: Cell::new(false),
+        }
+    }
+
+    pub fn call(&self, width: libc::c_int, height: libc::c_int) -> (libc::c_int, libc::c_int) {
+        unsafe {
+            let mut w = width;
+            let mut h = height;
+
+            if let Some(ref f) = self.size_func {
+                f(&mut w, &mut h, self.user_data);
+            };
+
+            (w, h)
+        }
+    }
+
+    pub fn start_loop(&self) {
+        assert!(!self.in_loop.get());
+        self.in_loop.set(true);
+    }
+
+    pub fn end_loop(&self) {
+        assert!(self.in_loop.get());
+        self.in_loop.set(false);
+    }
+
+    pub fn get_in_loop(&self) -> bool {
+        self.in_loop.get()
+    }
+}
+
+impl Default for SizeCallback {
+    fn default() -> SizeCallback {
+        SizeCallback {
+            size_func: None,
+            user_data: ptr::null_mut(),
+            destroy_notify: None,
+            in_loop: Cell::new(false),
+        }
+    }
+}
+
+impl Drop for SizeCallback {
+    fn drop(&mut self) {
+        unsafe {
+            if let Some(ref f) = self.destroy_notify {
+                f(self.user_data);
+            };
+        }
+    }
+}
+
 impl CHandle {
     fn set_base_url(&self, url: &str) {
         let state = self.load_state.borrow();
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 0cf51ea1..5d86d2fa 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -2,9 +2,6 @@
 //!
 //! This module provides the primitives on which the public APIs are implemented.
 
-use std::cell::Cell;
-use std::ptr;
-
 use crate::allowed_url::{AllowedUrl, Href};
 use crate::bbox::BoundingBox;
 use crate::css::{Origin, Stylesheet};
@@ -72,85 +69,6 @@ impl LoadOptions {
     }
 }
 
-// Keep in sync with rsvg.h:RsvgSizeFunc
-pub type RsvgSizeFunc = Option<
-    unsafe extern "C" fn(
-        inout_width: *mut libc::c_int,
-        inout_height: *mut libc::c_int,
-        user_data: glib_sys::gpointer,
-    ),
->;
-
-pub struct SizeCallback {
-    pub size_func: RsvgSizeFunc,
-    pub user_data: glib_sys::gpointer,
-    pub destroy_notify: glib_sys::GDestroyNotify,
-    pub in_loop: Cell<bool>,
-}
-
-impl SizeCallback {
-    pub fn new(
-        size_func: RsvgSizeFunc,
-        user_data: glib_sys::gpointer,
-        destroy_notify: glib_sys::GDestroyNotify,
-    ) -> Self {
-        SizeCallback {
-            size_func,
-            user_data,
-            destroy_notify,
-            in_loop: Cell::new(false),
-        }
-    }
-
-    pub fn call(&self, width: libc::c_int, height: libc::c_int) -> (libc::c_int, libc::c_int) {
-        unsafe {
-            let mut w = width;
-            let mut h = height;
-
-            if let Some(ref f) = self.size_func {
-                f(&mut w, &mut h, self.user_data);
-            };
-
-            (w, h)
-        }
-    }
-
-    pub fn start_loop(&self) {
-        assert!(!self.in_loop.get());
-        self.in_loop.set(true);
-    }
-
-    pub fn end_loop(&self) {
-        assert!(self.in_loop.get());
-        self.in_loop.set(false);
-    }
-
-    pub fn get_in_loop(&self) -> bool {
-        self.in_loop.get()
-    }
-}
-
-impl Default for SizeCallback {
-    fn default() -> SizeCallback {
-        SizeCallback {
-            size_func: None,
-            user_data: ptr::null_mut(),
-            destroy_notify: None,
-            in_loop: Cell::new(false),
-        }
-    }
-}
-
-impl Drop for SizeCallback {
-    fn drop(&mut self) {
-        unsafe {
-            if let Some(ref f) = self.destroy_notify {
-                f(self.user_data);
-            };
-        }
-    }
-}
-
 pub struct Handle {
     document: Document,
 }
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index fafbdc15..0b005705 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -53,7 +53,7 @@ pub use crate::dpi::{rsvg_rust_set_default_dpi_x_y, Dpi};
 
 pub use crate::error::{DefsLookupErrorKind, HrefError, LoadingError, RenderingError};
 
-pub use crate::handle::{Handle, LoadOptions, RsvgSizeFunc, SizeCallback};
+pub use crate::handle::{Handle, LoadOptions};
 
 pub use crate::length::{Length, LengthUnit, RsvgLength};
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]