/
copy_selected_out.py
executable file
·204 lines (166 loc) · 6.39 KB
/
copy_selected_out.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
#encoding=utf-8
import LibGlyph
from os import makedirs
from os.path import join, exists
# to copy file.
import shutil
import argparse
def copy_out(args):
source_ff = args.input
is_output_glyph = False # view log only
is_output_glyph = True # get real file.
upgrade_folder = args.output
target_string = args.string
string_file = args.file
range_string = args.range
#range_string_int = args.range_int
range_string_int = None
# from 1 to 3.
#unicode_field = 2 # for Noto Sans
unicode_field = args.unicode_field
check_altuni2 = False
if args.alt == "True":
check_altuni2 = True
# start to scan files.
print("source project:", source_ff)
print("output:", upgrade_folder)
print("string length:", len(target_string))
if not string_file is None:
if len(string_file) > 0:
print("string file:", string_file)
if len(target_string) > 0 and len(target_string) <= 80:
print("string:", target_string)
if check_altuni2:
print("check AltUni2")
if len(target_string) == 0:
# is need read from file.
if len(string_file) > 0:
if exists(string_file):
my_list = []
f = open(string_file,"r")
file_raw_list = f.readlines()
for line in file_raw_list:
line = line.strip()
for char in line:
if len(char) > 0:
my_list.append(char)
f.close()
target_string = ''.join(my_list)
print("string length in file:", len(target_string))
else:
print("input file not exist:", string_file)
if len(target_string) == 0:
print("range:", range_string)
if check_altuni2:
print("check altuni2: True")
source_unicode_set, source_dict = LibGlyph.load_files_to_set_dict(source_ff, unicode_field, check_altuni2)
# source set from string.
target_unicode_set = set()
if not target_string is None:
if len(target_string) > 0:
for char in target_string:
target_unicode_set.add(ord(char))
# string 優先, 避免衝突。
if len(target_unicode_set) == 0:
if not range_string is None:
if len(range_string) > 0:
# convert between symbole to ','
if '-' in range_string:
range_string = range_string.replace('-',',')
if '~' in range_string:
range_string = range_string.replace('~',',')
if ',' in range_string:
range_begin = range_string.split(',')[0]
range_end = range_string.split(',')[1]
for r in range(int(range_begin,16),int(range_end,16)+1):
target_unicode_set.add(r)
if not range_string_int is None:
if len(range_string_int) > 0:
if ',' in range_string_int:
range_begin = range_string_int.split(',')[0]
range_end = range_string_int.split(',')[1]
for r in range(int(range_begin),int(range_end)+1):
target_unicode_set.add(r)
diff_set_common = source_unicode_set & target_unicode_set
print("length source project:", len(source_unicode_set))
print("length selected string:", len(target_unicode_set))
print("length intersection:", len(diff_set_common))
if is_output_glyph:
print("copy lost glyph file to path:", upgrade_folder)
if not exists(upgrade_folder):
makedirs(upgrade_folder)
conflic_count = 0
copy_count = 0
for item in diff_set_common:
source_path = join(source_ff,source_dict[item])
#print("filename:", target_path)
target_path = join(upgrade_folder,source_dict[item])
if exists(target_path):
print("conflic at path:", source_path)
conflic_count += 1
else:
pass
# force overwrite
copy_count += 1
shutil.copy(source_path,target_path)
if conflic_count > 0:
print("conflic count:", conflic_count)
print("copy count:", copy_count)
def cli():
parser = argparse.ArgumentParser(
description="Get selected glyph from FontForge directory")
parser.add_argument("--input",
help="input more glyph font sfdir folder",
required=True,
type=str)
parser.add_argument("--string",
help="selected string",
default='',
type=str)
parser.add_argument("--file",
help="selected string file",
default='',
type=str)
# --range AC00,D7AF
# AC00 — D7AF 諺文音節 (Hangul Syllables)
# Hangul音節是一個Unicode塊,其中包含用於現代韓語的預先編寫的Hangul音節塊。音節可以通過算法直接映射到韓文字母Unicode塊中的兩個或三個字符的序列: U + 1100–U + 1112之一:19個現代韓文字母領先的輔音字母; U + 1161–U + 1175之一:21種現代韓文元音字母;
# CJK Radicals Supplement, U+2E80 - U+2EFF
# 中日韓統一表意文字擴充區A, 3400 – U+4DBF
# CJK Unified Ideographs, 4E00 - U+9FFF
# CJK Compatibility Ideographs, U+F900 - U+FAFF
# 中日韓統一表意文字擴充區B, U+20000 – U+2A6DF
# 中日韓統一表意文字擴展區G, U+30000 – U+3134F
# --range 20000,3134F
#print("unicode_int:", unicode_int)
#convert_range_list = [[13312,19903],[131072,201551]]
# for common non-chinese chars.
# --range 0,2E7F
parser.add_argument("--range",
help="unicode range hex",
default='',
type=str)
parser.add_argument("--range_int",
help="unicode range integer",
default='',
type=str)
parser.add_argument("--output",
help="output glyth folder",
default='.',
type=str)
parser.add_argument("--unicode_field",
help="unicode_field in glyth",
default=2,
type=int)
parser.add_argument("--log",
help="generate log file",
default="True",
type=str)
parser.add_argument("--alt",
help="check AltUni2",
default='False',
type=str)
args = parser.parse_args()
copy_out(args)
if __name__ == "__main__":
cli()