diff options
Diffstat (limited to 'text/wrap/src/gsttextwrap/imp.rs')
-rw-r--r-- | text/wrap/src/gsttextwrap/imp.rs | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 7572f3ad9..7db233288 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -52,36 +52,8 @@ impl Default for Settings { } } -// FIXME: https://github.com/mgeisler/textwrap/issues/412 -#[derive(Debug)] -struct WrappedWordSplitter(Box<dyn textwrap::word_splitters::WordSplitter + Send>); - -impl textwrap::word_splitters::WordSplitter for WrappedWordSplitter { - fn split_points(&self, word: &str) -> Vec<usize> { - self.0.split_points(word) - } -} - -impl Clone for WrappedWordSplitter { - fn clone(&self) -> Self { - WrappedWordSplitter(unsafe { - std::mem::transmute::< - Box<dyn textwrap::word_splitters::WordSplitter + 'static>, - Box<dyn textwrap::word_splitters::WordSplitter + Send + 'static>, - >(self.0.clone_box()) - }) - } -} - struct State { - options: Option< - textwrap::Options< - 'static, - textwrap::wrap_algorithms::OptimalFit, - textwrap::word_separators::UnicodeBreakProperties, - WrappedWordSplitter, - >, - >, + options: Option<textwrap::Options<'static>>, current_text: String, start_ts: Option<gst::ClockTime>, @@ -120,7 +92,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); @@ -143,16 +117,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( |