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

Fixes wrong font size handling relative units #112

Merged
merged 5 commits into from Jul 14, 2020

Conversation

zenker981
Copy link
Contributor

Closes #100

Closes yWorks#110 , but there is still much to do...
Fixes:
 - avoid infinite bboxes
 - fix wrong scaling of elements referenced by <use>
@yGuy
Copy link
Member

yGuy commented Oct 18, 2019

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.

src/svg2pdf.js Outdated
@@ -863,6 +897,20 @@ SOFTWARE.
return boundingBox;
};

var getBoundingBoxByChildren = function (node) {
boundingBox = [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.

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";
Copy link
Member

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
Copy link
Member

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 ;)

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

See above ;)

@HackbrettXXX HackbrettXXX merged commit 1fb3bfa into yWorks:master Jul 14, 2020
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.

Font-size in em unit does not work
3 participants