Skip to content

Commit 1ddaff9

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 maxRenderHeight 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] Renamed hardHeightLimit to maxRenderHeight; split from prescaling. Co-Authored-By: Dmitry Lyzo <[email protected]>
1 parent fe8c716 commit 1ddaff9

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+
- `maxRenderHeight`: 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.maxRenderHeight = options.maxRenderHeight || 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
@@ -420,6 +421,9 @@ var SubtitlesOctopus = function (options) {
420421
else if (sgn * newH < sgn * self.prescaleHeightLimit)
421422
newH = self.prescaleHeightLimit;
422423

424+
if (self.maxRenderHeight > 0 && newH > self.maxRenderHeight)
425+
newH = self.maxRenderHeight;
426+
423427
width *= newH / height;
424428
height = newH;
425429
}

0 commit comments

Comments
 (0)