-
Notifications
You must be signed in to change notification settings - Fork 3
/
abstractor.py
84 lines (76 loc) · 2.29 KB
/
abstractor.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
#!/usr/bin/env python
# encoding: utf-8
from defcon import Font, Color, Glyph
from argl import *
import shutil
import copy
path = "../../ali-uni/build/UFO/Ali-Uni_Samik_Regular.ufo"
path = "../sources/lots.ufo"
#path = "../sources/adobe.ufo"
mFont = Font(path)
mUnicodes = mFont.unicodeData
data = mFont.getDataForSerialization()
master = Font('../sources/font.ufo')
ufo = Font()
ufo.setDataFromSerialization({'info': data['info']})
layersDict = {}
layersColors = ('','1,0,0,1', '0,1,0,1', '0,0,1,1', '0.5,0.5,0,1', '0.5,0,0.5,1', '0,0.5,0.5,1', '0.5,0.5,0.5,1', '1,0,0,1', '1,0,0,1',
'1,0,0,1')
for nl in range(1, 9):
newLayer = ufo.layers.newLayer('background' + str(nl - 1))
newLayer.color = Color(layersColors[nl])
layersDict.update({'layer' + str(nl): newLayer})
ufo.newGlyph('.notdef')
for glf in RAWN2C:
layer = 0
glfSrc = RAWN2C[glf].split(',')
if glf == "legLG.isol":
m = 1
for g in glfSrc:
if layer == 10:
continue
try:
gCode = AGL2UV[g]
mgName = mUnicodes[gCode]
glyph = Glyph()
glyph.copyDataFromGlyph(mFont[mgName[0]])
glyph.name = glf
glyph.unicode = None
glyph.anchors = []
glyph.decomposeAllComponents()
if layer > 0:
currentLayer = layersDict['layer' + str(layer)]
currentLayer.insertGlyph(glyph)
else:
ufo.insertGlyph(glyph)
layer += 1
print(g + ' found :)' + ' L ' + str(layer))
except:
print(' ' + g + ' not found in font')
glyph = None
if layer == 0:
ufo.newGlyph(glf)
factor = 2
for gg in ufo:
try:
masterGlyphe = master[gg.name]
gg.anchors = copy.deepcopy(masterGlyphe.anchors)
for point in gg.anchors:
point.x *= factor
point.y *= factor
except:
pass
def sortLibGlyphs(ufo, type):
notSorted = ufo.lib['public.glyphOrder']
sorted = notSorted.sort()
return sorted
# print(ufo.glyphSet)
sortLibGlyphs(ufo, 'unicode')
outputFilePath = '../sources/build/xxxAA.ufo'
outputFilePath = '../sources/build/xxx888.ufo'
try:
shutil.rmtree(outputFilePath)
print(outputFilePath + " Deleted!")
except:
pass
ufo.save(outputFilePath)