def simplepolateFonts(registerobject, font): # Ask user how many children to create, default is 5 amount = 5 s = fontforge.askString("Simple Font Interpolation", "How many children?", str(amount)) try: amount = int(s) except: fontforge.postError("Bad value", "Expected whole number") # figure out the interpolation amount floats based on how many children the user requested interpolationamount = [0.0] calcamount = amount + 1 x = 1.0 / calcamount for y in range(1, calcamount): interpolationamount.append(x * y) interpolationamount.append(1.0) # TODO: This should ask the user to choose which is source1 and source2 # get the souce fonts from the 2 currently open (check for only 2 open is in shouldWeAppear()) fonts = fontforge.fonts() source1 = fonts[0] source2 = fonts[1] # get a name for the children - font-name-generator.py supplies gibberish() so if we have that available, lets use it name = source1.familyname + " Simp" newName = fontforge.askString("Simplepolate Fonts", "Base family name?", str(name)) # create all the children for x in range(amount + 2): # TODO I thought this would work but it doesn't # newFont = source1.interpolateFonts(interpolationamount[x],source2.path) # TODO and I thought this would work because it does on its own, but if its even just repeated twice right next to each other, it doesn't work!! :( source1.interpolateFonts(interpolationamount[x], source2.path) newFontName = newName + ' ' + str(int( interpolationamount[x] * 100)).zfill(3) newFont = fontforge.activeFont() # Set PostScript Style Name (FamilyName-Style) newFont.weight = "Regular" newFont.fontname = newFontName.replace(' ', '') + '-' + newFont.weight # Set PostScript Family Name (Family Name) newFont.familyname = newFontName # Set PostScript Full Name (Family Name Style) newFont.fullname = newFontName + ' ' + font.weight # let folks know what we did message = "Simplepolated %s: %s%%/%s%% %s/%s" % ( newFont.fullname, int(100 - interpolationamount[x] * 100), int(interpolationamount[x] * 100), source1.fontname, source2.fontname) note(message)
def simplepolateFonts(registerobject, font): # Ask user how many children to create, default is 5 amount = 5 s = fontforge.askString("Simple Font Interpolation", "How many children?", str(amount)) try: amount = int(s) except: fontforge.postError("Bad value", "Expected whole number") # figure out the interpolation amount floats based on how many children the user requested interpolationamount = [0.0] calcamount = amount +1 x = 1.0 / calcamount for y in range(1, calcamount): interpolationamount.append(x*y) interpolationamount.append(1.0) # TODO: This should ask the user to choose which is source1 and source2 # get the souce fonts from the 2 currently open (check for only 2 open is in shouldWeAppear()) fonts = fontforge.fonts() source1 = fonts[0] source2 = fonts[1] # get a name for the children - font-name-generator.py supplies gibberish() so if we have that available, lets use it name = source1.familyname + " Simp" newName = fontforge.askString("Simplepolate Fonts", "Base family name?", str(name)) # create all the children for x in range(amount+2): # TODO I thought this would work but it doesn't # newFont = source1.interpolateFonts(interpolationamount[x],source2.path) # TODO and I thought this would work because it does on its own, but if its even just repeated twice right next to each other, it doesn't work!! :( source1.interpolateFonts(interpolationamount[x],source2.path) newFontName = newName + ' ' + str(int(interpolationamount[x]*100)).zfill(3) newFont = fontforge.activeFont() # Set PostScript Style Name (FamilyName-Style) newFont.weight = "Regular" newFont.fontname = newFontName.replace(' ', '') + '-' + newFont.weight # Set PostScript Family Name (Family Name) newFont.familyname = newFontName # Set PostScript Full Name (Family Name Style) newFont.fullname = newFontName + ' ' + font.weight # let folks know what we did message = "Simplepolated %s: %s%%/%s%% %s/%s" % (newFont.fullname, int(100-interpolationamount[x]*100), int(interpolationamount[x]*100), source1.fontname, source2.fontname) note(message)
def _main(): mapping_dict = glyph_data.get_mapping_dict() source_font_dict = {i: open_font(i) for i in WEIGHT_LIST_A} source_font_dict.update({i: open_font(i, copy_bold=False) for i in WEIGHT_LIST_B}) for weight, val in source_font_dict.items(): new_font = initialize_font(weight) for style in val.keys(): # FontForge's selection will ignore the selection order, so we need to find the max # ordered list to speed up. The remaining glyphs will be selected one-by-one. mapping_list = [(i, v["fira-glyph"]) for i, v in mapping_dict.items() if v["source"] == style] mapping_list.sort(key=lambda _tuple: _tuple[0]) for i in _split_list(mapping_list, lambda _tuple: _tuple[1]): mapping_keys, mapping_values = tuple(zip(*i)) source_font = val[style] source_font.selection.select(*mapping_values) source_font.copy() new_font.selection.select(*mapping_keys) new_font.paste() new_font_file_name = os.sep.join([SFD_PATH, FONT_FAMILY_NAME + "-" + weight + ".sfd"]) new_font.save(new_font_file_name) for font in fontforge.fonts(): font.close()
import unicodedata as ud import fontforge f = fontforge.fonts()[0] WIDTH = 547 f.ascent -= 300 f.descent -= 300 for g in f.glyphs("encoding"): if ud.category(chr(abs(g.unicode))) == "Mn": g.width = 0 for i in range(2, 10): try: f[g.glyphname + ".{}".format(str(i))].width = 0 except: pass else: g.width = WIDTH for i in range(2, 10): try: f[g.glyphname + ".{}".format(str(i))].width = WIDTH except: pass
# fontforge.loadEncodingFile() # fontforge.loadNamelist() # fontforge.loadNamelistDir() # fontforge.preloadCidmap() fontforge.printSetup("lpr") if (fontforge.unicodeFromName("A")!=65) or (fontforge.unicodeFromName("uni030D")!=0x30D): raise ValueError("Wrong return from unicodeFromName") foo = fontforge.version() ambrosia = sys.argv[1] fonts = fontforge.fonts() if ( len(fonts)!=0 ) : raise ValueError("Wrong return from fontforge.fonts") fontforge.activeFont() fontforge.activeGlyph() fontforge.activeLayer() fontnames= fontforge.fontsInFile(ambrosia) if len(fontnames)!=1 or fontnames[0]!='Ambrosia': raise ValueError("Wrong return from fontforge.fontsInFile") font = fontforge.open(ambrosia) morefonts = fontforge.fonts() if len(morefonts)!=1: raise ValueError("Wrong return from fontforge.fonts") instrs = fontforge.parseTTInstrs("SRP0\nMIRP[min,rnd,black]")
def shouldWeAppear(registerobject, font): fonts = fontforge.fonts() if len(fonts) == 2: return True else: return False
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # To use: import into the fontforge user interface (see http://fontforge.org/) # vertical: -184 - 1638 # horizontal: 0 (80) - 2048 (2048-80) (padlock?) import types import fontforge import psMat #print "Start of script" #f = fontforge.open("myfont.sfd") f = fontforge.fonts()[0] initials = ("", "b", "p", "m", "f", "d", "t", "n", "l", "g", "k", "h", "j", "q", "x", "zh", "ch", "sh", "r", "z", "c", "s", "y", "w") vowels = ("i", "u", "a", "o", "e", "ia", "ua", "ai", "uai", "ao", "iao", "ie", "uo", "ei", "ui", "ou", "iu", "io") tones = (("one", "hyphen", 0.5, 1), ("two", "slash", 0.33, 1), ("three", "V", 0, 0.67), ("four", "backslash", 0.33, 1)) #coda_vowels = ("a", "e", "ia", "ua", "ie", "ue") # wrong codas = ("n", "ng") full_codas = (("a", "n"), ("e", "n"), ("ia", "n"), ("ua", "n"), ("i", "n"), ("u", "n"), ("a", "ng"), ("e", "ng"), ("ia", "ng"), ("ua", "ng"), ("i", "ng"), ("o", "ng")) ucolon_initials = ("n", "l") ucolon_vowels = ("u:", "u:a", "u:e") all_initials = initials all_vowels = vowels + ucolon_vowels