[librsvg] aspect_ratio.rs: New function for the C code, rsvg_aspect_ratio_parse()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] aspect_ratio.rs: New function for the C code, rsvg_aspect_ratio_parse()
- Date: Thu, 2 Feb 2017 04:00:44 +0000 (UTC)
commit 0cde6ad587116931d6039936b42e893a9322d5b1
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 1 14:33:17 2017 -0600
aspect_ratio.rs: New function for the C code, rsvg_aspect_ratio_parse()
rust/src/aspect_ratio.rs | 29 +++++++++++++++++++++++++++++
rust/src/lib.rs | 1 +
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/aspect_ratio.rs b/rust/src/aspect_ratio.rs
index 33d52f0..5f8f5a8 100644
--- a/rust/src/aspect_ratio.rs
+++ b/rust/src/aspect_ratio.rs
@@ -15,6 +15,10 @@
//! [`AspectRatio`]: struct.AspectRatio.html
//! [spec]: https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
+extern crate libc;
+extern crate glib;
+
+use self::glib::translate::*;
use std::fmt;
use std::str::FromStr;
@@ -62,6 +66,15 @@ impl Default for Align {
}
}
+impl Default for AspectRatio {
+ fn default () -> AspectRatio {
+ AspectRatio {
+ defer: false,
+ align: Default::default ()
+ }
+ }
+}
+
bitflags! {
flags AspectRatioFlags: u32 {
const XMIN_YMIN = (1 << 0),
@@ -259,6 +272,22 @@ impl fmt::Display for ParseAspectRatioError {
}
}
+#[no_mangle]
+pub extern fn rsvg_aspect_ratio_parse (c_str: *const libc::c_char) -> u32 {
+ let my_str = unsafe { &String::from_glib_none (c_str) };
+ let parsed = AspectRatio::from_str (my_str);
+
+ match parsed {
+ Ok (aspect_ratio) => { aspect_ratio_to_u32 (aspect_ratio) },
+ Err (_) => {
+ // We can't propagate the error here, so just return a default value
+ let a: AspectRatio = Default::default ();
+ aspect_ratio_to_u32 (a)
+ }
+ }
+}
+
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 32da440..e643d81 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -7,6 +7,7 @@ pub use aspect_ratio::{
Align,
AspectRatio,
ParseAspectRatioError,
+ rsvg_aspect_ratio_parse
};
pub use bbox::{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]