Created
July 13, 2015 14:21
-
-
Save lasconic/712f15ff9fddbd5edb7b to your computer and use it in GitHub Desktop.
Revisions
-
lasconic created this gist
Jul 13, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ import fontforge #Load the module import json import shutil import os source = "mscore" #source = "MScoreText" fontFile = source + ".sfd" tmpFile = source + "tmp.sfd" outFile = "out/" + source + ".ttf" with open('mscore.json') as data_file: mscoreData = json.load(data_file) with open('bravura.json') as data_file: smuflData = json.load(data_file) print "open font" shutil.copy2(fontFile, tmpFile) # open font file amb=fontforge.open(fontFile) # open tmp file ambTmp=fontforge.open(tmpFile) pastedCodePoint = [] pastedDict = {} for mscoreGlyph in mscoreData.keys(): mscoreCodePointStr = mscoreData[mscoreGlyph]["codepoint"].upper() mscoreCodePoint = int(mscoreCodePointStr.replace("U+", ""), 16) if mscoreGlyph in smuflData: smuflCodePointStr = smuflData[mscoreGlyph]["codepoint"].upper() smuflCodePoint = int(smuflCodePointStr.replace("U+", ""), 16) # delete from tmp file if not already pasted if not mscoreCodePoint in pastedCodePoint: ambTmp.selection.select(mscoreCodePoint) ambTmp.cut() # copy in original amb.selection.select(mscoreCodePoint) amb.copy() # paste in new font ambTmp.selection.select(smuflCodePoint) ambTmp.paste() pastedCodePoint.append(smuflCodePoint) pastedDict[mscoreGlyph] = smuflData[mscoreGlyph] else: print "%s not found in SMuFL" % mscoreGlyph ambTmp.generate(outFile) ambTmp.generate("out/" + source + ".otf") ambTmp.save("out/" + source + ".sfd") ambTmp.close() amb.close() os.remove(tmpFile) if (source == "mscore"): jsonGlyphs = json.dumps(pastedDict, sort_keys=True, indent=4) f = open("out/glyphnames.json","w") #opens file with name of "test.txt" f.write(jsonGlyphs) f.close()