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 12, 2022
1 parent 646fdb7 commit 9e9d4d5
Show file tree
Hide file tree
Showing 4 changed files with 27 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
1 change: 1 addition & 0 deletions test/common/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ window.tests = [
'nested-tspans',
'opacity-and-rgba',
'path-arc-support',
['pattern-offset', undefined, { x: 10, y: 10 }],
'pattern-units',
'patterns',
'polyline',
Expand Down
Binary file added test/specs/pattern-offset/reference.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions test/specs/pattern-offset/spec.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e9d4d5

Please sign in to comment.