Skip to content

Commit 67750b5

Browse files
committed
js: fix subtitles disappear when resizing
1. Missing `px` in offset comparison - deferred resizing resets the canvas by writing the same values to `width` and `height`. [turuslan <[email protected]>] found this bug. 2. Since RenderAhead resizes the canvas according to the rendered frame, the native properties will be overwritten, and we need additional properties for comparison.
1 parent 0df71b0 commit 67750b5

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/subtitles-octopus.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -742,26 +742,22 @@ var SubtitlesOctopus = function (options) {
742742
return;
743743
}
744744

745-
746-
if (
747-
self.canvas.width != width ||
748-
self.canvas.height != height ||
749-
self.canvas.style.top != top ||
750-
self.canvas.style.left != left
751-
) {
745+
if (videoSize != null) {
746+
self.canvasParent.style.position = 'relative';
747+
self.canvas.style.display = 'block';
748+
self.canvas.style.position = 'absolute';
749+
self.canvas.style.width = videoSize.width + 'px';
750+
self.canvas.style.height = videoSize.height + 'px';
751+
self.canvas.style.top = top + 'px';
752+
self.canvas.style.left = left + 'px';
753+
self.canvas.style.pointerEvents = 'none';
754+
}
755+
756+
if (self.canvas._width !== width || self.canvas._height !== height) {
752757
self.canvas.width = width;
753758
self.canvas.height = height;
754-
755-
if (videoSize != null) {
756-
self.canvasParent.style.position = 'relative';
757-
self.canvas.style.display = 'block';
758-
self.canvas.style.position = 'absolute';
759-
self.canvas.style.width = videoSize.width + 'px';
760-
self.canvas.style.height = videoSize.height + 'px';
761-
self.canvas.style.top = top + 'px';
762-
self.canvas.style.left = left + 'px';
763-
self.canvas.style.pointerEvents = 'none';
764-
}
759+
self.canvas._width = width;
760+
self.canvas._height = height;
765761

766762
self.worker.postMessage({
767763
target: 'canvas',

0 commit comments

Comments
 (0)