import os.path
from fontTools import ttLib
Normalized={}
Normalized['A']='1'
Normalized['a']='2'
Normalized['b']='3'
Normalized['p']='4'
Normalized['t']='5'
Normalized['T']='6'
Normalized['C']='7'
Normalized['j']='8'
Normalized['c']='9'
Normalized['H']='A'
Normalized['K']='B'
Normalized['d']='C'
Normalized['D']='D'
Normalized['Z']='E'
Normalized['r']='F'
Normalized['R']='G'
Normalized['z']='H'
Normalized['X']='I'
Normalized['s']='J'
Normalized['x']='K'
Normalized['S']='L'
Normalized['J']='M'
Normalized['v']='N'
Normalized['V']='O'
Normalized['e']='P'
Normalized['G']='Q'
Normalized['f']='R'
Normalized['q']='S'
Normalized['k']='T'
Normalized['g']='U'
Normalized['l']='V'
Normalized['m']='W'
Normalized['n']='X'
Normalized['N']='Y'
Normalized['w']='Z'
Normalized['W']='a'
Normalized['o']='b'
Normalized['h']='c'
Normalized['O']='d'
Normalized['U']='e'
Normalized['u']='f'
Normalized['i']='g'
Normalized['y']='h'
Normalized['1']='?'
Normalized['.']='?'
def getUrduText(strText):
strResult=''
for ch in strText:
strResult+= charMap[ch]
return strResult
def getNormalized(strWord):
strResult=""
count=len(strWord)
for c in strWord:
if(c in Normalized):
strResult+= Normalized[c]
else:
strResult+= '?'
return strResult
def cmpNormalized(str1, str2):
strNormalized1=getNormalized(str1)
strNormalized2=getNormalized(str2)
return cmp(strNormalized1, strNormalized2)
def sortGlyphs(adict):
keys = adict.keys()
keys.sort()
return [dict[key] for key in keys]
tt = ttLib.TTFont("mergedfont.ttf", recalcBBoxes=1)
glyphs= tt['glyf']
hmtx = tt['hmtx']
# pre-process the glyphs to delete unnecessary entries
for name in glyphs.keys():
try:
strNormalized=getNormalized(name)
except:
pass
# implement the logic to sort the glyphs in the font
keys= glyphs.keys()
keys.sort(cmpNormalized)
print "creating data for the output font"
del tt.glyphOrder[:]
i=1
for name in keys:
tt.glyphOrder.append(name)
print "saving output font"
tt.save('test.ttf')