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

parent 28227ae6
......@@ -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)",
......
......@@ -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"
......
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; }
......
......@@ -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);
}
}
......
......@@ -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,
......
......@@ -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) {
......
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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment