diff --git a/src/pgs.ts b/src/pgs.ts index 79c1de8..fa947b3 100644 --- a/src/pgs.ts +++ b/src/pgs.ts @@ -188,7 +188,8 @@ export class Pgs { // Builds the subtitle. const pixelData = this.getPixelDataFromComposition(compositionObject, palette, ctxObjects); if (pixelData) { - compositionData.push(new SubtitleCompositionData(window, pixelData)); + compositionData.push(new SubtitleCompositionData( + compositionObject.horizontalPosition, compositionObject.verticalPosition, window, pixelData)); } } diff --git a/src/renderer.ts b/src/renderer.ts index d05da90..b47e8e1 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -63,7 +63,7 @@ export class Renderer { * @param dirtyArea If given, it will extend the dirty rect to include the affected subtitle area. */ private drawSubtitleCompositionData(compositionData: SubtitleCompositionData, dirtyArea?: Rect): void { - this.context?.putImageData(compositionData.pixelData, compositionData.window.horizontalPosition, compositionData.window.verticalPosition); + this.context?.putImageData(compositionData.pixelData, compositionData.x, compositionData.y); // Mark this area as dirty. dirtyArea?.union(compositionData.window.horizontalPosition, compositionData.window.verticalPosition, diff --git a/src/subtitleData.ts b/src/subtitleData.ts index cbbabfe..fc645a9 100644 --- a/src/subtitleData.ts +++ b/src/subtitleData.ts @@ -30,6 +30,16 @@ export class SubtitleData { * This class contains the compiled subtitle data for a single composition. */ export class SubtitleCompositionData { + /** + * The x position of the image in pixels from the left edge of the canvas. + */ + public readonly x: number; + + /** + * The y position of the image in pixels from the top edge of the canvas. + */ + public readonly y: number; + /** * The pgs window to draw on (the on-screen position). */ @@ -40,7 +50,9 @@ export class SubtitleCompositionData { */ public readonly pixelData: ImageData; - public constructor(window: WindowDefinition, pixelData: ImageData) { + public constructor(x: number, y: number, window: WindowDefinition, pixelData: ImageData) { + this.x = x; + this.y = y; this.window = window; this.pixelData = pixelData; }