Skip to content

Commit 75c9b85

Browse files
committed
no message
1 parent 2a03e18 commit 75c9b85

File tree

8 files changed

+3597
-0
lines changed

8 files changed

+3597
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ ENV/
9999

100100
# mypy
101101
.mypy_cache/
102+
103+
*.ttf

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# python-fontforge-script
2+
23
Python Script for Font Manipulation using FontForge Module
4+
5+
# Please install python-fontforge module first
6+
https://github.com/Kennyl/python-fontforge-script/blob/master/README.md
7+
# [minizeFont.py](https://github.com/Kennyl/python-fontforge-script/blob/master/minizeFont.py)
8+
9+
Python script that minimize ttf font by input word list
10+
11+
Use [minifyTC](https://github.com/Kennyl/python-fontforge-script/blob/master/minifyTC) as input word list
12+
13+
Word list format
14+
```
15+
A
16+
B
17+
C
18+
```
19+
20+
# [copyReferenceAtoB.py](https://github.com/Kennyl/python-fontforge-script/blob/master/copyReferenceAtoB.py)
21+
22+
Python script that copy glyph 'A' to glyph 'B' by Reference
23+
24+
Use [copyReferenceAtoB](https://github.com/Kennyl/python-fontforge-script/blob/master/copyReferenceAtoB) as input word list
25+
26+
Word list format (Copy glyph 'A' to glyph 'B', copy glyph 'C' to glyph 'D')
27+
```
28+
A B
29+
C D
30+
```
31+
32+
# [checkMissingGlyph.py](https://github.com/Kennyl/python-fontforge-script/blob/master/checkMissingGlyph.py)
33+
34+
Check Missing Glyph in word list [missingGlyph](https://github.com/Kennyl/python-fontforge-script/blob/master/missingGlyph)

checkMissingGlyph.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from io import open
5+
import sys
6+
import collections
7+
import fontforge
8+
9+
#ignore warning
10+
# import warnings
11+
# warnings.filterwarnings("ignore")
12+
13+
# can use 3 or 2
14+
from PyQt5.QtWidgets import (QFileDialog, QDialog, QPushButton,
15+
QLineEdit, QLabel, QCheckBox,
16+
QApplication, QVBoxLayout)
17+
from PyQt5.QtCore import Qt
18+
from PyQt5.QtGui import QIntValidator
19+
20+
21+
class askSetting(QDialog):
22+
23+
def __init__(self,
24+
app=None,
25+
parent=None,
26+
items=None):
27+
28+
super(askSetting, self).__init__(parent)
29+
30+
self.app = app
31+
self.items = items
32+
33+
layout = QVBoxLayout()
34+
35+
self.lineedits = collections.OrderedDict()
36+
self.buttons = collections.OrderedDict()
37+
38+
for key in items.keys():
39+
if isinstance(items[key], bool):
40+
self.buttons[key] = QCheckBox(key)
41+
self.buttons[key].setChecked(items[key])
42+
self.buttons[key].setFocusPolicy(Qt.StrongFocus)
43+
layout.addWidget(self.buttons[key])
44+
else:
45+
46+
layout.addWidget(QLabel(key))
47+
self.lineedits[key] = QLineEdit()
48+
if isinstance(items[key], int):
49+
self.lineedits[key].setText(str(items[key]))
50+
# self.lineedits[key].setInputMask("000")
51+
self.lineedits[key].setMaxLength(3)
52+
self.lineedits[key].setValidator(
53+
QIntValidator(1, 999, self))
54+
55+
else:
56+
self.lineedits[key].setText(items[key])
57+
58+
# enable ime input
59+
self.lineedits[key].inputMethodQuery(Qt.ImEnabled)
60+
layout.addWidget(self.lineedits[key])
61+
62+
self.btn = QPushButton('TTF File to Read', self)
63+
self.btn.clicked.connect(lambda: (self.bye(items)))
64+
self.btn.setFocusPolicy(Qt.StrongFocus)
65+
66+
layout.addWidget(self.btn)
67+
68+
self.setLayout(layout)
69+
self.setWindowTitle(' Setting ')
70+
71+
def bye(self, items):
72+
fileName = QFileDialog.getOpenFileName(
73+
self, 'Dialog Title', '~/', initialFilter='*.ttf')
74+
if fileName == (u'', u'*.ttf'):
75+
print("Must Provide an input TTF file.")
76+
sys.exit()
77+
78+
for key in self.buttons.keys():
79+
self.items[key] = self.buttons[key].isChecked()
80+
for key in self.lineedits.keys():
81+
self.items[key] = self.lineedits[key].text()
82+
83+
self.items['getOpenFileName'] = fileName[0]
84+
self.close()
85+
self.app.exit(1)
86+
87+
88+
inFilePrompt = "File to read"
89+
defaultInFile = "missingGlyph"
90+
91+
items = collections.OrderedDict()
92+
items[inFilePrompt] = defaultInFile
93+
94+
app = QApplication(sys.argv)
95+
ask = askSetting(app=app, items=items)
96+
ask.show()
97+
rtnCode = app.exec_()
98+
#If press OK button rtnCode should be 1
99+
if rtnCode != 1:
100+
print('User abort by closing Setting dialog')
101+
sys.exit
102+
103+
# print(items)
104+
ttfFile = fontforge.open(items['getOpenFileName'])
105+
106+
f = open(items[inFilePrompt], 'r', encoding="utf-8")
107+
108+
ttfFile.selection.none()
109+
## file contents
110+
#問
111+
#问
112+
## ie. \w
113+
## ie. word
114+
115+
count = 0
116+
117+
for line in f:
118+
words = line.encode("raw_unicode_escape").split()
119+
if len(words) == 1:
120+
if words[0].startswith(b'\u'):
121+
ttfFile.selection.select(words[0][1:])
122+
elif len(words[0]) == 1:
123+
ttfFile.selection.select(words[0])
124+
125+
if sum(1 for _ in ttfFile.selection.byGlyphs) == 0:
126+
count += 1
127+
if count == 1:
128+
print("\n Missing Glyph for followings:")
129+
print("-1-2-3-4-5-6-7-8-9-⓵ -1-2-3-4-5-6-7-8-9-⓶ -")
130+
sys.stdout.write(" ")
131+
if words[0].startswith(b'\u'):
132+
sys.stdout.write(words[0].decode("raw_unicode_escape"))
133+
sys.stdout.write(" ")
134+
if count % 20 == 0:
135+
sys.stdout.write("\n ")
136+
sys.stdout.flush()
137+
138+
if count > 0:
139+
print("\n-1-2-3-4-5-6-7-8-9-⓵ -1-2-3-4-5-6-7-8-9-⓶ -")
140+
# print("\n-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-ー-")
141+
# print("\nーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー")
142+
print(" Total Missing Glyph: "+str(count))
143+
else:
144+
print("\n No Missing Glyph")

0 commit comments

Comments
 (0)