mojo.compile

from mojo.compile import *
  • FDKVersion
    Returns the version of the embedded FDK
  • makeotf(outputPath, outlineSourcePath=None, featuresPath=None, glyphOrderPath=None, menuNamePath=None, fontInfoPath=None, releaseMode=False)
    FDK makeotf
  • checkOutlines(fontPath, removeOverlap=True, correctContourDirection=True)
    FDK checkOutlines
  • otf2pfa(sourcePath, destinationPath)
    Convert a otf to pfa using FDK.
  • otf2svg(sourcePath, destinationPath)
    Convert a otf to a svg font using FDK.
  • autohint(fontPath)
    Autohint a postscript flavored font.
  • hasTTFAutoHint()
    Return a boolean if ttfautohint is installed.
  • ttfautohint(fontPath)
    Use ttf autohint if its locally installed to autohint a ttf file.
  • stemHist(fontPath, useCurves=None, blueZones=False)
    Use FDK stemhist on a binary font. See stemHist help for details.
  • setUseEmbeddedFDK(value)
    Set a boolean if RoboFont should use the embedded FDK.
  • getUseEmbeddedFDK()
    Returns a boolean if RoboFont will use the embedded FDK.
  • executeCommand(command, shell=False)
    Execute commands in the terminal. Commands must be a list of arguments.
    Optionally execute in the shell instead of inside RoboFont

mojo.extensions

from mojo.extensions import *

Classes

  • ExtensionBundle(name=None, path=None, libName="lib", htmlName="html", indexHTMLName="index.html", resourcesName="Resources")
    An extension bundle objects allowing access to different parts of an extension.
     
    initiate an ExtensionBundle object
    name: name of an extension (either name or path is required)
    path: path to an extension (either name or path is required) 
     
    version
    returns the version of the extension
    name
    returns the name of the extension
    developer
    returns the developer of the extension
    developerURL
    returns the developer URL of the extension
    requiresVersionMajor
    returns the required major version number of RoboFont
    requiresVersionMinor
    returns the required minor version number of RoboFont
    addToMenu
    returns a bool if the bundle should be added to the extension menu
    launchAtStartUp
    returns a bool if the bundle should be launched at start up
    mainScript
    returns the filename of the main script

    timeStamp
    returns the time stamp, stamped when the extension is build
     
    get(name, ext='*')
    returns the file within the extension, if its is an image it will return the NSImage object around that image.
    install()
    installs the extension
    deinstall()
    de-installs the extension 
    openHelp()
    Opens the help HTML in an HTMLHelpWindow
    validate()
    validates the extension
    validateErrors()
    returns a string of validation errors
    bundlePath()
    returns the path of the extension bundle
    libPath()
    returns the path of the lib folder inside the bundle
    HTMLPath()
    returns the path of the HTML folder inside the bundle
    resourcesPath()
    returns the path of the Resources folder inside the bundle
    infoDictionaryPath()
    returns the path of the info.plist inside the bundle
    mainScriptPath()
    returns the path of the main script
    hasHTML()
    returns a bool if the extension has HTML help
    HTMLIndexPath()
    returns the path of the index.html file
    bundleExists()
    returns if a bool if the extension bundle exists on disk  

    allExtensions()
    a class method returns all installed extensions

Methods

  • getExtensionDefault(key, fallback=None)
    returns the value for key from the extension user defaults
    if the key isn't used it returns the fallback
  • setExtensionDefault(key, value)
    set the value for key in the extensions user defaults
  • getExtensionDefaultColor(key, fallback=None)
    returns an NSColor object for key from the extension user defaults
  • setExtensionDefaultColor(key, fallback=None)
    set an NSColor for key in the extensions user defaults
  • registerExtensionsDefaults(defaults)
    register a dict with keys and values as defaults in the extension user defaults 

mojo.canvas

from mojo.canvas import Canvas

A vanilla object that sends all user input events to a given delegate.

Canvas(posSize,
       delegate=None,
       canvasSize=(1000, 1000),
       acceptsMouseMoved=False,
       hasHorizontalScroller=True,
       hasVerticalScroller=True,
       autohidesScrollers=False,
       backgroundColor=None,
       drawsBackground=True)

Methods

All events a delegate could have that can be used:

  • draw()
    Callback when the canvas get drawn.
  • becomeFirstResponder(event)
    Callback when the canvas becomes the first responder, when it starts to receive user interaction callbacks.
  • resignFirstResponder(event)
    Callback when the canvas resigns the first responder, when the canvas will not longer receive user interaction callbacks. 
  • mouseDown(event)
    Callback when the user hit the canvas with the mouse. 
  • mouseDragged(event)
    Callback when the user drag the mouse around in the canvas. 
  • mouseUp(event)
    Callback when the user lifts up the mouse from the canvas. 
  • mouseMoved(event)
    Callback when the user moves the mouse in de canvas. Be careful this is called frequently. (only when accepsMouseMoved is set True)
  • rightMouseDown(event)
    Callback when the user clicks inside the canvas with the right mouse button. 
  • rightMouseDragged(event)
    Callback when the users is dragging in the canvas with the right mouse button down.  
  • rightMouseUp(event)
    Callback when the users lift up the right mouse button from the canvas. 
  • keyDown(event)
    Callback when the users hits a key.
    The event object has a characters() method returns the pressed character key.
  • keyUp(event)
    Callback when the users lift up the key. 
  • flagChanged(event)
    Callback when the users changed a modifier flag:
    command  shift  control  alt

Example

from mojo.canvas import Canvas
from mojo.drawingTools import *
from vanilla import *

class ExampleWindow:

    def __init__(self):
        self.size = 50

        self.w = Window((400, 400), minSize=(200, 200))
        self.w.slider = Slider((10, 5, -10, 22),
                          value=self.size,
                          callback=self.sliderCallback)
        self.w.canvas = Canvas((0, 30, -0, -0), delegate=self)
        self.w.open()

    def sliderCallback(self, sender):
        self.size = sender.get()
        self.w.canvas.update()

    def draw(self):
        rect(10, 10, self.size, self.size)

ExampleWindow()

mojo.UI

from mojo.UI import *

Classes

  • AccordionView(posSize, descriptions, backgroundColor)
    A vanilla object hosting different kinds of other vanilla objects (like vanilla.List, vanilla.TextEditor, ....) in an accordion view.
     
    Initiate a AccordionView
    posSize: a tuple of four, setting the size
    descriptions: list of options for each item in the accordionView (see example) 
    backgroundColor: a NSColor object used as background color
     
    from mojo.UI import AccordionView
    from vanilla import *
    
    class MyInspector:
    
        def __init__(self):
    
            self.w = FloatingWindow((200, 600))
    
            self.firstItem = TextEditor((10, 10, -10, -10))
    
            self.secondItem = List((0, 0, -0, -0), ["a", "b", "c"])
    
            self.thirdItem = Tabs((10, 10, -10, -10), ["1", "2", "3"])
            
            self.fourthItem = Group((0, 0, -0, -0))
            
            self.fourthItem.checkBox = CheckBox((10, 10, 100, 22), "CheckBox")
            self.fourthItem.editText = EditText((10, 40, -10, 22))
            
    
            descriptions = [
                           dict(label="first item", view=self.firstItem, size=200, collapsed=False, canResize=False),
                           dict(label="second item", view=self.secondItem, minSize=100, size=140, collapsed=True, canResize=True),
                           dict(label="third item", view=self.thirdItem, minSize=100, size=140, collapsed=True, canResize=False),
                           dict(label="fourth item", view=self.fourthItem, size=140, collapsed=False, canResize=False)
                           ]
    
            self.w.accordionView = AccordionView((0, 0, -0, -0), descriptions)
    
            self.w.open()
    
    MyInspector()
  • HTMLView(posSize)
    Initiate a HTMLView
    posSize: a tuple of four, setting the size
     
    setHTMLPath(url)
    Set the url in the HTMLView
    goBack()
    Go forward in the history of the HTMLView
    goForward()
    Go forward in the history of the HTMLView
    clearHistory()
    Clear the history of the HTMLView 
  • HelpWindow(htmlPath, title="help", developer=None, developerURL=None)
    Initiate a HelpWindow
    htmlPath: html help path
    title: title of the help window
    developer: a string with the name of the developer, optionally
    developerURL: a URL link to the developer, optionally
     
    set(htmlPath)
    set a html path in the HTMLView of the HelpWindow 
     
    from mojo.UI import HelpWindow
    
    HelpWindow("http://robofont.com")
  • SmartSet(smartSet=dict())
    Initiate a smart set object
    smartSet: a dictionary containing smart set data
     
    name
    Set or get the smart set name. 
    glyphNames
    Set or get the a list of glyph names used by the smart set. 
    query
    Set or get a search query.
  • MultiLineView(posSize, pointSize=150, lineHeight=50, doubleClickCallbak=None, applyKerning=None, bordered=False, hasHorizontalScroller=False, hasVerticalScroller=True, displayOptions=None, selectionCallback=None, menuForEventCallback=None)
    A multi glyph line view vanilla object, this is the same objects that is used to build a Space Center.
    Initiate a multi line view object:
    posSize: a tuple of four, setting the size
    pointSize: the initial point size, optionally
    lineHeight: the initial lineHeight, , optionally
    doubleClickCallback: callback for a double click event
    applyKerning: enable kerning the view, optionally
    bordered: set a border around the view
    hasHorizontalScroller: set the horizontal scroller
    hasVerticalScroller: set the vertical scroller
    displayOptions: a dict with multi line view display options
    selectionCallback: callback when a glyph get selected
    menuForEventCallback: callback when a contextual menu will we used, required to return a NSMenu object

     
    get()
    Returns all glyphs in the line view
    set(glyphs)
    Sets a list of glyphs in the line view
    setFont(font)
    The glyph line view needs a font as fallback and for font metrics
    createNewLineGlyph()
    Returns a special glyph object that acts like a new line
    createEmptyGlyph(name)
    Returns a special glyph object that acts like an empty glyph (use this as fallback when a glyph is not in the font)
    setPointSize(pointSize)
    Sets the point size
    setLineHeight(lineHeight)
    Sets the line height
    setApplyKerning(value)
    Sets if kerning is applied in the line view
    getDisplayStates()
    Returns a dict with all display options
    setDisplayStates(options)
    Sets a dict of line view display options
    setLeftToRight(value)
    Sets the reading direction of the glyph line view
     

    from mojo.UI import MultiLineView
    from vanilla import *
        
    class MyOwnSpaceCenter:
    
        def __init__(self, font):
    
            self.w = Window((600, 400), minSize=(300, 300))
    
            self.w.lineView = MultiLineView((0, 0, -0, -0), 
                                                pointSize=30, 
                                                selectionCallback=self.lineViewSelectionCallback)
            self.w.lineView.setFont(font)
    
            glyphs = []
            for glyphName in font.glyphOrder:
                glyphs.append(font[glyphName])
    
            self.w.lineView.set(glyphs)
    
            self.w.open()
        
        def lineViewSelectionCallback(self, sender):
            print sender.getSelectedGlyph()
    
    MyOwnSpaceCenter(CurrentFont())

Methods

  • GlyphViewDisplaySettings(settings)
    Set display options for the current glyphview. Input as dict. These settings will be default for the glyphview. All options are: Fill, Stroke, Metrics, On Curve Points, Off Curve Points, Point Coordinates, Anchors, Curve Length, Blues, Family Blues, Rulers
  • AllSpaceCenters()
    Get all open space centers
  • CurrentSpaceCenter()
    methods:
    get()
    returns a list of glyph names in the space center
    getRaw()
    returns a string from the input of the space center
    set(glyphNames)
    sets the list of glyphNames in the space center
    setRaw(text)
    set a string in to the main input of the space center
    getTracking()
    returns the tracking used
    setTracking(value)
    set a tracking value between the glyphs
    getLeftToRight()
    returns the reading direction
    setLeftToRight(value)
    sets the reading direction
    getPointSize()
    returns the point size
    setPointSize(value)
    sets the points size
  • SpaceCenterToPDF(path, spaceCenter=None)
    Saves the Space Center to a pdf with vector data, if a spaceCenter is not provided the CurrentSpaceCenter() will be used.
  • AllGlyphWindows()
    Returns all open glyph windows.
  • CurrentGlyphWindow()
    Returns the current glyph window.
  • GlyphWindowToPDF(path, glyphWindow=None)
    Saves the Glyph Window to a pdf with vector data, if a Glyph Window is not provided the CurrentGlyphWindow() will be used.
  • AllFontWindows()
    Returns all open font windows. 
  • CurrentFontWindow()
    Returns the current font window. 
  • OpenGlyphWindow(glyph=None, newWindow=False)
    Opens a new glyph window
    glyph: a given glyph object
    newWindow: open a new window, even if there is already a glyph window open
  • OpenSpaceCenter(font, newWindow=False)
    Opens a new Space Center
    font: a given font object
    newWindow: open a new window, even if there is already a Space Center winow open
  • OutputWindow()
    Returns the output window
    write(text)
    Write a string in the output window
    clear()
    Clears the output window
  • SetCurrentGlyphByName(glyphName)
    Sets a glyph name in the current glyph editor
  • SetCurrentLayerByName(layerName)
    Sets the current layer by a layerName in the current glyph editor
  • UpdateCurrentGlyphView()
    Updates the current glyph editor
  • SetCurrentLayerByName(layerName)
    Sets the current layer by layer name 
  • addSmartSet(smartSet, index=-1)
    Add a smart set object. 
    Optionally set an index to insert the smart set object. 
  • removeSmartSet(smartSetName)
    Remove a smart set. 
  • getSmartSets()
    Get all current smart sets. 
  • setSmartSets(smartSets)
    Set a list of smart sets. 
  • setDefaultCharacterSet(characterSetName)
    Set the default character set by name as defined in the preferences. 
  • getDefaultCharacterSet()
    Get the current default character set name. 
  • addCharacterSet(characterSetName, glyphNames, useAsDefault=False)
    Add a character set with a name and a list of glyph names. 
  • removeCharacterSet(characterSetName)
    Remove a character set by name. 
  • getCharacterSets()
    Get all characeter sets as a dictionairy. 
  • setCharacterSets(characterSets)
    Set a dictionary of character sets. 
  • setMaxAmountOfVisibleTools(value)
    Set the maximum amount of visible tools in the toolbar.
    Must be in integer. 
  • getMaxAmountOfVisibleTools()
    Get the maximum amount of visible tools in the toolbar. 
  • setScriptingMenuNamingShortKey()
    Get the scripting menu names and shortkey dictionary. 
  • getScriptingMenuNamingShortKey(data)
    Set a scripting menu names and shortkey dictionary. 
  • setScriptingMenuNamingShortKeyForPath(path, preferredName, shortkey=None)
    Set the scripting menu names and shortkey dictionary. 
  • exportPreferences(path)
    Export all user preferences to a path. 
  • importPreferences(path)
    Import user preferences from a path. 

mojo.tools

from mojo.tools import IntersectGlyphWithLine
  • IntersectGlyphWithLine(glyph, ((sx, sy), (ex, ey)), canHaveComponent=False, addSideBearings=False)
    Returns a list of intersections of a glyph with a given line. 
  • union(glyph, subjectContours, clipContours, roundCoordinates=None)
    perform a union with subject contours and clip contours
    glyph: destination glyph
    subjectContours, clipContours: for union its not really important so you can mix both
    roundCoordinates: optionally round the result
  • intersect(glyph, subjectContours, clipContours, roundCoordinates=None)
    perform a intersection with subject contours and clip contours
    glyph: destination glyph
    subjectContours: the subject contours
    clipContours
    : the clip contours that will intersect with the subject contours
    roundCoordinates: optionally round the result
  • difference(glyph, subjectContours, clipContours, roundCoordinates=None)
    perform a difference with subject contours and clip contours
    glyph: destination glyph
    subjectContours: the subject contours
    clipContours: the clip contours that will difference with the subject contours
    roundCoordinates: optionally round the result
  • intersection(glyph, subjectContours, clipContours, roundCoordinates=None)
    perform a intersection with subject contours and clip contours
    glyph: destination glyph
    subjectContours: the subject contours
    clipContours: the clip contours that will intersection with the subject contours
    roundCoordinates: optionally round the result
  • xor(glyph, subjectContours, clipContours, roundCoordinates=None)
    perform a xor with subject contours and clip contours
    glyph: destination glyph
    subjectContours: the subject contours
    clipContours: the clip contours that will xor with the subject contours
    roundCoordinates: optionally round the result

Classes

  • BooleanGlyph(glyph, roundCoordinates=None)
    A object that can be used to perform simple math operations and acts like a glyph object. 
    union ⇢ BooleanGlyph(glyph) | BooleanGlyph(glyph2)
    difference ⇢ BooleanGlyph(glyph) - BooleanGlyph(glyph2)
    intersection ⇢ BooleanGlyph(glyph) & BooleanGlyph(glyph2)
    xor ⇢ BooleanGlyph(glyph) ^ BooleanGlyph(glyph2)
     
    Initiate a BooleanGlyph object
    glyph: the source glyph
    roundCoordinates: optionally round the result
     
    draw(pen)
    draws the booleanGlyph in a pen
    drawPoints(pointPen)
    draws the booleanGlyph in a pointPen
    union(other)
    performs an union operation
    difference(other)
    performs a difference operation
    intersection(other)
    performs a intersection operation
    xor(other)
    performs a xor operation
     
    width
    returns the width of the booleanGlyph

mojo.roboFont

from mojo.roboFont import *

Methods

  • AllFonts()
    returns a list of all open font objects, the list as some additional methods
    getFontsByStyleName(styleName)
    returns all fonts with the given styleName
    getFontsByFamilyName(familyName)
    returns all fonts with the given familyName
    getFontsByFamilyNameStyleName(familyName, styleName)
    returns the font with the given familyName and styleName 
  • CurrentFont()
    returns the current font, will be None if no font is opened
  • CurrentGlyph()
    returns the current glyph
  • NewFont(familyName=None, styleName=None, showUI=True)
    Creates a new font with the given familyName and styleName
    optionally you can create a new font without having a UI, this is much faster to do internal actions. 
  • OpenFont(path, showUI=True)
    opens a UFO with a given path
    optionally you can create a new font without having a UI, this is much faster to do internal actions. 
  • RFont(path=None, showUI=True)
    creates a new font with the given path
    optionally you can create a new font without having a UI, this is much faster to do internal actions.  
  • RGlyph()
  • RContour()
  • RInfo()
  • RAnchor()
  • RGroups()
  • RFeatures()
  • RComponent()
  • RKerning()
  • OpenWindow(controller, *args, **kwargs)
    opens a window from the controller objects with args, and kwargs
    use this if you want RoboFont to deal with already opened versions of your window controller 
  • CreateCursor(path, hotSpot=(4, 4))
    creates a cursor object for image path with the given hotSpot 

 Attributes

  • version
    Returns the version of RoboFont 

mojo.glyphPreview

from mojo.glyphPreview import GlyphPreview

A vanilla group subclass that previews a glyph.

  • GlyphPreview(posSize, contourColor=None, componentColor=None, selectionColor=None)

    posSize: tuple of 4 (left, top, right, bottom), those numbers can be negative
    contourColor: a NSColor object used to draw the contours, optionally
    componentColor: a NSColor object used to draw the components, optionally
    selectionColor: a NSColor object used to draw the selection
     
    setGlyph(glyph)
    set a glyph in the preview
    setSelection(points)
    sets a list of points to display

Example

from vanilla import Window
from mojo.glyphPreview import GlyphPreview
from mojo.events import addObserver, removeObserver
from mojo.roboFont import OpenWindow

class Preview:

    def __init__(self):
        ## create a window
        self.w = Window((400, 400), "Preview", minSize=(100, 100))

        ## add a GlyphPreview to the window
        self.w.preview = GlyphPreview((0, 0, -0, -0))

        ## set the currentGlyph
        self.setGlyph(CurrentGlyph())

        ## add an observer when the glyph changed in the glyph view
        addObserver(self, "_currentGlyphChanged", "currentGlyphChanged")
    
        ## bind a windows close callback to this object
        self.w.bind("close", self.windowClose)
        ## open the window
        self.w.open()

    def _currentGlyphChanged(self, info):
        ## notification callback when the glyph changed in the glyph view
        ## just set the new glyph in the glyph preview
        self.setGlyph(CurrentGlyph())

    def setGlyph(self, glyph):
        ## setting the glyph in the glyph Preview
        self.w.preview.setGlyph(glyph)

    def windowClose(self, sender):
        ## remove the observer if the window closes
        removeObserver(self, "_currentGlyphChanged")


## open the window with OpenWindow, so it can not be open twice
OpenWindow(Preview)

mojo.events

from mojo.events import *

Imports useful helpers when building extensions and scripts requiring app event callbacks.

When subclassing or building tools on top of other tools you can find some embedded tools here

  • installTool(tool)
    install tool
  • uninstallTool(tool)
    uninstall tool 
  • addObserver(observer, method, event)
    Add an observer for a specified event, callbacks will be send to the method of the observer.
  • removeObserver(observer, event)
    Removes an observer for a specific event.
  • BaseEventObserver
    The base class of an observer. 
  • BaseEventTool
    The base class of an Tool 
  • EditingTool
    A subclass-able EditingTool 
  • MeasurementTool
    A subclass-able MeasurementTool 
  • SliceTool
    A subclass-able SliceTool 
  • BezierDrawingTool
    A subclass-able BezierDrawingTool 

mojo.drawingTools

from mojo.drawingTools import *

Using similar tools to draw in Cocoa object like DrawBot. (see TinyDrawBot extension)

  • save()
    save the current graphic state 
  • restore()
    restore the current graphic state 
  • rect(x, y, width, height)
    draws a rectangle 
  • oval(x, y, width, height)
    draws an oval 
  • newPath()
    creates a new path 
  • moveTo((x, y))
    move to point
  • lineTo((x, y))
    line to point
  • curveTo((h1x, h1y), (h2x, h2y), (x, y))
    curve to point with bcps
  • closePath()
    close the path
  • drawPath()
    draws the path
  • fill(r, g, b, a=1)
    Set the fill color as RGB value.
  • stroke(r, g, b, a=1)
    Set the stroke color as RGB value.
  • strokeWidth(value)
    Set the stroke width for a path.
  • miterLimit(value)
    Set the miter limit for a path.
  • lineJoin(join)
    Set the line join for a path, possible join arguments are: "bevel", "miter" or "round"
  • dashLine(dash)
    dash is a list of of values 
  • translate(x, y)
    Translate the art board pane to "x", "y" 
  • rotate(angle)
    Rotate the art board by an angle.
  • scale(x, y)
    Scale the art board by "x", "y", if "y" is not set the art board will be scaled proportionally.
  • skew(a, b)
    Skew the art board by "a", "b", if "b" is not set the art board will be skew with "a" = "b"
  • font(fontName, fontSize=None)
    Set the font by PostScript name.
    Optionally set the font size. 
  • fontSize(fontSize)
    Set the font size.
  • text(textString, (x, y))
    Draw a text on position "x", "y".
  • image(filePath, (x, y), alpha=1)
    Draw an image on position "x", "y".
    Optionally set an alpha value.