Created
June 16, 2020 23:44
-
-
Save mathieureguer/6a7be5b61638ce0c7f5ed9140ca63a38 to your computer and use it in GitHub Desktop.
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
#menuTitle: ReMutate Support Layer | |
import ufoProcessor | |
import mojo.UI | |
import pathlib | |
# ---------------------------------------- | |
def get_sources_paths(designspace): | |
path = pathlib.Path(designspace.path) | |
root = path.parent | |
return [root / source.path for source in designspace.sources] | |
def get_support_layer_names(designspace): | |
return [source.layerName for source in designspace.sources if source.layerName] | |
def get_sources_by_support_layer_name(designspace, support_layer_name): | |
for source in designspace.sources: | |
if source.layerName == support_layer_name: | |
return source | |
# ---------------------------------------- | |
designSpacePath = mojo.UI.GetFile(message="Select your design space", fileTypes=("designspace",)) | |
f = CurrentFont() | |
g = CurrentGlyph() | |
designspace = ufoProcessor.DesignSpaceProcessor(ufoVersion=3) | |
designspace.roundGeometry = True | |
designspace.useVarlib = True | |
designspace.read(designSpacePath) | |
designspace.loadFonts() | |
designspace.findDefault() | |
# check that the design space is relevant to the current font | |
font_path = pathlib.Path(f.path) | |
sources_path = get_sources_paths(designspace) | |
assert font_path in sources_path, f"Oups, This designspace does not features the ufo {font_path.name}" | |
# check that the design space is relevant to the current layer | |
support_layer_name = g.layer.name | |
support_layers = get_support_layer_names(designspace) | |
assert g.layer.name in support_layers, f"Oups, This designspace does not features the support layer {support_layer_name}" | |
print(f"Mutating support layer {support_layer_name} for {g.name}") | |
# mute the support layer as a source, | |
# we dont want it to influence itself | |
support_source = get_sources_by_support_layer_name(designspace, support_layer_name) | |
support_source.mutedGlyphNames = f.keys() | |
glyph_mutator = designspace.getGlyphMutator(g.name) | |
mutated_glyph = glyph_mutator.makeInstance(support_source.location) | |
g.prepareUndo("ReMutate Support Layer") | |
g.clear() | |
mutated_glyph.drawPoints(g.getPointPen()) | |
g.width = mutated_glyph.width | |
g.performUndo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: anchors are not supported right now, for some reasons…