fonti 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fonti-0.1.0/PKG-INFO +102 -0
- fonti-0.1.0/README.md +88 -0
- fonti-0.1.0/pyproject.toml +35 -0
- fonti-0.1.0/pyproject.toml.orig +36 -0
- fonti-0.1.0/src/fonti/__init__.py +6 -0
- fonti-0.1.0/src/fonti/__main__.py +35 -0
- fonti-0.1.0/src/fonti/cli.py +68 -0
- fonti-0.1.0/src/fonti/info.py +20 -0
- fonti-0.1.0/src/fonti/install.py +137 -0
- fonti-0.1.0/src/fonti/ls.py +27 -0
- fonti-0.1.0/src/fonti/meta.py +94 -0
- fonti-0.1.0/src/fonti/scan.py +26 -0
- fonti-0.1.0/src/fonti/uninstall.py +101 -0
- fonti-0.1.0/src/fonti/win/__init__.py +1 -0
- fonti-0.1.0/src/fonti/win/active.py +66 -0
- fonti-0.1.0/src/fonti/win/env.py +23 -0
- fonti-0.1.0/src/fonti/win/reg.py +54 -0
fonti-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: fonti
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A command-line tool for installing fonts on Windows
|
|
5
|
+
Author: Noai-oss
|
|
6
|
+
Author-email: Noai-oss <jiuwoxiao@outlook.com>
|
|
7
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
8
|
+
Requires-Dist: fonttools>=4.62.1
|
|
9
|
+
Requires-Dist: pywin32>=311
|
|
10
|
+
Requires-Dist: typer>=0.24.1
|
|
11
|
+
Requires-Python: >=3.13
|
|
12
|
+
Project-URL: Repository, https://github.com/Noai-oss/fonti
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Fonti
|
|
16
|
+
|
|
17
|
+
Install a font file or a whole folder of fonts on Windows from PowerShell. Fonti supports `.ttf`, `.otf`, `.ttc`, and `.otc` files.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
With Git and [uv](https://docs.astral.sh/uv/getting-started/installation/) installed, run this in PowerShell. Fonti requires Python 3.13 or later.
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
uv tool install git+https://github.com/Noai-oss/fonti
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To install a single font for your Windows account, pass its path.
|
|
28
|
+
|
|
29
|
+
```powershell
|
|
30
|
+
fonti install .\Regular.ttf
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Install a font family from a release ZIP
|
|
34
|
+
|
|
35
|
+
Open PowerShell in an empty folder. Download the font archive from the [LXGW WenKai v1.530 release](https://github.com/lxgw/LxgwWenKai/releases/tag/v1.530) and extract it.
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
$url = 'https://github.com/lxgw/LxgwWenKai/releases/download/v1.530/lxgw-wenkai-v1.530.zip'
|
|
39
|
+
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile .\lxgw-wenkai-v1.530.zip -ErrorAction Stop
|
|
40
|
+
Expand-Archive -LiteralPath .\lxgw-wenkai-v1.530.zip -DestinationPath .\wenkai -ErrorAction Stop
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Preview the fonts, install the extracted directory for your account, then list the installed entries. Fonti searches subdirectories recursively.
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
fonti info .\wenkai
|
|
47
|
+
fonti install .\wenkai
|
|
48
|
+
fonti list WenKai
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The archive includes Light, Regular, and Medium weights for both LXGW WenKai and LXGW WenKai Mono. Look for six matching rows. Each shows an installed name and a filename, separated by a tab. One of them is the Regular weight.
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
LXGW WenKai (TrueType) LXGWWenKai-Regular.ttf
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Optional cleanup.** To remove just the Regular font shown above, pass its exact filename. The other five fonts from the archive will still appear in the list.
|
|
58
|
+
|
|
59
|
+
```powershell
|
|
60
|
+
fonti remove 'LXGWWenKai-Regular.ttf'
|
|
61
|
+
fonti list WenKai
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Installing fonts
|
|
65
|
+
|
|
66
|
+
Pass a directory to include its subdirectories, or give several files in one command.
|
|
67
|
+
|
|
68
|
+
```powershell
|
|
69
|
+
fonti install .\fonts
|
|
70
|
+
fonti install .\Regular.ttf .\Bold.ttf
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Current-user installs require Windows 10 version 1809 or later. To install for everyone, open PowerShell as administrator and use `--system`.
|
|
74
|
+
|
|
75
|
+
```powershell
|
|
76
|
+
fonti install .\fonts --system
|
|
77
|
+
fonti list --system
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
You can rerun an install. Fonti skips identical, registered files and finishes registration if a previous run stopped after copying. Use `--replace` to overwrite a file with the same filename and different contents. If the font name already points to another file, use `list` to find the conflicting entry.
|
|
81
|
+
|
|
82
|
+
## Inspecting and removing fonts
|
|
83
|
+
|
|
84
|
+
Use `info` on a file or directory to see the name Fonti will register. Use `list` to find installed fonts by name or filename. Its optional keyword is a case-insensitive, literal substring.
|
|
85
|
+
|
|
86
|
+
To uninstall a font, copy its exact filename or installed name from `list`. Quote names containing spaces. You can pass several targets. Fonti checks every target before removing any of them. If a filename is ambiguous, use the installed name. Files shared by other entries in the same scope and originals outside its font directory are preserved. To remove a system font, add `--system` in an elevated PowerShell window.
|
|
87
|
+
|
|
88
|
+
## Using Fonti in scripts
|
|
89
|
+
|
|
90
|
+
- `install` exits with code `0` when every input was installed or already present. A conflict, an input with no supported fonts, or a write failure stops the batch and returns a nonzero code. The error goes to stderr, and earlier successful installs remain in place.
|
|
91
|
+
- If Windows cannot activate a font immediately, Fonti reports a warning. The file and registration are in place, and a restart may be needed before apps can use it.
|
|
92
|
+
- `list` returns exit code `0` and prints nothing when its search has no matches.
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
Run the test suite from a checkout on Windows.
|
|
97
|
+
|
|
98
|
+
```powershell
|
|
99
|
+
uv sync --locked
|
|
100
|
+
uv run pytest
|
|
101
|
+
uv run fonti --help
|
|
102
|
+
```
|
fonti-0.1.0/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Fonti
|
|
2
|
+
|
|
3
|
+
Install a font file or a whole folder of fonts on Windows from PowerShell. Fonti supports `.ttf`, `.otf`, `.ttc`, and `.otc` files.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
With Git and [uv](https://docs.astral.sh/uv/getting-started/installation/) installed, run this in PowerShell. Fonti requires Python 3.13 or later.
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
uv tool install git+https://github.com/Noai-oss/fonti
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To install a single font for your Windows account, pass its path.
|
|
14
|
+
|
|
15
|
+
```powershell
|
|
16
|
+
fonti install .\Regular.ttf
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Install a font family from a release ZIP
|
|
20
|
+
|
|
21
|
+
Open PowerShell in an empty folder. Download the font archive from the [LXGW WenKai v1.530 release](https://github.com/lxgw/LxgwWenKai/releases/tag/v1.530) and extract it.
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
$url = 'https://github.com/lxgw/LxgwWenKai/releases/download/v1.530/lxgw-wenkai-v1.530.zip'
|
|
25
|
+
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile .\lxgw-wenkai-v1.530.zip -ErrorAction Stop
|
|
26
|
+
Expand-Archive -LiteralPath .\lxgw-wenkai-v1.530.zip -DestinationPath .\wenkai -ErrorAction Stop
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Preview the fonts, install the extracted directory for your account, then list the installed entries. Fonti searches subdirectories recursively.
|
|
30
|
+
|
|
31
|
+
```powershell
|
|
32
|
+
fonti info .\wenkai
|
|
33
|
+
fonti install .\wenkai
|
|
34
|
+
fonti list WenKai
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The archive includes Light, Regular, and Medium weights for both LXGW WenKai and LXGW WenKai Mono. Look for six matching rows. Each shows an installed name and a filename, separated by a tab. One of them is the Regular weight.
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
LXGW WenKai (TrueType) LXGWWenKai-Regular.ttf
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Optional cleanup.** To remove just the Regular font shown above, pass its exact filename. The other five fonts from the archive will still appear in the list.
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
fonti remove 'LXGWWenKai-Regular.ttf'
|
|
47
|
+
fonti list WenKai
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Installing fonts
|
|
51
|
+
|
|
52
|
+
Pass a directory to include its subdirectories, or give several files in one command.
|
|
53
|
+
|
|
54
|
+
```powershell
|
|
55
|
+
fonti install .\fonts
|
|
56
|
+
fonti install .\Regular.ttf .\Bold.ttf
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Current-user installs require Windows 10 version 1809 or later. To install for everyone, open PowerShell as administrator and use `--system`.
|
|
60
|
+
|
|
61
|
+
```powershell
|
|
62
|
+
fonti install .\fonts --system
|
|
63
|
+
fonti list --system
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
You can rerun an install. Fonti skips identical, registered files and finishes registration if a previous run stopped after copying. Use `--replace` to overwrite a file with the same filename and different contents. If the font name already points to another file, use `list` to find the conflicting entry.
|
|
67
|
+
|
|
68
|
+
## Inspecting and removing fonts
|
|
69
|
+
|
|
70
|
+
Use `info` on a file or directory to see the name Fonti will register. Use `list` to find installed fonts by name or filename. Its optional keyword is a case-insensitive, literal substring.
|
|
71
|
+
|
|
72
|
+
To uninstall a font, copy its exact filename or installed name from `list`. Quote names containing spaces. You can pass several targets. Fonti checks every target before removing any of them. If a filename is ambiguous, use the installed name. Files shared by other entries in the same scope and originals outside its font directory are preserved. To remove a system font, add `--system` in an elevated PowerShell window.
|
|
73
|
+
|
|
74
|
+
## Using Fonti in scripts
|
|
75
|
+
|
|
76
|
+
- `install` exits with code `0` when every input was installed or already present. A conflict, an input with no supported fonts, or a write failure stops the batch and returns a nonzero code. The error goes to stderr, and earlier successful installs remain in place.
|
|
77
|
+
- If Windows cannot activate a font immediately, Fonti reports a warning. The file and registration are in place, and a restart may be needed before apps can use it.
|
|
78
|
+
- `list` returns exit code `0` and prints nothing when its search has no matches.
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
Run the test suite from a checkout on Windows.
|
|
83
|
+
|
|
84
|
+
```powershell
|
|
85
|
+
uv sync --locked
|
|
86
|
+
uv run pytest
|
|
87
|
+
uv run fonti --help
|
|
88
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fonti"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A command-line tool for installing fonts on Windows"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"fonttools>=4.62.1",
|
|
9
|
+
"pywin32>=311",
|
|
10
|
+
"typer>=0.24.1",
|
|
11
|
+
]
|
|
12
|
+
classifiers = ["Operating System :: Microsoft :: Windows"]
|
|
13
|
+
|
|
14
|
+
[[project.authors]]
|
|
15
|
+
name = "Noai-oss"
|
|
16
|
+
email = "jiuwoxiao@outlook.com"
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Repository = "https://github.com/Noai-oss/fonti"
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
fonti = "fonti.__main__:main"
|
|
23
|
+
|
|
24
|
+
[build-system]
|
|
25
|
+
requires = ["uv_build>=0.11.7,<0.14.0"]
|
|
26
|
+
build-backend = "uv_build"
|
|
27
|
+
|
|
28
|
+
[dependency-groups]
|
|
29
|
+
dev = [
|
|
30
|
+
"pytest>=9.0.3",
|
|
31
|
+
"pytest-cov>=7.1.0",
|
|
32
|
+
"pytest-mock>=3.15.1",
|
|
33
|
+
"ruff>=0.15.12",
|
|
34
|
+
"ty>=0.0.34",
|
|
35
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fonti"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A command-line tool for installing fonts on Windows"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Noai-oss", email = "jiuwoxiao@outlook.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"fonttools>=4.62.1",
|
|
12
|
+
"pywin32>=311",
|
|
13
|
+
"typer>=0.24.1",
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Operating System :: Microsoft :: Windows",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Repository = "https://github.com/Noai-oss/fonti"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
fonti = "fonti.__main__:main"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["uv_build>=0.11.7,<0.14.0"]
|
|
27
|
+
build-backend = "uv_build"
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest>=9.0.3",
|
|
32
|
+
"pytest-cov>=7.1.0",
|
|
33
|
+
"pytest-mock>=3.15.1",
|
|
34
|
+
"ruff>=0.15.12",
|
|
35
|
+
"ty>=0.0.34",
|
|
36
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from fonti.cli import app
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
12
|
+
"""Main entry point for the fonti CLI."""
|
|
13
|
+
try:
|
|
14
|
+
app(prog_name="fonti", args=argv, standalone_mode=True)
|
|
15
|
+
return 0
|
|
16
|
+
except typer.Exit as exc:
|
|
17
|
+
return exc.exit_code
|
|
18
|
+
except (OSError, ValueError) as exc:
|
|
19
|
+
typer.echo(f"Error: {exc}", err=True)
|
|
20
|
+
return 1
|
|
21
|
+
except (KeyboardInterrupt, typer.Abort):
|
|
22
|
+
typer.echo("Interrupted.", err=True)
|
|
23
|
+
return 130
|
|
24
|
+
except SystemExit as exc:
|
|
25
|
+
if exc.code is None:
|
|
26
|
+
return 0
|
|
27
|
+
if isinstance(exc.code, int):
|
|
28
|
+
return exc.code
|
|
29
|
+
|
|
30
|
+
typer.echo(str(exc.code), err=True)
|
|
31
|
+
return 1
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
sys.exit(main())
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Annotated
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
from fonti.info import show_info
|
|
7
|
+
from fonti.install import install
|
|
8
|
+
from fonti.ls import list_installed_fonts
|
|
9
|
+
from fonti.uninstall import remove
|
|
10
|
+
|
|
11
|
+
app = typer.Typer(
|
|
12
|
+
name="fonti",
|
|
13
|
+
help="Install and manage Windows fonts. Start with: fonti install PATH",
|
|
14
|
+
add_completion=False,
|
|
15
|
+
no_args_is_help=True,
|
|
16
|
+
)
|
|
17
|
+
SystemScope = Annotated[
|
|
18
|
+
bool,
|
|
19
|
+
typer.Option("--system", help="Use system fonts instead of current-user fonts."),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.command("install")
|
|
24
|
+
def install_cmd(
|
|
25
|
+
paths: Annotated[
|
|
26
|
+
list[Path], typer.Argument(help="Font files or directories (recursive).")
|
|
27
|
+
],
|
|
28
|
+
system: SystemScope = False,
|
|
29
|
+
replace: Annotated[
|
|
30
|
+
bool,
|
|
31
|
+
typer.Option(
|
|
32
|
+
"--replace", help="Allow replacing different contents at the same filename."
|
|
33
|
+
),
|
|
34
|
+
] = False,
|
|
35
|
+
) -> None:
|
|
36
|
+
"""Install one or more font files or directories."""
|
|
37
|
+
install(paths, system=system, replace=replace)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@app.command("list")
|
|
41
|
+
def list_cmd(
|
|
42
|
+
keyword: Annotated[
|
|
43
|
+
str, typer.Argument(help="Literal text in the installed name or filename.")
|
|
44
|
+
] = "",
|
|
45
|
+
system: SystemScope = False,
|
|
46
|
+
) -> None:
|
|
47
|
+
"""List installed names and filenames, optionally filtering by keyword."""
|
|
48
|
+
list_installed_fonts(is_global=system, keyword=keyword)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@app.command("remove")
|
|
52
|
+
def remove_cmd(
|
|
53
|
+
targets: Annotated[
|
|
54
|
+
list[str],
|
|
55
|
+
typer.Argument(help="Exact installed names or filenames from 'fonti list'."),
|
|
56
|
+
],
|
|
57
|
+
system: SystemScope = False,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Remove one or more installed fonts."""
|
|
60
|
+
remove(targets, system=system)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@app.command("info")
|
|
64
|
+
def info_cmd(
|
|
65
|
+
path: Annotated[Path, typer.Argument(help="Font file or directory (recursive).")],
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Inspect font names before installing."""
|
|
68
|
+
show_info(path)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from fonti.meta import kind, reg_name
|
|
6
|
+
from fonti.scan import find
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def show_info(source: Path) -> None:
|
|
10
|
+
"""Show metadata from a font source and print the calculated registry name."""
|
|
11
|
+
any_found = False
|
|
12
|
+
|
|
13
|
+
for font_file in find(source):
|
|
14
|
+
any_found = True
|
|
15
|
+
print(f"{font_file}")
|
|
16
|
+
print(f" Registry name: {reg_name(font_file)}")
|
|
17
|
+
print(f" Kind: {kind(font_file)}")
|
|
18
|
+
|
|
19
|
+
if not any_found:
|
|
20
|
+
print(f"No supported font files found in: {source}")
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import sys
|
|
3
|
+
import winreg
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from tempfile import NamedTemporaryFile
|
|
7
|
+
|
|
8
|
+
from fonti.ls import find_installed_fonts
|
|
9
|
+
from fonti.meta import reg_name
|
|
10
|
+
from fonti.scan import find
|
|
11
|
+
from fonti.win.active import (
|
|
12
|
+
add_font_resource,
|
|
13
|
+
broadcast_font_change,
|
|
14
|
+
remove_font_resource,
|
|
15
|
+
)
|
|
16
|
+
from fonti.win.env import WIN10_1809_BUILD, get_windows_build_number, is_admin
|
|
17
|
+
from fonti.win.reg import (
|
|
18
|
+
FONT_REGISTRY_PATH,
|
|
19
|
+
get_font_install_dir,
|
|
20
|
+
get_registry_root,
|
|
21
|
+
get_registry_value_data,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def same_contents(source: Path, target: Path) -> bool:
|
|
26
|
+
if source.samefile(target):
|
|
27
|
+
return True
|
|
28
|
+
if source.stat().st_size != target.stat().st_size:
|
|
29
|
+
return False
|
|
30
|
+
with source.open("rb") as left, target.open("rb") as right:
|
|
31
|
+
while chunk := left.read(1024 * 1024):
|
|
32
|
+
if chunk != right.read(len(chunk)):
|
|
33
|
+
return False
|
|
34
|
+
return not right.read(1)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def copy_font(source: Path, target: Path, *, overwrite: bool, registered: bool) -> None:
|
|
38
|
+
# Publish a complete file so an interrupted copy can be retried.
|
|
39
|
+
with NamedTemporaryFile(dir=target.parent, delete=False) as temp:
|
|
40
|
+
staged = Path(temp.name)
|
|
41
|
+
try:
|
|
42
|
+
shutil.copyfile(source, staged)
|
|
43
|
+
deactivated = overwrite and registered and remove_font_resource(target)
|
|
44
|
+
try:
|
|
45
|
+
if overwrite:
|
|
46
|
+
staged.replace(target)
|
|
47
|
+
else:
|
|
48
|
+
# On Windows rename fails if another process created the destination.
|
|
49
|
+
staged.rename(target)
|
|
50
|
+
except OSError:
|
|
51
|
+
if deactivated:
|
|
52
|
+
add_font_resource(target)
|
|
53
|
+
raise
|
|
54
|
+
finally:
|
|
55
|
+
staged.unlink(missing_ok=True)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def install_one(source: Path, *, system: bool, replace: bool) -> bool:
|
|
59
|
+
name = reg_name(source)
|
|
60
|
+
target = get_font_install_dir(system) / source.name
|
|
61
|
+
registered = False
|
|
62
|
+
other_names = []
|
|
63
|
+
for font in find_installed_fonts(system):
|
|
64
|
+
if font.name.casefold() == name.casefold():
|
|
65
|
+
if font.path != target:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"'{name}' already points to '{font.path}'. Remove that entry first."
|
|
68
|
+
)
|
|
69
|
+
registered = True
|
|
70
|
+
elif font.path == target:
|
|
71
|
+
other_names.append(font.name)
|
|
72
|
+
|
|
73
|
+
exists = target.exists()
|
|
74
|
+
identical = exists and same_contents(source, target)
|
|
75
|
+
if identical and registered:
|
|
76
|
+
print(f"Already installed: {name}")
|
|
77
|
+
return False
|
|
78
|
+
if exists and not identical and not replace:
|
|
79
|
+
raise ValueError(
|
|
80
|
+
f"Different contents at '{target}'. Use --replace to overwrite."
|
|
81
|
+
)
|
|
82
|
+
if not identical and other_names:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
f"'{target}' is registered as {', '.join(other_names)}. Remove the conflicting entries first."
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
with winreg.CreateKeyEx(
|
|
88
|
+
get_registry_root(system), FONT_REGISTRY_PATH, 0, winreg.KEY_SET_VALUE
|
|
89
|
+
) as key:
|
|
90
|
+
if not identical:
|
|
91
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
92
|
+
copy_font(source, target, overwrite=exists, registered=registered)
|
|
93
|
+
if not registered:
|
|
94
|
+
winreg.SetValueEx(
|
|
95
|
+
key, name, 0, winreg.REG_SZ, get_registry_value_data(target, system)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
print(f"Installed: {name}")
|
|
99
|
+
if not other_names:
|
|
100
|
+
try:
|
|
101
|
+
if not add_font_resource(target):
|
|
102
|
+
print(
|
|
103
|
+
f"Warning: Immediate activation failed for '{target}'; a restart may be required.",
|
|
104
|
+
file=sys.stderr,
|
|
105
|
+
)
|
|
106
|
+
except OSError as exc:
|
|
107
|
+
print(
|
|
108
|
+
f"Warning: Immediate activation failed for '{target}': {exc}. A restart may be required.",
|
|
109
|
+
file=sys.stderr,
|
|
110
|
+
)
|
|
111
|
+
return True
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def install(
|
|
115
|
+
paths: Sequence[Path], *, system: bool = False, replace: bool = False
|
|
116
|
+
) -> None:
|
|
117
|
+
if system and not is_admin():
|
|
118
|
+
raise ValueError("Installing system fonts requires administrator privileges.")
|
|
119
|
+
if not system and get_windows_build_number() < WIN10_1809_BUILD:
|
|
120
|
+
raise ValueError("User fonts require Windows 10 version 1809 or later.")
|
|
121
|
+
|
|
122
|
+
changed = False
|
|
123
|
+
try:
|
|
124
|
+
for path in paths:
|
|
125
|
+
found = False
|
|
126
|
+
for source in find(path):
|
|
127
|
+
found = True
|
|
128
|
+
try:
|
|
129
|
+
if install_one(source, system=system, replace=replace):
|
|
130
|
+
changed = True
|
|
131
|
+
except OSError as exc:
|
|
132
|
+
raise OSError(f"Could not install '{source}': {exc}") from exc
|
|
133
|
+
if not found:
|
|
134
|
+
raise ValueError(f"No supported fonts in '{path}'.")
|
|
135
|
+
finally:
|
|
136
|
+
if changed:
|
|
137
|
+
broadcast_font_change()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import NamedTuple
|
|
4
|
+
|
|
5
|
+
from fonti.win.reg import iter_font_registry_values, resolve_registry_font_path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InstalledFont(NamedTuple):
|
|
9
|
+
name: str
|
|
10
|
+
path: Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def find_installed_fonts(
|
|
14
|
+
is_global: bool = False, keyword: str = ""
|
|
15
|
+
) -> Iterator[InstalledFont]:
|
|
16
|
+
text = keyword.casefold()
|
|
17
|
+
for name, value, _ in iter_font_registry_values(is_global):
|
|
18
|
+
if not isinstance(value, str) or not value:
|
|
19
|
+
continue
|
|
20
|
+
path = resolve_registry_font_path(value, is_global)
|
|
21
|
+
if text in name.casefold() or text in path.name.casefold():
|
|
22
|
+
yield InstalledFont(name, path)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def list_installed_fonts(is_global: bool = False, keyword: str = "") -> None:
|
|
26
|
+
for font in find_installed_fonts(is_global, keyword):
|
|
27
|
+
print(f"{font.name}\t{font.path.name}")
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from struct import error as StructError
|
|
5
|
+
|
|
6
|
+
from fontTools.ttLib import TTCollection, TTFont, TTLibError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def kind(path: Path) -> str:
|
|
10
|
+
"""Determine the Windows registry font kind from a font file extension."""
|
|
11
|
+
match path.suffix.lower():
|
|
12
|
+
case ".ttf" | ".ttc" | ".otf" | ".otc":
|
|
13
|
+
return "TrueType"
|
|
14
|
+
case _:
|
|
15
|
+
raise ValueError(f"unsupported font type: {path}")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def normalize_font_name(value: str | None) -> str | None:
|
|
19
|
+
"""Normalize whitespace in a font name string."""
|
|
20
|
+
if not value:
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
value = " ".join(value.split())
|
|
24
|
+
return value or None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_font_display_name(font: TTFont, fallback: str) -> str:
|
|
28
|
+
"""Return the best display name for a single face in a font file."""
|
|
29
|
+
name_table = font["name"]
|
|
30
|
+
|
|
31
|
+
if full_name := normalize_font_name(name_table.getBestFullName()):
|
|
32
|
+
return full_name
|
|
33
|
+
|
|
34
|
+
if family := normalize_font_name(name_table.getBestFamilyName()):
|
|
35
|
+
if subfamily := normalize_font_name(name_table.getBestSubFamilyName()):
|
|
36
|
+
return f"{family} {subfamily}"
|
|
37
|
+
return family
|
|
38
|
+
|
|
39
|
+
return fallback
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def reg_name(font_path: Path) -> str:
|
|
43
|
+
try:
|
|
44
|
+
return _read_registry_name(font_path)
|
|
45
|
+
except (
|
|
46
|
+
TTLibError,
|
|
47
|
+
StructError,
|
|
48
|
+
KeyError,
|
|
49
|
+
IndexError,
|
|
50
|
+
UnicodeError,
|
|
51
|
+
EOFError,
|
|
52
|
+
ValueError,
|
|
53
|
+
AssertionError,
|
|
54
|
+
) as exc:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"Cannot read font metadata from '{font_path}': {exc}"
|
|
57
|
+
) from exc
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _read_registry_name(font_path: Path) -> str:
|
|
61
|
+
"""
|
|
62
|
+
Generate the Windows registry value name for a font file.
|
|
63
|
+
|
|
64
|
+
Font collections (.ttc, .otc) may contain multiple faces, so their registry
|
|
65
|
+
name joins each unique face name before adding the Windows font kind suffix.
|
|
66
|
+
"""
|
|
67
|
+
font_path = font_path.resolve()
|
|
68
|
+
k = kind(font_path)
|
|
69
|
+
ext = font_path.suffix.lower()
|
|
70
|
+
|
|
71
|
+
if ext in {".ttc", ".otc"}:
|
|
72
|
+
with TTCollection(str(font_path)) as collection:
|
|
73
|
+
names: list[str] = []
|
|
74
|
+
seen: set[str] = set()
|
|
75
|
+
|
|
76
|
+
for index, font in enumerate(collection.fonts):
|
|
77
|
+
display_name = get_font_display_name(
|
|
78
|
+
font,
|
|
79
|
+
fallback=f"{font_path.stem}#{index}",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
key = display_name.casefold()
|
|
83
|
+
if key not in seen:
|
|
84
|
+
names.append(display_name)
|
|
85
|
+
seen.add(key)
|
|
86
|
+
|
|
87
|
+
if names:
|
|
88
|
+
return f"{' & '.join(names)} ({k})"
|
|
89
|
+
|
|
90
|
+
return f"{font_path.stem} ({k})"
|
|
91
|
+
|
|
92
|
+
with TTFont(str(font_path), fontNumber=0) as font:
|
|
93
|
+
display_name = get_font_display_name(font, fallback=font_path.stem)
|
|
94
|
+
return f"{display_name} ({k})"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
SUPPORTED_FONT_EXTENSIONS = {".ttf", ".otf", ".ttc", ".otc"}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def find(source: Path) -> Iterator[Path]:
|
|
10
|
+
"""Find supported font files from a file or recursively from a directory."""
|
|
11
|
+
source = source.resolve()
|
|
12
|
+
|
|
13
|
+
if source.is_file():
|
|
14
|
+
if source.suffix.lower() in SUPPORTED_FONT_EXTENSIONS:
|
|
15
|
+
yield source
|
|
16
|
+
return
|
|
17
|
+
|
|
18
|
+
if not source.exists():
|
|
19
|
+
raise FileNotFoundError(f"source does not exist: {source}")
|
|
20
|
+
|
|
21
|
+
if not source.is_dir():
|
|
22
|
+
raise ValueError(f"source is not a file or directory: {source}")
|
|
23
|
+
|
|
24
|
+
for path in sorted(source.rglob("*")):
|
|
25
|
+
if path.is_file() and path.suffix.lower() in SUPPORTED_FONT_EXTENSIONS:
|
|
26
|
+
yield path
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import winreg
|
|
3
|
+
from collections import Counter
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
|
|
6
|
+
from fonti.ls import InstalledFont, find_installed_fonts
|
|
7
|
+
from fonti.win.active import (
|
|
8
|
+
add_font_resource,
|
|
9
|
+
broadcast_font_change,
|
|
10
|
+
remove_font_resource,
|
|
11
|
+
)
|
|
12
|
+
from fonti.win.env import is_admin
|
|
13
|
+
from fonti.win.reg import (
|
|
14
|
+
FONT_REGISTRY_PATH,
|
|
15
|
+
get_font_install_dir,
|
|
16
|
+
get_registry_root,
|
|
17
|
+
resolve_registry_font_path,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def resolve_targets(
|
|
22
|
+
tokens: Sequence[str], installed: list[InstalledFont]
|
|
23
|
+
) -> list[InstalledFont]:
|
|
24
|
+
selected = {}
|
|
25
|
+
for token in tokens:
|
|
26
|
+
exact = token.casefold()
|
|
27
|
+
matches = [
|
|
28
|
+
font
|
|
29
|
+
for font in installed
|
|
30
|
+
if exact in (font.name.casefold(), font.path.name.casefold())
|
|
31
|
+
]
|
|
32
|
+
if not matches:
|
|
33
|
+
raise ValueError(f"No installed font matched '{token}'.")
|
|
34
|
+
if len(matches) > 1:
|
|
35
|
+
names = ", ".join(font.name for font in matches)
|
|
36
|
+
raise ValueError(
|
|
37
|
+
f"Ambiguous target '{token}' matches: {names}. Use an exact installed name."
|
|
38
|
+
)
|
|
39
|
+
font = matches[0]
|
|
40
|
+
selected[font.name] = font
|
|
41
|
+
return list(selected.values())
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def remove(tokens: Sequence[str], *, system: bool = False) -> None:
|
|
45
|
+
if system and not is_admin():
|
|
46
|
+
raise ValueError("Removing system fonts requires administrator privileges.")
|
|
47
|
+
installed = list(find_installed_fonts(system))
|
|
48
|
+
targets = resolve_targets(tokens, installed)
|
|
49
|
+
directory = get_font_install_dir(system).resolve()
|
|
50
|
+
references = Counter(font.path.resolve() for font in installed)
|
|
51
|
+
changed = False
|
|
52
|
+
try:
|
|
53
|
+
with winreg.OpenKey(
|
|
54
|
+
get_registry_root(system),
|
|
55
|
+
FONT_REGISTRY_PATH,
|
|
56
|
+
0,
|
|
57
|
+
winreg.KEY_QUERY_VALUE | winreg.KEY_SET_VALUE,
|
|
58
|
+
) as key:
|
|
59
|
+
for font in targets:
|
|
60
|
+
path = font.path.resolve()
|
|
61
|
+
try:
|
|
62
|
+
value, value_type = winreg.QueryValueEx(key, font.name)
|
|
63
|
+
if (
|
|
64
|
+
not isinstance(value, str)
|
|
65
|
+
or resolve_registry_font_path(value, system).resolve() != path
|
|
66
|
+
):
|
|
67
|
+
raise ValueError(
|
|
68
|
+
f"Registration for '{font.name}' changed. Run 'fonti list' again."
|
|
69
|
+
)
|
|
70
|
+
winreg.DeleteValue(key, font.name)
|
|
71
|
+
except OSError as exc:
|
|
72
|
+
raise OSError(
|
|
73
|
+
f"Could not remove registration for '{font.name}': {exc}"
|
|
74
|
+
) from exc
|
|
75
|
+
deactivated = False
|
|
76
|
+
try:
|
|
77
|
+
if references[path] == 1 and path.exists():
|
|
78
|
+
deactivated = remove_font_resource(path)
|
|
79
|
+
if (
|
|
80
|
+
path.parent == directory
|
|
81
|
+
and font.path.parent.resolve() == directory
|
|
82
|
+
):
|
|
83
|
+
font.path.unlink()
|
|
84
|
+
if not deactivated:
|
|
85
|
+
print(
|
|
86
|
+
f"Warning: Immediate deactivation failed for '{font.name}'; a restart may be required.",
|
|
87
|
+
file=sys.stderr,
|
|
88
|
+
)
|
|
89
|
+
except OSError as exc:
|
|
90
|
+
winreg.SetValueEx(key, font.name, 0, value_type, value)
|
|
91
|
+
if deactivated:
|
|
92
|
+
add_font_resource(path)
|
|
93
|
+
raise OSError(
|
|
94
|
+
f"Could not remove '{font.name}' at '{path}': {exc}"
|
|
95
|
+
) from exc
|
|
96
|
+
references[path] -= 1
|
|
97
|
+
changed = True
|
|
98
|
+
print(f"Removed: {font.name}")
|
|
99
|
+
finally:
|
|
100
|
+
if changed:
|
|
101
|
+
broadcast_font_change()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
from ctypes import wintypes
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def add_font_resource(font_path: Path) -> int:
|
|
9
|
+
"""Register a font file with the Windows GDI."""
|
|
10
|
+
gdi32 = ctypes.WinDLL("gdi32", use_last_error=True)
|
|
11
|
+
|
|
12
|
+
AddFontResourceW = gdi32.AddFontResourceW
|
|
13
|
+
AddFontResourceW.argtypes = [wintypes.LPCWSTR]
|
|
14
|
+
AddFontResourceW.restype = ctypes.c_int
|
|
15
|
+
|
|
16
|
+
return int(AddFontResourceW(str(font_path)))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def remove_font_resource(font_path: Path) -> bool:
|
|
20
|
+
"""Unregister a font file from the Windows GDI."""
|
|
21
|
+
gdi32 = ctypes.WinDLL("gdi32", use_last_error=True)
|
|
22
|
+
|
|
23
|
+
RemoveFontResourceW = gdi32.RemoveFontResourceW
|
|
24
|
+
RemoveFontResourceW.argtypes = [wintypes.LPCWSTR]
|
|
25
|
+
RemoveFontResourceW.restype = wintypes.BOOL
|
|
26
|
+
|
|
27
|
+
return bool(RemoveFontResourceW(str(font_path)))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def broadcast_font_change() -> None:
|
|
31
|
+
"""Broadcast the WM_FONTCHANGE message to running applications."""
|
|
32
|
+
user32 = ctypes.WinDLL("user32", use_last_error=True)
|
|
33
|
+
|
|
34
|
+
HWND_BROADCAST = 0xFFFF
|
|
35
|
+
WM_FONTCHANGE = 0x001D
|
|
36
|
+
SMTO_ABORTIFHUNG = 0x0002
|
|
37
|
+
|
|
38
|
+
DWORD_PTR = wintypes.WPARAM
|
|
39
|
+
result = DWORD_PTR()
|
|
40
|
+
|
|
41
|
+
SendMessageTimeoutW = user32.SendMessageTimeoutW
|
|
42
|
+
SendMessageTimeoutW.argtypes = [
|
|
43
|
+
wintypes.HWND,
|
|
44
|
+
wintypes.UINT,
|
|
45
|
+
wintypes.WPARAM,
|
|
46
|
+
wintypes.LPARAM,
|
|
47
|
+
wintypes.UINT,
|
|
48
|
+
wintypes.UINT,
|
|
49
|
+
ctypes.POINTER(DWORD_PTR),
|
|
50
|
+
]
|
|
51
|
+
SendMessageTimeoutW.restype = wintypes.LPARAM
|
|
52
|
+
|
|
53
|
+
ret = SendMessageTimeoutW(
|
|
54
|
+
HWND_BROADCAST,
|
|
55
|
+
WM_FONTCHANGE,
|
|
56
|
+
0,
|
|
57
|
+
0,
|
|
58
|
+
SMTO_ABORTIFHUNG,
|
|
59
|
+
1000,
|
|
60
|
+
ctypes.byref(result),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
if ret == 0:
|
|
64
|
+
error = ctypes.get_last_error()
|
|
65
|
+
if error:
|
|
66
|
+
print(f"Warning: WM_FONTCHANGE broadcast failed: {ctypes.WinError(error)}")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import winreg
|
|
5
|
+
|
|
6
|
+
WIN10_1809_BUILD = 17763
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_windows_build_number() -> int:
|
|
10
|
+
"""Retrieve the current Windows build number from the registry."""
|
|
11
|
+
with winreg.OpenKey(
|
|
12
|
+
winreg.HKEY_LOCAL_MACHINE,
|
|
13
|
+
r"SOFTWARE\Microsoft\Windows NT\CurrentVersion",
|
|
14
|
+
) as key:
|
|
15
|
+
return int(winreg.QueryValueEx(key, "CurrentBuildNumber")[0])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def is_admin() -> bool:
|
|
19
|
+
"""Check if the current process has administrative privileges."""
|
|
20
|
+
try:
|
|
21
|
+
return bool(ctypes.windll.shell32.IsUserAnAdmin())
|
|
22
|
+
except (AttributeError, OSError):
|
|
23
|
+
return False
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import winreg
|
|
5
|
+
from collections.abc import Iterator
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
FONT_REGISTRY_PATH = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_registry_root(is_global: bool) -> int:
|
|
12
|
+
"""Return the registry root HKEY based on the installation scope."""
|
|
13
|
+
return winreg.HKEY_LOCAL_MACHINE if is_global else winreg.HKEY_CURRENT_USER
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_font_install_dir(is_global: bool) -> Path:
|
|
17
|
+
"""Return the target directory for font installation based on scope."""
|
|
18
|
+
if is_global:
|
|
19
|
+
return Path(os.environ["WINDIR"]) / "Fonts"
|
|
20
|
+
|
|
21
|
+
return Path(os.environ["LOCALAPPDATA"]) / "Microsoft" / "Windows" / "Fonts"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_registry_value_data(target_path: Path, is_global: bool) -> str:
|
|
25
|
+
"""Determine the registry value data to write for a target font file."""
|
|
26
|
+
if is_global:
|
|
27
|
+
return target_path.name
|
|
28
|
+
|
|
29
|
+
return str(target_path)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def resolve_registry_font_path(value: str, is_global: bool) -> Path:
|
|
33
|
+
"""Resolve a registry value data string back to an absolute path."""
|
|
34
|
+
path = Path(value)
|
|
35
|
+
|
|
36
|
+
if path.is_absolute():
|
|
37
|
+
return path
|
|
38
|
+
|
|
39
|
+
return get_font_install_dir(is_global) / value
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def iter_font_registry_values(is_global: bool) -> Iterator[tuple[str, str, int]]:
|
|
43
|
+
"""Yield all value entries from the Windows font registry key."""
|
|
44
|
+
registry_root = get_registry_root(is_global)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
with winreg.OpenKey(registry_root, FONT_REGISTRY_PATH) as key:
|
|
48
|
+
count = winreg.QueryInfoKey(key)[1]
|
|
49
|
+
|
|
50
|
+
for index in range(count):
|
|
51
|
+
name, value, value_type = winreg.EnumValue(key, index)
|
|
52
|
+
yield name, value, value_type
|
|
53
|
+
except FileNotFoundError:
|
|
54
|
+
return
|