import ezui from mojo.subscriber import Subscriber, registerRoboFontSubscriber from mojo.roboFont import CurrentGlyph class GlyphVisualizer(Subscriber, ezui.WindowController): debug = True def build(self): self.glyph = CurrentGlyph() content = """ * MerzView @merzView """ descriptionData = dict( merzView=dict( backgroundColor=(1, 1, 1, 1), delegate=self ), ) self.w = ezui.EZWindow( title="Glyph Visualizer", content=content, size=(self.glyph.width, self.glyph.font.info.unitsPerEm), descriptionData=descriptionData, controller=self ) merzView = self.w.getItem("merzView") container = merzView.getMerzContainer() # a layer for the glyph and the baseline self.backgroundLayer = container.appendBaseSublayer( size=(self.glyph.width, self.glyph.font.info.unitsPerEm), backgroundColor=(1, 1, 1, 1) ) self.glyphLayer = self.backgroundLayer.appendPathSublayer( position=(0, -self.glyph.font.info.descender) ) glyphPath = self.glyph.getRepresentation("merz.CGPath") self.glyphLayer.setPath(glyphPath) self.lineLayer = self.backgroundLayer.appendLineSublayer( startPoint=(0, -self.glyph.font.info.descender), endPoint=(self.glyph.width, -self.glyph.font.info.descender), strokeWidth=1, strokeColor=(1, 0, 0, 1) ) def started(self): self.w.open() def glyphEditorDidSetGlyph(self, info): self.glyph = info['glyph'] glyphPath = self.glyph.getRepresentation("merz.CGPath") self.glyphLayer.setPath(glyphPath) self.backgroundLayer.setSize((self.glyph.width, self.glyph.font.info.unitsPerEm)) self.lineLayer.setEndPoint((self.glyph.width, -self.glyph.font.info.descender)) if __name__ == '__main__': registerRoboFontSubscriber(GlyphVisualizer)