-
Notifications
You must be signed in to change notification settings - Fork 5
/
outlines.py
executable file
·74 lines (64 loc) · 2.26 KB
/
outlines.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
#!/usr/local/bin/fontforge
##############################################################################
#
# Muktamsiddham stroke to outline font conversion script
#
# This script only runs under FontForge with Python scripting support.
# With Python 2.7 installed, FontForge may fail to be built. If you experience
# this issue, the following link may help you:
# http://old.nabble.com/Compiling-error-with-Python-td29226850.html
#
##############################################################################
import fontforge
from math import radians
font = fontforge.open("Muktamsiddham.sfd")
font.strokedfont = False
strokeType = {
'section01': ('circular', 40),
'section02': ('circular', 40),
'section03': ('circular', 40),
'section04': ('circular', 40),
'section05': ('circular', 40),
'section06': ('circular', 40),
'section07': ('circular', 40),
'section08': ('circular', 40),
'section09': ('circular', 30),
'section11': ('circular', 40),
'section12': ('circular', 40),
'section13': ('circular', 40),
'section14': ('circular', 40),
'section15': ('circular', 35),
}
for glyph in font.glyphs():
if glyph.isWorthOutputting():
if glyph.glyphname not in strokeType:
glyph.stroke("eliptical",100,40,radians(-30.0),"square","round")
elif strokeType[glyph.glyphname][0] == 'circular':
glyph.stroke("circular",strokeType[glyph.glyphname][1],"square","round")
else: # this should not occur
raise ValueError("unsupported stroke type")
font.selection.all()
font.addExtrema();font.round()
font.simplify();font.round()
font.removeOverlap();font.round()
font.simplify();font.round()
font.addExtrema();font.round()
latinFont = fontforge.open("LatinGlyphs.sfd")
font.encoding = "UnicodeBmp"
for glyph in latinFont.glyphs():
if glyph.isWorthOutputting():
assert glyph.unicode >= 0
latinFont.selection.select(glyph.glyphname)
latinFont.copy()
font.selection.select(("unicode",),glyph.unicode)
try:
font[glyph.unicode] # Check if the glyph already exists
# Already exists: do nothing
except TypeError: # No such glyph yet
font.paste()
font[glyph.unicode].glyphname = glyph.glyphname
font.encoding = "Original"
font.importLookups(latinFont, latinFont.gsub_lookups)
font.importLookups(latinFont, latinFont.gpos_lookups)
font.autoHint()
font.save("Outlines.sfd")