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
Fixes wrong font size handling relative units #112
Fixes wrong font size handling relative units #112
Conversation
Closes yWorks#110 , but there is still much to do... Fixes: - avoid infinite bboxes - fix wrong scaling of elements referenced by <use>
It seems the second batch of changes is for another feature/issue - we should separate the two pull requests, ideally and not mix them into a single pull-request. |
This reverts commit 55630c0.
src/svg2pdf.js
Outdated
@@ -863,6 +897,20 @@ SOFTWARE. | |||
return boundingBox; | |||
}; | |||
|
|||
var getBoundingBoxByChildren = function (node) { | |||
boundingBox = [0, 0, 0, 0]; |
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.
var
keyword is missing
src/svg2pdf.js
Outdated
var tfMatrix = computeNodeTransform(node); | ||
var bBox = getUntransformedBBox(node); | ||
|
||
var nestedViewport = nodeIs(node, "symbol") && getAttribute(node, "overflow")!="visible"; |
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.
You should almost always prefer ===
and !==
over ==
and !=
in JavaScript in order to prevent things like 0 == false
.
src/svg2pdf.js
Outdated
x = parseFloat(getAttribute(node, "x")) || 0; | ||
y = parseFloat(getAttribute(node, "y")) || 0; | ||
|
||
// x += parseFloat(node.getAttribute("refX")) || 0; // TODO: refX/refY feature is part of SVG 2 |
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.
Doesn't harm to support SVG 2.0 where we can ;)
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.
Note that refX/Y="0"
is different from absent refX/Y
. https://svgwg.org/svg2-draft/struct.html#SymbolAttributes
src/svg2pdf.js
Outdated
@@ -666,7 +699,7 @@ SOFTWARE. | |||
var i, minX, minY, maxX, maxY, viewBox, vb, boundingBox; | |||
var pf = parseFloat; | |||
|
|||
if (nodeIs(node, "polygon,polyline")) { | |||
if (nodeIs(node, "polygon,polyline") && node.getAttribute("points")) { // jspdf doesn't like infinite bboxes |
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.
Probably should use hasAttribute
here. Also check if the points string does contain at least one coordinate.
We should also probably not go to the default case if it is not there, since it expects x/y/etc. attributes on the node.
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.
So just overwriting infinite values before return may be a good idea?
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.
Or simply return [0,0,0,0]
when points has zero length.
src/svg2pdf.js
Outdated
@@ -685,7 +718,7 @@ SOFTWARE. | |||
maxX - minX, | |||
maxY - minY | |||
]; | |||
} else if (nodeIs(node, "path")) { | |||
} else if (nodeIs(node, "path") && getAttribute(node, "d")) { // see above |
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.
See above ;)
# Conflicts: # src/applyparseattributes.ts
Closes #100