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

Web: allow to use Fira Code in editor (Safari) #83294

Open
bpasero opened this issue Oct 25, 2019 · 14 comments
Open

Web: allow to use Fira Code in editor (Safari) #83294

bpasero opened this issue Oct 25, 2019 · 14 comments
Labels
feature-request Request for new features or functionality font-rendering Font rendering issues safari Issues running VSCode in Web on Safari web Issues related to running VSCode in the web
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Oct 25, 2019

Open web in Safari with "editor.fontFamily": "Fira Code". the font is not being loaded it seems. Works fine in other browsers.

image

The only workaround that helped as to directly import the font into the HTML (https://cdn.rawgit.com/tonsky/FiraCode/1.205/distr/fira_code.css). Maybe related to how they define a src for the font and we don't?

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug web Issues related to running VSCode in the web safari Issues running VSCode in Web on Safari labels Oct 25, 2019
@bpasero
Copy link
Member Author

bpasero commented Oct 28, 2019

//cc @alexandrudima who I think knows why this happens

Maybe one workaround would be to at least not fallback to a serif-font when this happens but rather pick our default (if we can possibly detect that).

@alexdima
Copy link
Member

My theory is that this is blocked to prevent finger-printing via installed fonts...

I am not sure how the editor itself can validate this setting, because the editor can be embedded in pages which do contain Fira Code via CSS...

So I think we might need special editor.fontFamily Safari validation, but only in the workbench (not the standalone editor)...

@alexdima alexdima self-assigned this Oct 29, 2019
@alexdima alexdima added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Oct 29, 2019
@bpasero
Copy link
Member Author

bpasero commented Oct 29, 2019

Maybe somewhere here: workbench#restoreFontInfo

@alexdima
Copy link
Member

AFAIK that piece of code only executes on startup (to load the previous font metrics from local storage and avoid measuring the font and doing a sync layout in the startup phase). It is possible to change editor.fontFamily after the workbench startup, so that place would not be good.

I think we need an editor contribution that only executes on the web, on Safari, and which listens to editor option change events, and checks if the fontFamily is configured with a font that work on Safari or not... But how should we know the entire list of fonts that work on Safari?

@alexdima
Copy link
Member

I have found this -- https://en.wikipedia.org/wiki/List_of_typefaces_included_with_macOS , should we ship with this list hard coded somewhere?

@bpasero
Copy link
Member Author

bpasero commented Oct 30, 2019

I like that. We can possibly put this somewhere into our workbench specific overrides for the editor? E.g. when running in Safari, we do not allow a font family that is not in that set?

Code pointer: getConfigurationOverrides

@alexdima
Copy link
Member

@bpasero When you played with the CSS variant, did you experiment with using local as a src?

https://stackoverflow.com/a/43502304

e.g.

@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400;
  src: url("font/montserrat/montserrat-latin-regular.eot");
  src: local("Montserrat-Regular"), url("font/montserrat/montserrat-latin-regular.eot?#iefix") format("embedded-opentype"), url("font/montserrat/montserrat-latin-regular.woff2") format("woff2"), url("font/montserrat/montserrat-latin-regular.woff") format("woff"), url("font/montserrat/montserrat-latin-regular.ttf") format("truetype"), url("font/montserrat/montserrat-latin-regular.svg#Montserrat") format("svg"); 
}

@alexdima
Copy link
Member

alexdima commented Oct 30, 2019

Actually it looks like this is a known limitation, for example designers try to use Figma in the browser with their local fonts... and they need to install an app for that... -- https://help.figma.com/article/356-use-local-fonts-with-figma-font-helper

image

@alexdima
Copy link
Member

Yeah, I finally could find a definitive answer -- it is done to avoid fingerprinting -- https://stackoverflow.com/a/52805055

@alexdima alexdima added this to the Backlog milestone Oct 30, 2019
@alexdima alexdima removed their assignment Oct 30, 2019
@bpasero
Copy link
Member Author

bpasero commented Nov 5, 2019

I actually think this is a fair workaround:

"editor.fontFamily": "Fira Code, Menlo, Monaco"

It works nicely on Safari to fallback to Menlo.

@bpasero bpasero changed the title Web: cannot use Fira Code in editor (Safari) Web: allow to use Fira Code in editor (Safari) Nov 5, 2019
@bpasero bpasero added the font-rendering Font rendering issues label Nov 5, 2019
@rebornix rebornix removed their assignment Oct 9, 2020
@Mara-Li
Copy link

Mara-Li commented Jul 7, 2022

Hello! Sorry to bother. I want to know if there is a way to import font (embedded using base64, for example) to change the font in safari ? Using HTML <style> or a CSS file ?

Thank you :)!

@oliverlabs
Copy link

Has anyone been able to work around this? Any Nerd Font in Safari seems to be blocked.

@7ombie
Copy link

7ombie commented Feb 12, 2024

Safari removed the workarounds a while ago (see this StackOverflow question).

The proper way to use Nerd Fonts in Safari is to serve them along with the client. I'm pretty sure browsers only load what they need (font-wise), so that would be an option, but requires changes on the server.

As a user, you'd need to achieve the same effect without access to the server (assuming you're not hosting VSCode yourself). It may be possible to use a browser extension to inject the font into the page, or just create a browser extension for injecting the font. IIUC, as long as the font is loaded by the page, referencing it will work.

@7ombie
Copy link

7ombie commented Feb 12, 2024

Another option is to install VSCode locally and attach to a remote server. For example, GitHub Codespaces allows you to open the codespace using your local VSCode installation:

Screenshot 2024-02-12 at 11 43 50 PM

I'm using Iosevka Nerd Font with this approach (without any issues).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality font-rendering Font rendering issues safari Issues running VSCode in Web on Safari web Issues related to running VSCode in the web
Projects
None yet
Development

No branches or pull requests

6 participants