-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchDiacritics.py
115 lines (89 loc) · 3.22 KB
/
batchDiacritics.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
from glyphConstruction import ParseGlyphConstructionListFromString, GlyphConstructionBuilder
import imp
import os
font = f = CurrentFont()
def processGlyph(font, comp, base, accent, anchor):
if base not in font.keys():
return
if accent not in font.keys():
return
inBase, height = anchorInGlyph(anchor, font[base])
if inBase and height > 600:
if accent+".cap" in font.keys():
accent = accent+".cap"
inAccent, height = anchorInGlyph(anchor, font[accent])
if not inBase:
return
if not inAccent:
return
construction = "%s = %s + %s@%s" % (comp, base, accent, anchor)
# print(construction) #line
# build a construction glyph
constructionGlyph = GlyphConstructionBuilder(construction, font)
# if the construction for this glyph was preceded by `?`
# and the glyph already exists in the font, skip it
# if constructionGlyph.name in font and constructionGlyph.name in ignoreExisting:
# return
# get the destination glyph in the font
glyph = font.newGlyph(constructionGlyph.name, clear=True)
# draw the construction glyph into the destination glyph
constructionGlyph.draw(glyph.getPen())
# copy construction glyph attributes to the destination glyph
glyph.name = constructionGlyph.name
glyph.unicode = constructionGlyph.unicode
glyph.width = constructionGlyph.width
glyph.markColor = 1, 1, 0, 0.5
# if no unicode was given, try to set it automatically
if glyph.unicode is None:
glyph.autoUnicodes()
# define glyph constructions
test = '''\
agrave = a + grave@top
aacute = a + acute@top
iogonek = i + ogonek@ogonek
Iacute = I+acute@top+acute@top
bdkjn = re+acute@top
'''
def anchorInGlyph(anchor, glyph):
for a in glyph.anchors:
if a.name == anchor:
return (True, a.y)
if a.name == "_"+anchor:
return (True, a.y)
return (False, None)
# try to load font constructions
if 'nl.hallotype.glyphConstructions' in f.lib:
batchConstructions = f.lib['nl.hallotype.glyphConstructions']
else:
# load default set
path = "_glyphContructionsRF3.py"
bc = imp.load_source('txt', path)
asList = ParseGlyphConstructionListFromString(bc.basics)
asDict = []
for i in asList:
if i.find("+") != i.rfind("+"):
continue
compo = i.split("=")[0][:-1]
base = i.split("=")[1][1:].split("+")[0].strip()
accent = i.split("=")[1][1:].split("+")[1].strip().split("@")[0]
anchor = i.split("=")[1][1:].split("+")[1].strip().split("@")[1]
# for now only one accent@anchor pair!
construction = i.split("+")[1].strip()
asDict.append(dict(
active=True,
compo=compo,
base=base,
accent=accent,
anchor=anchor,
construction=construction,
))
f.lib['nl.hallotype.glyphConstructions'] = asDict
batchConstructions = f.lib['nl.hallotype.glyphConstructions']
for construction in batchConstructions:
if construction['active'] == True:
processGlyph(font,
construction['compo'],
construction['base'],
construction['accent'],
construction['anchor']
)