I don't have Admin privilege on my working PC(Windows 7), so I can't install custom font(Fira Code) into my system. Is there a way to use such font without installing in VS Code?
Yes, you can load font without admin privileges. Take a look at the AddFontResource function. You can also use Font Xplorer (freeware) to load fonts from a local folder.
You can use AddFontResourceEx to add a physical font file for the application to use. int AddFontResourceEx( LPCTSTR lpszFilename, // font file name DWORD fl, // font characteristics PVOID pdv // reserved );
Right-click the fonts you want, and click Install. If you're prompted to allow the program to make changes to your computer, and if you trust the source of the font, click Yes. Your new fonts will appear in the fonts list in Word.
Find a ugly workaround for this issue: using webfont.
var styleNode = document.createElement('style');
styleNode.type = "text/css";
var styleText = document.createTextNode(`
@font-face{
font-family: 'Fira Code';
src: url('https://raw.githubusercontent.com/tonsky/FiraCode/master/distr/eot/FiraCode-Regular.eot') format('embedded-opentype'),
url('https://raw.githubusercontent.com/tonsky/FiraCode/master/distr/woff2/FiraCode-Regular.woff2') format('woff2'),
url('https://raw.githubusercontent.com/tonsky/FiraCode/master/distr/woff/FiraCode-Regular.woff') format('woff'),
url('https://raw.githubusercontent.com/tonsky/FiraCode/master/distr/ttf/FiraCode-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}`);
styleNode.appendChild(styleText);
document.getElementsByTagName('head')[0].appendChild(styleNode);
I found a way to do this without having to run the snippet every time you stat up VS Code.
File > Open Folder
Navigate to your VS Code installation, and then go to:
resources > app > out > vs > code > electron-browser > workbench
Open that folder.
Edit workbench.js
using VS Code and add the Tai's snippet to the end of it.
Ctrl+R
to reload the window and you should be done!Again, make sure that you have Fira Code as the first option in your Font Family settings within VS Code, and make sure that font ligatures are enabled.
Tai Zhang's great little hack can be automated with the Monkey Patch extension.
After installing Monkey Patch, paste Tai's code into a new file, e.g. %USERPROFILE%\vscode-monkeypatch-modules\custom-fonts.js
.
Now add the file to your settings.json
, e.g.:-
"monkeyPatch.folderMap": {
"my-custom-modules" : "~/vscode-monkeypatch-modules",
},
"monkeyPatch.browserModules": [
"my-custom-modules/custom-fonts"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With