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 support for line vertical alignment #5945

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Changes from 5 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
31 changes: 20 additions & 11 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,37 +707,46 @@ shaka.text.UITextDisplayer = class {
// (for vertical growing left) is aligned at the line.
// TODO: Implement line alignment with line number.
// TODO: Implement lineAlignment of 'CENTER'.
if (cue.line != null) {
let line = cue.line;
if (line != null) {
let lineInterpretation = cue.lineInterpretation;
// HACK: the current implementation of UITextDisplayer only handled
// PERCENTAGE, as cue.line=0 is zero, we can interpret it as percentage
// safely.
if (cue.line == 0 &&
lineInterpretation == Cue.lineInterpretation.LINE_NUMBER) {
// PERCENTAGE, so we need convert LINE_NUMBER to PERCENTAGE
if (lineInterpretation == Cue.lineInterpretation.LINE_NUMBER) {
lineInterpretation = Cue.lineInterpretation.PERCENTAGE;
let maxLines = 16;
// The maximum number of lines is different if it is a vertical video.
if (this.aspectRatio_ && this.aspectRatio_ < 1) {
maxLines = 32;
}
if (line < 0) {
line = 100 + line / maxLines * 100;
avelad marked this conversation as resolved.
Show resolved Hide resolved
} else {
line = line / maxLines * 100;
}
}
if (lineInterpretation == Cue.lineInterpretation.PERCENTAGE) {
style.position = 'absolute';
if (cue.writingMode == Cue.writingMode.HORIZONTAL_TOP_TO_BOTTOM) {
style.width = '100%';
if (cue.lineAlign == Cue.lineAlign.START) {
style.top = cue.line + '%';
style.top = line + '%';
} else if (cue.lineAlign == Cue.lineAlign.END) {
style.bottom = (100 - cue.line) + '%';
style.bottom = (100 - line) + '%';
}
} else if (cue.writingMode == Cue.writingMode.VERTICAL_LEFT_TO_RIGHT) {
style.height = '100%';
if (cue.lineAlign == Cue.lineAlign.START) {
style.left = cue.line + '%';
style.left = line + '%';
} else if (cue.lineAlign == Cue.lineAlign.END) {
style.right = (100 - cue.line) + '%';
style.right = (100 - line) + '%';
}
} else {
style.height = '100%';
if (cue.lineAlign == Cue.lineAlign.START) {
style.right = cue.line + '%';
style.right = line + '%';
} else if (cue.lineAlign == Cue.lineAlign.END) {
style.left = (100 - cue.line) + '%';
style.left = (100 - line) + '%';
}
}
}
Expand Down
Loading