-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelete_selected_glyph.py
More file actions
176 lines (143 loc) · 5.67 KB
/
delete_selected_glyph.py
File metadata and controls
176 lines (143 loc) · 5.67 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
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
#!/usr/bin/env python3
#encoding=utf-8
import LibGlyph
from os.path import join, exists
import argparse
def remove_out(args):
source_ff = args.input
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.check_alt:
check_altuni2 = True
# start to scan files.
print("source project:", source_ff)
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)
print("check altuni2:", 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", encoding='utf-8')
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)
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:
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))
remove_count = 0
for item in diff_set_common:
source_path = join(source_ff,source_dict[item])
if exists(source_path):
remove_count += 1
#print("exist at path:", source_path)
else:
pass
#shutil.copy(source_path,target_path)
if not args.check_only:
os.remove(source_path)
if remove_count > 0:
print("remove count:", remove_count)
else:
print("target string not exist in project!")
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("--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('--check_only', action='store_true')
parser.add_argument('--check_alt', action='store_true')
args = parser.parse_args()
remove_out(args)
if __name__ == "__main__":
cli()