[librsvg: 1/2] Call cairo_has_current_point() by hand since cairo-rs-sys is buggy




commit c3015b072db1d15c9e9ea759d35ccd7f40b1696b
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Nov 5 12:54:01 2021 -0600

    Call cairo_has_current_point() by hand since cairo-rs-sys is buggy
    
    See https://github.com/gtk-rs/gtk-rs-core/issues/335
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/627>

 tests/src/api.rs | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/tests/src/api.rs b/tests/src/api.rs
index 4d099ba4d..6f219519d 100644
--- a/tests/src/api.rs
+++ b/tests/src/api.rs
@@ -1,4 +1,5 @@
 use cairo;
+use libc;
 use librsvg::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
 use librsvg::{CairoRenderer, RenderingError};
 
@@ -220,6 +221,20 @@ fn set_stylesheet() {
         .evaluate(&output_surf, "set_stylesheet");
 }
 
+fn has_current_point(cr: &cairo::Context) -> bool {
+    // https://github.com/gtk-rs/gtk-rs-core/issues/335
+    //
+    // cairo-rs-sys incorrectly declares cairo_bool_t as a repr(C)
+    // struct; it needs to be repr(transparent).  So, we'll call
+    // has_current_point by hand.
+
+    extern "C" {
+        fn cairo_has_current_point(cr: *mut cairo::ffi::cairo_t) -> libc::c_int;
+    }
+
+    unsafe { cairo_has_current_point(cr.to_raw_none()) != 0 }
+}
+
 // https://gitlab.gnome.org/GNOME/librsvg/-/issues/799
 #[test]
 fn text_doesnt_leave_points_in_current_path() {
@@ -237,7 +252,7 @@ fn text_doesnt_leave_points_in_current_path() {
     let output = cairo::ImageSurface::create(cairo::Format::ARgb32, 100, 100).unwrap();
     let cr = cairo::Context::new(&output).unwrap();
 
-    assert!(!cr.has_current_point().unwrap());
+    assert!(!has_current_point(&cr));
 
     let viewport = cairo::Rectangle {
         x: 0.0,
@@ -248,5 +263,5 @@ fn text_doesnt_leave_points_in_current_path() {
 
     renderer.render_document(&cr, &viewport).unwrap();
 
-    assert!(!cr.has_current_point().unwrap());
+    assert!(!has_current_point(&cr));
 }


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