diff --git a/text/wrap/Cargo.toml b/text/wrap/Cargo.toml index 929f14a7..95fc0e01 100644 --- a/text/wrap/Cargo.toml +++ b/text/wrap/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs" [dependencies] once_cell = "1.0" -textwrap = { version = "0.14", features = ["hyphenation"] } +textwrap = { version = "0.15", features = ["hyphenation"] } hyphenation = "0.8" [dependencies.gst] diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 32ab807b..8ea8221e 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -53,36 +53,8 @@ impl Default for Settings { } } -// FIXME: https://github.com/mgeisler/textwrap/issues/412 -#[derive(Debug)] -struct WrappedWordSplitter(Box); - -impl textwrap::word_splitters::WordSplitter for WrappedWordSplitter { - fn split_points(&self, word: &str) -> Vec { - self.0.split_points(word) - } -} - -impl Clone for WrappedWordSplitter { - fn clone(&self) -> Self { - WrappedWordSplitter(unsafe { - std::mem::transmute::< - Box, - Box, - >(self.0.clone_box()) - }) - } -} - struct State { - options: Option< - textwrap::Options< - 'static, - textwrap::wrap_algorithms::OptimalFit, - textwrap::word_separators::UnicodeBreakProperties, - WrappedWordSplitter, - >, - >, + options: Option>, current_text: String, start_ts: Option, @@ -121,7 +93,9 @@ impl TextWrap { return; } - state.options = if let Some(dictionary) = &settings.dictionary { + let mut options = textwrap::Options::new(settings.columns as usize); + + if let Some(dictionary) = &settings.dictionary { let dict_file = match File::open(dictionary) { Err(err) => { gst_error!(CAT, obj: element, "Failed to open dictionary file: {}", err); @@ -144,16 +118,12 @@ impl TextWrap { Ok(standard) => standard, }; - Some(textwrap::Options::with_word_splitter( - settings.columns as usize, - WrappedWordSplitter(Box::new(standard)), - )) + options.word_splitter = textwrap::WordSplitter::Hyphenation(standard); } else { - Some(textwrap::Options::with_word_splitter( - settings.columns as usize, - WrappedWordSplitter(Box::new(textwrap::word_splitters::NoHyphenation)), - )) - }; + options.word_splitter = textwrap::WordSplitter::NoHyphenation; + } + + state.options = Some(options); } fn sink_chain(