Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions pango/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;
use std::{ffi::c_char, ptr};

pub use crate::auto::functions::*;
#[cfg(feature = "v1_44")]
Expand All @@ -23,17 +24,17 @@ pub fn shape_full(
analysis: &Analysis,
glyphs: &mut GlyphString,
) {
let paragraph_length = match paragraph_text {
Some(s) => s.len(),
None => 0,
} as i32;
let paragraph_text = paragraph_text.to_glib_none();
let item_length = item_text.len() as i32;
let paragraph_length = paragraph_text.map(|t| t.len() as i32).unwrap_or_default();
let paragraph_ptr = paragraph_text.map_or(ptr::null(), |t| t.as_ptr() as *const c_char);
unsafe {
// The function does not take null-terminated strings when a length is provided.
// It also requires item_text to point to a subsequence of paragraph_text.
// Using to_glib_none() on &str will copy the string and cause problems.
ffi::pango_shape_full(
item_text.to_glib_none().0,
item_text.as_ptr() as *const c_char,
item_length,
paragraph_text.0,
paragraph_ptr,
paragraph_length,
analysis.to_glib_none().0,
glyphs.to_glib_none_mut().0,
Expand All @@ -53,11 +54,13 @@ pub fn shape_with_flags(
) {
let item_length = item_text.len() as i32;
let paragraph_length = paragraph_text.map(|t| t.len() as i32).unwrap_or_default();
let paragraph_ptr = paragraph_text.map_or(ptr::null(), |t| t.as_ptr() as *const c_char);
unsafe {
// See: shape_full
ffi::pango_shape_with_flags(
item_text.to_glib_none().0,
item_text.as_ptr() as *const c_char,
item_length,
paragraph_text.to_glib_none().0,
paragraph_ptr,
paragraph_length,
analysis.to_glib_none().0,
glyphs.to_glib_none_mut().0,
Expand Down
Loading