Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active Nov 24, 2021
Embed
What would you like to do?
an update of marky mark extension, rebuilt for robofont 4
from merz import MerzView
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber
size = 50
class earMark(Subscriber):
debug = True
def build(self):
self.merzView = MerzView((-size, 0, 0, size))
merzContainer = self.merzView.getMerzContainer()
self.triangle = merzContainer.appendPathSublayer(
name='okayType.earMark',
position=(0, 0)
)
pen = self.triangle.getPen()
pen.moveTo((0, size))
pen.lineTo((size, size))
pen.lineTo((size, 0))
pen.closePath()
self.getGlyphEditor().addGlyphEditorSubview(self.merzView)
def destroy(self):
self.getGlyphEditor().removeGlyphEditorSubview(self.merzView)
def glyphEditorDidSetGlyph(self, info):
glyph = info['glyph']
if glyph == None:
return
self.setGlyphMarkColor(glyph)
def glyphEditorGlyphDidChangeInfo(self, info):
glyph = info['glyph']
if glyph == None:
return
self.setGlyphMarkColor(glyph)
def setGlyphMarkColor(self, glyph):
color = glyph.markColor
if color != None:
r, g, b, a = color
color = (r, g, b, a * .9)
if color == None:
color = (0, 0, 0, .05)
self.triangle.setFillColor(color)
registerGlyphEditorSubscriber(earMark)
@typemytype
Copy link

typemytype commented Nov 23, 2021

the markColorChanged notification is bundled in ˋglyphDidChangeInfoˋ so the method will be ˋglyphEditorGlyphDidChangeInfoˋ

This will be called when any of Glyph.NameChanged, Glyph.UnicodesChanged, Glyph.NoteChanged, Glyph.MarkColorChanged are posted. Default delay: 0.033 seconds.

https://robofont.com/documentation/reference/api/mojo/mojo-subscriber/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment