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(WebVTT): Fix rendering of WebVTT in UITextDisplayer #7023

Merged
merged 3 commits into from
Jul 22, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,15 @@ shaka.text.UITextDisplayer = class {
style.display = 'flex';
style.flexDirection = 'column';
style.alignItems = 'center';
if (cue.textAlign == Cue.textAlign.LEFT ||
cue.textAlign == Cue.textAlign.START) {
style.width = '100%';
style.alignItems = 'start';
} else if (cue.textAlign == Cue.textAlign.RIGHT ||
cue.textAlign == Cue.textAlign.END) {
style.width = '100%';
style.alignItems = 'end';
}

if (cue.displayAlign == Cue.displayAlign.BEFORE) {
style.justifyContent = 'flex-start';
Expand Down Expand Up @@ -811,23 +820,41 @@ shaka.text.UITextDisplayer = class {

style.lineHeight = cue.lineHeight;

// The position defines the indent of the text container in the
// direction defined by the writing direction.
if (cue.position != null) {
if (cue.writingMode == Cue.writingMode.HORIZONTAL_TOP_TO_BOTTOM) {
style.paddingLeft = cue.position;
} else {
style.paddingTop = cue.position;
}
}

// The positionAlign attribute is an alignment for the text container in
// the dimension of the writing direction.
const computedPositionAlign = this.computeCuePositionAlignment_(cue);
if (computedPositionAlign == Cue.positionAlign.LEFT) {
style.cssFloat = 'left';
if (cue.position !== null) {
style.position = 'absolute';
if (cue.writingMode == Cue.writingMode.HORIZONTAL_TOP_TO_BOTTOM) {
style.left = cue.position + '%';
style.width = 'auto';
} else {
style.top = cue.position + '%';
}
}
} else if (computedPositionAlign == Cue.positionAlign.RIGHT) {
style.cssFloat = 'right';
if (cue.position !== null) {
style.position = 'absolute';
if (cue.writingMode == Cue.writingMode.HORIZONTAL_TOP_TO_BOTTOM) {
style.right = cue.position + '%';
style.width = 'auto';
} else {
style.bottom = cue.position + '%';
}
}
} else {
if (cue.position !== null && cue.position != 50) {
style.position = 'absolute';
if (cue.writingMode == Cue.writingMode.HORIZONTAL_TOP_TO_BOTTOM) {
style.left = cue.position + '%';
style.width = 'auto';
} else {
style.top = cue.position + '%';
}
}
}

style.textAlign = cue.textAlign;
Expand Down
6 changes: 0 additions & 6 deletions test/text/web_vtt_layout_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('align-center-position-50');
});

// FIXME: UI version is wrong: not positioned on the right
it('align center position 90%', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand All @@ -115,7 +114,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('align-center-position-10');
});

// FIXME: UI version is wrong: not positioned on the left
it('align center position 10% size 10%', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand All @@ -127,7 +125,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('align-center-position-10-size-10');
});

// FIXME: UI version is wrong: not positioned on the right
it('align end', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand All @@ -152,7 +149,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('align-end-long');
});

// FIXME: UI version is wrong: not positioned on the left
it('align start', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand Down Expand Up @@ -201,7 +197,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('size-50');
});

// FIXME: UI version is wrong: not positioned by line
it('line -2', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand All @@ -224,7 +219,6 @@ filterDescribe('WebVTT layout', shaka.test.TextLayoutTests.supported, () => {
await helper.checkScreenshot('line-0');
});

// FIXME: UI version is wrong: not positioned by line
it('line 1', async () => {
parseAndDisplay([
'WEBVTT\n',
Expand Down
Loading