qtawesome icon indicating copy to clipboard operation
qtawesome copied to clipboard

Icons are blocked because of untrusted fonts on Windows 10

Open giumas opened this issue 3 years ago • 7 comments

I need to deploy an app using qtawesome on some machines where the Untrusted Font Blocking policy is set to "Block untrusted fonts and log events" (https://docs.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/feature-to-block-untrusted-fonts).

With such a policy, the example.py in the root of the repository returns:

Traceback (most recent call last):
  File "C:/code/example.py", line 167, in <module>
    main()
  File "C:/code/example.py", line 162, in main
    _ = AwesomeExample()
  File "C:/code/example.py", line 18, in __init__
    fa5_icon = qta.icon('fa5.flag')
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\__init__.py", line 173, in icon
    return _instance().icon(*names, **kwargs)
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\__init__.py", line 77, in _instance
    'materialdesignicons-webfont-charmap.json')
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\iconic_font.py", line 214, in __init__
    self.load_font(*fargs)
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\iconic_font.py", line 270, in load_font
    os.path.join(directory, ttf_filename)))
qtawesome.iconic_font.FontError: Font at 'C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\fonts\fontawesome4.7-webfont.ttf' appears to be empty. If you are on Windows 10, please read https://support.microsoft.com/en-us/kb/3053676 to know how to prevent Windows from blocking the fonts that come with QtAwesome.

The issue is present also when running the PyInstaller-based frozen version of the app: https://github.com/ausseabed/qax/issues/9

giumas avatar Sep 21 '21 19:09 giumas

Hi @giumas thank you for the feedback! As described in the traceback if the font file is unable to load we suggest checking the link you describe for the user to allow/setup properly the font since from the package I think there is not much we can do (to enable the font load you either install the font or exclude the application/process using it from validation). However if you know a way to handle this from QtAwesome let us know :+1:

dalthviz avatar Sep 22 '21 08:09 dalthviz

Thanks! Can you confirm that there is no way to get the QtAwesome icons without loading those fonts?

CC: @lachlanhurst

giumas avatar Sep 23 '21 09:09 giumas

From my understanding yep, without loading the fonts there is no way for QtAwesome to be able to work. However, just in case, pinging @ccordoba12

dalthviz avatar Sep 23 '21 12:09 dalthviz

I think a possible workaround is to install those fonts in the user AppData directory. But that only works for a recent Windows 10 build.

ccordoba12 avatar Sep 23 '21 14:09 ccordoba12

Interesting! It seems something that could be done/checked at the app initialization. What do you mean with 'install those fonts'? Copying them? How to then ask QTAwesome to search in that folder?

giumas avatar Sep 23 '21 14:09 giumas

Checking seems like there is a way to setup/install fonts only for the current user (so without admin rights) since the Windows 10 build from 2018 (RS5): https://blogs.windows.com/windows-insider/2018/06/27/announcing-windows-10-insider-preview-build-17704/#vtHzS6SkLWyrfI4D.97 However, I'm not totally sure in the programmatic approach to do it (probably it requires copying the fonts sources in a directory under the user folder and some registry entry?)

dalthviz avatar Sep 27 '21 19:09 dalthviz

However, I'm not totally sure in the programmatic approach to do it (probably it requires copying the fonts sources in a directory under the user folder and some registry entry?)

Yeah, I think it should be enough.

ccordoba12 avatar Jun 06 '22 16:06 ccordoba12

Note: This SO post could be useful here (needs adaptation to install for the user and not to the whole machine) - https://stackoverflow.com/a/41841088/15954282

dalthviz avatar Oct 04 '22 18:10 dalthviz