Created
August 29, 2023 17:09
-
-
Save connordavenport/fb4b8a19c970a6fb61fd8e59a7b2f6ae to your computer and use it in GitHub Desktop.
interpolates a support glyph at the current layer. Must have a {x,y,z} formatted layer name. Designspace file path is stored in your font's lib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fontTools.designspaceLib import DesignSpaceDocument, InstanceDescriptor | |
| from ufoProcessor import DesignSpaceProcessor, ufoOperator | |
| import tempfile | |
| import os | |
| import shutil | |
| from mojo.UI import GetFile | |
| f = CurrentFont() | |
| file = f.lib.get("com.connordavenport.interpolateSupport.designspaceFile") | |
| if file: | |
| sourcePath = file | |
| else: | |
| sourcePath = GetFile() | |
| f.lib["com.connordavenport.interpolateSupport.designspaceFile"] = sourcePath | |
| sourcedsp = DesignSpaceDocument.fromfile(sourcePath) | |
| # make temp dsp with no supports | |
| d = DesignSpaceDocument() | |
| for a in sourcedsp.axes: | |
| d.addAxis(a) | |
| for s in sourcedsp.sources: | |
| if not s.layerName: | |
| d.addSource(s) | |
| p = f"{tempfile.NamedTemporaryFile().name}.designspace" | |
| d.write(p) | |
| # ----------- | |
| test = False | |
| g = CurrentGlyph() | |
| gname = g.name | |
| lname = g.layer.name | |
| #check that we are in a support layer | |
| if lname[0] == "{" and lname[-1] == "}": | |
| loc = [float(l) for l in lname[1:-1].split(", ")] | |
| if len(loc) != len(d.axes): | |
| print("layer locations != designspace axes") | |
| else: | |
| loc = {a.name:loc[i] for i,a in enumerate(d.axes)} | |
| doc = ufoOperator.UFOOperator(p, useVarlib=False, debug=False) | |
| doc.loadFonts() | |
| glyph = doc.makeOneGlyph(gname, loc) | |
| if glyph is not None: | |
| dest = RGlyph() | |
| dest.fromMathGlyph(glyph) | |
| dest.name = glyph.name | |
| g.layer[gname] = dest | |
| os.remove(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment