List the font paths known to the Windows registry.
()
| 219 | |
| 220 | |
| 221 | def _get_win32_installed_fonts(): |
| 222 | """List the font paths known to the Windows registry.""" |
| 223 | import winreg |
| 224 | items = set() |
| 225 | # Search and resolve fonts listed in the registry. |
| 226 | for domain, base_dirs in [ |
| 227 | (winreg.HKEY_LOCAL_MACHINE, [win32FontDirectory()]), # System. |
| 228 | (winreg.HKEY_CURRENT_USER, MSUserFontDirectories), # User. |
| 229 | ]: |
| 230 | for base_dir in base_dirs: |
| 231 | for reg_path in MSFontDirectories: |
| 232 | try: |
| 233 | with winreg.OpenKey(domain, reg_path) as local: |
| 234 | for j in range(winreg.QueryInfoKey(local)[1]): |
| 235 | # value may contain the filename of the font or its |
| 236 | # absolute path. |
| 237 | key, value, tp = winreg.EnumValue(local, j) |
| 238 | if not isinstance(value, str): |
| 239 | continue |
| 240 | try: |
| 241 | # If value contains already an absolute path, |
| 242 | # then it is not changed further. |
| 243 | path = Path(base_dir, value).resolve() |
| 244 | except RuntimeError: |
| 245 | # Don't fail with invalid entries. |
| 246 | continue |
| 247 | items.add(path) |
| 248 | except (OSError, MemoryError): |
| 249 | continue |
| 250 | return items |
| 251 | |
| 252 | |
| 253 | @cache |
no test coverage detected
searching dependent graphs…