Skip to content

Update subtitle position styling #6766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/subtitlesettings/subtitleappearancehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ function getTextStyles(settings, preview) {
if (!preview) {
const pos = parseInt(settings.verticalPosition, 10);
const lineHeight = 1.35; // FIXME: It is better to read this value from element
const line = Math.abs(pos * lineHeight);
if (pos < 0) {
list.push({ name: 'min-height', value: `${line}em` });
const margin = Math.abs(pos + 1) * lineHeight;
list.push({ name: 'margin-bottom', value: `${margin}em` });
list.push({ name: 'margin-top', value: '' });
} else {
list.push({ name: 'min-height', value: '' });
list.push({ name: 'margin-top', value: `${line}em` });
const margin = pos * lineHeight;
list.push({ name: 'margin-bottom', value: '' });
list.push({ name: 'margin-top', value: `${margin}em` });
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/plugins/htmlVideoPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,10 +1532,16 @@ export class HtmlVideoPlayer {
// in safari, the cues need to be added before setting the track mode to showing
for (const trackEvent of data.TrackEvents) {
const TrackCue = window.VTTCue || window.TextTrackCue;
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, normalizeTrackEventText(trackEvent.Text, false));
const text = normalizeTrackEventText(trackEvent.Text, false);
const cue = new TrackCue(trackEvent.StartPositionTicks / 10000000, trackEvent.EndPositionTicks / 10000000, text);

if (cue.line === 'auto') {
cue.line = cueLine;
if (cueLine < 0) {
const lineCount = (text.match(/\n/g) || []).length;
cue.line = cueLine - lineCount;
} else {
cue.line = cueLine;
}
}

trackElement.addCue(cue);
Expand Down
Loading