-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support context.letterSpacing #1014
Comments
I found this possible solution that uses measure text to compute it manually: |
It could be done inside canvas with |
Perhaps look at https://stackoverflow.com/questions/33955754/adding-letter-spacing-in-html-canvas (my post on Stack Overflow) that proposes a different method to the link above that resolves some of the issues mentioned in the link above. I'm sure it could be adapted. |
I do not think the canvas style should influence drawing on the bitmap data. |
Chrome now supports letter-spacing in |
if it is part of canvas api why not. we would need a jsdom patch too then. At this point the title 'kerning' is misleading. Letter spacing is not kerning. |
Tracking/letter-spacing is not part of the HTML Canvas spec. Chrome (and only Chrome) applies the canvas element's current In any case, I'm not opposed to adding it as either |
my old comment was a I'm developer/mantainer of fabricJS and for me this node-canvas is the way to support the library in node. The less offspec things it does, the better i feel. Imagine if i want to throw a letterSpacing in the middle of the things, as a personal preference, no. If that would be a canvas api standard part, why not. Adding a .style object to the node-canvas object that is not meant to be in the DOM is confusing in my opinion. |
I totally agree with @asturur that adding a I took a stab at adding the feature in the form of a new Here's a quick demo: ctx.fillStyle = 'black'
ctx.font = '48px "Zilla Slab"'
ctx.fillText("Anyone who would letterspace lowercase", 30,75)
ctx.textTracking = 500
ctx.fillText("would steal sheep", 30,150)
ctx.textTracking = -60
ctx.fillText("—FREDERIC GOUDY", 30,225) |
Im fifty fifty on this. |
I do think the ideal future for node-canvas wouldn't involve Pango at all. The only thing we need it for is fallback glyphs and font lookups, and font lookups on custom fonts have been buggy in a few cases since Pango doesn't give us enough control. |
I may have this already in another thread and i lost it, or at the end i did not press the comment button. What would stop somoeone to take the full firefox source code for canvas, and make the binding for it under node? |
I like that idea. It looks like it's fairly isolated in https://searchfox.org/mozilla-central/source/gfx/2d, but that's basically a cross-backend (Skia/Cairo) C++ API that provides the primitives for HTML Canvas. The actual Canvas API would be hard to extract but we could parallel its logic in a manual conversion (see https://searchfox.org/mozilla-central/source/dom/canvas/CanvasRenderingContext2D.cpp). That'd give us:
Things I haven't figured out yet:
If we do that, I'd propose starting with NAPI and doing it under the node-gfx org since Automattic isn't involved in this repo anymore. |
If you want to try that i would love to be involved in some way. |
Did this get implemented as per https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/letterSpacing#browser_compatibility ? |
+1 |
please 🙏 |
CanvasRenderingContext2D.letterSpacing is supported since Chrome 99 and Firefox 115 |
Any news on this? :/ |
I just migrated to Fabric.js for letterSpacing |
Time has changed, the only browser that doesn't support letterSpacing is Safari.
Damn, I just migrated from node-canvas due to the lack of CSS filters... |
Issue or Feature
I would like to be able to adjust the kerning/letter-spacing of fonts when drawing text on node-canvas. In a browser this is possible by setting canvas.style.letterSpacing to something like "-3px". But canvas.style I believe does not exist on node-canvas.
(BTW we love node-canvas, it is an amazing piece of software.)
Steps to Reproduce
Interactive example of it working with browser-based Canvas:
https://jsfiddle.net/hg4pbsne/1/
Example code:
This is not possible to reproduce with node-canvas as there is no canvas.style property exposed.
Your Environment
All versions of node-canvas.
My Suggestion
We add a non-standard ctx._letterSpacing parameter to node-canvas that exposes this functionality?
The text was updated successfully, but these errors were encountered: