Skip to content

Commit

Permalink
fix(WebVTT): Fix rendering of WebVTT in UITextDisplayer (#7023)
Browse files Browse the repository at this point in the history
Fix rendering of align:start and align:end in UITextDisplayer
Fix rendering of position in UITextDisplayer

Fixes #4486
  • Loading branch information
avelad authored Jul 22, 2024
1 parent 3390a96 commit 22a7c49
Show file tree
Hide file tree
Showing 68 changed files with 37 additions and 16 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test/assets/screenshots/chrome-Linux/webvtt-ui-align-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test/assets/screenshots/chrome-Mac/webvtt-ui-align-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test/assets/screenshots/chrome-Mac/webvtt-ui-align-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test/assets/screenshots/firefox-Linux/webvtt-ui-align-end.png
Binary file modified test/test/assets/screenshots/firefox-Mac/webvtt-ui-align-end.png
Binary file modified test/test/assets/screenshots/firefox-Mac/webvtt-ui-align-start.png
Binary file modified test/test/assets/screenshots/msedge-Linux/webvtt-ui-align-end.png
Binary file modified test/test/assets/screenshots/msedge-Mac/webvtt-ui-align-end.png
Binary file modified test/test/assets/screenshots/msedge-Mac/webvtt-ui-align-start.png
Binary file modified test/test/assets/screenshots/safari-Mac/webvtt-ui-align-end.png
Binary file modified test/test/assets/screenshots/safari-Mac/webvtt-ui-align-start.png
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

0 comments on commit 22a7c49

Please sign in to comment.