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
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
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()
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
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
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)
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
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.