From f6cca3a723147f4ffc6930c99d2adb9591549567 Mon Sep 17 00:00:00 2001 From: Erik van Blokland Date: Tue, 12 Dec 2023 14:03:03 +0100 Subject: [PATCH] Improve previewFont-to-spacecenter * make only a couple of glyphs, take input from a string. * use glyphNames and decomposeComponents --- Scripting examples/db_currentDesignspace_grid.py | 4 ++-- Scripting examples/db_simpleGlyphPreview.py | 16 ++++++++-------- .../rf_previewFont_to_spacecenter.py | 12 +++++++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Scripting examples/db_currentDesignspace_grid.py b/Scripting examples/db_currentDesignspace_grid.py index 564e190..1f7324c 100644 --- a/Scripting examples/db_currentDesignspace_grid.py +++ b/Scripting examples/db_currentDesignspace_grid.py @@ -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 diff --git a/Scripting examples/db_simpleGlyphPreview.py b/Scripting examples/db_simpleGlyphPreview.py index 640b684..a9f59e2 100644 --- a/Scripting examples/db_simpleGlyphPreview.py +++ b/Scripting examples/db_simpleGlyphPreview.py @@ -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) \ No newline at end of file + translate(100, 100) + scale(0.8) + drawGlyph(r) \ No newline at end of file diff --git a/Scripting examples/rf_previewFont_to_spacecenter.py b/Scripting examples/rf_previewFont_to_spacecenter.py index 34fbe7c..e4e7875 100644 --- a/Scripting examples/rf_previewFont_to_spacecenter.py +++ b/Scripting examples/rf_previewFont_to_spacecenter.py @@ -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 erik@letterror.com 12.12.2023 +proofText = "Designspace & UFOProcessor" + # have a desigspace open in DSE2 ds = CurrentDesignspace() @@ -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() @@ -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 @@ -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()