Skip to content

Instantly share code, notes, and snippets.

@mekkablue
Created July 27, 2019 21:13
Show Gist options
  • Save mekkablue/e9b35c6e6ecf33c184dbdc1c575797ff to your computer and use it in GitHub Desktop.
Save mekkablue/e9b35c6e6ecf33c184dbdc1c575797ff to your computer and use it in GitHub Desktop.
smcp <-> c2sc
#MenuTitle: Make c2sc from smcp
# -*- coding: utf-8 -*-
__doc__="""
Makes component based c2sc glyphs, using the smcp glyphs as components.
Ignores selected glyphs without an .smcp ending.
"""
Font = Glyphs.font
selectedGlyphs = [ x.parent for x in Font.selectedLayers if x.parent.name[-5:] == ".smcp" ]
def smcpToC2scName( smcpname ):
"""Turns 'aacute.smcp' into 'Aacute.c2sc'."""
if smcpname[0:2] in ["ae","oe","ij"]:
glyphname = smcpname[0:2].upper() + smcpname[2:smcpname.find(".")]
else:
glyphname = smcpname[:smcpname.find(".")].title()
suffix = smcpname[smcpname.find("."):].replace("smcp", "c2sc")
return glyphname + suffix
def process( smcpGlyph ):
# Check if the c2scGlyph already exists
smcpName = smcpGlyph.name
c2scName = smcpToC2scName( smcpName )
if Font.glyphs[ c2scName ] == None:
# Create the c2scGlyph:
c2scGlyph = GSGlyph()
c2scGlyph.name = c2scName
Font.glyphs.append( c2scGlyph ) # now there must be a Font.glyphs[ c2scName ]
# Fill up c2scGlyph's layers with corresponding smcpGlyphs as components:
c2scGlyph = Font.glyphs[ c2scName ]
print "Processing %s >>> %s (%i layers):" % (smcpGlyph.name, c2scGlyph.name, len([l for l in c2scGlyph.layers]))
for m in range(len( Font.masters )):
currentMaster = Font.masters[ m ]
currentLayer = c2scGlyph.layers[ currentMaster.id ]
print " Master: %s" % currentMaster.name
smcpComponent = GSComponent( smcpName )
currentLayer.components.append( smcpComponent )
else:
print "%s already exists." % c2scName
Font.disableUpdateInterface()
for thisGlyph in selectedGlyphs:
process( thisGlyph )
Font.enableUpdateInterface()
#MenuTitle: Make smcp from c2sc
# -*- coding: utf-8 -*-
__doc__="""
Makes component based smcp glyphs, using the c2sc glyphs as components.
Ignores selected glyphs without a .c2sc ending.
"""
Font = Glyphs.font
selectedGlyphs = [ x.parent for x in Font.selectedLayers if x.parent.name[-5:] == ".smcp" ]
def c2scToSmcpName( c2scname ):
"""Turns 'Aacute.c2sc' into 'aacute.smcp'."""
glyphname = c2scname[:c2scname.find(".")].lower()
suffix = c2scname[c2scname.find("."):].replace("c2sc", "smcp")
return glyphname + suffix
def process( c2scGlyph ):
# Check if the smcpGlyph already exists
c2scName = c2scGlyph.name
smcpName = c2scToSmcpName( c2scGlyph.name )
if Font.glyphs[ smcpName ] == None:
# Create the smcpGlyph:
smcpGlyph = GSGlyph()
smcpGlyph.name = smcpName
Font.glyphs.append( smcpGlyph ) # now there must be a Font.glyphs[ smcpName ]
# Fill up smcpGlyph's layers with corresponding c2scGlyphs as components:
smcpGlyph = Font.glyphs[ c2scName ]
print "Processing %s >>> %s (%i layers):" % (c2scGlyph.name, smcpGlyph.name, len([l for l in smcpGlyph.layers]))
for m in range(len( Font.masters )):
currentMaster = Font.masters[ m ]
currentLayer = smcpGlyph.layers[ currentMaster.id ]
print " Master: %s" % currentMaster.name
c2scComponent = GSComponent( c2scName )
currentLayer.components.append( c2scComponent )
else:
print "%s already exists." % c2scName
Font.disableUpdateInterface()
for thisGlyph in selectedGlyphs:
process( thisGlyph )
Font.enableUpdateInterface()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment