-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvfont.py
51 lines (39 loc) · 1.34 KB
/
vfont.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
import os
import subprocess
import shutil
import random
import fontTools
from fontTools.ttLib import TTFont
import tempfile
import uuid
pathToFontToolsMutator = os.path.join(os.path.split(fontTools.__file__)[0], 'varLib/mutator.py')
class VFInstance:
def __init__(self, sourcePath, location, DEBUG=False):
self.instancePath = tempfile.mkstemp()[1]
tempPath = sourcePath.replace('.ttf', '-instance.ttf')
cmds = ['python', pathToFontToolsMutator, sourcePath]
for k, v in location.items():
cmds.append('%s=%s' %(k, v))
proc = subprocess.Popen(cmds, stdout=subprocess.PIPE)
out = proc.communicate()[0]
if DEBUG:
print ('---')
print (' '.join(cmds))
print ('---')
print (out)
myUUID = str(uuid.uuid4()).replace('-', '')
f = TTFont(tempPath)
self.fontName = 'VF'+str(myUUID)
f['name'].setName(self.fontName, 6, 1, 0, 0) # Macintosh
f['name'].setName(self.fontName, 6, 3, 1, 0x409) # Windows
os.remove(tempPath)
f.save(self.instancePath)
def getName(self):
return self.fontName
def getPath(self):
return self.instancePath
def remove(self):
try:
os.remove(self.instancePath)
except:
pass