Skip to content

Commit abfc14d

Browse files
authored
Update subtitle position styling (#6766)
1 parent 110f442 commit abfc14d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/components/subtitlesettings/subtitleappearancehelper.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ function getTextStyles(settings, preview) {
101101
if (!preview) {
102102
const pos = parseInt(settings.verticalPosition, 10);
103103
const lineHeight = 1.35; // FIXME: It is better to read this value from element
104-
const line = Math.abs(pos * lineHeight);
105104
if (pos < 0) {
106-
list.push({ name: 'min-height', value: `${line}em` });
105+
const margin = Math.abs(pos + 1) * lineHeight;
106+
list.push({ name: 'margin-bottom', value: `${margin}em` });
107107
list.push({ name: 'margin-top', value: '' });
108108
} else {
109-
list.push({ name: 'min-height', value: '' });
110-
list.push({ name: 'margin-top', value: `${line}em` });
109+
const margin = pos * lineHeight;
110+
list.push({ name: 'margin-bottom', value: '' });
111+
list.push({ name: 'margin-top', value: `${margin}em` });
111112
}
112113
}
113114

src/plugins/htmlVideoPlayer/plugin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,16 @@ export class HtmlVideoPlayer {
15321532
// in safari, the cues need to be added before setting the track mode to showing
15331533
for (const trackEvent of data.TrackEvents) {
15341534
const TrackCue = window.VTTCue || window.TextTrackCue;
1535-
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, normalizeTrackEventText(trackEvent.Text, false));
1535+
const text = normalizeTrackEventText(trackEvent.Text, false);
1536+
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, text);
15361537

15371538
if (cue.line === 'auto') {
1538-
cue.line = cueLine;
1539+
if (cueLine < 0) {
1540+
const lineCount = (text.match(/\n/g) || []).length;
1541+
cue.line = cueLine - lineCount;
1542+
} else {
1543+
cue.line = cueLine;
1544+
}
15391545
}
15401546

15411547
trackElement.addCue(cue);

0 commit comments

Comments
 (0)