[librsvg] Bind state::get_font_decor() to Rust



commit 862a44eda862915e38472e87f96509c97b252481
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 15 11:33:01 2017 -0600

    Bind state::get_font_decor() to Rust

 rsvg-styles.h     |  1 +
 rust/src/state.rs | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
---
diff --git a/rsvg-styles.h b/rsvg-styles.h
index aede7da..aef6a5f 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -36,6 +36,7 @@
 
 G_BEGIN_DECLS 
 
+/* Keep in sync with rust/src/state.rs:TextDecoration */
 typedef struct {
     gboolean overline;
     gboolean underline;
diff --git a/rust/src/state.rs b/rust/src/state.rs
index 8c88f82..0a5a944 100644
--- a/rust/src/state.rs
+++ b/rust/src/state.rs
@@ -1,5 +1,6 @@
 use libc;
 use glib::translate::*;
+use glib_sys;
 use pango;
 use pango_sys;
 
@@ -15,6 +16,31 @@ pub enum UnicodeBidi {
     Override,
 }
 
+// Keep in sync with rsvg-styles.h:TextDecoration
+#[repr(C)]
+#[derive(Copy, Clone)]
+struct TextDecoration {
+    overline:  glib_sys::gboolean,
+    underline: glib_sys::gboolean,
+    strike:    glib_sys::gboolean
+}
+
+pub struct FontDecor {
+    pub overline:  bool,
+    pub underline: bool,
+    pub strike:    bool,
+}
+
+impl From<TextDecoration> for FontDecor {
+    fn from(td: TextDecoration) -> FontDecor {
+        FontDecor {
+            overline:  from_glib(td.overline),
+            underline: from_glib(td.underline),
+            strike:    from_glib(td.strike),
+        }
+    }
+}
+
 extern "C" {
     fn rsvg_state_get_language       (state: *const RsvgState) -> *const libc::c_char;
     fn rsvg_state_get_unicode_bidi   (state: *const RsvgState) -> UnicodeBidi;
@@ -26,6 +52,7 @@ extern "C" {
     fn rsvg_state_get_font_weight    (state: *const RsvgState) -> pango_sys::PangoWeight;
     fn rsvg_state_get_font_stretch   (state: *const RsvgState) -> pango_sys::PangoStretch;
     fn rsvg_state_get_letter_spacing (state: *const RsvgState) -> RsvgLength;
+    fn rsvg_state_get_font_decor     (state: *const RsvgState) -> *const TextDecoration;
 }
 
 pub fn get_language(state: *const RsvgState) -> Option<String> {
@@ -69,3 +96,14 @@ pub fn get_font_stretch(state: *const RsvgState) -> pango::Stretch {
 pub fn get_letter_spacing(state: *const RsvgState) -> RsvgLength {
     unsafe { rsvg_state_get_letter_spacing(state) }
 }
+
+pub fn get_font_decor(state: *const RsvgState) -> Option<FontDecor> {
+    unsafe {
+        let td = rsvg_state_get_font_decor(state);
+        if td.is_null() {
+            None
+        } else {
+            Some(FontDecor::from(*td))
+        }
+    }
+}


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