gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
293 stars 115 forks source link

[BUG] The function `pango::LayoutLine::x_ranges` return a malformed value #1563

Closed GrounzerLiu closed 3 weeks ago

GrounzerLiu commented 3 weeks ago

Bug description

Pango.LayoutLine.get_x_ranges The Pango documentation states that the length of the ranges is 2 * n_ranges.

    pub fn x_ranges(&self, start_index: i32, end_index: i32) -> Vec<i32> {
        unsafe {
            let mut ranges = std::ptr::null_mut();
            let mut n_ranges = std::mem::MaybeUninit::uninit();
            ffi::pango_layout_line_get_x_ranges(
                self.to_glib_none().0,
                start_index,
                end_index,
                &mut ranges,
                n_ranges.as_mut_ptr(),
            );
            FromGlibContainer::from_glib_full_num(ranges, n_ranges.assume_init() as _)
        }
    }

Here, FromGlibContainer::from_glib_full_num(ranges, n_ranges.assume_init() as _) should be FromGlibContainer::from_glib_full_num(ranges, (2 * n_ranges.assume_init()) as _).

sdroege commented 3 weeks ago

Thanks, see https://github.com/gtk-rs/gtk-rs-core/pull/1564