10
10
current_dir = os .path .dirname (os .path .abspath (__file__ ))
11
11
source_dirs = [
12
12
os .path .join (current_dir , "../application/src/i18n" ),
13
- os .path .join (current_dir , "../application/src/amiidb" )
13
+ os .path .join (current_dir , "../application/src/amiidb" ),
14
14
]
15
15
16
16
# Absolute path to the directory where the output file will be saved
22
22
23
23
24
24
def write_to_file (file_path , content ):
25
- with open (file_path , 'w' , encoding = ' utf-8' ) as f :
25
+ with open (file_path , "w" , encoding = " utf-8" ) as f :
26
26
f .write (content )
27
27
28
28
@@ -34,24 +34,28 @@ def extract_non_printable_chars():
34
34
if file .endswith (".c" ):
35
35
with open (os .path .join (root , file ), "r" , encoding = "utf-8" ) as f :
36
36
content = f .read ()
37
- non_printable_chars .update (re .findall (r' [^\x20-\x7E]' , content ))
37
+ non_printable_chars .update (re .findall (r" [^\x20-\x7E]" , content ))
38
38
39
- write_to_file (os .path .join (data_dir , output_file ), '\n ' .join (sorted (non_printable_chars )))
39
+ write_to_file (
40
+ os .path .join (data_dir , output_file ), "\n " .join (sorted (non_printable_chars ))
41
+ )
40
42
41
43
42
44
def convert_and_sort (unicode_strings ):
43
- return sorted (set (f'${ ord (char ):04X} ,' for string in unicode_strings for char in string ))
45
+ return sorted (
46
+ set (f"${ ord (char ):04X} ," for string in unicode_strings for char in string )
47
+ )
44
48
45
49
46
50
def run_bdfconv (map_path , output_path , bdf_path ):
47
51
# Construct the path to the bdfconv executable relative to the script directory
48
52
system = platform .system ()
49
- if system == ' Windows' :
50
- bdfconv_path = os .path .join (current_dir , ' bdfconv.exe' )
51
- elif system == ' Darwin' :
52
- bdfconv_path = os .path .join (current_dir , ' bdfconv_macos_universal' )
53
- elif system == ' Linux' :
54
- bdfconv_path = os .path .join (current_dir , ' bdfconv_linux' )
53
+ if system == " Windows" :
54
+ bdfconv_path = os .path .join (current_dir , " bdfconv.exe" )
55
+ elif system == " Darwin" :
56
+ bdfconv_path = os .path .join (current_dir , " bdfconv_macos_universal" )
57
+ elif system == " Linux" :
58
+ bdfconv_path = os .path .join (current_dir , " bdfconv_linux" )
55
59
else :
56
60
raise OSError ("Unsupported operating system" )
57
61
@@ -61,47 +65,63 @@ def run_bdfconv(map_path, output_path, bdf_path):
61
65
abs_bdf_path = os .path .abspath (bdf_path )
62
66
63
67
cmd = [
64
- bdfconv_path , '-b' , '0' , '-f' , '1' , '-M' , abs_map_path ,
65
- '-n' , 'u8g2_font_wqy12_t_gb2312a' , '-o' , abs_output_path , abs_bdf_path
68
+ bdfconv_path ,
69
+ "-b" ,
70
+ "0" ,
71
+ "-f" ,
72
+ "1" ,
73
+ "-M" ,
74
+ abs_map_path ,
75
+ "-n" ,
76
+ "u8g2_font_wqy12_t_gb2312a" ,
77
+ "-o" ,
78
+ abs_output_path ,
79
+ abs_bdf_path ,
66
80
]
67
81
subprocess .run (cmd , check = True )
68
82
69
83
70
84
def main ():
71
85
extract_non_printable_chars ()
72
86
73
- combined_content = ''
74
- for file_name in [' chinese3.txt' , ' pixjs.txt' ]:
75
- with open (os .path .join (data_dir , file_name ), 'r' , encoding = ' utf-8' ) as file :
87
+ combined_content = ""
88
+ for file_name in [" chinese3.txt" , " pixjs.txt" ]:
89
+ with open (os .path .join (data_dir , file_name ), "r" , encoding = " utf-8" ) as file :
76
90
combined_content += file .read ()
77
91
78
92
sorted_converted = convert_and_sort (combined_content .splitlines ())
79
- write_to_file (os .path .join (data_dir , 'gb2312a.map' ), '32-128,\n ' + '\n ' .join (sorted_converted ))
93
+ write_to_file (
94
+ os .path .join (data_dir , "gb2312a.map" ), "32-128,\n " + "\n " .join (sorted_converted )
95
+ )
80
96
81
97
run_bdfconv (
82
- map_path = os .path .join (data_dir , ' gb2312a.map' ),
83
- output_path = os .path .join (mui_dir , ' u8g2_font_wqy12_t_gb2312a_t.c' ),
84
- bdf_path = os .path .join (data_dir , ' wenquanyi_9pt_u8g2.bdf' )
98
+ map_path = os .path .join (data_dir , " gb2312a.map" ),
99
+ output_path = os .path .join (mui_dir , " u8g2_font_wqy12_t_gb2312a_t.c" ),
100
+ bdf_path = os .path .join (data_dir , " wenquanyi_9pt_u8g2.bdf" ),
85
101
)
86
102
87
103
# Write to u8g2_font_wqy12_t_gb2312a.c
88
- with open (os .path .join (mui_dir , 'u8g2_font_wqy12_t_gb2312a.c' ), 'w+' , encoding = 'utf-8' ) as final_file :
89
- final_file .write ('''
104
+ with open (
105
+ os .path .join (mui_dir , "u8g2_font_wqy12_t_gb2312a.c" ), "w+" , encoding = "utf-8"
106
+ ) as final_file :
107
+ final_file .write (
108
+ """
90
109
#include "mui_u8g2.h"
91
110
92
111
#include "u8x8.h"
93
112
94
- ''' )
113
+ """
114
+ )
95
115
96
116
# Read the content of the temporary file and append it to the final file
97
- temp_file_path = os .path .join (mui_dir , ' u8g2_font_wqy12_t_gb2312a_t.c' )
98
- with open (temp_file_path , 'r' , encoding = ' utf-8' ) as temp_file :
117
+ temp_file_path = os .path .join (mui_dir , " u8g2_font_wqy12_t_gb2312a_t.c" )
118
+ with open (temp_file_path , "r" , encoding = " utf-8" ) as temp_file :
99
119
final_file .write (temp_file .read ())
100
120
101
121
# Remove the temporary files
102
122
os .remove (temp_file_path )
103
123
os .remove (os .path .join (data_dir , output_file ))
104
- os .remove (os .path .join (data_dir , ' gb2312a.map' ))
124
+ os .remove (os .path .join (data_dir , " gb2312a.map" ))
105
125
106
126
107
127
if __name__ == "__main__" :
0 commit comments