Skip to content

Commit a14e9c1

Browse files
JustAMandmitrylyzo
authored andcommitted
Add option to limit canvas size
JSO struggles with complex subtitles on HiDPI canvasses, so limiting the size can make sense if such subtitles are expected. This was ported from jellyfin's fork and jellyfin-web uses this on at least some devices. In the original implementation prescaleHeightLimit would override hardHeightLimit if it was larger. This undocumentend behaviour was dropped here as it seemed unintuitive and unhelpful. [Vasily <[email protected]>] Original implementation together with prescaling in jellyfin@345d701 jellyfin@4c5f018 [Dmitry Lyzo] Rebased for upstream; seperated from the prescaling; removed default height limit and added docs [Oneric] Removed prescaleHeightLimit overriding hardHeightLimit if larger; split hard height limit from prescaling. Co-Authored-By: Dmitry Lyzo <[email protected]>
1 parent 2f5baff commit a14e9c1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ When creating an instance of SubtitleOctopus, you can set the following options:
137137
(Default: `1.0` - no scaling; must be a number > 0)
138138
- `prescaleHeightLimit`: The height beyond which the subtitles canvas won't be prescaled.
139139
(Default: `1080`)
140+
- `hardHeightLimit`: The maximum rendering height of the subtitles canvas.
141+
Beyond this subtitles will be upscaled by the browser.
142+
(Default: `0` - no limit)
140143

141144
### Rendering Modes
142145
#### JS Blending

src/subtitles-octopus.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var SubtitlesOctopus = function (options) {
1919
self.targetFps = options.targetFps || 24;
2020
self.prescaleFactor = options.prescaleFactor || 1.0;
2121
self.prescaleHeightLimit = options.prescaleHeightLimit || 1080;
22+
self.hardHeightLimit = options.hardHeightLimit || 0; // 0 - no limit
2223
self.isOurCanvas = false; // (internal) we created canvas and manage it
2324
self.video = options.video; // HTML video element (optional if canvas specified)
2425
self.canvasParent = null; // (internal) HTML canvas parent element
@@ -408,6 +409,7 @@ var SubtitlesOctopus = function (options) {
408409

409410
function _computeCanvasSize(width, height) {
410411
var scalefactor = self.prescaleFactor <= 0 ? 1.0 : self.prescaleFactor;
412+
var hardHeightLimit = self.hardHeightLimit <= 0 ? height : self.hardHeightLimit;
411413

412414
if (height == 0) {
413415
width = 0;
@@ -418,6 +420,8 @@ var SubtitlesOctopus = function (options) {
418420
newH *= self.prescaleFactor;
419421
else if (sgn * newH < sgn * self.prescaleHeightLimit)
420422
newH = self.prescaleHeightLimit;
423+
if (newH > hardHeightLimit)
424+
newH = hardHeightLimit;
421425

422426
width *= newH / height;
423427
height = newH;

0 commit comments

Comments
 (0)