This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.py
136 lines (87 loc) · 3.74 KB
/
start.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
import pathlib
import log
import files
from create import createFont
from manifest.manifest import checkTransformManifest
from validate.aliases import validateAliases
from glyphProc import getGlyphs
from format import formats, compilers
# start.py
# -------------------------------
#
# All of the data gathering and validation required before initiating font export.
# Also initiates font export when all of these things are completed and satisfactory.
def start( inputPath
, outputPath
, manifestPath
, aliasesPath
, delim_codepoint
, outputFormats
, compiler
, flags
):
"""
Performs a variety of initial data gathering and validation tasks,
designed to make sure all of the user-given data is valid and usable.
Once this has all been validated, it starts the font making process.
"""
log.out(f'\nFetching resources...', 35)
log.out("----------------------------------", 90)
# check folder stuff
# ------------------------------------------------
log.out(f'Checking file + folder locations...')
inputPathPath = pathlib.Path(inputPath).absolute()
files.tryUserDirectory(inputPathPath, "dir", "input folder")
outputPathPath = pathlib.Path(outputPath).absolute()
files.tryUserDirectory(outputPathPath, "dir", "output folder", tryMakeFolder=True)
manifestPathPath = pathlib.Path(manifestPath).absolute()
files.tryUserDirectory(manifestPathPath, "file", "manifest file")
if aliasesPath:
aliasesPathPath = pathlib.Path(aliasesPath).absolute()
files.tryUserDirectory(aliasesPathPath, "file", "aliases file")
log.out(f'File + folder locations OK!\n', 32)
# determine what image formats need to be used
# (also check if the output formats are valid)
# ------------------------------------------------
glyphImageFormats = set()
log.out(f'Checking output parameters...')
for f in outputFormats:
# check if it's in the list of accepted formats
if f not in formats:
raise ValueError(f"'{f}' isn't a valid output format!")
# check what formats are needed
if formats[f]["imageFormat"] == 'svg':
glyphImageFormats.add('svg')
elif formats[f]["imageFormat"] == 'png':
glyphImageFormats.add('png')
log.out(f'Output format(s) OK!\n', 32)
# check compiler
# ------------------------------------------------
if compiler not in compilers:
raise ValueError(f"You gave '{compiler}' as the compiler to use. This doesn't exist in forc. Check the help menu (-h) to see which compilers you can use.")
# manifest
# ------------------------------------------------
log.out(f'Getting + checking manifest data...')
manifest = files.loadJson(manifestPath, "manifest file")
checkTransformManifest(outputFormats, manifest)
log.out(f'Manifest OK!.\n', 32)
# aliases (file)
# ------------------------------------------------
if aliasesPath:
log.out(f'Getting + checking aliases data...')
aliases = files.loadJson(aliasesPath, "aliases file")
validateAliases(aliases)
log.out(f'Aliases OK!.\n', 32)
else:
aliases = None
# glyphs
# ------------------------------------------------
log.out(f'Getting + checking glyphs...')
glyphs = getGlyphs(inputPathPath, manifest, aliases, delim_codepoint, glyphImageFormats, flags)
log.out(f'Glyphs OK!\n', 32)
log.out(f'All resources OK!', 32)
# assemble each font format.
# ------------------------------------------------
log.out(f'Starting font compilation...\n\n', 35)
for f in outputFormats:
createFont(f, outputPath, manifest, glyphs, compiler, flags)