Skip to content

Commit

Permalink
fix(ttml): Default TTML background color to transparent if unspecified (
Browse files Browse the repository at this point in the history
#4496)

Closes #4468
  • Loading branch information
joeyparrish committed Sep 28, 2022
1 parent b3621c2 commit 32b0a90
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ shaka.text.TtmlTextParser = class {
cellResolutionInfo, /* parentCueElement= */ null,
/* isContent= */ false);
if (cue) {
// According to the TTML spec, backgrounds default to transparent.
// So default the background of the top-level element to transparent.
// Nested elements may override that background color already.
if (!cue.backgroundColor) {
cue.backgroundColor = 'transparent';
}
cues.push(cue);
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/test/util/ttml_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ shaka.test.TtmlUtils = class {
region,
nestedCues: jasmine.any(Object),
payload: '',
startTime: 0,
endTime: Infinity,
isContainer: true,
});
Object.assign(containerCue, properties);
Expand Down
46 changes: 46 additions & 0 deletions test/text/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,52 @@ describe('TtmlTextParser', () => {
{startTime: 1, endTime: 2});
});

// Regression test for #4468
it('defaults the body background to transparent', () => {
verifyHelper(
// One cue, don't care about the details
[{}],
'<tt xmlns:tts="http://www.w3.org/ns/ttml#styling">' +
'<head>' +
'<styling>' +
'<style xml:id="s1" tts:backgroundColor="black" />' +
'</styling>' +
'</head>' +
'<body><div>' +
'<p begin="00:01.00" end="00:02.00">' +
'<span style="s1">Test</span>' +
'</p>' +
'</div></body></tt>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0},
// The body must have these properties:
{backgroundColor: 'transparent'},
// The div must have these properties:
{}); // don't care
});

// Regression test for #4468
it('allows the body background color to be set', () => {
verifyHelper(
// One cue, don't care about the details
[{}],
'<tt xmlns:tts="http://www.w3.org/ns/ttml#styling">' +
'<head>' +
'<styling>' +
'<style xml:id="s1" tts:backgroundColor="black" />' +
'</styling>' +
'</head>' +
'<body style="s1"><div>' +
'<p begin="00:01.00" end="00:02.00">' +
'<span>Test</span>' +
'</p>' +
'</div></body></tt>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0},
// The body must have these properties:
{backgroundColor: 'black'},
// The div must have these properties:
{}); // don't care
});

it('parses wrapping option', () => {
verifyHelper(
[
Expand Down

0 comments on commit 32b0a90

Please sign in to comment.