Skip to content

Commit

Permalink
feat: Add support to text-shadow in VTT parser (shaka-project#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored and theodab committed Jun 3, 2022
1 parent 7f38c38 commit c1bdf97
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions externs/shaka/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ shaka.extern.Cue = class {
*/
this.fontFamily;

/**
* Text shadow color as a CSS text-shadow value.
* @type {string}
* @exportDoc
*/
this.textShadow = '';

/**
* Text stroke color as a CSS color, e.g. "#FFFFFF" or "white".
* @type {string}
Expand Down
6 changes: 6 additions & 0 deletions lib/text/cue.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ shaka.text.Cue = class {
*/
this.border = '';

/**
* @override
* @exportInterface
*/
this.textShadow = '';

/**
* @override
* @exportInterface
Expand Down
1 change: 1 addition & 0 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ shaka.text.UITextDisplayer = class {
style.paddingRight =
shaka.text.UITextDisplayer.convertLengthValue_(
cue.linePadding, cue, this.videoContainer_);
style.textShadow = cue.textShadow;

if (cue.backgroundImage) {
style.backgroundImage = 'url(\'' + cue.backgroundImage + '\')';
Expand Down
4 changes: 4 additions & 0 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ shaka.text.VttTextParser = class {
validStyle = true;
cue.opacity = parseFloat(value);
break;
case 'text-shadow':
validStyle = true;
cue.textShadow = value;
break;
case 'white-space':
validStyle = true;
cue.wrapLine = value != 'noWrap';
Expand Down
4 changes: 4 additions & 0 deletions test/text/vtt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ describe('VttTextParser', () => {
});

it('supports global style blocks', () => {
const textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
verifyHelper(
[
{
Expand All @@ -632,20 +633,23 @@ describe('VttTextParser', () => {
payload: 'Test',
color: 'cyan',
fontSize: '10px',
textShadow: textShadow,
},
{
startTime: 40,
endTime: 50,
payload: 'Test2',
color: 'cyan',
fontSize: '10px',
textShadow: textShadow,
},
],
'WEBVTT\n\n' +
'STYLE\n' +
'::cue {\n' +
'color: cyan;\n'+
'font-size: 10px;\n'+
`text-shadow: ${textShadow};\n`+
'}\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'Test\n\n' +
Expand Down

0 comments on commit c1bdf97

Please sign in to comment.