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