Skip to content

Instantly share code, notes, and snippets.

@typesupply
Created May 18, 2022 14:21
Show Gist options
  • Save typesupply/0448ac6243ac3cd40578db6b7e3c93bc to your computer and use it in GitHub Desktop.
Save typesupply/0448ac6243ac3cd40578db6b7e3c93bc to your computer and use it in GitHub Desktop.
Bot that automatically fixes the smooth setting when it isn't correct.
from fontPens.guessSmoothPointPen import GuessSmoothPointPen
from fontParts.world import RGlyph
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber, disableSubscriberEvents
class SmoothBot(Subscriber):
debug = False
def glyphEditorGlyphDidChangeContours(self, info):
glyph = info["glyph"]
ghost = RGlyph()
pointPen = GuessSmoothPointPen(
outPen=ghost.getPointPen()
)
glyph.drawPoints(
pointPen,
components=False
)
with disableSubscriberEvents():
for contourIndex, ghostContour in enumerate(ghost.contours):
contour = glyph.contours[contourIndex]
for segmentIndex, ghostSegment in enumerate(ghostContour.segments):
segment = contour.segments[segmentIndex]
if segment.smooth != ghostSegment.smooth:
segment.smooth = ghostSegment.smooth
registerGlyphEditorSubscriber(SmoothBot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment