-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use pdfkit instead of canvas #496
Conversation
I definitely know the struggle of getting it to work! It is one of the secret reasons to switch away from Heroku (although installing libcairo has been decently easy on raw Linux so far). It's great to have an experiment to play with, thanks a lot!
Not sure how that is possible. Will make more tests. Of course, we'll need to have comparisons of actual badge images, with extremes (little text, huge chunk of text, unicode…) |
I also had this idea to avoid the problem of sending literal text in badges which will always be seen wrong with people that don't have the right font, by converting it to an SVG path, which I had implemented in node-canvas. But I never got around to doing the last step in shields, so I guess it isn't that valuable at this point. |
That looks like a massive performance impact! Am I reading those numbers correctly? I would think converting them to paths would make the file size a fair bit larger for very little real gain. Most browsers have a sufficient set of fonts and the fallbacks won't usually look too bad. I also would think that the literal text could be better handled by screen readers (although I don't know if any screen readers actually do that) |
I'm not surprised, well optimised JavaScript modules are usually faster than their C counterparts when they are called from JavaScript unless they are very long running because of the large amount of time spent crossing the boundary between languages. (for example, the JavaScript MySQL driver consistently outperforms C bindings). I could implement this as a fail over (i.e. use canvas if available, otherwise fall back to pdfkit) if the accuracy on long strings is too much of an issue? Another alternative would be to just allow slightly larger tolerances for very long strings (which risks having excessive margins but would prevent things being cut of) For |
Right now, my feeling is that long strings are uncommon enough that the benefit of removing the cairo dependency outweighs the issue. But it feels like an IEEE754 bug that might be fixable in pdfkit. Otherwise, a hack for long strings (such as adding a few pixels to the result of the computation) might work.
Given that it isn't a regression, it isn't necessary for this pull request. I wonder if I'm right about fallback fonts though. |
Not sure about fallback fonts in PDFkit. It errors if the ttf doesn't exist, and if you were actually using it to generate a PDF, it would embed the font in the pdf. I'll add support for falling back to a default font if the ttf file doesn't exist so that we can run tests on travis again. |
Right, but what happens if the glyph isn't defined in the font? |
I'm not sure, that may be an issue |
While reading this interesting implementation of OTF-based font measurement, I realized that we may have been mistaken. I think that perhaps PDFKit's Trying to figure out the exact unit used for
Chapter 1 unveils that it reflects the density of the master grid on which curve points are set. The more FUnits there are in an em, the more precise typographs can be when placing curve points.
As a result, after cancellation of units in the original formula, I believe |
I am not deeply knowledgeable about Microsoft fonts, but I accidentally noticed today that the md5 of my local Verdana font, from the Ubuntu package (3ba52ab1fa0cd726e7868e9c6673902c, 137K) is distinct from that of my Mac (4ba636f1f53078cdd483de8f7630600f, 182K). PDFkit seems to have been built with a Mac. None of the issues I reported are there with the Mac version of Maybe Linux' Verdana was always broken and Cairo (or is it Pango?) used tricks around that. Maybe Mac's Verdana includes hinting information that PDFkit uses and that is absent from Linux' version, which assumes you read data from a field which PDFkit doesn't currently support. We may never know. |
As an aside to get back to in the future, I'd like to note another possibility, which we might consider if font choice becomes necessary. This library makes use of |
This removes the dependency on the native "canvas" module and instead uses pdfkit. I did this because I was unable to get canvas installed on my machine. I'm not sure if this will perform better or worse, but it seems like something that may be worth benchmarking.