mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-02 09:43:48 +00:00
tttocea708/translate: improve logic for prepending spaces
No space needs to be prepended after inserting a carriage return or clearing the screen. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2345>
This commit is contained in:
parent
4ad8295ae3
commit
75e2582802
2 changed files with 22 additions and 8 deletions
|
@ -391,6 +391,7 @@ impl TextToCea708 {
|
||||||
}
|
}
|
||||||
self.pen_location.column = origin_column as u8;
|
self.pen_location.column = origin_column as u8;
|
||||||
need_pen_location = true;
|
need_pen_location = true;
|
||||||
|
cleared = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,12 +438,17 @@ impl TextToCea708 {
|
||||||
|
|
||||||
for (i, chunk) in line.chunks.iter().enumerate() {
|
for (i, chunk) in line.chunks.iter().enumerate() {
|
||||||
let (cr, mut prepend_space) = if i == 0 {
|
let (cr, mut prepend_space) = if i == 0 {
|
||||||
(line.carriage_return, true)
|
(
|
||||||
|
line.carriage_return,
|
||||||
|
line.carriage_return.map(|cr| !cr).unwrap_or(!cleared),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(Some(false), false)
|
(Some(false), false)
|
||||||
};
|
};
|
||||||
self.open_line(chunk, cr);
|
self.open_line(chunk, cr);
|
||||||
|
|
||||||
|
cleared = false;
|
||||||
|
|
||||||
if is_punctuation(&chunk.text) {
|
if is_punctuation(&chunk.text) {
|
||||||
prepend_space = false;
|
prepend_space = false;
|
||||||
}
|
}
|
||||||
|
@ -463,9 +469,7 @@ impl TextToCea708 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = Code::from_char(c).unwrap_or(Code::Space);
|
let mut push_code = true;
|
||||||
self.service_writer.push_codes(&[code]);
|
|
||||||
self.pen_location.column += 1;
|
|
||||||
|
|
||||||
if self.mode == Cea708Mode::RollUp {
|
if self.mode == Cea708Mode::RollUp {
|
||||||
/* In roll-up mode, we introduce carriage returns automatically.
|
/* In roll-up mode, we introduce carriage returns automatically.
|
||||||
|
@ -488,8 +492,18 @@ impl TextToCea708 {
|
||||||
self.pen_location.column = self.origin_column as u8;
|
self.pen_location.column = self.origin_column as u8;
|
||||||
|
|
||||||
self.open_line(chunk, Some(true));
|
self.open_line(chunk, Some(true));
|
||||||
|
|
||||||
|
push_code = !c.is_ascii_whitespace();
|
||||||
}
|
}
|
||||||
} else if self.pen_location.column > 31 {
|
}
|
||||||
|
|
||||||
|
if push_code {
|
||||||
|
let code = Code::from_char(c).unwrap_or(Code::Space);
|
||||||
|
self.service_writer.push_codes(&[code]);
|
||||||
|
self.pen_location.column += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.mode != Cea708Mode::RollUp && self.pen_location.column > 31 {
|
||||||
if chars.peek().is_some() {
|
if chars.peek().is_some() {
|
||||||
gst::warning!(CAT, "Dropping characters after 32nd column: {}", c);
|
gst::warning!(CAT, "Dropping characters after 32nd column: {}", c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ static PADDING: [u8; 60] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
static POP_ON_PREAMBLE: [u8; 24] = [
|
static POP_ON_PREAMBLE: [u8; 24] = [
|
||||||
0xff, 0x0d, 0x37, 0xfe, 0x88, 0x01, 0xfe, 0x8c, 0xfe, 0xfe, 0x99, 0x18, 0xfe, 0xe4, 0x32, 0xfe,
|
0xff, 0x0c, 0x36, 0xfe, 0x88, 0x01, 0xfe, 0x8c, 0xfe, 0xfe, 0x99, 0x18, 0xfe, 0xe4, 0x32, 0xfe,
|
||||||
0x7e, 0x1f, 0xfe, 0x11, 0x92, 0xfe, 0x0e, 0x00,
|
0x7e, 0x1f, 0xfe, 0x11, 0x92, 0xfe, 0x0e, 0x00,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@ fn test_tttocea708_one_timed_buffer_and_eos() {
|
||||||
expected0[..3].copy_from_slice(&[0xfc, 0x94, 0x20]);
|
expected0[..3].copy_from_slice(&[0xfc, 0x94, 0x20]);
|
||||||
expected0[6..30].copy_from_slice(&POP_ON_PREAMBLE);
|
expected0[6..30].copy_from_slice(&POP_ON_PREAMBLE);
|
||||||
// Hello ETX
|
// Hello ETX
|
||||||
expected0[30..45].copy_from_slice(&[
|
expected0[30..42].copy_from_slice(&[
|
||||||
0xfe, 0x20, 0x48, 0xfe, 0x65, 0x6c, 0xfe, 0x6c, 0x6f, 0xfe, 0x8b, 0x03, 0xfe, 0x03, 0x00,
|
0xfe, 0x48, 0x65, 0xfe, 0x6c, 0x6c, 0xfe, 0x6f, 0x8b, 0xfe, 0x03, 0x03,
|
||||||
]);
|
]);
|
||||||
let mut expected1 = PADDING;
|
let mut expected1 = PADDING;
|
||||||
expected1[..3].copy_from_slice(&[0xfc, 0x94, 0xae]);
|
expected1[..3].copy_from_slice(&[0xfc, 0x94, 0xae]);
|
||||||
|
|
Loading…
Reference in a new issue