1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
3
use glib:: translate:: * ;
4
+ use std:: { ffi:: c_char, ptr} ;
4
5
5
6
pub use crate :: auto:: functions:: * ;
6
7
#[ cfg( feature = "v1_44" ) ]
@@ -23,17 +24,17 @@ pub fn shape_full(
23
24
analysis : & Analysis ,
24
25
glyphs : & mut GlyphString ,
25
26
) {
26
- let paragraph_length = match paragraph_text {
27
- Some ( s) => s. len ( ) ,
28
- None => 0 ,
29
- } as i32 ;
30
- let paragraph_text = paragraph_text. to_glib_none ( ) ;
31
27
let item_length = item_text. len ( ) as i32 ;
28
+ let paragraph_length = paragraph_text. map ( |t| t. len ( ) as i32 ) . unwrap_or_default ( ) ;
29
+ let paragraph_ptr = paragraph_text. map_or ( ptr:: null ( ) , |t| t. as_ptr ( ) as * const c_char ) ;
32
30
unsafe {
31
+ // The function does not take null-terminated strings when a length is provided.
32
+ // It also requires item_text to point to a subsequence of paragraph_text.
33
+ // Using to_glib_none() on &str will copy the string and cause problems.
33
34
ffi:: pango_shape_full (
34
- item_text. to_glib_none ( ) . 0 ,
35
+ item_text. as_ptr ( ) as * const c_char ,
35
36
item_length,
36
- paragraph_text . 0 ,
37
+ paragraph_ptr ,
37
38
paragraph_length,
38
39
analysis. to_glib_none ( ) . 0 ,
39
40
glyphs. to_glib_none_mut ( ) . 0 ,
@@ -53,11 +54,13 @@ pub fn shape_with_flags(
53
54
) {
54
55
let item_length = item_text. len ( ) as i32 ;
55
56
let paragraph_length = paragraph_text. map ( |t| t. len ( ) as i32 ) . unwrap_or_default ( ) ;
57
+ let paragraph_ptr = paragraph_text. map_or ( ptr:: null ( ) , |t| t. as_ptr ( ) as * const c_char ) ;
56
58
unsafe {
59
+ // See: shape_full
57
60
ffi:: pango_shape_with_flags (
58
- item_text. to_glib_none ( ) . 0 ,
61
+ item_text. as_ptr ( ) as * const c_char ,
59
62
item_length,
60
- paragraph_text . to_glib_none ( ) . 0 ,
63
+ paragraph_ptr ,
61
64
paragraph_length,
62
65
analysis. to_glib_none ( ) . 0 ,
63
66
glyphs. to_glib_none_mut ( ) . 0 ,
0 commit comments