This repository was 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
/
Copy pathcreate.py
85 lines (57 loc) · 2.49 KB
/
create.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
import subprocess
import pathlib
import log
import shutil
import files
from font import TTFont
import compile.ttx
import compile.forc
import compile.ios.create
from format import formats
def createFont(fontFormat, outputPath, manifest, glyphs, compiler, flags):
log.out(f'{fontFormat}', 96)
log.out("-----------------", 90)
# prepare some variables
# --------------------------------------------------------------
# output folder
outPath = pathlib.Path(outputPath).absolute()
tempPath = outPath / '.forc_tmp'
files.tryDirectory(tempPath, "dir", "temporary font build folder", tryMakeFolder=True)
# filenames
# the user setting custom filenames in the manifest is optional.
# If none are given, just use the font format as the base filename.
if "filenames" in manifest["metadata"]:
filename = manifest['metadata']['filenames'][fontFormat]
else:
filename = fontFormat
# format information
formatData = formats[fontFormat]
# create the font!
# --------------------------------------------------------------
log.out(f'🛠 Assembling font...')
emojiFont = TTFont(formatData["name"], manifest, glyphs, flags)
log.out(f'🛠 Performing internal tests...')
emojiFont.test()
log.out(f'✅ Font successfully assembled.\n', 32)
# pass it to compilers and packagers
# --------------------------------------------------------------
log.out(f"⚙️ Compiling and externally testing font...")
if compiler == 'ttx':
tempFontPath = compile.ttx.createFont(formatData, outPath, tempPath, filename, flags, emojiFont)
elif compiler == 'forc':
tempFontPath = compile.forc.createFont(formatData, outPath, tempPath, filename, flags, emojiFont)
else:
raise ValueError("Something went wrong with the build process. I'm not able to run the font data through a compiler.")
log.out(f'✅ Compiling and testing OK.\n', 32)
if formats[fontFormat]["iOSCompile"]:
log.out(f"⚙️ Packaging font...")
compile.ios.create.createPackage(formatData, filename, outPath, tempFontPath, manifest)
log.out(f'✅ Packaging OK.\n', 32)
else:
shutil.copy(str(tempFontPath), str(outPath / (filename + formatData["extension"])))
# finish!
# --------------------------------------------------------------
# delete the temporary folder (recursively)
log.out(f'🗑 Cleaning up...')
shutil.rmtree(tempPath)
log.out(f'✅ Format finished!\n\n', 32)