Skip to content

Commit e15a7c1

Browse files
committed
Minor formatting fixes
1 parent 50fc5dd commit e15a7c1

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

fw/scripts/font_data_gen.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
current_dir = os.path.dirname(os.path.abspath(__file__))
1111
source_dirs = [
1212
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"),
1414
]
1515

1616
# Absolute path to the directory where the output file will be saved
@@ -22,7 +22,7 @@
2222

2323

2424
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:
2626
f.write(content)
2727

2828

@@ -34,24 +34,28 @@ def extract_non_printable_chars():
3434
if file.endswith(".c"):
3535
with open(os.path.join(root, file), "r", encoding="utf-8") as f:
3636
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))
3838

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+
)
4042

4143

4244
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+
)
4448

4549

4650
def run_bdfconv(map_path, output_path, bdf_path):
4751
# Construct the path to the bdfconv executable relative to the script directory
4852
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")
5559
else:
5660
raise OSError("Unsupported operating system")
5761

@@ -61,47 +65,63 @@ def run_bdfconv(map_path, output_path, bdf_path):
6165
abs_bdf_path = os.path.abspath(bdf_path)
6266

6367
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,
6680
]
6781
subprocess.run(cmd, check=True)
6882

6983

7084
def main():
7185
extract_non_printable_chars()
7286

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:
7690
combined_content += file.read()
7791

7892
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+
)
8096

8197
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"),
85101
)
86102

87103
# 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+
"""
90109
#include "mui_u8g2.h"
91110
92111
#include "u8x8.h"
93112
94-
''')
113+
"""
114+
)
95115

96116
# 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:
99119
final_file.write(temp_file.read())
100120

101121
# Remove the temporary files
102122
os.remove(temp_file_path)
103123
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"))
105125

106126

107127
if __name__ == "__main__":

0 commit comments

Comments
 (0)