JavascriptSubtitlesOctopus icon indicating copy to clipboard operation
JavascriptSubtitlesOctopus copied to clipboard

Resize makes subtitle disappear

Open fifv opened this issue 2 years ago • 1 comments

Due to weird chromium behavior, Alt+Tab at fullscreen resizes the window a bit, then subtitle disappears.

The resize event is handled by resizeWithTimeout() in subtitles-octopus.js, which is:

self.resizeWithTimeout = function () {
    self.resize();
    setTimeout(self.resize, 100);
};

I don't understand the purpose to resize twice, but the resize() call do this:

// --snip--
if (
  self.canvas.width != width ||
  self.canvas.height != height ||
  self.canvas.style.top != top ||
  self.canvas.style.left != left
) {
// --snip--
    self.canvas.width = width;
    self.canvas.height = height;
// --snip--
}
// --snip--

The canvas will clear all contents and context if its width and height is assigned, which causes subtitle disappear.

And these conditions in the if seems not work, for width and height are float while self.canvas.width and self.canvas.height are int.

One workaround:

if (
    self.canvas.width != Math.floor(width) ||
    self.canvas.height != Math.floor(height) ||
    self.canvas.style.top != top + 'px' ||
    self.canvas.style.left != left + 'px'
}

One more workaround:

just remove setTimeout(self.resize, 100);, this works fine for me.

One more workaround:

In src/post-worker.js, find function onMessageFromMainEmscriptenThread(), then switch ... case 'canvas', then self.getRenderMethod()();, change it to:

`self.getRenderMethod()(true);` 

to force render when resizing.

fifv avatar Feb 23 '23 05:02 fifv

I didn't notice this PR when I was writing the issue https://github.com/libass/JavascriptSubtitlesOctopus/pull/132 But hope these will help someone. :)

fifv avatar Feb 23 '23 06:02 fifv