Skip to content

Commit

Permalink
Made kernMaker.py detect which kerning context to use
Browse files Browse the repository at this point in the history
  • Loading branch information
weiweihuanghuang committed Mar 19, 2016
1 parent a91a6f2 commit eefec58
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 42 deletions.
19 changes: 10 additions & 9 deletions Metrics/Show All Kerning Pairs With.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#MenuTitle: Show All Kerning Pairs With searchString in Context
#MenuTitle: Show All Kerning Pairs With searchString
# -*- coding: utf-8 -*-
__doc__="""
Show All Kerning Pairs for this Master with searchString in a new tab in context
Show All Kerning Pairs for this Master with searchString
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter
import kernMakerFunc
reload(kernMakerFunc)
from kernMakerFunc import kernMaker

Glyphs.clearLog()
Expand All @@ -15,7 +16,7 @@
masterID = selectedMaster.id

editString = ""
searchString = u".sc"
searchString = u"colon"
kerningCount = 0

def nameMaker(kernGlyph):
Expand All @@ -28,21 +29,21 @@ def nameMaker(kernGlyph):
# print str(nameMaker(L))
try:
# if searchString is in L
if str(nameMaker(L)).endswith(searchString):
if str(nameMaker(L)) == searchString:
for R in Font.kerning[masterID][L]:
# print str(nameMaker(R))
kernPair = "/%s/%s" % (nameMaker(L), nameMaker(R))
editString += kernMaker(kernPair)
editString += kernPair + " " # kernMaker(kernPair)
kerningCount += 1
# if searchString is in R
for R in Font.kerning[masterID][L]:
if str(nameMaker(R)).endswith(searchString):
if str(nameMaker(R)) == searchString:
kernPair = "/%s/%s" % (nameMaker(L), nameMaker(R))
editString += kernMaker(kernPair)
editString += kernPair + " " # kernMaker(kernPair)
kerningCount += 1
except:
pass

callAfter( Doc.windowController().addTabWithString_, editString )
Font.newTab(editString)
# print editString
print "%s kerning pairs found" % kerningCount
3 changes: 1 addition & 2 deletions Metrics/Show All Kerning Pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Show All Kerning Pairs for this Master in a new tab
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter

Font = Glyphs.font
Doc = Glyphs.currentDocument
Expand All @@ -28,4 +27,4 @@ def nameMaker(kernGlyph):
except:
pass

callAfter( Doc.windowController().addTabWithString_, editString )
Glyphs.font.newTab(editString)
3 changes: 1 addition & 2 deletions Metrics/Show Glyphs in Kerning Groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import GlyphsApp
from PyObjCTools.AppHelper import callAfter

Doc = Glyphs.currentDocument
Font = Glyphs.font
Expand All @@ -28,4 +27,4 @@
print allLeftGlyphs
print allRightGlyphs

callAfter( Doc.windowController().addTabWithString_, allLeftGlyphs + '\n' + allRightGlyphs )
Font.newTab( allLeftGlyphs + '\n' + allRightGlyphs )
5 changes: 3 additions & 2 deletions Metrics/Show Kerning Pairs Context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Show Kerning Pairs in context for the selected glyphs in a new tab.
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter
import kernMakerFunc
reload(kernMakerFunc)
from kernMakerFunc import kernMaker

Font = Glyphs.font
Expand Down Expand Up @@ -47,4 +48,4 @@ def nameMaker(kernGlyph):
except:
pass

callAfter( Doc.windowController().addTabWithString_, editString )
Glyphs.font.newTab(editString)
3 changes: 1 addition & 2 deletions Metrics/Show Kerning Pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Show Kerning Pairs for this glyph in a new tab.
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter

Font = Glyphs.font
Doc = Glyphs.currentDocument
Expand Down Expand Up @@ -46,4 +45,4 @@ def nameMaker(kernGlyph):
except:
pass

callAfter( Doc.windowController().addTabWithString_, editString )
Font.newTab(editString)
10 changes: 5 additions & 5 deletions Metrics/Show these in Context-Space.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Show selected items, each separated by /space, in spacing context in a new tab.
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter
import kernMakerFunc
reload(kernMakerFunc)
from kernMakerFunc import kernMaker
Expand All @@ -14,28 +13,29 @@
Doc = Glyphs.currentDocument
selectedLayers = Font.selectedLayers

TextStoreage = Doc.windowController().activeEditViewController().graphicView().textStorage()
String = TextStoreage.text().string()

editString = ""

# Get the name of each selected glyph and insert a '/space\n/space' for new line character instead (/space added to slit this into it's own item)
namesOfSelectedGlyphs = ''.join([ "/%s" % l.parent.name if hasattr(l.parent, 'name') else '/space\n/space' for l in selectedLayers ])
# namesOfSelectedGlyphs = ''.join([ "/%s" % l.parent.name for l in selectedLayers if hasattr(l.parent, 'name')])

originalCharString = ''.join([ "/%s" % l.parent.name if hasattr(l.parent, 'name') else '\n' for l in selectedLayers ])

editList = namesOfSelectedGlyphs.split('/space')
# Removed blank items which were added as a result of filtering out new line characters
editList = filter(None, editList)

print editList

for eachItem in editList:
print eachItem, type(eachItem)
if eachItem == u"\n":
editString += "\n"
else:
editString += kernMaker(eachItem)
editString += "\n"

editString = "{0}\n{1}".format(String, editString)
editString = "{0}\n{1}".format(originalCharString, editString)

# print editString
# callAfter( Doc.windowController().addTabWithString_, editString )
Expand Down
7 changes: 4 additions & 3 deletions Metrics/Show this in Context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
Show selected text in spacing context in a new tab.
"""
import GlyphsApp
from PyObjCTools.AppHelper import callAfter
import kernMakerFunc
reload(kernMakerFunc)
from kernMakerFunc import kernMaker

Font = Glyphs.font
Doc = Glyphs.currentDocument
selectedLayers = Font.selectedLayers
namesOfSelectedGlyphs = [ "/%s" % l.parent.name for l in selectedLayers ]
namesOfSelectedGlyphs = [ "/%s" % l.parent.name for l in selectedLayers if hasattr(l.parent, 'name') ]

editString = "".join(namesOfSelectedGlyphs)

callAfter( Doc.windowController().addTabWithString_, kernMaker(editString) )
Glyphs.font.newTab( kernMaker(editString) )
82 changes: 65 additions & 17 deletions Metrics/kernMakerFunc.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
# -*- coding: utf-8 -*-
# The function that creates the kerning text, change the Option="lc" to any of the options or, define your own
def kernMaker(kernPair, Option="lc"):
# If small caps
if ".sc" in kernPair:
return u"""/h.sc /o.sc /h.sc {0} /h.sc /o.sc /h.sc HOH{0} /h.sc /o.sc /h.sc \n/n.sc /o.sc /n.sc {0} /h.sc /h.sc /h.sc HHH{0} /n.sc /n.sc /n.sc \n/o.sc /o.sc /o.sc {0} /o.sc /o.sc /o.sc OOO{0} /o.sc /o.sc /o.sc \n/x.sc /h.sc /x.sc {0} /x.sc /h.sc /x.sc XHX{0} /x.sc /h.sc /x.sc \n""".format(kernPair)
elif Option == "full":
return u"""HOH{0} non HOH{0} HOH non{0} npn\nHHH{0} nnn HHH{0} HHH nnn{0} nnn\nOOO{0} ooo OOO{0} OOO ooo{0} ooo\nXHX{0} xhx XHX{0} XHX xox{0} xox\n""".format(kernPair)
elif Option == "CAPS":
return u"""HOH{0} HOH\nHHH{0} HHH\nOOO{0} OOO\nXHX{0} XHX\n""".format(kernPair)
elif Option == "CAPS-sc":
return u"""HOH{0} /h.sc /o.sc /h.sc \nHHH{0} /h.sc /h.sc /h.sc \nOOO{0} /o.sc /o.sc /o.sc \nXHX{0} /x.sc /h.sc /x.sc \n""".format(kernPair)
elif Option == "CAPS-lc":
return u"""HOH{0} non\nHHH{0} nnn\nOOO{0} ooo\nXHX{0} xox\n""".format(kernPair)
elif Option == "lc":
return u"""non{0} non nnn{0} nnn ooo{0} ooo xox{0} xox\n""".format(kernPair)
elif Option == "basic":
return u"""nn{0} nono{0} oo\n""".format(kernPair)
# The function that creates the kerning text, define your own texts

if __name__ != '__main__':
from __main__ import *
import GlyphsApp

def subCat(eachGlyph, subCat):
if Glyphs.glyphInfoForName( eachGlyph ).subCategory == subCat:
return True
else:
return False

def kernMaker(kernPair, Option=None):

myGlyphs = kernPair.split('/')
# Remove blank items in myGlyphs
myGlyphs = filter(None, myGlyphs)
# print myGlyphs

# Default Fallback
# return u"""HOH{0} non HOH{0} HOH non{0} npn\nHHH{0} nnn HHH{0} HHH nnn{0} nnn\nOOO{0} ooo OOO{0} OOO ooo{0} ooo\nXHX{0} xhx XHX{0} XHX xox{0} xox""".format(kernPair)
# return u"""nn{0} nono{0} oo""".format(kernPair)
# pass

if Option == "Basic":
return u"""non{0} nonnn{0} nnoo{0} ooo""".format(kernPair) # Basic

# UC UC
elif all(subCat(eachGlyph, "Uppercase") for eachGlyph in myGlyphs):
return u"""HOH{0} HOH HHH{0} HHH OOO{0} OOO""".format(kernPair) # Basic
# return u"""HH{0} HOHOO""".format(kernPair) # Basic Alt
# return u"""HOH{0} HOH HHH{0} HHH OOO{0} OOO XHX{0} XHX""".format(kernPair) # Full

# UC lc
elif subCat(myGlyphs[0], "Uppercase") and subCat(myGlyphs[-1], "Lowercase") :
# return u"""HOH{0} non\nHHH{0} nnn\nOOO{0} ooo\nXHX{0} xox""".format(kernPair) # \n
return u"""HOH{0} non HHH{0} nnn OOO{0} ooo XHX{0} xox""".format(kernPair)

# lc UC
elif subCat(myGlyphs[0], "Lowercase") and subCat(myGlyphs[-1], "Uppercase") :
return u"""non{0} HOH\nnnn{0} HHH\nooo{0} OOO\nxhx{0} XOX""".format(kernPair)

# lc lc
elif subCat(myGlyphs[0], "Lowercase") and subCat(myGlyphs[-1], "Lowercase") :
return u"""non{0} nonnn{0} nnoo{0} ooo""".format(kernPair) # Basic
# return u"""non{0} non nnn{0} nnn ooo{0} ooo xox{0} xox""".format(kernPair) # Full
# return u"""non{0} nonnn{0} nnnooo{0} oooxox{0} xox""".format(kernPair) # Full Alt

# UC sc
elif subCat(myGlyphs[0], "Uppercase") and subCat(myGlyphs[-1], "Smallcaps") :
return u"""HOH{0} /h.sc /o.sc /h.sc \nHHH{0} /h.sc /h.sc /h.sc \nOOO{0} /o.sc /o.sc /o.sc \nXHX{0} /x.sc /h.sc /x.sc """.format(kernPair)

# sc sc
elif all(subCat(eachGlyph, "Smallcaps") for eachGlyph in myGlyphs):
return u"""/n.sc/o.sc/n.sc {0} /n.sc/o.sc/n.sc/n.sc/n.sc {0} /n.sc/n.sc/o.sc/o.sc {0} /o.sc/o.sc/o.sc""".format(kernPair)

# sc sc symmetry

# sc lc
elif subCat(myGlyphs[0], "Smallcaps") and subCat(myGlyphs[-1], "Lowercase") :
return u"""/h.sc/o.osc/h.sc {0} non\n/h.sc/h.sc/h.sc {0} nnn\n/o.sc/o.sc/o.sc {0} ooo\n/x.sc/h.sc/x.sc {0} xox""".format(kernPair)

# fallback
else:
return u"""HOH{0} non HOH{0} HOH non{0} npn\nHHH{0} nnn HHH{0} HHH nnn{0} nnn\nOOO{0} ooo OOO{0} OOO ooo{0} ooo\nXHX{0} xhx XHX{0} XHX xox{0} xox""".format(kernPair)

0 comments on commit eefec58

Please sign in to comment.