-
Notifications
You must be signed in to change notification settings - Fork 29
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
Change drawSvg to be synchronous #53
Conversation
src/api/svg.ts
Outdated
}; | ||
} | ||
|
||
export const drawSvgSync = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, you missed half of the point.
We want to expose the same API as Images. This means that you need and embedSvg
that will return a PDFSvg object method and a drawSvgSync
that will take that PDFSvg and draw it on the pdf page.
Your methods also seem to be misplaced between PDFPage and svg. The method drawSvg from svg has no more reason to be async and should be made sync. No need to create a drawSvgAsync here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the implementation, but it's a bit different from your suggestion. I didn't implement the PDFSvg
class because it would be a breaking change of the current drawSvg
api.
@@ -897,10 +894,10 @@ const parse = ( | |||
); | |||
}; | |||
|
|||
export const drawSvg = async ( | |||
export const drawSvg = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have this signature: drawSvg(page: PDFPage, svg: PDFSvg, options: PDFPageDrawSVGElementOptions)
type PDFSvg = {
svg: string,
images: Record<string, image>
}
src/api/PDFPageOptions.ts
Outdated
@@ -174,4 +175,5 @@ export interface PDFPageDrawSVGElementOptions { | |||
height?: number; | |||
fontSize?: number; | |||
fonts?: { [fontName: string]: PDFFont }; | |||
images?: Record<string, PDFImage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be part of the options
@@ -1585,22 +1585,23 @@ export default class PDFPage { | |||
* @param svg The SVG to be drawn. | |||
* @param options The options to be used when drawing the SVG. | |||
*/ | |||
async drawSvg( | |||
drawSvg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to avoid breaking changes, this method can't be made sync, because it is exposed to the public. But we could decide to make a breaking change. In this case, we should change the signature of this method to drawSvg(svg: PDFSvg, options: PDFPageDrawSVGElementOptions)
In case you want to go with the no breaking change option, you'd need to create the method:
drawSvgSync(svg: PDFSvg, options: PDFPageDrawSVGElementOptions): void {
drawSvg(this, svg, options)
}
async drawSvg(svg: string, options: PDFPageDrawSVGElementOptions): void {
const svgPdf = await embedSvg(svg)
this.drawSvgSync(svgPdf, options)
}
The other option would lead to only:
drawSvg(svg: PDFSvg, options: PDFPageDrawSVGElementOptions): void {
drawSvg(this, svg, options)
}
Of course, you can keep the asserts and detail the options like in the current code
3f93a29
to
b1a9a26
Compare
b1a9a26
to
372bfce
Compare
No description provided.