-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 modern canvas2D api for text where is available #7748
Conversation
Partial solution for pixijs#7729 on latest Chrome by newest Canvas2D API. See: https://github.com/fserb/canvas2D/blob/master/spec/text-modifiers.md
Older Chrome use a `textLetterSpacing` instead of proposed API `letterSpacing`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think this is the correct approach for RTL and letter-spacing.
My only tiny suggestion would be to avoid the any
cast. Create a stricter type.
interface ModernContext2D extends ContextRenderingContext2D {
textLetterSpacing?: number;
letterSpacing?: number;
}
public canvas: ModernContext2D;
Thanks 👍 |
My query here; does this change mean that text on Chrome can now look different to text on any other browser? Consistency of visuals is pretty essential imo. If there is a visual difference, maybe there's a flag that is off by default that devs can opt into if they understand the ramifications? |
Fair point @themoonrat. I could see this being an issue if someone is using line wrapping or expecting a certain width. Makes it more fragmented a dev experience. Though the impact is probably on the smaller side. Adding a flag is similar to what we did with the new line height behavior, would be good approach here too. This should probably be opt-in. |
Problem that users should select different implementation when native letter spacing not supported.
Looks like dirty, but allow to change bechavior globally for all Texts. Upd. Or maybe enum?
|
I think you're over complicating this from the API design. There are two cases we should consider:
We do not need to allow disabling letter-spacing. I don't see a case where that is useful. I also don't think we need to allow this on a per-instance basis, so global flag is fine. The case for using native is RTL or situations where emulated spacing fails. I'd suggest a simple flag on Text, not settings. Text.nativeLetterSpacing = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Chrome 94 was shipped and letter spacing arrived.😁 |
Partial solution for #7729 on latest Chrome by newest Canvas2D API.
At the moment there are not way solving this case for all cases outside browser implementation without external library that will include glyphs database order, reconstruct ordering of glyphs and ligatures.
See:
https://github.com/fserb/canvas2D/blob/master/spec/text-modifiers.md
https://chromestatus.com/feature/6051647656558592
Description of change
Using canvas2D
letterSpacing
for avoid flipping text for RTL and broking a glyphs for ligatures-heavy language.Example:
https://exponenta.games/games/fix-spacing/
NOTE: You should use Chrome Canary or enable
chrome://flags/#new-canvas-2d-api
in stable chrome.Current version of chrome 92 origin trials still not workig (for me) how should.
Pre-Merge Checklist
npm run lint
)npm run test
)