Created
October 8, 2019 11:39
-
-
Save gferreira/ad572c62d9f7914189d8434fa8e0190d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, operator | |
from fontParts.world import OpenFont | |
def autoStartPoints(glyph): | |
if not glyph.bounds: | |
return | |
for contour in glyph: | |
points = [(pt.x, pt.y, pt) for pt in contour.points if pt.type != 'offcurve'] | |
sortedPoints = sorted(points, key=operator.itemgetter(1, 0)) | |
firstPoint = sortedPoints[0][2] | |
startSegmentIndex = [i for i, segment in enumerate(contour) if firstPoint in segment.points][0] | |
contour.setStartSegment(startSegmentIndex) | |
def autoStartPointsRF(glyph): | |
for contour in glyph: | |
contour.autoStartSegment() | |
folder = '/_code/mutatorSans' | |
ufos = [os.path.join(folder, f) for f in os.listdir(folder) if os.path.splitext(f)[-1] == '.ufo'] | |
glyphNames = ['A', 'B', 'C'] | |
for ufo in ufos: | |
font = OpenFont(ufo) | |
for glyphName in glyphNames: | |
if glyphName not in font: | |
continue | |
glyph = font[glyphName] | |
autoStartPoints(glyph) | |
font.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment