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

Fix <use> with no contents #279

Merged
merged 2 commits into from Dec 11, 2023
Merged

Fix <use> with no contents #279

merged 2 commits into from Dec 11, 2023

Conversation

edemaine
Copy link
Contributor

@edemaine edemaine commented Dec 6, 2023

Fixes #278 by correctly checking for empty paths in GeometryNode.prototype.getBoundingBoxCore. Indeed, the line mentioned in #278 (comment) had a bug that wasn't correctly checking for empty paths.

I've confirmed that this fixes #278 in my setting. I didn't add tests because I don't know how they're organized...

@@ -80,7 +80,7 @@ export abstract class GeometryNode extends GraphicsNode {

protected getBoundingBoxCore(context: Context): Rect {
const path = this.getCachedPath(context)
if (!path) {
if (!path || !path.segments.length) {
return [0, 0, 0, 0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a bounding box with zero width and height "located at 0,0" handled properly in the rest of the code?
When we calculate the union of two bounding boxes do we filter "empty" bounding boxes like this?
What's the bounding box of a point at (0,0)?

E.g. in yFiles, a truely empty bounding box uses negative width and height as sentinel values, so that you can distinguish between non-existing and infinitely small bounding box rectangles...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this is not 100% exact at this point and [0,0,0,0] isn't handled specially on the caller side. However, throughout the codebase we use [0,0,0,0] for empty bounding boxes and this hasn't been an issue so far. We could improve this in a separate PR, but let's keep it like this for the moment.

Copy link
Member

@HackbrettXXX HackbrettXXX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

@edemaine
Copy link
Contributor Author

edemaine commented Dec 7, 2023

Sorry about the extra changes in dist and yarn.lock. I didn't mean to include them, but git commit -a is a hard habit to break. 😅

Thanks for the README pointer. I added the test case from #278. If you'd rather a more interesting test (such as a larger output from MathJax where this occurs), or rather it integrated into the existing svg-use example, let me know.

Copy link
Member

@HackbrettXXX HackbrettXXX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Thanks for adding the test case, looks good!

@HackbrettXXX HackbrettXXX merged commit 6f663a1 into yWorks:master Dec 11, 2023
1 check passed
@HackbrettXXX
Copy link
Member

I published the bugfix: https://github.com/yWorks/svg2pdf.js/releases/tag/v2.2.3

@edemaine
Copy link
Contributor Author

I confirmed that the new release fixes my issues. Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty path def crashes jspdf
3 participants