Skip to content

Commit d4c9a6f

Browse files
committed
pango: Implement pango_shape() bindings manually and ignore pango_shape_item() for now
Fixes #1692
1 parent 53497a5 commit d4c9a6f

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

pango/Gir.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,17 @@ status = "generate"
112112
manual = true
113113
[[object.function]]
114114
name = "shape_with_flags"
115-
# ivanlid length computation on a Option<str>, it should fallback to 0.
115+
# invalid length computation on a Option<str>, it should fallback to 0.
116116
manual = true
117+
[[object.function]]
118+
name = "shape"
119+
# invalid length computation on Stash instead of str
120+
manual = true
121+
[[object.function]]
122+
name = "shape_item"
123+
# invalid length computation on Stash instead of str
124+
# Needs PangoLogAttr bindings
125+
ignore = true
117126

118127
[[object]]
119128
name = "Pango.Attribute"

pango/src/auto/functions.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// DO NOT EDIT
44

55
use crate::{
6-
ffi, Analysis, AttrIterator, AttrList, Context, Direction, GlyphString, Item, Stretch, Style,
7-
Variant, Weight,
6+
ffi, AttrIterator, AttrList, Context, Direction, Item, Stretch, Style, Variant, Weight,
87
};
98
use glib::translate::*;
109

@@ -245,28 +244,6 @@ pub fn quantize_line_geometry(thickness: &mut i32, position: &mut i32) {
245244
}
246245
}
247246

248-
#[doc(alias = "pango_shape")]
249-
pub fn shape(text: &str, analysis: &Analysis) -> GlyphString {
250-
let length = text.len() as _;
251-
unsafe {
252-
let mut glyphs = GlyphString::uninitialized();
253-
ffi::pango_shape(
254-
text.to_glib_none().0,
255-
length,
256-
analysis.to_glib_none().0,
257-
glyphs.to_glib_none_mut().0,
258-
);
259-
glyphs
260-
}
261-
}
262-
263-
//#[cfg(feature = "v1_50")]
264-
//#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
265-
//#[doc(alias = "pango_shape_item")]
266-
//pub fn shape_item(item: &mut Item, paragraph_text: Option<&str>, log_attrs: /*Ignored*/Option<&mut LogAttr>, flags: ShapeFlags) -> GlyphString {
267-
// unsafe { TODO: call ffi:pango_shape_item() }
268-
//}
269-
270247
//#[cfg(feature = "v1_44")]
271248
//#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
272249
//#[doc(alias = "pango_tailor_break")]

pango/src/functions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ pub fn shape_full(
4242
}
4343
}
4444

45+
#[doc(alias = "pango_shape")]
46+
pub fn shape(item_text: &str, analysis: &Analysis, glyphs: &mut GlyphString) {
47+
let item_length = item_text.len() as i32;
48+
unsafe {
49+
// The function does not take null-terminated strings when a length is provided.
50+
// Using to_glib_none() on &str will copy the string unnecessarily.
51+
ffi::pango_shape(
52+
item_text.as_ptr() as *const c_char,
53+
item_length,
54+
analysis.to_glib_none().0,
55+
glyphs.to_glib_none_mut().0,
56+
);
57+
}
58+
}
59+
4560
#[cfg(feature = "v1_44")]
4661
#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
4762
#[doc(alias = "pango_shape_with_flags")]

0 commit comments

Comments
 (0)