forked from PriaRavichandran/Glyphs-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create .case alternate.py
49 lines (39 loc) · 1.52 KB
/
Create .case alternate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#MenuTitle: Create .case alternate
# -*- coding: utf-8 -*-
__doc__="""
Duplicates selected glyphs but as components, giving them .case suffix and the sidebearings. Ideal for making uppercase alternate signs. Modified from Mekkablue's "Create .ssXX glyph from current layer" script.
"""
import GlyphsApp
Font = Glyphs.font
FirstMasterID = Font.masters[0].id
allGlyphNames = [ x.name for x in Font.glyphs ]
selectedLayers = Font.selectedLayers
def findSuffix( glyphName ):
nameIsFree = False
duplicateNumber = -1
while nameIsFree is False:
duplicateNumber += 1
targetSuffix = ".case.0%.2d" % duplicateNumber
targetGlyphName = glyphName + targetSuffix
if allGlyphNames.count( targetGlyphName ) == 0:
nameIsFree = True
if targetSuffix == ".case.000":
targetSuffix = ".case"
return targetSuffix
def process( sourceLayer ):
# find suffix
sourceGlyphName = sourceLayer.parent.name
targetSuffix = findSuffix( sourceGlyphName )
# append suffix, create glyph:
targetGlyphName = sourceGlyphName + targetSuffix
targetGlyph = GSGlyph( targetGlyphName )
Font.glyphs.append( targetGlyph )
# place component to all layers in the new glyph:
for thisMaster in Font.masters:
sourceComponent = GSComponent( sourceGlyphName )
targetGlyph.layers[thisMaster.id].components.append(sourceComponent)
targetGlyph.layers[thisMaster.id].setLeftMetricsKeyUI_(sourceGlyphName)
targetGlyph.layers[thisMaster.id].setRightMetricsKeyUI_(sourceGlyphName)
print "Created", targetGlyphName
for thisLayer in selectedLayers:
process( thisLayer )