Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testString appended to body twice as svg text on doc.svg() #272

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface ContextOptions {
attributeState?: AttributeState
refsHandler: ReferencesHandler
styleSheets: StyleSheets
textMeasure?: TextMeasure
textMeasure: TextMeasure
transform?: Matrix
withinClipPath?: boolean
withinUse?: boolean
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/clippath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class ClipPath extends NonRenderedNode {
styleSheets: context.styleSheets,
viewport: context.viewport,
withinClipPath: true,
svg2pdfParameters: context.svg2pdfParameters
svg2pdfParameters: context.svg2pdfParameters,
textMeasure: context.textMeasure
})
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class ImageNode extends GraphicsNode {
refsHandler: new ReferencesHandler(idMap),
styleSheets: context.styleSheets,
viewport: new Viewport(width, height),
svg2pdfParameters: context.svg2pdfParameters
svg2pdfParameters: context.svg2pdfParameters,
textMeasure: context.textMeasure
})
)
return
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class MarkerNode extends NonRenderedNode {
refsHandler: parentContext.refsHandler,
styleSheets: parentContext.styleSheets,
viewport: parentContext.viewport,
svg2pdfParameters: parentContext.svg2pdfParameters
svg2pdfParameters: parentContext.svg2pdfParameters,
textMeasure: parentContext.textMeasure
})

// "Properties do not inherit from the element referencing the 'marker' into the contents of the
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class Pattern extends NonRenderedNode {
refsHandler: context.refsHandler,
styleSheets: context.styleSheets,
viewport: context.viewport,
svg2pdfParameters: context.svg2pdfParameters
svg2pdfParameters: context.svg2pdfParameters,
textMeasure: context.textMeasure
})
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class Use extends GraphicsNode {
styleSheets: context.styleSheets,
withinUse: true,
viewport: refNodeOpensViewport ? new Viewport(width!, height!) : context.viewport,
svg2pdfParameters: context.svg2pdfParameters
svg2pdfParameters: context.svg2pdfParameters,
textMeasure: context.textMeasure
})
const color = context.attributeState.color
await context.refsHandler.getRendered(id, color, node =>
Expand Down
11 changes: 10 additions & 1 deletion src/svg2pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ColorFill } from './fill/ColorFill'
import { jsPDF } from 'jspdf'
import { StyleSheets } from './context/stylesheets'
import { Viewport } from './context/viewport'
import { TextMeasure } from './context/textmeasure'

export async function svg2pdf(
element: Element,
Expand All @@ -28,7 +29,15 @@ export async function svg2pdf(

const svg2pdfParameters = { ...options, element }

const context = new Context(pdf, { refsHandler, styleSheets, viewport, svg2pdfParameters })
const textMeasure = new TextMeasure()

const context = new Context(pdf, {
refsHandler,
styleSheets,
viewport,
svg2pdfParameters,
textMeasure
})

pdf.advancedAPI()
pdf.saveGraphicsState()
Expand Down
4 changes: 4 additions & 0 deletions test/unit/all.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ for (const test of window.tests) {
// await svg2pdf(svgElement, pdf, svg2pdfOptions)

comparePdf(pdf.output(), `/test/specs/${name}/reference.pdf`, debug)

if (document.querySelector('svg')) {
expect.fail('svg measuring element must not remain in document')
}
})
})
}
Loading