diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2021-08-26 09:18:58 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2021-08-26 09:44:43 +0300 |
commit | 4a870af19ce3cbaef63c3d21c29467e05504e81b (patch) | |
tree | 6d8958e3dfad6efe65609ad2036f11ac657de552 /text/wrap | |
parent | a8a3a6ec3eaeac2c3a15c7a5db3dd440ff16d3d2 (diff) |
Update various dependencies
Diffstat (limited to 'text/wrap')
-rw-r--r-- | text/wrap/Cargo.toml | 2 | ||||
-rw-r--r-- | text/wrap/src/gsttextwrap/imp.rs | 42 |
2 files changed, 36 insertions, 8 deletions
diff --git a/text/wrap/Cargo.toml b/text/wrap/Cargo.toml index 303f4a850..0e6a7ef11 100644 --- a/text/wrap/Cargo.toml +++ b/text/wrap/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs" [dependencies] once_cell = "1.0" -textwrap = { version = "0.13.2", features = ["hyphenation"] } +textwrap = { version = "0.14", features = ["hyphenation"] } hyphenation = "0.8" [dependencies.gst] diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 293c884bf..7fef1f067 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -62,8 +62,36 @@ 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, Box<dyn textwrap::WordSplitter + Send>>>, + options: Option< + textwrap::Options< + 'static, + textwrap::wrap_algorithms::OptimalFit, + textwrap::word_separators::UnicodeBreakProperties, + WrappedWordSplitter, + >, + >, current_text: String, start_ts: Option<gst::ClockTime>, @@ -125,14 +153,14 @@ impl TextWrap { Ok(standard) => standard, }; - Some(textwrap::Options::with_splitter( + Some(textwrap::Options::with_word_splitter( settings.columns as usize, - Box::new(standard), + WrappedWordSplitter(Box::new(standard)), )) } else { - Some(textwrap::Options::with_splitter( + Some(textwrap::Options::with_word_splitter( settings.columns as usize, - Box::new(textwrap::NoHyphenation), + WrappedWordSplitter(Box::new(textwrap::word_splitters::NoHyphenation)), )) }; } @@ -221,7 +249,7 @@ impl TextWrap { .as_ref() .expect("We should have a wrapper by now"); - let lines = textwrap::wrap(¤t_text, options); + let lines = textwrap::wrap(¤t_text, &*options); let mut chunks = lines.chunks(n_lines as usize).peekable(); let mut trailing = "".to_string(); @@ -287,7 +315,7 @@ impl TextWrap { .options .as_ref() .expect("We should have a wrapper by now"); - textwrap::fill(data, options) + textwrap::fill(data, &*options) }; // If the lines property was set, we want to split the result into buffers |