[librsvg] bbox.rs: Use glib_sys::gboolean, not bool for repr(C) structs



commit 35042a16f2de1b8c146580e8d3741e4d58f0811f
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 26 15:37:04 2017 -0500

    bbox.rs: Use glib_sys::gboolean, not bool for repr(C) structs

 rust/Cargo.lock       |    1 +
 rust/Cargo.toml       |    4 +++
 rust/src/bbox.rs      |   29 +++++++++++++++--------
 rust/src/marker.rs    |    6 ++--
 rust/src/pattern.rs   |    2 +-
 rust/src/structure.rs |    2 +-
 rust/src/viewbox.rs   |   59 +++++++++++++++++++++++++++++--------------------
 7 files changed, 64 insertions(+), 39 deletions(-)
---
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index d9b1aa7..d8f2c30 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -7,6 +7,7 @@ dependencies = [
  "cairo-sys-rs 0.3.2 (git+https://github.com/federicomenaquintero/cairo.git)",
  "downcast-rs 1.0.0 (git+https://github.com/marcianx/downcast-rs)",
  "glib 0.1.1 (git+https://github.com/gtk-rs/glib)",
+ "glib-sys 0.3.2 (git+https://github.com/gtk-rs/sys)",
  "lalrpop 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "lalrpop-util 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index bb85a74..8a548f3 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -26,6 +26,10 @@ git = "https://github.com/federicomenaquintero/cairo.git";
 git = "https://github.com/gtk-rs/glib";
 version = "0.1.1"
 
+[dependencies.glib-sys]
+git = "https://github.com/gtk-rs/sys";
+version = "0.3.2"
+
 [dependencies.nom]
 #git = "https://github.com/Geal/nom";
 git = "https://github.com/federicomenaquintero/nom.git";
diff --git a/rust/src/bbox.rs b/rust/src/bbox.rs
index 75a0e55..cc5dccb 100644
--- a/rust/src/bbox.rs
+++ b/rust/src/bbox.rs
@@ -1,13 +1,22 @@
 extern crate cairo;
+extern crate glib_sys;
+extern crate glib;
 
 use self::cairo::MatrixTrait;
+use self::glib::translate::*;
 
 /* Keep this in sync with ../../rsvg-private.h:RsvgBbox */
 #[repr(C)]
 pub struct RsvgBbox {
     pub rect:   cairo::Rectangle,
     pub affine: cairo::Matrix,
-    pub virgin: bool
+    virgin:     glib_sys::gboolean
+}
+
+impl RsvgBbox {
+    pub fn is_virgin (&self) -> bool {
+        from_glib (self.virgin)
+    }
 }
 
 #[no_mangle]
@@ -17,7 +26,7 @@ pub extern fn rsvg_bbox_init (raw_bbox: *mut RsvgBbox, raw_matrix: *const cairo:
 
     let bbox: &mut RsvgBbox = unsafe { &mut (*raw_bbox) };
 
-    bbox.virgin = true;
+    bbox.virgin = true.to_glib ();
     bbox.affine = unsafe { *raw_matrix };
 }
 
@@ -29,7 +38,7 @@ pub extern fn rsvg_bbox_insert (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox
     let dst: &mut RsvgBbox = unsafe { &mut (*raw_dst) };
     let src: &RsvgBbox = unsafe { &*raw_src };
 
-    if src.virgin {
+    if src.is_virgin () {
         return;
     }
 
@@ -38,7 +47,7 @@ pub extern fn rsvg_bbox_insert (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox
     let mut xmax: f64;
     let mut ymax: f64;
 
-    if !dst.virgin {
+    if !dst.is_virgin () {
         xmin = dst.rect.x;
         ymin = dst.rect.y;
         xmax = dst.rect.x + dst.rect.width;
@@ -68,12 +77,12 @@ pub extern fn rsvg_bbox_insert (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox
         let x: f64  = affine.xx * rx + affine.xy * ry + affine.x0;
         let y: f64  = affine.yx * rx + affine.yy * ry + affine.y0;
 
-        if dst.virgin {
+        if dst.is_virgin () {
             xmin = x;
             xmax = x;
             ymin = y;
             ymax = y;
-            dst.virgin = false;
+            dst.virgin = false.to_glib ();
         } else {
             if x < xmin { xmin = x; }
             if x > xmax { xmax = x; }
@@ -96,7 +105,7 @@ pub extern fn rsvg_bbox_clip (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox)
     let dst: &mut RsvgBbox = unsafe { &mut (*raw_dst) };
     let src: &RsvgBbox = unsafe { &*raw_src };
 
-    if src.virgin {
+    if src.is_virgin () {
         return;
     }
 
@@ -105,7 +114,7 @@ pub extern fn rsvg_bbox_clip (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox)
     let mut xmax: f64;
     let mut ymax: f64;
 
-    if !dst.virgin {
+    if !dst.is_virgin () {
         xmin = dst.rect.x + dst.rect.width;
         ymin = dst.rect.y + dst.rect.height;
         xmax = dst.rect.x;
@@ -129,12 +138,12 @@ pub extern fn rsvg_bbox_clip (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox)
         let x = affine.xx * rx + affine.xy * ry + affine.x0;
         let y = affine.yx * rx + affine.yy * ry + affine.y0;
 
-        if dst.virgin {
+        if dst.is_virgin () {
             xmin = x;
             xmax = x;
             ymin = y;
             ymax = y;
-            dst.virgin = false;
+            dst.virgin = false.to_glib ();
         } else {
             if x < xmin { xmin = x; }
             if x > xmax { xmax = x; }
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 48a282a..728208f 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -141,7 +141,7 @@ impl NodeMarker {
 
         let vbox = self.vbox.get ();
 
-        if vbox.active {
+        if vbox.is_active () {
             let (_, _, w, h) = self.aspect.get ().compute (vbox.rect.width, vbox.rect.height,
                                                            0.0, 0.0,
                                                            marker_width, marker_height);
@@ -167,7 +167,7 @@ impl NodeMarker {
         let state = drawing_ctx::get_current_state (draw_ctx);
 
         if !drawing_ctx::state_is_overflow (state) {
-            if vbox.active {
+            if vbox.is_active () {
                 drawing_ctx::add_clipping_rect (draw_ctx,
                                                 vbox.rect.x,
                                                 vbox.rect.y,
@@ -188,7 +188,7 @@ impl NodeMarker {
 
         drawing_ctx::state_pop (draw_ctx);
 
-        if vbox.active {
+        if vbox.is_active () {
             drawing_ctx::pop_view_box (draw_ctx);
         }
     }
diff --git a/rust/src/pattern.rs b/rust/src/pattern.rs
index 1780aeb..a10b8cc 100644
--- a/rust/src/pattern.rs
+++ b/rust/src/pattern.rs
@@ -343,7 +343,7 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
     let pushed_view_box: bool;
 
     // Create the pattern contents coordinate system
-    if vbox.active {
+    if vbox.is_active () {
         // If there is a vbox, use that
         let (mut x, mut y, w, h) = preserve_aspect_ratio.compute (vbox.rect.width,
                                                                   vbox.rect.height,
diff --git a/rust/src/structure.rs b/rust/src/structure.rs
index 64d9d8e..83a13ef 100644
--- a/rust/src/structure.rs
+++ b/rust/src/structure.rs
@@ -197,7 +197,7 @@ impl NodeTrait for NodeSvg {
 
         let vbox = self.vbox.get ();
 
-        if vbox.active {
+        if vbox.is_active () {
             // viewBox width==0 or height==0 disables rendering of the element
             // https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
             if double_equals (vbox.rect.width, 0.0) || double_equals (vbox.rect.height, 0.0) {
diff --git a/rust/src/viewbox.rs b/rust/src/viewbox.rs
index f25bb4c..798ccce 100644
--- a/rust/src/viewbox.rs
+++ b/rust/src/viewbox.rs
@@ -1,4 +1,5 @@
 extern crate cairo;
+extern crate glib_sys;
 extern crate glib;
 
 use std::str::FromStr;
@@ -7,26 +8,36 @@ use error::*;
 use parsers::ParseError;
 use parsers;
 
-use glib::translate::*;
+use self::glib::translate::*;
 
 /* Keep this in sync with rsvg-private.h:RsvgViewBox */
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq)]
 pub struct RsvgViewBox {
-    pub rect:   cairo::Rectangle,
-    pub active: glib::ffi::gboolean
+    pub rect: cairo::Rectangle,
+    active:   glib_sys::gboolean
 }
 
 impl RsvgViewBox {
-    pub fn new_inactive () -> RsvgViewBox {
+    pub fn new (rect: cairo::Rectangle,
+                active: bool) -> RsvgViewBox {
         RsvgViewBox {
-            rect: cairo::Rectangle { x: 0.0,
-                                     y: 0.0,
-                                     width: 0.0,
-                                     height: 0.0 },
-            active: false
+            rect: rect,
+            active: active.to_glib ()
         }
     }
+
+    pub fn new_inactive () -> RsvgViewBox {
+        RsvgViewBox::new (cairo::Rectangle { x: 0.0,
+                                             y: 0.0,
+                                             width: 0.0,
+                                             height: 0.0 },
+                          false)
+    }
+
+    pub fn is_active (&self) -> bool {
+        from_glib (self.active)
+    }
 }
 
 impl Default for RsvgViewBox {
@@ -44,11 +55,11 @@ impl FromStr for RsvgViewBox {
         match result {
             Ok ((x, y, w, h)) => {
                 if w >= 0.0 && h >= 0.0 {
-                    Ok (RsvgViewBox { rect: cairo::Rectangle { x: x,
-                                                               y: y,
-                                                               width: w,
-                                                               height: h },
-                                      active: true })
+                    Ok (RsvgViewBox::new (cairo::Rectangle { x: x,
+                                                             y: y,
+                                                             width: w,
+                                                             height: h },
+                                          true))
                 } else {
                     Err (AttributeError::Value ("width and height must not be negative".to_string ()))
                 }
@@ -69,18 +80,18 @@ mod tests {
     #[test]
     fn parses_valid_viewboxes () {
         assert_eq! (RsvgViewBox::from_str ("  1 2 3 4"),
-                    Ok (RsvgViewBox { rect: cairo::Rectangle { x: 1.0,
-                                                               y: 2.0,
-                                                               width: 3.0,
-                                                               height: 4.0 },
-                                      active: true }));
+                    Ok (RsvgViewBox::new (cairo::Rectangle { x: 1.0,
+                                                             y: 2.0,
+                                                             width: 3.0,
+                                                             height: 4.0 },
+                                          true)));
 
         assert_eq! (RsvgViewBox::from_str (" -1.5 -2.5e1,34,56e2  "),
-                    Ok (RsvgViewBox { rect: cairo::Rectangle { x: -1.5,
-                                                               y: -25.0,
-                                                               width: 34.0,
-                                                               height: 5600.0 },
-                                      active: true }));
+                    Ok (RsvgViewBox::new (cairo::Rectangle { x: -1.5,
+                                                             y: -25.0,
+                                                             width: 34.0,
+                                                             height: 5600.0 },
+                                          true)));
     }
 
     #[test]


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