From 2e12368c218d1672c5704d235fc0765d8720dc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 29 Oct 2021 01:15:43 +0300 Subject: [PATCH] pango: Implement GlyphItemIter constructors Fixes https://github.com/gtk-rs/gtk-rs-core/issues/36 --- pango/Gir.toml | 9 ++++++- pango/src/auto/glyph_item_iter.rs | 23 ---------------- pango/src/glyph_item_iter.rs | 44 +++++++++++++++++++++++++++++++ pango/src/lib.rs | 1 + 4 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 pango/src/glyph_item_iter.rs diff --git a/pango/Gir.toml b/pango/Gir.toml index b5b0fd1cbab4..06f7937d4228 100644 --- a/pango/Gir.toml +++ b/pango/Gir.toml @@ -30,7 +30,6 @@ generate = [ "Pango.FontsetSimple", "Pango.Glyph", "Pango.GlyphItem", - "Pango.GlyphItemIter", "Pango.GlyphString", "Pango.GlyphUnit", "Pango.Gravity", @@ -237,6 +236,14 @@ status = "generate" name = "language" const = true +[[object]] +name = "Pango.GlyphItemIter" +status = "generate" + [[object.function]] + pattern = "init.*" + # converted to proper constructors + manual = true + [[object]] name = "Pango.Layout" status = "generate" diff --git a/pango/src/auto/glyph_item_iter.rs b/pango/src/auto/glyph_item_iter.rs index 93fa9620dfc4..b3c3a745f95a 100644 --- a/pango/src/auto/glyph_item_iter.rs +++ b/pango/src/auto/glyph_item_iter.rs @@ -2,7 +2,6 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT -use crate::GlyphItem; use glib::translate::*; glib::wrapper! { @@ -17,28 +16,6 @@ glib::wrapper! { } impl GlyphItemIter { - #[doc(alias = "pango_glyph_item_iter_init_end")] - pub fn init_end(&mut self, glyph_item: &mut GlyphItem, text: &str) -> bool { - unsafe { - from_glib(ffi::pango_glyph_item_iter_init_end( - self.to_glib_none_mut().0, - glyph_item.to_glib_none_mut().0, - text.to_glib_none().0, - )) - } - } - - #[doc(alias = "pango_glyph_item_iter_init_start")] - pub fn init_start(&mut self, glyph_item: &mut GlyphItem, text: &str) -> bool { - unsafe { - from_glib(ffi::pango_glyph_item_iter_init_start( - self.to_glib_none_mut().0, - glyph_item.to_glib_none_mut().0, - text.to_glib_none().0, - )) - } - } - #[doc(alias = "pango_glyph_item_iter_next_cluster")] pub fn next_cluster(&mut self) -> bool { unsafe { diff --git a/pango/src/glyph_item_iter.rs b/pango/src/glyph_item_iter.rs new file mode 100644 index 000000000000..029d6c3868d3 --- /dev/null +++ b/pango/src/glyph_item_iter.rs @@ -0,0 +1,44 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::GlyphItem; +use crate::GlyphItemIter; +use glib::translate::*; +use std::mem; + +impl GlyphItemIter { + #[doc(alias = "pango_glyph_item_iter_init_end")] + pub fn new_end(glyph_item: &GlyphItem, text: &str) -> Result { + unsafe { + let mut iter = mem::MaybeUninit::zeroed(); + let res: bool = from_glib(ffi::pango_glyph_item_iter_init_end( + iter.as_mut_ptr(), + mut_override(glyph_item.to_glib_none().0), + text.to_glib_none().0, + )); + + if res { + Ok(from_glib_none(&iter.assume_init() as *const _)) + } else { + Err(glib::bool_error!("Failed to create glyph item iter")) + } + } + } + + #[doc(alias = "pango_glyph_item_iter_init_start")] + pub fn new_start(glyph_item: &GlyphItem, text: &str) -> Result { + unsafe { + let mut iter = mem::MaybeUninit::zeroed(); + let res: bool = from_glib(ffi::pango_glyph_item_iter_init_start( + iter.as_mut_ptr(), + mut_override(glyph_item.to_glib_none().0), + text.to_glib_none().0, + )); + + if res { + Ok(from_glib_none(&iter.assume_init() as *const _)) + } else { + Err(glib::bool_error!("Failed to create glyph item iter")) + } + } + } +} diff --git a/pango/src/lib.rs b/pango/src/lib.rs index acae3521c5e2..6b13dc2ac5f4 100644 --- a/pango/src/lib.rs +++ b/pango/src/lib.rs @@ -84,6 +84,7 @@ pub use glyph_geometry::GlyphGeometry; mod glyph_info; pub use glyph_info::GlyphInfo; mod glyph_item; +mod glyph_item_iter; mod glyph_string; mod coverage;