Comments (15)
Emergency fix for the crash. The while loop goes eternal because the length
is -1. It is prevented by defining a length for the arc operators:
var length = "zZ".indexOf(type) >= 0 ? 0 :
"hHvV".indexOf(type) >= 0 ? 1 :
"mMlLtT".indexOf(type) >= 0 ? 2 :
"sSqQ".indexOf(type) >= 0 ? 4 :
"cC".indexOf(type) >= 0 ? 6 :
"aA".indexOf(type) >= 0 ? 7 : -1; // <== Add length for arcs
from svg2pdf.js.
If we can use svg-arc-to-cubic-bezier, here's how to implement the arcToBezier
function:
case "a":
case "A":
var last = pathSegList[pathSegList.length - 1];
var curves = arcToBezier({
px: last.x,
py: last.y,
cx: coords[i + 5],
cy: coords[i + 6],
rx: coords[i + 0],
ry: coords[i + 1],
xAxisRotation: coords[i + 2],
largeArcFlag: coords[i + 3],
sweepFlag: coords[i + 4]
});
curves.forEach(function (curve, i) {
pathSeg = curve;
pathSeg.pathSegTypeAsLetter = 'C';
// Push all except the last one
if (i < curves.length - 1) {
pathSegList.push(pathSeg);
}
});
break;
from svg2pdf.js.
But if we can get the author's permission to use the lightweight contents of svg-arc-to-cubic-bezier inside the svg2pdf library, wouldn't it be better to have a self-contained solution instead of another dependency?
from svg2pdf.js.
Allright, I'll leave it up to you to decide. If you go for a dependency, we can make a bundle of pdfjs + rgbcolor + svg2pdf + others and serve it from our CDN, for the convenience of our users.
from svg2pdf.js.
I am actually just working on it - I'll keep you updated or maybe will just publish 1.0.0 (it's incompatible from the file layout point of view - the api will be the same) later today.
from svg2pdf.js.
👍
from svg2pdf.js.
That's true and is due to the "// TODO" in line 104. at least breaking the while loop would stop the browser from crashing. Converting svg arcs to pdf arcs is the right fix, here. Right now arcs simply aren't supported.
I don't currently have a fix for this, but we would welcome pull requests, since we also don't currently have the time, nor the need, for fixing this properly.
from svg2pdf.js.
http://stackoverflow.com/a/30279817/351836
from svg2pdf.js.
@yGuy
Here's a project that converts the arc path segment to bezier curves with a nice function API that would probably fit our need perfectly: https://github.com/colinmeinke/svg-arc-to-cubic-bezier.
It comes with a liberal license that requires the copyright be added in all copies. How would it be to include this script in the svg2pdf.js file? Should we ask the author for a special permission? It would also have to be downgraded from ES6.
from svg2pdf.js.
I think, we'll rather pull in https://github.com/fontello/svgpath as another dependency (MIT) and reuse this (and more) functionality from the other project. Just like we depend on jspdf (the fork), svg2pdf.js will then also have the dependency on svgpath - this simplifies the code we currently have a lot and should also make it more robust - svgpath looks like a very complete and robust implementation to me.
from svg2pdf.js.
I'm not so sure whether getting the permission from someone who just copied the code from another project and applied a different license is something that would be legally advisable. svgPath is the original source of the sources in svg-arg-to-cubic. And the original sources look a lot better to me, to - they are commented, and are es5 compatible - just their usage of greek letters is a bit annoying to me.
I think we have written similar code for another project some years ago - I'll see whether taking that code would work, too, and then we could contribute that code directly to svg2pdf - copying over the code from svgPath and properly crediting them would work, too, but in the sense of npm where every line of code is a separate module, pulling that dependency in and then possibly baking it into svg2pdf seems like the easier and more robust solution.
from svg2pdf.js.
How do we proceed? Should we create a PR where we depend on svgPath, or do you want to do a more thorough rewrite? Or we can do both, just fix this issue for now, and you can do the rewrite over time?
from svg2pdf.js.
Please check the version I just published - note that the file now is in dist/svg2pdf.min.js and has rgbcolor and svgpath bundled.
from svg2pdf.js.
Thanks, it seems to work perfectly!
What I do miss is license headers. In the source file they are a bit buried, and in the minified file they are completely removed. Since the built file now contains three different projects I think the license header should mention that, and each project's license conditions. Or perhaps the minified license section can just point to the LICENCE file, where also the dependencies are listed?
Also, a mention of the version in the license header would be nice, but not crucial.
from svg2pdf.js.
Epic! Thanks, yGuy!
from svg2pdf.js.
Related Issues (20)
- Force stroke='none' if 'stroke-width' === 0 HOT 3
- Support for XML HOT 1
- SVG is upscaled in the pdf-file HOT 3
- When font-size declared in rem, text is missing in the exported file. HOT 4
- Artifacts at letter s of font Aleo after conversion - but font Aleo itself has no such issue in jspdf HOT 5
- Latest master doesn't build HOT 1
- Excess clipping of nested SVG HOT 8
- Marker clipping HOT 2
- Error: Invalid argument passed to jsPDF.scale Error HOT 4
- Black background added to paths HOT 8
- Chinese is not supported HOT 2
- The exported PDF is not rendering custom fonts on some of the PDF text objects. HOT 8
- How to concatenate multiple SVG files? HOT 2
- Setting width and height as floats throws t. HOT 2
- How to ignore invalid dataurl HOT 6
- Accept spaces in data urls in image urls
- adding support for the CMYK color space HOT 5
- greek letters in text HOT 1
- tspan dx makes incorrect offset HOT 1
- Incorrect Gradient rendering in svg2pdf HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svg2pdf.js.