RoboFont 3.4

The scripts below demonstrate the new mojo.smartSet API.

Getting Smart Sets

from mojo.smartSet import getSmartSets

# get default sets
defaultSets = getSmartSets()
print(defaultSets)

# get font sets
f = CurrentFont()
fontSets = getSmartSets(f)
print(fontSets)

Setting Smart Sets

This will overwrite all existing Smart Sets!

from mojo.smartSet import SmartSet, setSmartSets, updateAllSmartSets

# create new smart sets
items = [
    SmartSet(smartSetName="foo", glyphNames=["a", "b"]),
    SmartSet(smartSetName="bar", query="Width < 200")
]

# set default smarts sets
setSmartSets(items)

# set font sets
f = CurrentFont()
setSmartSets(items, font=f)

# update the Smart Sets panel
updateAllSmartSets()

Adding Smart Sets

from mojo.smartSet import SmartSet, addSmartSet, updateAllSmartSets

# create new smart sets
items = [
    SmartSet(smartSetName="vowels", glyphNames=["a", "e", "i", "o", "u"]),
    SmartSet(smartSetName="empty", query="Empty == 'True'")
]

# add new sets to default sets
for item in items:
  addSmartSet(item)

# add new sets to font sets
f = CurrentFont()
for item in items:
    addSmartSet(item, font=f)

# update the Smart Sets panel
updateAllSmartSets()

Query-based Smart Sets

Queries are expressed using Apple’s Predicate Format String Syntax.

Language tokens

These are the main building blocks of the predicate language:

construct examples
literals False True 'a' 42 {'a', 'b'}
compound expressions and or not
aggregate operations any some all none in
basic comparisons = >= <= > < != between
string comparisons contains beginswith endswith like matches

The matches comparison requires a regular expression. (see the example below)

Glyph attributes and supported comparisons

These are the glyph attribute names, their data types and supported comparisons.

type attributes comparisons
str Name
ComponentsNames
AnchorNames
in contains beginswith endswith like matches
int or float Width
LeftMargin
RightMargin
Unicode
Contours
Components
Anchors
< = > != between in
str MarkColor = != contains matches
bool Empty
GlyphChanged
Template
SkipExport
True False
str Note contains

Example queries

"Name == 'a'"
"Name in {'a', 'b'}"
"Empty == 'True'"
"Name contains 'a' AND Width < 300"
"Name matches '[A-z]'"
"Width in {120, 240, 360}")
Last edited on 14/01/2020