-
Notifications
You must be signed in to change notification settings - Fork 1.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
Better support for web fonts #1164
Comments
@vincentwoo Good point. Since we use the canvas for rendering, there is no automatic swap-out of fonts anymore. In general you have to make sure that the font is available when your terminal creation code runs. To do that, make sure the terminal creation code is loaded in head or body after the stylesheet that loads the font (see https://stackoverflow.com/questions/9899372/pure-javascript-equivalent-of-jquerys-ready-how-to-call-a-function-when-t). You could also force xterm.js into refreshing its char atlas by setting the fontFamily on the theme once you know that the font is available: term.setOption('theme', { fontFamily: 'YourFontFamily' }) @Tyriar Do you think we should handle this case automatically (refreshing the char atlas once the window finished loading)? |
It's tricky because even if your scripts occur at the end of |
@vincentwoo I think you'll want to call open after the web fonts have finished loading, that would prevent flickering of a different font initially. Anyone know if there an easy way to tell whether a font has been loaded/changed? |
It might be useful to have xterm incorporate one of the polyfills mentioned here: https://stackoverflow.com/questions/5680013/how-to-be-notified-once-a-web-font-has-loaded. Right now, anyone who wants to use a webfont with xterm will have to go through something similar, so it might have good utility for users as an addon. I can look into it if you don't have the time. |
I'd prefer this to be done at a higher level than xterm.js, https://github.com/bramstein/fontfaceobserver is a lot of code to ship to everyone. As for making it an addon, I think we should eventually move away from the current addon model once we have a more complete API as currently the maintenance burden for all addons is put on the xterm.js team. I recommend using fontfaceobserver on your side and only calling |
Hm, even using fontfaceobserver to delay terminal creation, I sometimes see the wrong font loaded. Additionally, in Firefox, it appears to also cause some foreground text to render as black (on black). Has anyone spent a lot of time getting xterm 3.x working in production with webfonts? |
Here's a more detailed use case that I think warrants examination by the team. Let's take a pretty plausible situation: You're a user of xterm.js who wants to use a custom webfont for just terminal display. xterm is the only consumer of your special monospace webfont on your website. You might think, plausibly, that importing the proper font family, waiting an acceptable amount of time for the load, and then instantiating xterm would be enough. This works well enough in Chrome. Firefox, instead of merely lowering the priority of fonts that are unused on the page at load time actuals skips downloading those fonts altogether. In this case, you get a black screen. See this codepen for an example: https://codepen.io/anon/pen/wmPJrQ. In that pen, you'll see a I think there is a lot of virtue in xterm rendering a hidden dummy span which triggers the loading of any font variants it may need for the chosen |
I can see value in an addon that does this and then forces a repaint and refresh of the texture atlas after things are finished. Open to PRs. |
@Tyriar these internals are a bit hard for me. Is there a golden path way to force a refresh of the texture atlas? It seems that |
For anyone wanting this support @vincentwoo published an addon to make working with web fonts easy which you can grab at https://www.npmjs.com/package/xterm-webfont |
Playing with v3, it seems that on some browser hard refereshes, xterm doesn't seem to pick up the custom fontFamily I set and renders oddly:
On a normal refresh after:
Is there a recommended flow for loading xterm with webfonts?
The text was updated successfully, but these errors were encountered: