Repository navigation
fix(subtitles): trim the grid padding off teletext rows at interior line breaks (#233) - #258
Merged
Merged
Conversation
…ine breaks (#233) A teletext row that libzvbi does not curate arrives at full column width. On a page it does not flag as a subtitle page, `gen_sub_ass` writes each row with `decode_string(page, row, &buf, 0, page->columns, ...)`, one `\h` per grid space, and appends `" \N"` after it. Two passes handled whitespace and neither reached the inside of a line break: - `edgeTrimmed` trims the leading and trailing edge of the whole run sequence, so the first row's leading pad and the last row's trailing pad only. - `collapseInteriorBlankLines` folds what sits BETWEEN two newlines. Against a single retained newline it drops nothing, and it never looks at the characters before one at all. So a two-row caption reached the host as `row one<pad>\n<pad>row two`. A renderer that centres each line puts row two visibly off centre and draws the cue's background box wider than its text. `trimGridRows` now takes the padding off both ends of every row. Like the fold it works on the flattened character sequence and re-splits along the original run boundaries, because a row's pad carries the spacing attribute that changes colour and therefore lands in a whitespace-only run of its own, which a per-run walk steps right over. Both share one `rewritingFlattened` helper now. The pass is gated, and the fold is gated with it. Both only correct a raw grid dump, which is exactly the page that arrives without an `\an`: `gen_sub_ass` emits `{\anN}` on the first row of a flagged page holding any character, and a flagged page holding none produces no cue, so an arriving `\an` and a curated body are equivalent. On a curated page both of the things these passes remove are decisions instead of noise. The `empty_lines / 2` fillers are its vertical fine-positioning inside the block, and the residual padding is the relative indentation that carries the horizontal alignment it picked: `leading = min_leading` for left, `trailing = min_trailing` for right, both for its non-centrable centre case. A curated body is passed through whole now, including that fold, which had been folding those fillers away since #107. Not taken, though the trim makes it measurable: deriving the horizontal anchor the way `can_align_left` / `_right` / `_center` do. Where that analysis leaves more than one of the three viable it resolves the tie from `last_ass_alignment`, the answer given to the previous cue. A stateless parser has to fall back to centre there, so an unambiguous left-aligned cue followed by an ambiguous one would jump, which is the same blink the vertical derivation already refuses. Reported by tresby, who had solved it row-wise in a proxy implementation and supplied the failing sequence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported by tresby on #233. A two-row teletext caption reached the host as
row one<pad>\n<pad>row two, so a renderer that centres each line put row two off centre and drew the background box wider than its text.Where it comes from
On a page libzvbi does not flag as a subtitle page,
gen_sub_asswrites each row at full column width (decode_string(page, row, &buf, 0, page->columns, ...), one\hper grid space) and appends" \N"after it. Two passes handled whitespace and neither reached the inside of a line break:edgeTrimmedtrims the leading and trailing edge of the whole run sequence, so the first row's leading pad and the last row's trailing pad only.collapseInteriorBlankLinesfolds what sits BETWEEN two newlines. Against a single retained newline it drops nothing, and it never looks at the characters before one at all.The fix
trimGridRowstakes the padding off both ends of every row. Like the fold it works on the flattened character sequence and re-splits along the original run boundaries, since a row's pad carries the spacing attribute that changes colour and therefore lands in a whitespace-only run of its own, which a per-run walk steps over. Both passes share onerewritingFlattenedhelper now.The gate, and why the fold moves behind it too
Both passes only correct a raw grid dump, which is exactly the page that arrives without an
\an. The equivalence holds by construction:gen_sub_assemits{\anN}on the first row of a flagged page that holds any character, and a flagged page holding none produces no cue at all.On a curated page both of the things these passes remove are decisions rather than noise:
empty_lines / 2fillers, vertical fine-positioning inside the blockleading = min_leadingleft,trailing = min_trailingright, both for the non-centrable centre case)So a curated body is passed through whole now, including through the fold, which had been folding those fillers away since #107. That half is unreported and there is no flagged-page source here to shoot it against, but leaving the fold unconditional while gating the trim would give two passes with the same premise two different answers.
Not taken
Deriving the horizontal anchor the way
can_align_left/_right/_centerdo, which the trim does make measurable. Where that analysis leaves more than one of the three viable it resolves the tie fromlast_ass_alignment, the answer given to the previous cue. A stateless parser has to fall back to centre there, so an unambiguous left-aligned cue followed by an ambiguous one would jump, which is the same blink the vertical derivation already refuses. The comment ongridPlacementnow says that instead of the stale reason.Tests
13 new in
Issue233TeletextRowPaddingTests, built on agridRowhelper that reproduces ffmpeg's emission shape rather than a hand-written string: the reported two-row case, the separator space, padding that lands in its own coloured run, indentation inside a row surviving, colours surviving, and the curated page keeping both its indentation and its fillers. Full suite green, 1328 Swift Testing + 392 XCTest (1 skipped).Closes nothing yet, the reporter retest on page 801 is what settles it.
🤖 Generated with Claude Code
https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N