Skip to content

Commit

Permalink
feat(WebVTT): Add support to ruby, rt, rp html tags (#5642)
Browse files Browse the repository at this point in the history
Related to #2853
  • Loading branch information
avelad committed Sep 12, 2023
1 parent eed393f commit 76ffd38
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/text/cue.js
Expand Up @@ -299,6 +299,14 @@ shaka.text.Cue = class {
*/
this.lineBreak = false;

/**
* Used to indicate the type of ruby tag that should be used when rendering
* the cue. Valid values: ruby, rp, rt.
* @type {?string}
* @exportDoc
*/
this.rubyTag = null;

/**
* The number of horizontal and vertical cells into which the Root Container
* Region area is divided.
Expand Down
3 changes: 3 additions & 0 deletions lib/text/ui_text_displayer.js
Expand Up @@ -452,6 +452,9 @@ shaka.text.UITextDisplayer = class {
if (cue.lineBreak) {
type = 'br';
}
if (cue.rubyTag) {
type = cue.rubyTag;
}

const needWrapper = !isNested && cue.nestedCues.length > 0;

Expand Down
6 changes: 6 additions & 0 deletions lib/text/vtt_text_parser.js
Expand Up @@ -676,6 +676,7 @@ shaka.text.VttTextParser = class {
cue.fontWeight = refCue.fontWeight;
cue.fontStyle = refCue.fontStyle;
cue.opacity = refCue.opacity;
cue.rubyTag = refCue.rubyTag;
cue.textCombineUpright = refCue.textCombineUpright;
cue.textShadow = refCue.textShadow;
cue.wrapLine = refCue.wrapLine;
Expand Down Expand Up @@ -747,6 +748,11 @@ shaka.text.VttTextParser = class {
}
break;
}
case 'ruby':
case 'rp':
case 'rt':
nestedCue.rubyTag = tag;
break;
default:
break;
}
Expand Down
35 changes: 35 additions & 0 deletions test/text/vtt_text_parser_unit.js
Expand Up @@ -921,6 +921,41 @@ describe('VttTextParser', () => {
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
});

it('supports ruby html tags', () => {
verifyHelper(
[
{
startTime: 20,
endTime: 40,
payload: '',
nestedCues: [
{
startTime: 20,
endTime: 40,
payload: 'Test',
rubyTag: 'ruby',
},
{
startTime: 20,
endTime: 40,
payload: '2',
rubyTag: 'rt',
},
{
startTime: 20,
endTime: 40,
payload: '3',
rubyTag: 'rp',
},
],
},
],
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'<ruby>Test<rt>2</rt><rp>3</rp></ruby>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
});

it('supports only two digits in the timestamp', () => {
verifyHelper(
[
Expand Down

0 comments on commit 76ffd38

Please sign in to comment.