From ef8fb2cb0ab61c98ff160d63f392bd2758bc13ec Mon Sep 17 00:00:00 2001 From: stratuma Date: Sat, 22 Jun 2024 22:53:32 +0200 Subject: [PATCH] added: added ass resampler map support --- src/api/services/subs.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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')