fix: Fix WebVTT position handling in UITextDisplayer (#9017)

Fixes https://github.com/shaka-project/shaka-player/issues/8948
This commit is contained in:
Álvaro Velad Galván
2025-08-25 15:05:29 +02:00
committed by GitHub
parent d3fcb2b598
commit aaef0abd84
11 changed files with 10 additions and 0 deletions
+10
View File
@@ -640,6 +640,7 @@ shaka.text.UITextDisplayer = class {
* See https://www.w3.org/TR/webvtt1/#webvtt-cue-position-alignment
*
* @param {!shaka.text.Cue} cue
* @return {!shaka.text.Cue.positionAlign}
* @private
*/
computeCuePositionAlignment_(cue) {
@@ -873,6 +874,12 @@ shaka.text.UITextDisplayer = class {
// The positionAlign attribute is an alignment for the text container in
// the dimension of the writing direction.
const computedPositionAlign = this.computeCuePositionAlignment_(cue);
// According to the W3C WebVTT specification
// See: https://www.w3.org/TR/webvtt1/#webvtt-cue-position
// The position of the cue box depends on the cue alignment.
// If align: start, then the position specifies the left edge.
// If align: center, then it specifies the center of the cue box.
// If align: end, then it refers to the right edge.
if (computedPositionAlign == Cue.positionAlign.LEFT) {
style.cssFloat = 'left';
if (cue.position !== null) {
@@ -904,6 +911,9 @@ shaka.text.UITextDisplayer = class {
} else {
style.top = cue.position + '%';
}
if (cue.size) {
style.transform = 'translateX(-50%)';
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB