Skip to content

Commit

Permalink
Merge pull request #3270 from video-dev/bugfix/cea-608-row-column-to-vtt
Browse files Browse the repository at this point in the history
Improve CEA-608 column to VTT position
  • Loading branch information
robwalch committed Dec 7, 2020
2 parents 4696e35 + e65e1a6 commit 2ac1c85
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/cues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { fixLineBreaks } from './vttparser';
import { CaptionScreen, Row } from './cea-608-parser';

const WHITESPACE_CHAR = /\s/;

export interface CuesInterface {
newCue (track: TextTrack | null, startTime: number, endTime: number, captionScreen: CaptionScreen): VTTCue[]
}
Expand All @@ -23,7 +25,7 @@ export function newCue (track: TextTrack | null, startTime: number, endTime: num

if (!row.isEmpty()) {
for (let c = 0; c < row.chars.length; c++) {
if (row.chars[c].uchar.match(/\s/) && indenting) {
if (WHITESPACE_CHAR.test(row.chars[c].uchar) && indenting) {
indent++;
} else {
text += row.chars[c].uchar;
Expand All @@ -48,8 +50,10 @@ export function newCue (track: TextTrack | null, startTime: number, endTime: num

cue.line = r + 1;
cue.align = 'left';
// Clamp the position between 0 and 100 - if out of these bounds, Firefox throws an exception and captions break
cue.position = Math.max(0, Math.min(100, 100 * (indent / 32)));
// Clamp the position between 10 and 80 percent (CEA-608 PAC indent code)
// https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-608
// Firefox throws an exception and captions break with out of bounds 0-100 values
cue.position = 10 + Math.min(80, Math.floor(indent * 8 / 32) * 10);
result.push(cue);
}
}
Expand Down

0 comments on commit 2ac1c85

Please sign in to comment.