diff --git a/src/nodes/pattern.ts b/src/nodes/pattern.ts index fcd65384..17185f86 100644 --- a/src/nodes/pattern.ts +++ b/src/nodes/pattern.ts @@ -13,26 +13,30 @@ export class Pattern extends NonRenderedNode { } // the transformations directly at the node are written to the pattern transformation matrix + const x = context.svg2pdfParameters.x ?? 0 + const y = context.svg2pdfParameters.y ?? 0 const bBox = this.getBoundingBox(context) - const pattern = new TilingPattern( - [bBox[0], bBox[1], bBox[0] + bBox[2], bBox[1] + bBox[3]], - bBox[2], - bBox[3] - ) + const startX = bBox[0] + x + const startY = bBox[1] + y + const width = bBox[2] + const height = bBox[3] + const endX = startX + width + const endY = startY + height + const pattern = new TilingPattern([startX, startY, endX, endY], width, height) context.pdf.beginTilingPattern(pattern) // continue without transformation for (const child of this.children) { - await child.render( - new Context(context.pdf, { - attributeState: context.attributeState, - refsHandler: context.refsHandler, - styleSheets: context.styleSheets, - viewport: context.viewport, - svg2pdfParameters: context.svg2pdfParameters - }) - ) + const childContext = new Context(context.pdf, { + attributeState: context.attributeState, + refsHandler: context.refsHandler, + styleSheets: context.styleSheets, + viewport: context.viewport, + svg2pdfParameters: context.svg2pdfParameters, + transform: context.pdf.Matrix(1, 0, 0, 1, x, y) + }) + await child.render(childContext) } context.pdf.endTilingPattern(id, pattern) }