Skip to content

Commit 60f99c7

Browse files
authored
Subtitles: stop cutting a cue off after three lines (#588)
1 parent b3298e2 commit 60f99c7

1 file changed

Lines changed: 41 additions & 16 deletions

File tree

‎rust-modules/appkit/src/player_hud.rs‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,10 @@ pub fn draw_subtitles(hud_up: bool, burned: bool) {
153153
draw_subtitle_message(&text, hud_up);
154154
}
155155

156-
/// Shared caption placement for plain text and a styled-renderer failure message. Text size and
157-
/// vertical placement follow the viewer's Settings > Playback picks (`route::subtitle_size`,
158-
/// `route::subtitle_position`) — native ASS/SSA keeps its authored style instead
159-
/// (`docs/ass-subtitles.md`).
160-
pub fn draw_subtitle_message(text: &str, hud_up: bool) {
161-
let scale = subtitle_size_scale(plx_media::route::subtitle_size());
162-
let max_chars = ((42.0 / scale).round() as usize).max(20);
156+
/// The wrapped lines [`draw_subtitle_message`] stacks for one cue: each authored line break
157+
/// starts a new line, each segment word-wraps to `max_chars`, and at most [`MAX_CAPTION_LINES`]
158+
/// survive (the rest of a pathologically long cue is dropped).
159+
fn caption_lines(text: &str, max_chars: usize) -> Vec<String> {
163160
let mut lines: Vec<String> = Vec::new();
164161
for seg in text.split('\n') {
165162
let seg = seg.trim();
@@ -172,6 +169,17 @@ pub fn draw_subtitle_message(text: &str, hud_up: bool) {
172169
}
173170
}
174171
}
172+
lines
173+
}
174+
175+
/// Shared caption placement for plain text and a styled-renderer failure message. Text size and
176+
/// vertical placement follow the viewer's Settings > Playback picks (`route::subtitle_size`,
177+
/// `route::subtitle_position`) — native ASS/SSA keeps its authored style instead
178+
/// (`docs/ass-subtitles.md`).
179+
pub fn draw_subtitle_message(text: &str, hud_up: bool) {
180+
let scale = subtitle_size_scale(plx_media::route::subtitle_size());
181+
let max_chars = ((42.0 / scale).round() as usize).max(20);
182+
let lines = caption_lines(text, max_chars);
175183
if lines.is_empty() {
176184
return;
177185
}
@@ -246,18 +254,23 @@ fn subtitle_position_lift(position: plx_plex::plex::session::SubtitlePosition) -
246254
const SUB_BASE_Y: f32 = SCR_H - 100.0;
247255
const SUB_CEIL_Y: f32 = SCR_H - 300.0;
248256

249-
/// The most caption lines [`draw_subtitle_message`] ever stacks (the rest of a longer cue is
250-
/// dropped), and the reason the Timing capsule's y is fixed rather than following the caption
251-
/// block (`appkit::timing_capsule`, plan `subtitle-menu-capsule` §4): a live cue's line count changes
252-
/// frame to frame, and a capsule that tracked it would jump under a viewer's thumb mid-hold.
253-
const MAX_CAPTION_LINES: usize = 3;
257+
/// The most caption lines [`draw_subtitle_message`] ever stacks — a safety bound against a
258+
/// pathological cue, not a layout choice: the block grows upward from its baseline, and a cue of
259+
/// authored line breaks that each wrap again (#585) legitimately runs past three lines, so the
260+
/// cap sits well above anything a real cue needs rather than cutting its tail.
261+
const MAX_CAPTION_LINES: usize = 8;
262+
/// The caption lines the Timing capsule clears (`appkit::timing_capsule`, plan
263+
/// `subtitle-menu-capsule` §4). Its y is fixed rather than following the caption block — a live
264+
/// cue's line count changes frame to frame, and a capsule that tracked it would jump under a
265+
/// viewer's thumb mid-hold — so it clears the usual cue; a rarer taller one overlaps it.
266+
const CAPSULE_CLEAR_LINES: usize = 3;
254267
/// The vertical pitch of one caption line in [`draw_subtitle_message`] — its 36 px face plus
255268
/// leading.
256269
const CAPTION_LINE_PITCH: f32 = 48.0;
257-
/// The Timing capsule's bottom y — [`SUB_BASE_Y`] cleared by the tallest caption block this app
258-
/// ever draws ([`MAX_CAPTION_LINES`] at [`CAPTION_LINE_PITCH`]), so the capsule never overlaps
259-
/// even a three-line cue.
260-
pub const CAPSULE_BOTTOM_Y: f32 = SUB_BASE_Y - MAX_CAPTION_LINES as f32 * CAPTION_LINE_PITCH;
270+
/// The Timing capsule's bottom y — [`SUB_BASE_Y`] cleared by the caption block this app
271+
/// usually draws ([`CAPSULE_CLEAR_LINES`] at [`CAPTION_LINE_PITCH`]), so the capsule never
272+
/// overlaps even a three-line cue.
273+
pub const CAPSULE_BOTTOM_Y: f32 = SUB_BASE_Y - CAPSULE_CLEAR_LINES as f32 * CAPTION_LINE_PITCH;
261274

262275
/// Map a decoded image-subtitle rect from the stream's `cw`×`ch` authoring canvas onto the video
263276
/// rect — which is always the full panel here (the video track is authored 1920×1080; see the
@@ -1936,6 +1949,18 @@ pub fn overscan_rects(out: &mut Vec<(&'static str, Rect)>) {
19361949

19371950
#[cfg(test)]
19381951
mod tests {
1952+
/// #585: a cue of authored line breaks that each wrap again ran past three lines and the tail
1953+
/// was silently dropped. Every line of an ordinary long cue must survive.
1954+
#[test]
1955+
fn a_long_cue_keeps_every_line_past_three() {
1956+
let cue = "First authored line that is long enough to wrap onto a second row\n\
1957+
Second authored line that is long enough to wrap onto a second row\n\
1958+
Third authored line that is long enough to wrap onto a second row";
1959+
let lines = super::caption_lines(cue, 42);
1960+
assert_eq!(lines.len(), 6, "{lines:?}");
1961+
assert!(lines.last().unwrap().ends_with("second row"), "{lines:?}");
1962+
}
1963+
19391964
#[test]
19401965
fn chapter_panel_retains_selection_without_borrowing_hud_focus() {
19411966
assert_eq!(super::hud_tab_state(false, 2, 1, 1), (false, true));

0 commit comments

Comments
 (0)