diff --git a/src/analysis.rs b/src/analysis.rs index 68149dd..38507b7 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -49,9 +49,7 @@ impl Analysis { } pub fn extra_attrs(&self) -> Vec { - unsafe { - FromGlibPtrContainer::from_glib_none(self.0.extra_attrs) - } + unsafe { FromGlibPtrContainer::from_glib_none(self.0.extra_attrs) } } } diff --git a/src/attr_class.rs b/src/attr_class.rs index 3ef3188..a54ef54 100644 --- a/src/attr_class.rs +++ b/src/attr_class.rs @@ -2,10 +2,10 @@ // See the COPYRIGHT file at the top-level directory of this distribution. // Licensed under the MIT license, see the LICENSE file or -use AttrType; use glib::translate::from_glib; use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, Stash, ToGlibPtr}; use pango_sys; +use AttrType; #[doc(hidden)] impl<'a> ToGlibPtr<'a, *mut pango_sys::PangoAttrClass> for &'a AttrClass { diff --git a/src/attr_color.rs b/src/attr_color.rs deleted file mode 100644 index 650c885..0000000 --- a/src/attr_color.rs +++ /dev/null @@ -1,76 +0,0 @@ -use glib::translate::from_glib_none; -use glib::translate::from_glib_full; -use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, Stash, ToGlibPtr}; -use pango_sys; -use Attribute; -use Color; - -#[doc(hidden)] -impl<'a> ToGlibPtr<'a, *mut pango_sys::PangoAttrColor> for &'a AttrColor { - type Storage = &'a AttrColor; - - fn to_glib_none(&self) -> Stash<'a, *mut pango_sys::PangoAttrColor, Self> { - Stash(self.0, *self) - } -} - -#[doc(hidden)] -impl FromGlibPtrNone<*mut pango_sys::PangoAttrColor> for AttrColor { - unsafe fn from_glib_none(ptr: *mut pango_sys::PangoAttrColor) -> Self { - assert!(!ptr.is_null()); - AttrColor(ptr) - } -} - -#[doc(hidden)] -impl FromGlibPtrFull<*mut pango_sys::PangoAttrColor> for AttrColor { - unsafe fn from_glib_full(ptr: *mut pango_sys::PangoAttrColor) -> Self { - assert!(!ptr.is_null()); - AttrColor(ptr) - } -} - -#[doc(hidden)] -impl FromGlibPtrNone<*const pango_sys::PangoAttrColor> for AttrColor { - unsafe fn from_glib_none(ptr: *const pango_sys::PangoAttrColor) -> Self { - assert!(!ptr.is_null()); - AttrColor(ptr as *mut _) - } -} - -#[doc(hidden)] -impl FromGlibPtrFull<*const pango_sys::PangoAttrColor> for AttrColor { - unsafe fn from_glib_full(ptr: *const pango_sys::PangoAttrColor) -> Self { - assert!(!ptr.is_null()); - AttrColor(ptr as *mut _) - } -} - -#[derive(Debug)] -pub struct AttrColor(*mut pango_sys::PangoAttrColor); - -impl AttrColor { - pub fn get_color(&self) -> Color { - unsafe { - let color: *const pango_sys::PangoColor = &(*self.0).color; - from_glib_none(color) - } - } -} - -impl From for AttrColor { - fn from(attribute: Attribute) -> Self { - unsafe { - let attr_color = std::mem::transmute::<*const pango_sys::PangoAttribute, *const pango_sys::PangoAttrColor>(attribute.to_glib_none().0); - from_glib_full(attr_color) - } - } -} - -impl PartialEq for AttrColor { - fn eq(&self, other: &AttrColor) -> bool { - self.0 == other.0 - } -} - -impl Eq for AttrColor {} diff --git a/src/attribute.rs b/src/attribute.rs index 92f2c18..da095a5 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -1,19 +1,23 @@ // Copyright 2017, The Gtk-rs Project Developers. // See the COPYRIGHT file at the top-level directory of this distribution. -// Licensed under the MIT license, see the LICENSE file or +// Licensed under the MIT license, see the LICENSE file or -use glib::translate::*; -use pango_sys; use AttrClass; use Attribute; +use FontDescription; use Gravity; use GravityHint; +use Language; +use Rectangle; use Stretch; use Style; use Underline; -use Variant; use Weight; +use glib::translate::from_glib_full; +use glib::translate::ToGlib; +use glib::translate::ToGlibPtr; + impl Attribute { #[cfg(any(feature = "v1_38", feature = "dox"))] pub fn new_background_alpha(alpha: u16) -> Option { @@ -32,10 +36,54 @@ impl Attribute { } } + // TODO: available at 1.44 + // pub fn new_allow_breaks(allow_breaks: bool) -> Option { + // unsafe { + // from_glib_full(pango_sys::pango_attr_allow_breaks_new( + // allow_breaks.to_glib(), + // )) + // } + // } + + // TODO: available at 1.44 + // pub fn new_insert_hyphens(insert_hyphens: bool) -> Option { + // unsafe { + // from_glib_full(pango_sys::pango_attr_insert_hyphens_new( + // insert_hyphens.to_glib(), + // )) + // } + // } + + // TODO: available at 1.44, needs PangoShowFlags + // pub fn new_show(flags: PangoShowFlags) -> Option { + // unsafe { + // from_glib_full(pango_sys::pango_attr_show_new( + // flags.to_glib(), + // )) + // } + // } + + pub fn new_language(language: &Language) -> Option { + unsafe { + from_glib_full(pango_sys::pango_attr_language_new( + language.to_glib_none().0, + )) + } + } + pub fn new_family(family: &str) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_family_new(family.to_glib_none().0)) } } + #[cfg(any(feature = "v1_38", feature = "dox"))] + pub fn new_font_features(features: &str) -> Option { + unsafe { + from_glib_full(pango_sys::pango_attr_font_features_new( + features.to_glib_none().0, + )) + } + } + #[cfg(any(feature = "v1_38", feature = "dox"))] pub fn new_foreground_alpha(alpha: u16) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_foreground_alpha_new(alpha)) } @@ -61,18 +109,34 @@ impl Attribute { unsafe { from_glib_full(pango_sys::pango_attr_rise_new(rise)) } } - pub fn new_scale(scale_factor: f64) -> Option { - unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) } - } - pub fn new_size(size: i32) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_size_new(size)) } } - pub fn new_size_absolute(size: i32) -> Option { + pub fn new_absolute_size(size: i32) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_size_new_absolute(size)) } } + pub fn new_font_desc(desc: &FontDescription) -> Option { + unsafe { from_glib_full(pango_sys::pango_attr_font_desc_new(desc.to_glib_none().0)) } + } + + pub fn new_shape( + ink_rect: &Rectangle, + logical_rect: &Rectangle, + ) -> Option { + unsafe { + from_glib_full(pango_sys::pango_attr_shape_new( + ink_rect.to_glib_none().0, + logical_rect.to_glib_none().0, + )) + } + } + + pub fn new_scale(scale_factor: f64) -> Option { + unsafe { from_glib_full(pango_sys::pango_attr_scale_new(scale_factor)) } + } + pub fn new_stretch(stretch: Stretch) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_stretch_new(stretch.to_glib())) } } @@ -105,9 +169,9 @@ impl Attribute { unsafe { from_glib_full(pango_sys::pango_attr_underline_new(underline.to_glib())) } } - pub fn new_variant(variant: Variant) -> Option { + /*pub fn attr_variant_new(variant: Variant) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_variant_new(variant.to_glib())) } - } + }*/ pub fn new_weight(weight: Weight) -> Option { unsafe { from_glib_full(pango_sys::pango_attr_weight_new(weight.to_glib())) } @@ -117,31 +181,31 @@ impl Attribute { unsafe { from_glib_full((*self.to_glib_none().0).klass) } } - pub fn get_start_index(&self) -> u32 { + pub fn get_end_index(&self) -> u32 { unsafe { let stash = self.to_glib_none(); - (*stash.0).start_index + (*stash.0).end_index } } - pub fn get_end_index(&self) -> u32 { + pub fn set_end_index(&mut self, index: u32) { unsafe { - let stash = self.to_glib_none(); - (*stash.0).end_index + let stash = self.to_glib_none_mut(); + (*stash.0).end_index = index; } } - pub fn set_start_index(&mut self, index: u32) { + pub fn get_start_index(&self) -> u32 { unsafe { - let stash = self.to_glib_none_mut(); - (*stash.0).start_index = index; + let stash = self.to_glib_none(); + (*stash.0).start_index } } - pub fn set_end_index(&mut self, index: u32) { + pub fn set_start_index(&mut self, index: u32) { unsafe { let stash = self.to_glib_none_mut(); - (*stash.0).end_index = index; + (*stash.0).start_index = index; } } } diff --git a/src/lib.rs b/src/lib.rs index 145449b..546439e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,8 +31,6 @@ pub mod analysis; pub use analysis::Analysis; pub mod attr_class; pub use attr_class::AttrClass; -pub mod attr_color; -pub use attr_color::AttrColor; pub mod attr_iterator; pub mod attr_list; pub mod attribute;