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

Font Kerning #6

Open
joafalves opened this issue Sep 20, 2017 · 6 comments
Open

Font Kerning #6

joafalves opened this issue Sep 20, 2017 · 6 comments
Labels

Comments

@joafalves
Copy link

joafalves commented Sep 20, 2017

Hello :)

Do you have any plans to support font kerning on this? When we use chars with different widths, the spacing between characters is always the same.

What are your thoughts on a possible implementation?

Thanks.

@mourner
Copy link
Member

mourner commented Oct 4, 2017

I have no idea how to implement this unfortunately. I made this library for CJK glyphs use case, where all characters are the same size. But I'm welcome to any ideas.

@joafalves
Copy link
Author

I've recently stumbled on this: https://opentype.js.org
It has all the features we needed to adjust the font rendering correctly 👍

@joafalves
Copy link
Author

joafalves commented Oct 4, 2017

We are using it on our all-in-one platform though (https://github.com/scarlettgamestudio/scarlett-editor) you might need to adjust for a "tiny" integration :)

@monfera
Copy link

monfera commented Sep 22, 2021

I was wondering about memory, CPU/runtime and Canvas2d scalability, as rendering all words (ahead of time or on demand) can be resource intensive or sometimes prohibitive. This thread answers it, it's per glyph, so no or low resource issue. May be worth mentioning it in the description that it's glyph based and specifically for monospaced fonts (and I guess tile and sprite based 2D games)

@mourner
Copy link
Member

mourner commented Sep 22, 2021

@monfera good point — probably needs clarification. Although technically nothing prevents drawing TinySDF for whole labels if a use case doesn't require too many. Also, the primary use case for it currently is rendering Chinese/Japanese/Korean glyphs in Mapbox GL JS — so not necessarily monospaced, if the language uses relatively same-size glyphs and doesn't depend on kerning.

@controversial
Copy link

You can calculate the kerning for a pair of characters on a canvas by comparing the measured width of the combined characters to the measured width of the characters individually:

const unkernedWidth = tinySdf.ctx.measureText('A').width + tinySdf.ctx.measureText('V').width;
const kernedWidth = tinySdf.ctx.measureText('AV').width;
const kerning = kernedWidth - unkernedWidth; // a negative value indicates you should adjust the SDFs closer together by that much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants