-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16 Outline Glyph.py
51 lines (40 loc) · 1.28 KB
/
16 Outline Glyph.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
# MenuTitle: 16 Outline Glyph
from mojo.roboFont import CurrentGlyph, RGlyph
from penCollection.outlinePen import OutlinePen
"""
OutlinePen:
def __init__(self,
glyphSet,
offset=10,
contrast=0,
contrastAngle=0,
connection="square",
cap="round",
miterLimit=None,
closeOpenPaths=True,
preserveComponents=False
):
"""
def outline_glyph(glyph):
source = glyph
font = glyph.font
# Save the anchors from the original glyph in a list
anchors = [a for a in source.anchors]
# Remove all anchors from the glyph so they don't interfere with our processing
source.clear(contours=False, components=False, anchors=True)
# Temporary glyph to which the pen is writing
target = RGlyph()
target_pen = target.getPointPen()
source_pen = OutlinePen(font, contrast=1, offset=5, connection="round")
source.draw(source_pen)
source_pen.drawSettings(drawInner=True, drawOuter=True)
source_pen.drawPoints(target_pen)
# Clear the original glyph and add the modfied outline
source.clear()
source.appendGlyph(target)
# Restore the saved anchors
for a in anchors:
source.appendAnchor(a.name, a.position)
if __name__ == "__main__":
g = CurrentGlyph()
outline_glyph(g)