-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathanalyze_font.py
More file actions
110 lines (94 loc) · 2.98 KB
/
analyze_font.py
File metadata and controls
110 lines (94 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import argparse
import sys
from configs import FontProcessingConfig
from utils.argparse.argparse_utils import update_config_from_args
from utils.font import FontCoverageAnalyzer
from utils.validation.project_validator import ProjectValidationError, ProjectValidator
def parse_args() -> argparse.Namespace:
"""
Parse command-line arguments for font analysis.
"""
parser = argparse.ArgumentParser(
description="Analyze font hanzi coverage",
)
parser.add_argument(
"--target_font_path",
type=str,
help="Target font path",
)
parser.add_argument(
"--reference_fonts_dir",
type=str,
help="Reference fonts directory",
)
parser.add_argument(
"--analyze_target_font",
action="store_true",
help="Analyze target font",
)
parser.add_argument(
"--analyze_reference_fonts",
action="store_true",
help="Analyze reference fonts",
)
return parser.parse_args()
def analyze_target_font(
target_font_path: str,
font_processing_config: FontProcessingConfig,
) -> None:
"""
Analyze hanzi coverage of the target font.
"""
analyzer = FontCoverageAnalyzer.from_target_font(
target_font_path=target_font_path,
font_processing_config=font_processing_config,
)
analyzer.analyze_coverage()
def analyze_reference_fonts(
reference_fonts_dir: str,
font_processing_config: FontProcessingConfig,
) -> None:
"""
Analyze hanzi coverage of reference fonts in the specified directory.
"""
analyzers = FontCoverageAnalyzer.from_reference_fonts(
reference_fonts_dir=reference_fonts_dir,
font_processing_config=font_processing_config,
)
for analyzer in analyzers:
analyzer.analyze_coverage()
def main() -> None:
"""
Main function to run the font analysis.
"""
try:
args = parse_args()
font_processing_config = update_config_from_args(
converting_config=FontProcessingConfig(),
args=args,
)
if args.analyze_target_font:
ProjectValidator.validate_font_file(
file_path=args.target_font_path,
name="Target font",
)
analyze_target_font(
target_font_path=args.target_font_path,
font_processing_config=font_processing_config,
)
if args.analyze_reference_fonts:
ProjectValidator.validate_fonts_directory(
dir_path=args.reference_fonts_dir,
name="Reference fonts directory",
)
analyze_reference_fonts(
reference_fonts_dir=args.reference_fonts_dir,
font_processing_config=font_processing_config,
)
print("✅ Font analysis completed successfully")
except ProjectValidationError as e:
print(f"❌ {e}")
print("❌ Font analysis failed")
sys.exit(1)
if __name__ == "__main__":
main()