Skip to content

Commit

Permalink
fix pattern position (yWorks#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Bretzigheimer committed Aug 11, 2022
1 parent 0b3a452 commit 73b45f3
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/nodes/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 73b45f3

Please sign in to comment.