-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmonospacifier_api.py
65 lines (56 loc) · 2.36 KB
/
monospacifier_api.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
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os.path as p
sys.path.insert(0, p.join(p.dirname(p.abspath(__file__)), 'monospacifier'))
import monospacifier as m
import unicodedata
class Args:
def __init__(self, inputs, references, save_to, merge, copy_metrics, renames):
self.inputs = inputs
self.references = references
self.save_to = save_to
self.merge = merge
self.copy_metrics = copy_metrics
self.rename = renames
def needs_scaling(self, glyph):
uni = glyph.unicode
def _unichr(u):
try:
return unichr(u)
except Exception:
return chr(u)
category = unicodedata.category(_unichr(uni)) if (uni >= 0) and (uni <= sys.maxunicode) else None
return glyph.width > 0 and category not in ['Mn', 'Mc', 'Me']
m.GlyphScaler.needs_scaling = needs_scaling
def monospacifier(inputs, references, save_to=".", merge=False, copy_metrics=False, renames=()):
"""
Parameters
----------
inputs : Union[list, str]
Variable-width fonts to monospacify.
references : Union[list, str]
Reference monospace fonts. The metrics (character width, ...) of the newly created monospace fonts are inherited from these.
save_to : str
Where to save the newly generated monospace fonts. Defaults to current directory.
merge : bool
Whether to create copies of the reference font, extended with monospacified glyphs of the inputs.
copy_metrics : bool
Whether to apply the metrics of the reference font to the new font.
renames : Tuple[Tuple[str, str]]
Like: (('STIX', 'ST1X'),)
"""
def parse_arguments():
return Args(inputs, references, save_to, merge, copy_metrics, renames)
m.parse_arguments = parse_arguments
m.main()