This example shows a very simple tool which displays the current glyph in a system font at the bottom of the glyph window.

This is how the code works:

  • an observer is added to the draw event
  • when the event is triggered, the tool uses the unicode value of the current glyph to get the corresponding character
  • finally, if there is a character for the glyph, text properties (fill, font, font size) are set, and the text placed
from import addObserver
from mojo.drawingTools import *

class DrawReferenceGlyph(object):

    def __init__(self):
        addObserver(self, "drawReferenceGlyph", "draw")

    def drawReferenceGlyph(self, info):
        # get the current glyph
        glyph = info["glyph"]

        # define a fill color
        color = 0, 0, 0, 0.5

        # make sure we have a character
        if glyph is not None and glyph.unicode is not None and glyph.unicode < 0xFFFF:

            # get character for glyph
            t = unichr(glyph.unicode)

            # draw reference glyph
            font("Georgia", 20)
            text(t, (glyph.width + 10, 10))

# turn tool on

Last edited on 02/06/2020