-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheckMissingGlyph.py
149 lines (119 loc) · 4.5 KB
/
checkMissingGlyph.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections
import fontforge
from io import open
import sys
# ignore warning
# import warnings
# warnings.filterwarnings("ignore")
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import (QFileDialog, QDialog, QPushButton,
QLineEdit, QLabel, QCheckBox,
QApplication, QVBoxLayout)
class askSetting(QDialog):
def __init__(self,
app=None,
parent=None,
items=None):
super(askSetting, self).__init__(parent)
self.app = app
self.items = items
layout = QVBoxLayout()
self.lineedits = collections.OrderedDict()
self.buttons = collections.OrderedDict()
for key in items.keys():
if isinstance(items[key], bool):
self.buttons[key] = QCheckBox(key)
self.buttons[key].setChecked(items[key])
self.buttons[key].setFocusPolicy(Qt.StrongFocus)
layout.addWidget(self.buttons[key])
else:
layout.addWidget(QLabel(key))
self.lineedits[key] = QLineEdit()
if isinstance(items[key], int):
self.lineedits[key].setText(str(items[key]))
# self.lineedits[key].setInputMask("000")
self.lineedits[key].setMaxLength(3)
self.lineedits[key].setValidator(
QIntValidator(1, 999, self))
else:
self.lineedits[key].setText(items[key])
# enable ime input
self.lineedits[key].inputMethodQuery(Qt.ImEnabled)
layout.addWidget(self.lineedits[key])
self.btn = QPushButton('TTF File to Read', self)
self.btn.clicked.connect(lambda: (self.bye(items)))
self.btn.setFocusPolicy(Qt.StrongFocus)
layout.addWidget(self.btn)
self.setLayout(layout)
self.setWindowTitle(' Setting ')
def bye(self, items):
fileName = QFileDialog.getOpenFileName(
self, 'Dialog Title', '~/', initialFilter='*.ttf')
if fileName == (u'', u'*.ttf'):
print("Must Provide an input TTF file.")
sys.exit()
for key in self.buttons.keys():
self.items[key] = self.buttons[key].isChecked()
for key in self.lineedits.keys():
self.items[key] = self.lineedits[key].text()
self.items['getOpenFileName'] = fileName[0]
self.close()
self.app.exit(1)
inFilePrompt = "File to read"
defaultInFile = "missingGlyphs"
items = collections.OrderedDict()
items[inFilePrompt] = defaultInFile
app = QApplication(sys.argv)
ask = askSetting(app=app, items=items)
ask.show()
rtnCode = app.exec_()
# If press OK button rtnCode should be 1
if rtnCode != 1:
print('User abort by closing Setting dialog')
sys.exit
# print(items)
ttfFile = fontforge.open(items['getOpenFileName'])
f = open(items[inFilePrompt], 'r', encoding="utf-8")
ttfFile.selection.none()
###
# file contents
# ## start with "##" line will be ignore to read
# 問
# 问
# ie. \w
# ie. word
###
count = 0
for line in f:
if line.startswith("##"):
continue
words = line.encode("raw_unicode_escape").split()
if len(words) == 1:
if words[0].startswith(b'\u'):
ttfFile.selection.select(words[0][1:])
elif len(words[0]) == 1:
ttfFile.selection.select(words[0])
if sum(1 for _ in ttfFile.selection.byGlyphs) == 0:
count += 1
if count == 1:
print("\n Missing Glyph for followings:")
print("-1-2-3-4-5-6-7-8-9-⓵ -1-2-3-4-5-6-7-8-9-⓶ -")
sys.stdout.write(" ")
if words[0].startswith(b'\u'):
sys.stdout.write(words[0].decode("raw_unicode_escape"))
sys.stdout.write(" ")
if count % 20 == 0:
sys.stdout.write("\n ")
sys.stdout.flush()
else:
count -= 1
if count > 0:
print("\n-1-2-3-4-5-6-7-8-9-⓵ -1-2-3-4-5-6-7-8-9-⓶ -")
# print("\n-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-")
# print("\nーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー")
print(" Total Missing Glyph: "+str(count))
else:
print("\n No Missing Glyph")