mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 02:26:35 +00:00
textwrap: Update for textwrap 0.15 API changes
This commit is contained in:
parent
de2ea8a1b2
commit
2a4f9fbd54
2 changed files with 10 additions and 40 deletions
|
@ -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]
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue