From 32b0a90a8c583bba03a3d7b035a1244d325e3da6 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 27 Sep 2022 19:51:46 -0700 Subject: [PATCH] fix(ttml): Default TTML background color to transparent if unspecified (#4496) Closes #4468 --- lib/text/ttml_text_parser.js | 6 ++++ test/test/util/ttml_utils.js | 2 -- test/text/ttml_text_parser_unit.js | 46 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/text/ttml_text_parser.js b/lib/text/ttml_text_parser.js index de34a05241..bf26ec4509 100644 --- a/lib/text/ttml_text_parser.js +++ b/lib/text/ttml_text_parser.js @@ -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); } } diff --git a/test/test/util/ttml_utils.js b/test/test/util/ttml_utils.js index bb7ed09482..a8417bade4 100644 --- a/test/test/util/ttml_utils.js +++ b/test/test/util/ttml_utils.js @@ -51,8 +51,6 @@ shaka.test.TtmlUtils = class { region, nestedCues: jasmine.any(Object), payload: '', - startTime: 0, - endTime: Infinity, isContainer: true, }); Object.assign(containerCue, properties); diff --git a/test/text/ttml_text_parser_unit.js b/test/text/ttml_text_parser_unit.js index 32f4e3353a..a0b09bb0fb 100644 --- a/test/text/ttml_text_parser_unit.js +++ b/test/text/ttml_text_parser_unit.js @@ -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 + [{}], + '' + + '' + + '' + + '