-
Notifications
You must be signed in to change notification settings - Fork 12
/
03_build_lato_fontmake.py
executable file
·118 lines (107 loc) · 4.62 KB
/
03_build_lato_fontmake.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
#!/usr/bin/env python3
import os
import os.path
from fontmake.font_project import FontProject
from ufo2ft import CFFOptimization
class LatoFontMake(object):
def __init__(self, config):
self.build = config.get('build', 'all')
self.cwd = os.path.dirname(__file__)
self.basefonts = {
'Lato3Upr': None,
'Lato3Ita': None,
}
if self.build in ('all', 'vf', 'vf2'):
for basefont in self.basefonts:
self.buildVF2(basefont)
if self.build in ('all', 'vf', 'vf3'):
for basefont in self.basefonts:
self.buildVF3(basefont)
if self.build in ('all', 'ttf'):
for basefont in self.basefonts:
self.buildTTF(basefont)
if self.build in ('all', 'otf'):
for basefont in self.basefonts:
self.buildOTF(basefont)
if self.build in ('test'):
for basefont in self.basefonts:
self.buildTest(basefont)
def build_fontmake(self, designspace_path, output = ['variable'], output_dir = None, remove_overlaps = False, interpolate = False, autohint = None):
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
project = FontProject()
fontmake_args = {
'output': output,
'output_path': None,
'output_dir': output_dir,
# 'feature_writers': None,
'interpolate': interpolate,
'remove_overlaps': remove_overlaps,
'overlaps_backend': 'booleanOperations',
'autohint': autohint,
'use_production_names': False
}
if 'variable' in output:
fontmake_args['optimize_gvar'] = True
if 'otf' in output:
fontmake_args['optimize_cff'] = CFFOptimization.SUBROUTINIZE
print(
project.run_from_designspace(
designspace_path=designspace_path,
**fontmake_args)
)
def buildVF2(self, basefont):
print('\n\nBuilding %s 2-master TTF VF...' % basefont)
designspace_path = os.path.join(self.cwd, '..', 'sources', basefont+'2M.designspace')
output = ['variable']
output_dir = os.path.join('..', 'build', basefont+'2M', 'vf-2master')
remove_overlaps = False
interpolate = False
self.build_fontmake(designspace_path, output, output_dir, remove_overlaps, interpolate)
def buildVF3(self, basefont):
print('\n\nBuilding %s 3-master TTF VF...' % basefont)
designspace_path = os.path.join(self.cwd, '..', 'sources', basefont+'3M.designspace')
output = ['variable']
output_dir = os.path.join('..', 'build', basefont+'2M', 'vf-3master')
remove_overlaps = False
interpolate = False
self.build_fontmake(designspace_path, output, output_dir, remove_overlaps, interpolate)
def buildTTF(self, basefont):
print('\n\nBuilding %s static TTFs...' % basefont)
designspace_path = os.path.join(self.cwd, '..', 'sources', basefont+'2M.designspace')
output = ['ttf']
output_dir = os.path.join('..', 'build', basefont+'2M', 'static-ttf')
remove_overlaps = True
interpolate = True
self.build_fontmake(designspace_path, output, output_dir, remove_overlaps, interpolate)
def buildOTF(self, basefont):
print('\n\nBuilding %s static OTFs...' % basefont)
designspace_path = os.path.join(self.cwd, '..', 'sources', basefont+'2M.designspace')
output = ['otf']
output_dir = os.path.join('..', 'build', basefont+'2M', 'static-otf')
remove_overlaps = True
interpolate = True
self.build_fontmake(designspace_path, output, output_dir, remove_overlaps, interpolate)
def buildTest(self, basefont):
print('\n\nBuilding %s test font...' % basefont)
designspace_path = os.path.join(self.cwd, '..', 'sources', basefont+'Test.designspace')
output = ['ttf']
output_dir = os.path.join('..', 'build', basefont+'Test', 'test-ttf')
remove_overlaps = True
interpolate = True
self.build_fontmake(designspace_path, output, output_dir, remove_overlaps, interpolate)
if __name__ == "__main__":
import argparse
# ...
parser = argparse.ArgumentParser(
prog="build_lato_fontmake",
description="""Build Lato variable and static fonts from DesignSpace+UFO\
source using fontmake"""
)
parser.add_argument(
"build",
nargs="?",
default='all',
choices=['all', 'vf', 'vf2', 'vf3', 'otf', 'ttf', 'test']
)
mk = LatoFontMake(vars(parser.parse_args()))