Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TTML - font-size is not applied in nested cues #3837

Merged
merged 3 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/text/ttml_text_parser.js
Expand Up @@ -154,7 +154,8 @@ shaka.text.TtmlTextParser = class {
const cue = TtmlTextParser.parseCue_(
p, time.periodStart, rateInfo, metadataElements, styles,
regionElements, cueRegions, whitespaceTrim,
/* isNested= */ false, cellResolutionInfo);
/* isNested= */ false, cellResolutionInfo,
/* parentCueElement= */ null);
if (cue) {
cues.push(cue);
}
Expand All @@ -164,7 +165,8 @@ shaka.text.TtmlTextParser = class {
const cue = TtmlTextParser.parseCue_(
div, time.periodStart, rateInfo, metadataElements, styles,
regionElements, cueRegions, whitespaceTrim,
/* isNested= */ false, cellResolutionInfo);
/* isNested= */ false, cellResolutionInfo,
/* parentCueElement= */ null);
if (cue) {
cues.push(cue);
}
Expand All @@ -188,12 +190,13 @@ shaka.text.TtmlTextParser = class {
* @param {boolean} whitespaceTrim
* @param {boolean} isNested
theodab marked this conversation as resolved.
Show resolved Hide resolved
* @param {?{columns: number, rows: number}} cellResolution
* @param {?Element} parentCueElement
* @return {shaka.text.Cue}
* @private
*/
static parseCue_(
cueNode, offset, rateInfo, metadataElements, styles, regionElements,
cueRegions, whitespaceTrim, isNested, cellResolution) {
cueRegions, whitespaceTrim, isNested, cellResolution, parentCueElement) {
/** @type {Element} */
let cueElement;
/** @type {Element} */
Expand Down Expand Up @@ -245,6 +248,7 @@ shaka.text.TtmlTextParser = class {
localWhitespaceTrim,
/* isNested= */ true,
cellResolution,
cueElement,
);

// This node may or may not generate a nested cue.
Expand Down Expand Up @@ -358,10 +362,19 @@ shaka.text.TtmlTextParser = class {

const isLeaf = nestedCues.length == 0;

let regionElementForStyle = regionElement;
if (parentCueElement && isNested && !cueElement.getAttribute('region') &&
!cueElement.getAttribute('style')) {
regionElementForStyle =
shaka.text.TtmlTextParser.getElementsFromCollection_(
parentCueElement, 'region', regionElements, /* prefix= */ '')[0];
}


shaka.text.TtmlTextParser.addStyle_(
cue,
cueElement,
regionElement,
regionElementForStyle,
imageElement,
styles,
isNested,
Expand Down
60 changes: 60 additions & 0 deletions test/text/ttml_text_parser_unit.js
Expand Up @@ -1702,6 +1702,66 @@ describe('TtmlTextParser', () => {
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

// Regression test for https://github.com/google/shaka-player/issues/3743
it('inherits styles from other styles on nestedCues', () => {
verifyHelper(
[
{
// p element
startTime: 0,
endTime: 60,
payload: '',
fontSize: '',
nestedCues: [
{
startTime: 0,
endTime: 60,
payload: 'A',
fontSize: '16px',
},
{
startTime: 0,
endTime: 60,
payload: '',
fontSize: '',
},
{
startTime: 0,
endTime: 60,
payload: 'B',
fontSize: '16px',
},
],
},
],
'<tt xmlns:tts="http://www.w3.org/ns/ttml#styling">' +
'<head>' +
' <styling>' +
' <style tts:backgroundColor="rgba(0,0,0,100)" ' +
' tts:displayAlign="center" ' +
' tts:extent="80% 10%" ' +
' tts:fontFamily="proportionalSansSerif" ' +
' tts:fontSize="16px" ' +
' tts:origin="10% 85%" ' +
' tts:textAlign="center" ' +
' xml:id="backgroundStyle"/>' +
' <style style="backgroundStyle" ' +
' tts:backgroundColor="transparent" ' +
' tts:color="white" ' +
' xml:id="speakerStyle"/>' +
' </styling>' +
' <layout>' +
' <region style="speakerStyle" tts:zIndex="1" xml:id="speaker"/>' +
' </layout>' +
'</head>' +
'<body><div>' +
' <p begin="00:00" end="01:00" region="speaker">' +
' A<br/>B' +
' </p>' +
'</div></body></tt>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

/**
* @param {!Array} cues
* @param {string} text
Expand Down