diff --git a/src/api/services/subs.ts b/src/api/services/subs.ts index 92428e4..f141bb6 100644 --- a/src/api/services/subs.ts +++ b/src/api/services/subs.ts @@ -134,7 +134,7 @@ function resamplePOSSubtitle(subtitle: string, ox: number, oy: number, nx: numbe } if (line.includes('\\fs')) { - let posMatches = line.matchAll(/\\fs(-?\d+(?:\.\d+)?)/g) + let posMatches = line.matchAll(/\\fs(\d+(?:\.\d+)?)/g) for (let posMatch of posMatches) { let font = parseInt(posMatch[1]) let newFontSize = Math.round((font / oy) * ny) @@ -154,6 +154,22 @@ function resamplePOSSubtitle(subtitle: string, ox: number, oy: number, nx: numbe } lines[i] = line } + + if (line.match(/m\s|l\s/)) { + let posMatches = line.matchAll(/([ml])\s*(-?\d+(?:\.\d+)?)\s*(-?\d+(?:\.\d+)?)/g) + for (let posMatch of posMatches) { + let command = posMatch[1] + let oldX = parseFloat(posMatch[2]) + let oldY = parseFloat(posMatch[3]) + + let newX = Math.round((oldX / ox) * nx) + let newY = Math.round((oldY / oy) * ny) + + let newCommand = `${command} ${newX} ${newY}` + line = line.replace(posMatch[0], newCommand) + } + lines[i] = line + } } return lines.join('\n')