Skip to content

Commit

Permalink
Improve previewFont-to-spacecenter
Browse files Browse the repository at this point in the history
* make only a couple of glyphs, take input from a string.
* use glyphNames and decomposeComponents
  • Loading branch information
LettError committed Dec 12, 2023
1 parent f051d85 commit f6cca3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Scripting examples/db_currentDesignspace_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def grid(ds, glyphName, horizontalAxis, verticalAxis, columns, rows):
return items

# parameters
glyphName = "R"
glyphName = "S"
horizontalAxis = "width"
verticalAxis = "weight"
columns =
columns = 7

rows = 9
margin = 100
Expand Down
16 changes: 8 additions & 8 deletions Scripting examples/db_simpleGlyphPreview.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#drawbot
d = CurrentDesignspace()
previewLoc = d.randomLocation()
d.setPreviewLocation(previewLoc)
print(dir(d))
if d is not None:
previewLoc = d.randomLocation()
d.setPreviewLocation(previewLoc)

loc = dict(weight=800, width=800)
r = d.makeOneGlyph("R", loc)
loc = dict(weight=800, width=800)
r = d.makeOneGlyph("R", loc)

translate(100, 100)
scale(0.8)
drawGlyph(r)
translate(100, 100)
scale(0.8)
drawGlyph(r)
12 changes: 9 additions & 3 deletions Scripting examples/rf_previewFont_to_spacecenter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from fontTools.designspaceLib import InstanceDescriptor
from mojo.UI import CurrentSpaceCenter, OpenSpaceCenter
from mojo.UI import CurrentSpaceCenter, OpenSpaceCenter, splitText

# Scripting with live designspaces
# demo [email protected] 12.12.2023

proofText = "Designspace & UFOProcessor"

# have a desigspace open in DSE2
ds = CurrentDesignspace()

Expand All @@ -23,6 +25,8 @@
# get the default font
# note we ask for the default of a specific discrete location here
defaultFont = ds.findDefaultFont(discreteLocation=discretePart)
glyphNames = splitText(proofText, defaultFont.asFontParts().getCharacterMapping())
print("glyphNames", glyphNames)

# make an "instance descriptor" object to specify what we want to see
preview = InstanceDescriptor()
Expand All @@ -32,7 +36,7 @@
# now we're asking the designspace to make a font object with these specs
# This makes the whole font. If you're just looking at a couple of characters
# there are faster ways to do that.
previewFont = ds.makeInstance(preview).asFontParts()
previewFont = ds.makeInstance(preview, glyphNames=glyphNames, decomposeComponents=True).asFontParts()

# finally, we give the resulting font to the space center.
# have a spacecenter open
Expand All @@ -41,7 +45,9 @@
sp = OpenSpaceCenter(previewFont)

sp.setFont(previewFont)
sp.setRaw(f'HHOHOO \n {defaultFont.info.styleName}')
spString = "/" + "/".join(glyphNames)
print('spString', spString)
sp.setRaw(spString)

# optionally, open the font window
#previewFont.openInterface()

0 comments on commit f6cca3a

Please sign in to comment.