Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/text
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2022-02-27 12:00:30 +0300
committerSebastian Dröge <sebastian@centricular.com>2022-02-28 10:05:07 +0300
commit2a4f9fbd5400e189da0047e6e63229e440990d03 (patch)
treedc5c5bc538d8b89bbc203703f61899c7ea9f509f /text
parentde2ea8a1b20d451d93ae15637c14b4afe55a1270 (diff)
textwrap: Update for textwrap 0.15 API changes
Diffstat (limited to 'text')
-rw-r--r--text/wrap/Cargo.toml2
-rw-r--r--text/wrap/src/gsttextwrap/imp.rs48
2 files changed, 10 insertions, 40 deletions
diff --git a/text/wrap/Cargo.toml b/text/wrap/Cargo.toml
index 5c5271571..8e33d9410 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 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(