Fonction OpenType pour remplacer suite de caractères par un glyphe

Unicode

formyGlyphinGlyphs.font.glyphs:
print'sub',
print" ".join(list(myGlyph.name)).replace("-","minus"),
print'by',
print'uni’+myGlyph.unicode+’;'

cela donne

scriptlatn;
sub s p a c e by uni0020;
sub p l u s by uni002B;
sub m i n u s by uni2212;
sub a r r o w u p by uni2191;

Nom du caractère

formyGlyphinGlyphs.font.glyphs:
print'sub',
print" ".join(list(myGlyph.name)).replace("-","dash"),
print'by',
printmyGlyph.name+';'

cela donne

scriptlatn;
sub s p a c e by space;
sub p l u s by plus;
sub m i n u s by minus;
sub a r r o w u p by arrowup;

Générer ligatures OTF

invisChars = ['.notdef', 'g1', 'g2', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'underscore', 'space']
print 'script latn;'
for myGlyph in Glyphs.font.glyphs:
	n = myGlyph.name
	isInvisible = 0 #boolean to check and not display characters we don't want to display
	hasUni = 0 #if glyph starts with 'uniF' then we don't display it
	for i in range(len(invisChars)):
		if n == invisChars[i]:
			isInvisible = 1
	if n.find('uniF') > -1:
		hasUni = 1
	if isInvisible != 1 and hasUni != 1: #if we dont have invisible or uni glyph, then we display
		print 'sub '+" ".join(list(n)).replace("_", "underscore")+' by '+n+';'

Générer HTML

print '<!doctype html><html class="no-js" lang="en"><head> <meta charset="utf-8"> <title>Use Design - Icons font</title> <link rel="stylesheet" href="css/udwi.css" title="" type="text/css" media="screen" charset="utf-8"> <link rel="stylesheet" href="css/preview.css" title="" type="text/css" media="screen" charset="utf-8"> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/app.js"></script></head><body> <header class="header"> <div class="wrapper"> <h1>Icons font by Use Design</h1> <button class="switch" type="button"><i class="ico ico-medium">constrast</i>&nbsp;&nbsp;&nbsp;Inverser la luminosit&eacute;</button> </div> </header> <div class="cellbox">'
invisChars = ['.notdef', 'g1', 'g2', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'underscore', 'space']
for myGlyph in Glyphs.font.glyphs:
	n = myGlyph.name
	isInvisible = 0 #boolean to check and not display characters we don't want to display
	hasUni = 0 #if glyph starts with 'uniF' then we don't display it
	for i in range(len(invisChars)):
		if n == invisChars[i]:
			isInvisible = 1
	if n.find('uniF') > -1:
		hasUni = 1
	if isInvisible != 1 and hasUni != 1: #if we dont have invisible or uni glyph, then we display
		print '<div class="cell"><i class="ico ico-large">'+n+'</i><p>'+n+'</p></div>',
print '</div></body></html>'

Générer CSS

print "@font-face{font-family:'fontIcon';src:url('../fonts/UDiconwebfont-Regular.otf');font-weight:normal;font-style:normal}[class^='ico-'],[class*=' ico-'],.ico{display:inline-block;font:normal normal normal 14px/1 'fontIcon';font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;vertical-align:middle}.ico-small{font-size:1rem}.ico-medium{font-size:1.5rem}.ico-large{font-size:2rem}"

invisChars = ['.notdef', 'g1', 'g2', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'underscore', 'space']
for myGlyph in Glyphs.font.glyphs:
	n = myGlyph.name
	isInvisible = 0 #boolean to check and not display characters we don't want to display
	hasUni = 0 #if glyph starts with 'uniF' then we don't display it
	for i in range(len(invisChars)):
		if n == invisChars[i]:
			isInvisible = 1
	if n.find('uniF') > -1:
		hasUni = 1
	if isInvisible != 1 and hasUni != 1: #if we dont have invisible or uni glyph, then we display
		print ".i-"+n+":before {content: '"+n+"'; }"