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

Weird behavior for installed fonts after Windows 11 22H2 update #198

Closed
mkvlrn opened this issue Oct 6, 2022 · 18 comments · Fixed by #227
Closed

Weird behavior for installed fonts after Windows 11 22H2 update #198

mkvlrn opened this issue Oct 6, 2022 · 18 comments · Fixed by #227

Comments

@mkvlrn
Copy link

mkvlrn commented Oct 6, 2022

TL;DR:

Fonts installed (they were installed before the update) appear to be installed but do not work - installing them manually from the cache folder works.

Not really sure if this should be opened here or elsewhere, could be a manifest problem? Here's what happened:

I have 2 NF fonts installed from this bucket: firacode-nf-mono for vscode and hack-nf-mono for the terminal. They are used with the names "FiraCode NFM" and "Hack NFM", respectively, and have been working fine for months.

Day after my windows 11 22h2 update, when I opened windows-terminal I've received the warning that "Hack NFM" coulndn't be found and it defaulted to Consolas. Checked scoop list, fonts still there. Checked the "Fonts" control panel applet, fonts are there.

But I cannot find them in a list, for example, trying to change Notepad's font. They are not there.

So I uninstall and reinstall both, restart computer, same problem.

BUT - after uninstalling them again, I go to scoops cache folder, see the .ttf files, and try to install them manually - by double clicking and hitting "Install". It worked! They appear exactly the same as before in the "Fonts" applet, but now are also listed on the font change dropdown for apps and work correctly as before.

Repeated the process 3 times to check my own sanity, it happened as described again and again.

@gitolicious
Copy link

Had the same problem and just now understood that it broke with the 22H2 update. Thanks for the workaround which at least temporarily fixes the problem.

@mrjohannchang
Copy link

I believe the root cause is: microsoft/terminal#3257

@mkvlrn
Copy link
Author

mkvlrn commented Oct 9, 2022

I believe the root cause is: microsoft/terminal#3257

It's not only on windows-terminal, it's system wide. It also happens to vscode, notepad, any applications. It's like the font was never installed to begin with.

@hfziu
Copy link

hfziu commented Oct 13, 2022

Same issue here. I just did a fresh re-install of Windows 11 22H2. I then installed JetBrainsMono NF font via scoop. This puts the font files into %LOCALAPPDATA%\Microsoft\Windows\Fonts.

image

I can even successfully set the font in Windows Terminal. The weirdest part is that the setting won't survive a system reboot.

After reboot:

  • I navigated into %LOCALAPPDATA%\Microsoft\Windows\Fonts, and the font files are still there;
  • I can still select the fonts in Windows Terminal settings, and the font preview in the settings page works well: image
  • However, Windows Terminal complained that the font could not be found when I clicked 'Save'.
    image
  • Other apps, e.g., VS Code, could not recognize the fonts either.

@FDUZS
Copy link

FDUZS commented Oct 15, 2022

Same issue here.

And for me, it happens after the installation of
2022-10 Cumulative Update for Windows 11 Version 22H2 for x64-based Systems (KB5018427)
yesterday.


ADD:
It seems like this issue only happens to nerd-fonts like JetBrainsMono-NF (scoop install JetBrainsMono-NF), while JetBrains-Mono (scoop install JetBrains-Mono) has no such thing. Can you guys reproduce this?

@rozbo
Copy link

rozbo commented Oct 17, 2022

me too......

@hfziu
Copy link

hfziu commented Oct 17, 2022

It seems like this issue only happens to nerd-fonts like JetBrainsMono-NF (scoop install JetBrainsMono-NF), while JetBrains-Mono (scoop install JetBrains-Mono) has no such thing. Can you guys reproduce this?

For me, none of the fonts (installed by scoop into %LOCALAPPDATA%\Microsoft\Windows\Fonts) survive a reboot, including JetBrains-Mono.

@Dabombber
Copy link

There's nothing wrong with the font installation, it's an issue with the Windows font cache. You can use the following command to get them working again.

 Restart-Service -Name FontCache

@hfziu
Copy link

hfziu commented Oct 18, 2022

Seems like Windows has a feature that can block untrusted fonts from loading outside of the %windir%/Fonts directory. However, the last time I checked, this feature was Not configured on my system.

https://learn.microsoft.com/en-us/windows/security/threat-protection/block-untrusted-fonts-in-enterprise

@DavidZhang73
Copy link

TL;DR sudo scoop install -g <font> instead of scoop install <font>
I encountered this issue after upgraded to 22H2, Restart-Service -Name FontCache does not help, untrusted fonts was also not configured, but microsoft/terminal#14231 (comment) seems to be a workable solution.
BTW, following that comment, I found #161, which introduces installing font in user scope instead of system level. I suspect it conflicts with 22H2 upgrade. However, I have another desktop PC, which also upgraded to 22H2 recently, the font works fine.

@gitolicious
Copy link

Great hint, thanks a lot for that! Solved the problem for me.

@jonz94
Copy link
Collaborator

jonz94 commented Oct 23, 2022

Hi there,

Sorry for being late...
and BIG THANKS to everyone here for providing so much useful information!

Base on DavidZhang73's comment and #180.
It seems that the best solution for now is using sudo scoop install -g <font> to install font for all users.

@hungpham3112
Copy link

According to this issue, it seems we need to install Nerd Fonts for all users instead of current user.

@felipecrp
Copy link

I think the problem is that the installer is trying to install the fonts in the user space. Installing to the system to all users, apparently, solve the problem.

More info available here -> microsoft/cascadia-code#137 (comment)

@felipecrp
Copy link

#200 will probably solve this issue.

@mkvlrn
Copy link
Author

mkvlrn commented Oct 24, 2022

Alright, so it's definitely not an issue in this repo, but the discussion finally got to a solution. Thanks! Closing this.

@jonz94
Copy link
Collaborator

jonz94 commented Mar 29, 2023

I think I may have found the root cause of the original issue.
It appears to caused by misconfigured permissions of the user font install folder (%LOCALAPPDATA%\Microsoft\Windows\Fonts), which is preventing the fonts from functioning properly.

Investigation

On a fresh installed Windows (Windows 10 1809 onward), if we install a font using the normal way:

  • Double-click the font file, and then press the Install button on the font viewer app.
  • Or, right-click the font file, and then select Install (not Install for all users) on the menu.

Windows will automatically create the user font install folder (%LOCALAPPDATA%\Microsoft\Windows\Fonts) for us.
And the important part is that Windows will give it the proper permission settings,
which included permissions for ALL APPLICATION PACKAGES and ALL RESTRICTED APPLICATION PACKAGES.

Screenshot of the correct permission settings:
correct-full

On the other hand, if we manually create this folder using File Explorer,
or in the case of the PowerShell script introduced in #161, using New-Item PowerShell command:

"$fontInstallDir = if ($global) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($global) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null",

The folder will not have the same permission settings as the user font install folder created by Windows.
In particular, the permissions for ALL APPLICATION PACKAGES and ALL RESTRICTED APPLICATION PACKAGES will be missing.

Screenshot of the wrong permission settings:
wrong-full

The mysterious part is that if the user font install folder has the misconfigured permissions problem:

  • On Windows 10 1809 to Windows 11 22H1, everything works just fine.
  • But on Windows 11 22H2 onward, it makes all the fonts installed in this folder malfunction and cannot be accessed by any Windows apps.

Solution

To address this issue, we just need to make sure the user font install folder has the correct permission settings.

There are a few ways to do this:

1. Use Set-Acl PowerShell command to add back the missing permissions

$userFontInstallFolder = "${env:LOCALAPPDATA}\Microsoft\Windows\Fonts"

$accessControlList = Get-Acl $userFontInstallFolder

# ALL APPLICATION PACKAGES
$allApplicationPackagesAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule([System.Security.Principal.SecurityIdentifier]::new("S-1-15-2-1"), "ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow")

# ALL RESTRICTED APPLICATION PACKAGES
$allRestrictedApplicationPackagesAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule([System.Security.Principal.SecurityIdentifier]::new("S-1-15-2-2"), "ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow")

$accessControlList.SetAccessRule($allApplicationPackagesAccessRule)
$accessControlList.SetAccessRule($allRestrictedApplicationPackagesAccessRule)

Set-Acl -AclObject $accessControlList $userFontInstallFolder

Q: What does "S-1-15-2-1" and "S-1-15-2-2" mean?

A: These are the security identifiers for ALL APPLICATION PACKAGES and ALL RESTRICTED APPLICATION PACKAGES respectively.

References I used to write this script:

2. Remove the existing user font install folder and let Windows create a new one

  1. Go to the user font install folder (%LOCALAPPDATA%\Microsoft\Windows\Fonts).
  2. Copy all of the fonts inside the user font install folder to another location (e.g. Desktop) for later use (for step 5).
  3. Open Registry Editor, go to Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts, and then delete all of the font entries except for the first (Default) entry.
  4. Delete the entire user font install folder.
  5. Select all of the fonts that you copied in step 2, right-click, and click Install.
  6. Done!

I will probably send a PR using the first solution (maybe this weekend), so users who have used this Scoop bucket to install fonts before can retrive the fix by updating/reinstalling the font using Scoop.

@jonz94 jonz94 reopened this Mar 29, 2023
@iquiw
Copy link

iquiw commented Mar 29, 2023

@jonz94 Awesome!!
The first solution fixed the problem for me!

just a typo.

- $accessControlList = Get-Acl $userFontInstallDir
+ $accessControlList = Get-Acl $userFontInstallFolder

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

Successfully merging a pull request may close this issue.